os/persistentdata/loggingservices/eventlogger/LogServ/src/LogNotify.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "LogNotify.h"
    17 #include "logservpanic.h"
    18 #include "LogServBackupInterface.h"
    19 #include "LogServDatabaseChangeInterface.h"
    20 
    21 
    22 CLogNotify::CLogNotify(MLogServBackupInterface& aBackupInterface, MLogServDatabaseChangeInterface& aChangeInterface, TInt aPriority)
    23 :	CTimer(aPriority), iBackupInterface(aBackupInterface), iChangeInterface(aChangeInterface), iCompleteClientMessage(ETrue)
    24 	{
    25 	CActiveScheduler::Add(this);
    26 	}
    27 
    28 CLogNotify::~CLogNotify()
    29 	{
    30 	LOGTEXT("CLogNotify::~CLogNotify()");
    31 
    32 	// This will only complete the client-side request if its not already
    33 	// been completed
    34 	Cancel();
    35 	//
    36 	iChangeInterface.DCIRequestChangeNotificationsCancel(*this);
    37 	iBackupInterface.BIObserverRemove(*this);
    38 
    39 	LOGTEXT("CLogNotify::~CLogNotify() - end");
    40 	}
    41 
    42 void CLogNotify::ConstructL()
    43 	{
    44 	LOGTEXT("CLogNotify::ConstructL()");
    45 
    46 	CTimer::ConstructL();
    47 
    48 	// Register for change events
    49 	iChangeInterface.DCIRequestChangeNotificationsL(*this);
    50 
    51 	// Register for backup events
    52 	iBackupInterface.BIObserverAddL(*this, MLogServBackupInterface::EObjectClientChangeNotifications);
    53 
    54 	LOGTEXT("CLogNotify::ConstructL() - end");
    55 	}
    56 
    57 CLogNotify* CLogNotify::NewL(MLogServBackupInterface& aBackupInterface, MLogServDatabaseChangeInterface& aChangeInterface, TInt aPriority)
    58 	{
    59 	CLogNotify* self = new(ELeave)CLogNotify(aBackupInterface, aChangeInterface, aPriority);
    60 	CleanupStack::PushL(self);
    61 	self->ConstructL();
    62 	CleanupStack::Pop(); // self
    63 	return self;
    64 	}
    65 
    66 /////////////////////////////////////////////////////////////////////////////////////////
    67 /////////////////////////////////////////////////////////////////////////////////////////
    68 /////////////////////////////////////////////////////////////////////////////////////////
    69 
    70 void CLogNotify::DCOHandleChangeEventsL(const CLogChangeDefinition& /*aChanges*/)
    71 //
    72 //	Handle changes within the log database
    73 //
    74 	{
    75 	LOGTEXT2("CLogNotify::DCOHandleChangeEventsL() - client thread is: %S", &iClientThreadName);
    76 
    77 	// Increment number of changes but only notify the client side request
    78 	// if the delay timer isn't running.
    79 	++iCommit;
    80 	//
    81 	if	(!IsActive())
    82 		CheckForChanges();
    83 
    84 	LOGTEXT("CLogNotify::DCOHandleChangeEventsL() - end");
    85 	}
    86 
    87 /////////////////////////////////////////////////////////////////////////////////////////
    88 /////////////////////////////////////////////////////////////////////////////////////////
    89 /////////////////////////////////////////////////////////////////////////////////////////
    90 
    91 void CLogNotify::BOHandleEventL(TLogServBackupEvent aEvent)
    92 	{
    93 	switch(aEvent)
    94 		{
    95 	case EBackupStarting:
    96 		LOGTEXT("CLogNotify::BOHandleEventL(EBackupStarting)");
    97 
    98 		// A rather inelegant fix but gets rid of one whole class
    99 		iCompleteClientMessage = EFalse;
   100 		Cancel();
   101 		iCompleteClientMessage = ETrue;
   102 		break;
   103 
   104 	case EBackupEnded:
   105 		LOGTEXT("CLogNotify::BOHandleEventL(EBackupEnded)");
   106 		// Simulate a change
   107 		++iCommit;
   108 		if	(!IsActive())
   109 			CheckForChanges();
   110 		break;
   111 		}
   112 
   113 	LOGTEXT("CLogNotify::BOHandleEventL() - end");
   114 	}
   115 
   116 /////////////////////////////////////////////////////////////////////////////////////////
   117 /////////////////////////////////////////////////////////////////////////////////////////
   118 /////////////////////////////////////////////////////////////////////////////////////////
   119 
   120 void CLogNotify::Notify(TTimeIntervalMicroSeconds32 aDelay, const RMessage2& aMessage)
   121 
   122 	{
   123 #ifdef LOGGING_ENABLED
   124 	RThread t;
   125 	aMessage.Client(t);
   126 	iClientThreadName = t.Name();
   127 	t.Close();
   128 	LOGTEXT3("CLogNotify::Notify(%d, %S)", aDelay.Int(), &iClientThreadName);
   129 #endif
   130 
   131 	__ASSERT_DEBUG(!IsActive(), Panic(ELogAlreadyActive18));
   132 	Cancel();
   133 
   134 	// Reset our change counter
   135 	if (iLastCommit == 0)
   136 		iLastCommit = iCommit;
   137 
   138 	// Save a message pointer to client request status
   139 	iMessagePtr = aMessage;
   140 
   141 	// Wait until the delay has passed before notifying clients of changes
   142 	After(aDelay);
   143 
   144 	LOGTEXT("CLogNotify::Notify() - end");
   145 	}
   146 
   147 /////////////////////////////////////////////////////////////////////////////////////////
   148 /////////////////////////////////////////////////////////////////////////////////////////
   149 /////////////////////////////////////////////////////////////////////////////////////////
   150 
   151 void CLogNotify::Cancel()
   152 	{
   153 	LOGTEXT2("CLogNotify::Cancel() - client thread is: %S", &iClientThreadName);
   154 
   155 	CActive::Cancel();
   156 
   157 	// Reset
   158 	iLastCommit = 0;
   159 
   160 	// Complete the client-side observer
   161 	if	(iCompleteClientMessage)
   162 		CompleteClientRequest(KErrCancel);
   163 
   164 	LOGTEXT("CLogNotify::Cancel() - end");
   165 	}
   166 
   167 void CLogNotify::RunL()
   168 //
   169 //	RunL is called if the timer has expired
   170 //
   171 	{
   172 	LOGTEXT3("CLogNotify::RunL(%d) - client thread is: %S", iStatus.Int(), &iClientThreadName);
   173 
   174 	CheckForChanges();
   175 
   176 	LOGTEXT("CLogNotify::RunL() - end");
   177 	}
   178 
   179 void CLogNotify::DoCancel()
   180 	{
   181 	LOGTEXT2("CLogNotify::DoCancel() - client thread is: %S", &iClientThreadName);
   182 
   183 	// This is what really cancel's us
   184 	CTimer::DoCancel();
   185 
   186 	LOGTEXT("CLogNotify::DoCancel() - end");
   187 	}
   188 
   189 /////////////////////////////////////////////////////////////////////////////////////////
   190 /////////////////////////////////////////////////////////////////////////////////////////
   191 /////////////////////////////////////////////////////////////////////////////////////////
   192 
   193 void CLogNotify::CheckForChanges()
   194 	{
   195 	LOGTEXT4("CLogNotify::CheckForChanges() - iLastCommit = %d, iCommit = %d, client thread name: %S", iLastCommit, iCommit, &iClientThreadName);
   196 
   197 	if	(iLastCommit != iCommit)
   198 		{
   199 		LOGTEXT("CLogNotify::CheckForChanges() - changes detected, attempting to notify client");
   200 		iLastCommit = iCommit;
   201 		CompleteClientRequest(RDbNotifier::ECommit);
   202 		}
   203 
   204 	LOGTEXT("CLogNotify::CheckForChanges() - end");
   205 	}
   206 
   207 void CLogNotify::CompleteClientRequest(TInt aCompletionCode)
   208 	{
   209 	LOGTEXT3("CLogNotify::CompleteClientRequest() - aCompletionCode = %d, thread: %S", aCompletionCode, &iClientThreadName);
   210 
   211 	if	(!iMessagePtr.IsNull())
   212 		{
   213 		LOGTEXT2("CLogNotify::CompleteClientRequest() - completing outstanding client request status for thread: %S", &iClientThreadName);
   214 		iMessagePtr.Complete(aCompletionCode);
   215 		}
   216 	else
   217 		{
   218 		LOGTEXT2("CLogNotify::CompleteClientRequest() - thread %S doesn't have an outstanding notification request", &iClientThreadName);
   219 		}
   220 
   221 	LOGTEXT("CLogNotify::CompleteClientRequest() - end");
   222 	}