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.
 
    18 #include <barsc2.h> // For CResourceFile
 
    19 #include <barsread2.h> // For RResourceReader
 
    24 #include "logservcli.h"
 
    25 #include "LogServShared.h"
 
    26 #include "logpackage.h"
 
    27 #include "logclipanic.h"
 
    28 #include "logclientop.h"
 
    29 #include "LogClientObserver.h"
 
    31 //**********************************
 
    33 //**********************************
 
    37 maximum age of events to zero
 
    39 maximum number of events to appear in the log to zero
 
    41 maximum number of events to appear in a recent event list to zero */
 
    42 EXPORT_C TLogConfig::TLogConfig()
 
    43 : iMaxLogSize(0), iMaxRecentLogSize(0), iMaxEventAge(0)
 
    47 void TLogConfig::InternalizeL(RReadStream& aStream)
 
    49 	aStream >> iMaxLogSize;
 
    50 	aStream >> iMaxRecentLogSize;
 
    51 	aStream >> iMaxEventAge;
 
    54 void TLogConfig::ExternalizeL(RWriteStream& aStream) const
 
    56 	aStream << iMaxLogSize;
 
    57 	aStream << iMaxRecentLogSize;
 
    58 	aStream << iMaxEventAge;
 
    61 //**********************************
 
    63 //**********************************
 
    65 EXPORT_C CLogClient* CLogClient::NewL(RFs& aFs, TInt aPriority/* = CActive::EPriorityStandard*/)
 
    67 	CLogClient* self = new(ELeave)CLogClient(aFs, aPriority);
 
    68 	CleanupStack::PushL(self);
 
    70 	CleanupStack::Pop(); // self
 
    74 void CLogClient::ConstructL()
 
    79 	iSession = new(ELeave)RLogSession;
 
    80 	User::LeaveIfError(iSession->Connect());
 
    81 	iPackage = CLogPackage::NewL();
 
    83 	iAddEvent = new(ELeave)CLogAddEventClientOp(*iSession, *iPackage, Priority());
 
    84 	iChangeEvent = new(ELeave)CLogChangeEventClientOp(*iSession, *iPackage, Priority());
 
    85 	iGetEvent = new(ELeave)CLogGetEventClientOp(*iSession, *iPackage, Priority());
 
    86 	iDeleteEvent = new(ELeave)CLogDeleteEventClientOp(*iSession, *iPackage, Priority());
 
    87 	iAddType = new(ELeave)CLogAddTypeClientOp(*iSession, *iPackage, Priority());
 
    88 	iChangeType = new(ELeave)CLogChangeTypeClientOp(*iSession, *iPackage, Priority());
 
    89 	iGetType = new(ELeave)CLogGetTypeClientOp(*iSession, *iPackage, Priority());
 
    90 	iDeleteType = new(ELeave)CLogDeleteTypeClientOp(*iSession, *iPackage, Priority());
 
    91 	iGetConfig = new(ELeave)CLogGetConfigClientOp(*iSession, *iPackage, Priority());
 
    92 	iChangeConfig = new(ELeave)CLogChangeConfigClientOp(*iSession, *iPackage, Priority());
 
    93 	iClearLog = new(ELeave)CLogClearLogClientOp(*iSession, *iPackage, Priority());
 
    94 	iClearRecent = new(ELeave)CLogClearRecentClientOp(*iSession, *iPackage, Priority());
 
    97 /** Frees all resources owned by the Log Engine object prior to its destruction. 
 
    98 In particular, any outstanding asynchronous request is cancelled, the database, 
 
    99 the database session and the resource file are all closed. */
 
   100 EXPORT_C CLogClient::~CLogClient()
 
   104 	delete iChangeObserver;
 
   105 	if (iSession && iSession->Handle())
 
   107 		// Complete change notification
 
   108 		NotifyChangeCancel();
 
   123 	delete iChangeConfig;
 
   128 CLogClient::CLogClient(RFs& aFs, TInt aPriority)
 
   129 : CLogBase(aPriority), iFs(aFs)
 
   133 /** Adds an event to the log database. This is an asynchronous request.
 
   135 There must be no asynchronous request outstanding when this function is called, 
 
   136 otherwise the function raises a LogCli 0 panic.
 
   138 @param aEvent A log event detail object containing the attributes of the event 
 
   139 to be added. The Log Engine sets the unique event ID, the UTC time and the event 
 
   140 description, replacing any supplied values. The caller must ensure that this 
 
   141 object remains in existence and valid until the request is complete.
 
   142 @param aStatus The request status. On request completion,contains: KErrNone, 
 
   143 if the event has been successfully added to the log database; KErrNotFound, 
 
   144 if the event type is not registered with the Log Engine; KErrNotSupported, 
 
   145 if the logging of events of this type has been disabled; otherwise, one of 
 
   146 the other system wide error codes.
 
   147 @capability Note For built-in event types, the required capability level is defined in
 
   148 the event type's write access policy.
 
   149 @see CLogEventType::SetLoggingEnabled() */
 
   150 EXPORT_C void CLogClient::AddEvent(CLogEvent& aEvent, TRequestStatus& aStatus)
 
   153 	iAddEvent->Start(aEvent, iStatus);
 
   157 /** Changes the details of an existing event. This is an asynchronous request.
 
   159 There must be no asynchronous request outstanding when this function is called, 
 
   160 otherwise the function raises a LogCli 0 panic.
 
   162 Note that it is not possible to change the event type using this function.
 
   164 @param aEvent The event detail object containing the attributes of the event 
 
   165 to be changed. Before calling the function, this object must contain the appropriate 
 
   166 unique event ID; if no unique event ID is set, the function raises a LogCli 
 
   167 13 panic. The caller must ensure that this object remains in existence and 
 
   168 valid until the request is complete.
 
   169 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   170 if successful; otherwise, one of the other system wide error codes.
 
   171 @capability Note For built-in event types, the required capability level is defined in
 
   172 the event type's write access policy.
 
   174 EXPORT_C void CLogClient::ChangeEvent(const CLogEvent& aEvent, TRequestStatus& aStatus)
 
   177 	iChangeEvent->Start(aEvent, iStatus);
 
   181 /** Gets the details of the specified event. This is an asynchronous request.
 
   183 There must be no asynchronous request outstanding when this function is called, 
 
   184 otherwise the function raises a LogCli 0 panic.
 
   186 @param aEvent A reference to a log event detail object. Before calling the 
 
   187 function, this object must contain the appropriate unique event ID; if no 
 
   188 unique event ID is set, the function raises a LogServ 50 panic. The caller 
 
   189 must ensure that this object remains in existence and valid until the request 
 
   190 is complete. On successful completion of the request, it contains the appropriate 
 
   192 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   193 if successful; otherwise, one of the other system wide error codes.
 
   194 @capability Note For built-in event types, the required capability level is defined in
 
   195 the event type's read access policy.
 
   197 EXPORT_C void CLogClient::GetEvent(CLogEvent& aEvent, TRequestStatus& aStatus)
 
   200 	iGetEvent->Start(aEvent, iStatus);
 
   204 /** Deletes the event with the specified unique event ID, from the main event log.
 
   206 @param aId The unique event ID of the event to be deleted. This must not be 
 
   207 the null unique event ID, KLogNullId, otherwise the function raises a LogCli 
 
   209 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   210 if successful; otherwise, one of the other system wide error codes. 
 
   211 @capability Note For built-in event types, the required capability level is defined in
 
   212 the event type's write access policy.
 
   214 EXPORT_C void CLogClient::DeleteEvent(TLogId aId, TRequestStatus& aStatus)
 
   217 	iDeleteEvent->Start(aId, iStatus);
 
   221 /** Registers a new event type. This is an asynchronous request.
 
   223 There must be no asynchronous request outstanding when this function is called, 
 
   224 otherwise the function raises a LogCli 0 panic.
 
   226 @param aType The event type detail object containing the attributes of the 
 
   227 event type to be registered. The caller must ensure that this object remains 
 
   228 in existence and valid until the request is complete.
 
   229 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   230 if successful; otherwise, one of the other system wide error codes.
 
   231 @capability WriteDeviceData
 
   233 EXPORT_C void CLogClient::AddEventType(const CLogEventType& aType, TRequestStatus& aStatus)
 
   236 	iAddType->Start(aType, iStatus);
 
   240 /** Gets the details of an event type. This is an asynchronous request.
 
   242 There must be no asynchronous request outstanding when this function is called, 
 
   243 otherwise the function raises a LogCli 0 panic.
 
   245 @param aType A reference to an event type detail object. Before calling the 
 
   246 function, this object must contain the UID identifying the event type; if 
 
   247 no UID is set, the function raises a LogCli 13 panic. The caller must ensure 
 
   248 that this object remains in existence and valid until the request is complete. 
 
   249 On successful completion of the request, it contains the appropriate event 
 
   251 @param aStatus The request status. On request completion, contains: KErrNone, 
 
   252 if successful; otherwise one of the other system wide error codes.
 
   253 @capability Note None required.
 
   255 EXPORT_C void CLogClient::GetEventType(CLogEventType& aType, TRequestStatus& aStatus)
 
   258 	iGetType->Start(aType, iStatus);
 
   262 /** Changes the details of an existing event type. This is an asynchronous request.
 
   264 There must be no asynchronous request outstanding when this function is called, 
 
   265 otherwise the function raises a LogCli 0 panic.
 
   267 @param aType The event type detail object containing the attributes of the 
 
   268 event type to be changed. Before calling the function, this object must contain 
 
   269 the UID identifying the event type; if no UID is set, the function raises 
 
   270 a LogCli 13 panic. The caller must ensure that this object remains in existence 
 
   271 and valid until the request is complete.
 
   272 @param aStatus The request status. On request completion, contains: KErrNone, 
 
   273 if successful; otherwise, one of the other system wide error codes.
 
   274 @capability WriteDeviceData
 
   276 EXPORT_C void CLogClient::ChangeEventType(const CLogEventType& aType, TRequestStatus& aStatus)
 
   279 	iChangeType->Start(aType, iStatus);
 
   283 /** Removes an existing event type. This is an asynchronous request.
 
   285 There must be no asynchronous request outstanding when this function is called, 
 
   286 otherwise the function raises a LogCli 0 panic.
 
   288 Note that this function does not remove events from the event log, so it is 
 
   289 possible to have events in the log that are of an unknown type. This function 
 
   290 allows an event type associated with a component to be removed when that component 
 
   293 @param aId The UID of the event type to be deleted.
 
   294 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   295 if successful; otherwise, one of the other system wide error codes. 
 
   296 @capability WriteDeviceData
 
   298 EXPORT_C void CLogClient::DeleteEventType(TUid aId, TRequestStatus& aStatus)
 
   301 	iDeleteType->Start(aId, iStatus);
 
   305 /** Gets the Log Engine configuration. This is an asynchronous request.
 
   307 There must be no asynchronous request outstanding when this function is called, 
 
   308 otherwise the function raises a LogCli 0 panic.
 
   310 @param aConfig A reference to a Log Engine configuration object. The caller 
 
   311 must ensure that this object remains in existence and valid until the request 
 
   312 is complete. On successful completion of the request, it contains the Log 
 
   313 Engine configuration data.
 
   314 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   315 if successful; otherwise, one of the other system wide error codes. 
 
   316 @capability Note None required.
 
   318 EXPORT_C void CLogClient::GetConfig(TLogConfig& aConfig, TRequestStatus& aStatus)
 
   321 	iGetConfig->Start(aConfig, iStatus);
 
   325 /** Changes the Log Engine configuration. This is an asynchronous request.
 
   327 There must be no asynchronous request outstanding when this function is called, 
 
   328 otherwise the function raises a LogCli 0 panic.
 
   330 @param aConfig The new configuration values for the Log Engine.
 
   331 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   332 if successful; otherwise, one of the other system wide error codes. 
 
   333 @capability WriteDeviceData */
 
   334 EXPORT_C void CLogClient::ChangeConfig(const TLogConfig& aConfig, TRequestStatus& aStatus)
 
   337 	iChangeConfig->Start(aConfig, iStatus);
 
   341 /** Clears all events from the main event log that occurred before the specified 
 
   342 date and time. This is an asynchronous request.
 
   344 There must be no asynchronous request outstanding when this function is called, 
 
   345 otherwise the function raises a LogCli 0 panic.
 
   347 @param aDate The UTC date and time.
 
   348 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   349 if successful; otherwise, one of the other system wide error codes. 
 
   350 @capability WriteDeviceData  */
 
   351 EXPORT_C void CLogClient::ClearLog(const TTime& aDate, TRequestStatus& aStatus)
 
   354 	iClearLog->Start(aDate, iStatus);
 
   358 /** Clears the specified recent event list. This is an asynchronous request.
 
   360 There must be no asynchronous request outstanding when this function is called, 
 
   361 otherwise the function raises a LogCli 0 panic.
 
   363 @param aRecentList Identifies the recent event list to be cleared. The value 
 
   364 KlogNullRecentList indicates that all recent event lists are to be cleared.
 
   365 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   366 if successful; otherwise, one of the other system wide error codes. 
 
   367 @capability WriteDeviceData  */
 
   368 EXPORT_C void CLogClient::ClearLog(TInt aRecentList, TRequestStatus& aStatus)
 
   371 	iClearRecent->Start((TLogRecentList)aRecentList, iStatus);
 
   375 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
 
   378 Clears all events from the main event log that occurred before the specified 
 
   379 date and time and logged with the supplied SIM short Id. This is an asynchronous request.
 
   381 There must be no asynchronous request outstanding when this function is called, 
 
   382 otherwise the function raises a LogCli 0 panic.
 
   384 Note: If KLogNullSimId is passed as value of aSimId parameter, then the method will produce the same result as the
 
   385            ClearLog() method without SimId parameter - all events occured before  the specified data will be deleted,
 
   386 	disregarding the SimId event property.
 
   388 @param aDate   The UTC date and time.
 
   389 @param aSimId  SIM card short Id.
 
   390 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   391                if successful; otherwise, one of the other system wide error codes. 
 
   392 @capability WriteDeviceData  
 
   394 EXPORT_C void CLogClient::ClearLog(const TTime& aDate, TSimId aSimId, TRequestStatus& aStatus)
 
   395 	{//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is defined
 
   397 	iClearLog->Start(aDate, iStatus, aSimId);
 
   402 Clears the specified recent event list from events with the specified SIM short Id. 
 
   403 This is an asynchronous request.
 
   405 There must be no asynchronous request outstanding when this function is called, 
 
   406 otherwise the function raises a LogCli 0 panic.
 
   408 Note: If KLogNullSimId is passed as value of aSimId parameter, then the method will produce the same result as the
 
   409            ClearLog() method without SimId parameter - all events from the specified event list will be cleared,
 
   410 	disregarding the SimId event property.
 
   412 @param aRecentList Identifies the recent event list to be cleared. The value 
 
   413                    KlogNullRecentList indicates that all recent event lists are to be cleared.
 
   414 @param aSimId      SIM card short Id.
 
   415 @param aStatus     The request status. On request completion, contains:KErrNone, 
 
   416                    if successful; otherwise, one of the other system wide error codes. 
 
   417 @capability WriteDeviceData  
 
   419 EXPORT_C void CLogClient::ClearLog(TInt aRecentList, TSimId aSimId, TRequestStatus& aStatus)
 
   420 	{//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is defined
 
   422 	iClearRecent->Start((TLogRecentList)aRecentList, iStatus, aSimId);
 
   426 #else //SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
 
   428 #pragma BullseyeCoverage off
 
   433 EXPORT_C void CLogClient::ClearLog(const TTime&, TSimId, TRequestStatus&)
 
   434 	{//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is not defined
 
   435 	__ASSERT_ALWAYS(0, ::Panic(ELogDualSimNotSupported));
 
   441 EXPORT_C void CLogClient::ClearLog(TInt, TSimId, TRequestStatus&)
 
   442 	{//Compiled when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM is not defined
 
   443 	__ASSERT_ALWAYS(0, ::Panic(ELogDualSimNotSupported));
 
   446 #pragma BullseyeCoverage on
 
   448 #endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM
 
   450 /** Requests notification of changes to the Log Engine database. This is an asynchronous 
 
   453 The function requires the caller to specify a minimum time that must elapse 
 
   454 before this notification request can complete. The Log Engine buffers all 
 
   455 changes that occur during this time; the request, then completes after this 
 
   456 minimum time period has elapsed. If no changes occur within this time period, 
 
   457 then the request completes when the next change to the database occurs.
 
   459 There must be no asynchronous request outstanding when this function is called, 
 
   460 otherwise the function raises a LogCli 0 panic.
 
   462 Note that once a notification request has completed, this function must be 
 
   463 called again to get further change notifications.
 
   465 @param aDelay The minimum time, in microseconds, that elapses before the notification 
 
   466 request can complete.
 
   467 @param aStatus The request status. On request completion, contains:KErrNone, 
 
   468 if successful;KErrCancel, if an outstanding notification request is cancelled; 
 
   469 otherwise, one of the other system wide error codes. 
 
   470 @capability Note None required.
 
   472 EXPORT_C void CLogClient::NotifyChange(TTimeIntervalMicroSeconds32 aDelay, TRequestStatus& aStatus)
 
   474 	aStatus = KRequestPending;
 
   476 	iSession->Send(ELogNotify, TIpcArgs(aDelay.Int()), aStatus);
 
   479 /** Cancels any outstanding notification request for changes to Log Engine database.
 
   481 This function can be called even if there is no outstanding notification request. 
 
   482 @capability Note None required  */
 
   483 EXPORT_C void CLogClient::NotifyChangeCancel()
 
   485 	iSession->Send(ELogNotifyCancel, TIpcArgs());
 
   489 @capability Note None required
 
   491 EXPORT_C void CLogClient::SetGlobalChangeObserverL(MLogClientChangeObserver* aObserver)
 
   493 	delete iChangeObserver;
 
   494 	iChangeObserver = NULL;
 
   498 		iChangeObserver = CLogClientObserver::NewL(*this, *aObserver, Priority());
 
   502 /** Gets a standard string from the specified resource in logwrap.dll resource 
 
   505 The function can be used to populate some of the event fields in a CLogEvent 
 
   506 object before creating or changing an event.
 
   508 Note that TLogString is a modifiable buffer descriptor that is guaranteed 
 
   509 to be large enough to contain all standard strings used in the Log Engine; 
 
   510 pass an instance of this type to this function.
 
   512 @param aString A modifiable descriptor into which the string is copied.
 
   513 @param aId The resource id.
 
   514 @return KErrNone, if successful; otherwise, one of the other system wide error 
 
   516 @capability Note None required.
 
   518 EXPORT_C TInt CLogClient::GetString(TDes& aString, TInt aId) const
 
   521 	TRAPD(err, DoGetStringL(aString, aId));
 
   525 void CLogClient::DoGetStringL(TDes& aString, TInt aId) const
 
   527 	RResourceReader reader;
 
   529 	const CResourceFile* rcFile = ResourceFile();
 
   530 	__ASSERT_DEBUG(rcFile != NULL, Panic(ELogNullRcFile));
 
   532 	reader.OpenLC(ResourceFile(), aId);
 
   533 	aString.Copy(reader.ReadTPtrCL());
 
   534 	CleanupStack::PopAndDestroy();			// reader
 
   537 void CLogClient::DoCancel()
 
   539 	LOGTEXT("CLogClient::DoCancel()");
 
   542 	iChangeEvent->Cancel();
 
   544 	iDeleteEvent->Cancel();
 
   546 	iChangeType->Cancel();
 
   548 	iDeleteType->Cancel();
 
   549 	iGetConfig->Cancel(); 
 
   550 	iChangeConfig->Cancel();
 
   552 	iClearRecent->Cancel();
 
   554 	CLogBase::DoCancel();
 
   555 	LOGTEXT("CLogClient::DoCancel() - end");
 
   558 void CLogClient::DoRunL()
 
   560 	LOGTEXT2("CLogClient::DoRunL(%d)", iStatus.Int());
 
   561 	User::LeaveIfError(iStatus.Int());
 
   562 	LOGTEXT("CLogClient::DoRunL() - end");
 
   565 RLogSession& CLogClient::Session() const
 
   570 #pragma BullseyeCoverage off
 
   572 EXPORT_C void CLogClient::CLogBase_Reserved1()
 
   576 #pragma BullseyeCoverage on