genericservices/taskscheduler/SCHSVR/SCHLOG.CPP
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2004-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 // System includes
       
    17 #include <logwrap.h>
       
    18 
       
    19 // User includes
       
    20 #include "SCHLOG.h"
       
    21 
       
    22 
       
    23 //Constants
       
    24 const TInt KLogEventQueueGranularity = 3;
       
    25 
       
    26 CSchLogManager::CSchLogManager()
       
    27 :	CActive(EPriorityLow)
       
    28 	{
       
    29 	CActiveScheduler::Add(this);
       
    30 	}
       
    31 
       
    32 CSchLogManager::~CSchLogManager()
       
    33 	{
       
    34 	Cancel();
       
    35   	if(iPendingLogEvents)
       
    36   		{
       
    37   		iPendingLogEvents->ResetAndDestroy();
       
    38   		delete iPendingLogEvents;
       
    39   		}
       
    40 	delete iLogEvent;
       
    41 	if(iLogWrapper)
       
    42  		delete iLogWrapper;
       
    43 	}
       
    44 	
       
    45 void CSchLogManager::ConstructL(RFs& aFileSession)
       
    46 	{
       
    47 	iFileSession = &aFileSession;
       
    48 	iLogWrapper = NULL;
       
    49 	iLogEvent = CLogEvent::NewL();
       
    50 	iLogEvent->SetEventType(KLogTaskSchedulerEventTypeUid);
       
    51 	iPendingLogEvents = new(ELeave) CArrayPtrFlat<CLogEvent>(KLogEventQueueGranularity);
       
    52 	}
       
    53 
       
    54 CSchLogManager* CSchLogManager::NewL(RFs& aFileSession)
       
    55 	{
       
    56 	CSchLogManager* self = new(ELeave) CSchLogManager();
       
    57 	CleanupStack::PushL(self);
       
    58 	self->ConstructL(aFileSession);
       
    59 	CleanupStack::Pop(self);
       
    60 	return self;
       
    61 	}
       
    62 
       
    63 /*
       
    64 Creates a new log engine entry of type KLogTaskSchedulerEventTypeUid
       
    65 with aError as its entry.
       
    66 */
       
    67 void CSchLogManager::LogError(TInt aError)
       
    68 	{
       
    69 	// Add error code as a descriptor
       
    70 	TBuf<10> errorCodeAsDescriptor;
       
    71 	errorCodeAsDescriptor.Num(aError);
       
    72 	iLogEvent->SetNumber(errorCodeAsDescriptor);
       
    73 	// Add to log or queue
       
    74   	if (!IsActive())
       
    75     	{
       
    76 		iStatus=KRequestPending;
       
    77 	
       
    78 		TRAPD(error, GetLogWrapperL()->Log().AddEvent(*iLogEvent, iStatus));
       
    79 		if (error != KErrNone)
       
    80 			return; 
       
    81 		SetActive();
       
    82 		}
       
    83 	else
       
    84 		{
       
    85 		// add the request to the queue, it will be processed asap
       
    86 		CLogEvent* event = 0;
       
    87 		TRAPD(error, event = CLogEvent::NewL());
       
    88 		if (KErrNone != error)
       
    89 			{
       
    90 			return; // event is discarded!
       
    91 			}
       
    92 		//coverity[cleanup_stack]
       
    93 		/* NewL() and AppendL() are enclosed in TRAP and handled. 
       
    94 		* So no need of pushing the variable event onto the cleanup stack
       
    95 		*/
       
    96 		// add to the queue
       
    97 		TRAP(error, iPendingLogEvents->AppendL(event));
       
    98 		if (KErrNone != error)
       
    99 			{
       
   100 			delete event; // event is discarded!
       
   101 			return;
       
   102 			}
       
   103 		}	
       
   104 	}
       
   105 
       
   106 /*
       
   107 Creates a new log engine entry of type KLogTaskSchedulerEventTypeUid 
       
   108 and subject aSubject with aError as its entry.
       
   109 */
       
   110 void CSchLogManager::LogError(const TDesC& aSubject, TInt aError)
       
   111 	{
       
   112 	//AddSubject
       
   113 	iLogEvent->SetSubject(aSubject);
       
   114 	LogError(aError);
       
   115 	}
       
   116 	
       
   117 void CSchLogManager::RunL()
       
   118   	{
       
   119     if (iPendingLogEvents->Count()>0)
       
   120         {
       
   121         CLogEvent* nextEventPtr = iPendingLogEvents->At(0);
       
   122         iLogEvent->CopyL(*nextEventPtr);
       
   123 		iStatus=KRequestPending;
       
   124 		
       
   125 		//If error occur trap it and ignore, so that log manager can continue 
       
   126         TRAPD(error, GetLogWrapperL()->Log().AddEvent(*iLogEvent, iStatus));
       
   127        	//Following code is only to ignore build warnings        
       
   128         if (error == KErrNone)
       
   129 				error = KErrNone;
       
   130         SetActive();
       
   131         // delete the ongoing CLogEvent we just copied
       
   132         delete nextEventPtr;
       
   133         //remove the pointer from the queue
       
   134         iPendingLogEvents->Delete(0);
       
   135         }
       
   136   	}
       
   137   
       
   138 void CSchLogManager::DoCancel()
       
   139   	{
       
   140     if(iLogWrapper)
       
   141         iLogWrapper->Log().Cancel();
       
   142    	}
       
   143 /*
       
   144 Creates a new CLogWrapper and initialise iLogWrapper if it doesn't exist otherwise 
       
   145 return iLogWrapper
       
   146 */
       
   147 CLogWrapper* CSchLogManager::GetLogWrapperL()
       
   148 	{
       
   149 	if(iLogWrapper)
       
   150 		return iLogWrapper;
       
   151 	
       
   152 	iLogWrapper = CLogWrapper::NewL(*iFileSession, CActive::EPriorityStandard);
       
   153 
       
   154 	return iLogWrapper;
       
   155 	}
       
   156 
       
   157