1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/SCHSVR/SCHLOG.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,157 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +// System includes
1.20 +#include <logwrap.h>
1.21 +
1.22 +// User includes
1.23 +#include "SCHLOG.h"
1.24 +
1.25 +
1.26 +//Constants
1.27 +const TInt KLogEventQueueGranularity = 3;
1.28 +
1.29 +CSchLogManager::CSchLogManager()
1.30 +: CActive(EPriorityLow)
1.31 + {
1.32 + CActiveScheduler::Add(this);
1.33 + }
1.34 +
1.35 +CSchLogManager::~CSchLogManager()
1.36 + {
1.37 + Cancel();
1.38 + if(iPendingLogEvents)
1.39 + {
1.40 + iPendingLogEvents->ResetAndDestroy();
1.41 + delete iPendingLogEvents;
1.42 + }
1.43 + delete iLogEvent;
1.44 + if(iLogWrapper)
1.45 + delete iLogWrapper;
1.46 + }
1.47 +
1.48 +void CSchLogManager::ConstructL(RFs& aFileSession)
1.49 + {
1.50 + iFileSession = &aFileSession;
1.51 + iLogWrapper = NULL;
1.52 + iLogEvent = CLogEvent::NewL();
1.53 + iLogEvent->SetEventType(KLogTaskSchedulerEventTypeUid);
1.54 + iPendingLogEvents = new(ELeave) CArrayPtrFlat<CLogEvent>(KLogEventQueueGranularity);
1.55 + }
1.56 +
1.57 +CSchLogManager* CSchLogManager::NewL(RFs& aFileSession)
1.58 + {
1.59 + CSchLogManager* self = new(ELeave) CSchLogManager();
1.60 + CleanupStack::PushL(self);
1.61 + self->ConstructL(aFileSession);
1.62 + CleanupStack::Pop(self);
1.63 + return self;
1.64 + }
1.65 +
1.66 +/*
1.67 +Creates a new log engine entry of type KLogTaskSchedulerEventTypeUid
1.68 +with aError as its entry.
1.69 +*/
1.70 +void CSchLogManager::LogError(TInt aError)
1.71 + {
1.72 + // Add error code as a descriptor
1.73 + TBuf<10> errorCodeAsDescriptor;
1.74 + errorCodeAsDescriptor.Num(aError);
1.75 + iLogEvent->SetNumber(errorCodeAsDescriptor);
1.76 + // Add to log or queue
1.77 + if (!IsActive())
1.78 + {
1.79 + iStatus=KRequestPending;
1.80 +
1.81 + TRAPD(error, GetLogWrapperL()->Log().AddEvent(*iLogEvent, iStatus));
1.82 + if (error != KErrNone)
1.83 + return;
1.84 + SetActive();
1.85 + }
1.86 + else
1.87 + {
1.88 + // add the request to the queue, it will be processed asap
1.89 + CLogEvent* event = 0;
1.90 + TRAPD(error, event = CLogEvent::NewL());
1.91 + if (KErrNone != error)
1.92 + {
1.93 + return; // event is discarded!
1.94 + }
1.95 + //coverity[cleanup_stack]
1.96 + /* NewL() and AppendL() are enclosed in TRAP and handled.
1.97 + * So no need of pushing the variable event onto the cleanup stack
1.98 + */
1.99 + // add to the queue
1.100 + TRAP(error, iPendingLogEvents->AppendL(event));
1.101 + if (KErrNone != error)
1.102 + {
1.103 + delete event; // event is discarded!
1.104 + return;
1.105 + }
1.106 + }
1.107 + }
1.108 +
1.109 +/*
1.110 +Creates a new log engine entry of type KLogTaskSchedulerEventTypeUid
1.111 +and subject aSubject with aError as its entry.
1.112 +*/
1.113 +void CSchLogManager::LogError(const TDesC& aSubject, TInt aError)
1.114 + {
1.115 + //AddSubject
1.116 + iLogEvent->SetSubject(aSubject);
1.117 + LogError(aError);
1.118 + }
1.119 +
1.120 +void CSchLogManager::RunL()
1.121 + {
1.122 + if (iPendingLogEvents->Count()>0)
1.123 + {
1.124 + CLogEvent* nextEventPtr = iPendingLogEvents->At(0);
1.125 + iLogEvent->CopyL(*nextEventPtr);
1.126 + iStatus=KRequestPending;
1.127 +
1.128 + //If error occur trap it and ignore, so that log manager can continue
1.129 + TRAPD(error, GetLogWrapperL()->Log().AddEvent(*iLogEvent, iStatus));
1.130 + //Following code is only to ignore build warnings
1.131 + if (error == KErrNone)
1.132 + error = KErrNone;
1.133 + SetActive();
1.134 + // delete the ongoing CLogEvent we just copied
1.135 + delete nextEventPtr;
1.136 + //remove the pointer from the queue
1.137 + iPendingLogEvents->Delete(0);
1.138 + }
1.139 + }
1.140 +
1.141 +void CSchLogManager::DoCancel()
1.142 + {
1.143 + if(iLogWrapper)
1.144 + iLogWrapper->Log().Cancel();
1.145 + }
1.146 +/*
1.147 +Creates a new CLogWrapper and initialise iLogWrapper if it doesn't exist otherwise
1.148 +return iLogWrapper
1.149 +*/
1.150 +CLogWrapper* CSchLogManager::GetLogWrapperL()
1.151 + {
1.152 + if(iLogWrapper)
1.153 + return iLogWrapper;
1.154 +
1.155 + iLogWrapper = CLogWrapper::NewL(*iFileSession, CActive::EPriorityStandard);
1.156 +
1.157 + return iLogWrapper;
1.158 + }
1.159 +
1.160 +