Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "logservcli.h"
23 #include "LogServShared.h"
25 static TInt StartServer()
27 // Start the server process/thread which lives in an EPOCEXE object
30 const TUidType serverUid(KNullUid,KNullUid,KServerUid3);
33 // EPOC is easy, we just create a new server process. Simultaneous launching
34 // of two such processes should be detected when the second one attempts to
35 // create the server object, failing with KErrAlreadyExists.
38 TInt r=server.Create(KLogServerName,KNullDesC,serverUid);
40 server.SetPriority(EPriorityForeground);
46 server.Rendezvous(stat);
47 if (stat!=KRequestPending)
48 server.Kill(0); // abort startup
50 server.Resume(); // logon OK - start the server
51 User::WaitForRequest(stat); // wait for start or death
52 // we can't use the 'exit reason' if the server panicked as this
53 // is the panic 'reason' and may be '0' which cannot be distinguished
55 r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
61 // Initialise the operation and view ids
62 RLogSession::RLogSession()
63 : iOperationId(KLogNullOperationId + 1), iViewId(KLogNullViewId + 1)
67 TInt RLogSession::Connect()
69 // Connect to the server, attempting to start it if necessary
75 TInt r=CreateSession(KLogServerFullName,TVersion(0,0,0));
76 if (r!=KErrNotFound && r!=KErrServerTerminated)
81 if (r!=KErrNone && r!=KErrAlreadyExists)
87 void RLogSession::Send(TInt aType, const TIpcArgs& aArgs, TRequestStatus& aStatus) const
89 SendWithRetryAsync(aType, aArgs, aStatus);
92 TInt RLogSession::Send(TInt aType, const TIpcArgs& aArgs) const
94 return SendWithRetry(aType, aArgs);
97 TInt RLogSession::SendWithRetry(TInt aType, const TIpcArgs& aParam) const
99 TInt ret = SendReceive(aType, aParam);
102 if(ret == KErrServerTerminated || ret == KErrNotFound)
105 const_cast<RLogSession&>(*this).Close();
106 ret = const_cast<RLogSession&>(*this).Connect();
110 ret = SendReceive(aType, aParam);
118 void RLogSession::SendWithRetryAsync(TInt aType, const TIpcArgs& aParam, TRequestStatus& aStatus) const
120 SendReceive(aType, aParam, aStatus);
133 #ifdef LOGGING_ENABLED
135 const TInt KLogEngLogBufferSize = 256;
139 _LIT(KNewLogText, "===== NEW LOG =====");
142 TInt ret=logger.Connect();
145 logger.CreateLog(KLogFolder, KLogFileName, EFileLoggingModeOverwrite);
146 logger.Write(KNewLogText);
151 void Log::Write(const TDesC& aText)
156 TInt ret=logger.Connect();
159 logger.SetDateAndTime(EFalse,EFalse);
160 logger.CreateLog(KLogFolder, KLogFileName,EFileLoggingModeAppend);
161 TBuf<KLogEngLogBufferSize> buf;
163 // The debug log uses hometime rather than UTC for its timestamps. This is
164 // purely a debugging aid.
169 dateTime = now.DateTime();
170 buf.Format(KTimeFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond());
171 buf.AppendFormat(KTextFormat,&aText);
179 void Log::WriteFormat(TRefByValue<const TDesC> aFmt,...)
186 TBuf<2*KLogEngLogBufferSize> buf;
190 // The debug log uses hometime rather than UTC for its timestamps. This is
191 // purely a debugging aid.
196 dateTime = now.DateTime();
197 buf.Format(KTimeFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond());
198 buf.AppendFormatList(aFmt, list );
201 TInt ret=logger.Connect();
204 logger.SetDateAndTime(EFalse,EFalse);
205 logger.CreateLog(KLogFolder, KLogFileName,EFileLoggingModeAppend);
212 void Log::PruneLogFile()
214 const TInt KMaxLogSize = 1024 * 500;
216 _LIT(KBaseFolder, "_:\\Logs\\");
217 TFileName fileName(KBaseFolder);
218 fileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
219 fileName.Append(KLogFolder);
220 fileName.Append(KPathDelimiter);
221 fileName.Append(KLogFileName);
224 if (fsSession.Connect() == KErrNone)
227 if (fsSession.Entry(fileName, entry) == KErrNone)
229 // Check size and delete if its too big
230 if (entry.iSize >= KMaxLogSize)
232 TInt fileDeleteErr=fsSession.Delete(fileName);
234 // If a debug build - record error
236 if (fileDeleteErr != KErrNone)
238 RDebug::Print(_L("Log::PruneLogFile - Failed to delete file. Error = %d"), fileDeleteErr);