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 "LogNotify.h"
17 #include "logservpanic.h"
18 #include "LogServBackupInterface.h"
19 #include "LogServDatabaseChangeInterface.h"
22 CLogNotify::CLogNotify(MLogServBackupInterface& aBackupInterface, MLogServDatabaseChangeInterface& aChangeInterface, TInt aPriority)
23 : CTimer(aPriority), iBackupInterface(aBackupInterface), iChangeInterface(aChangeInterface), iCompleteClientMessage(ETrue)
25 CActiveScheduler::Add(this);
28 CLogNotify::~CLogNotify()
30 LOGTEXT("CLogNotify::~CLogNotify()");
32 // This will only complete the client-side request if its not already
36 iChangeInterface.DCIRequestChangeNotificationsCancel(*this);
37 iBackupInterface.BIObserverRemove(*this);
39 LOGTEXT("CLogNotify::~CLogNotify() - end");
42 void CLogNotify::ConstructL()
44 LOGTEXT("CLogNotify::ConstructL()");
48 // Register for change events
49 iChangeInterface.DCIRequestChangeNotificationsL(*this);
51 // Register for backup events
52 iBackupInterface.BIObserverAddL(*this, MLogServBackupInterface::EObjectClientChangeNotifications);
54 LOGTEXT("CLogNotify::ConstructL() - end");
57 CLogNotify* CLogNotify::NewL(MLogServBackupInterface& aBackupInterface, MLogServDatabaseChangeInterface& aChangeInterface, TInt aPriority)
59 CLogNotify* self = new(ELeave)CLogNotify(aBackupInterface, aChangeInterface, aPriority);
60 CleanupStack::PushL(self);
62 CleanupStack::Pop(); // self
66 /////////////////////////////////////////////////////////////////////////////////////////
67 /////////////////////////////////////////////////////////////////////////////////////////
68 /////////////////////////////////////////////////////////////////////////////////////////
70 void CLogNotify::DCOHandleChangeEventsL(const CLogChangeDefinition& /*aChanges*/)
72 // Handle changes within the log database
75 LOGTEXT2("CLogNotify::DCOHandleChangeEventsL() - client thread is: %S", &iClientThreadName);
77 // Increment number of changes but only notify the client side request
78 // if the delay timer isn't running.
84 LOGTEXT("CLogNotify::DCOHandleChangeEventsL() - end");
87 /////////////////////////////////////////////////////////////////////////////////////////
88 /////////////////////////////////////////////////////////////////////////////////////////
89 /////////////////////////////////////////////////////////////////////////////////////////
91 void CLogNotify::BOHandleEventL(TLogServBackupEvent aEvent)
96 LOGTEXT("CLogNotify::BOHandleEventL(EBackupStarting)");
98 // A rather inelegant fix but gets rid of one whole class
99 iCompleteClientMessage = EFalse;
101 iCompleteClientMessage = ETrue;
105 LOGTEXT("CLogNotify::BOHandleEventL(EBackupEnded)");
113 LOGTEXT("CLogNotify::BOHandleEventL() - end");
116 /////////////////////////////////////////////////////////////////////////////////////////
117 /////////////////////////////////////////////////////////////////////////////////////////
118 /////////////////////////////////////////////////////////////////////////////////////////
120 void CLogNotify::Notify(TTimeIntervalMicroSeconds32 aDelay, const RMessage2& aMessage)
123 #ifdef LOGGING_ENABLED
126 iClientThreadName = t.Name();
128 LOGTEXT3("CLogNotify::Notify(%d, %S)", aDelay.Int(), &iClientThreadName);
131 __ASSERT_DEBUG(!IsActive(), Panic(ELogAlreadyActive18));
134 // Reset our change counter
135 if (iLastCommit == 0)
136 iLastCommit = iCommit;
138 // Save a message pointer to client request status
139 iMessagePtr = aMessage;
141 // Wait until the delay has passed before notifying clients of changes
144 LOGTEXT("CLogNotify::Notify() - end");
147 /////////////////////////////////////////////////////////////////////////////////////////
148 /////////////////////////////////////////////////////////////////////////////////////////
149 /////////////////////////////////////////////////////////////////////////////////////////
151 void CLogNotify::Cancel()
153 LOGTEXT2("CLogNotify::Cancel() - client thread is: %S", &iClientThreadName);
160 // Complete the client-side observer
161 if (iCompleteClientMessage)
162 CompleteClientRequest(KErrCancel);
164 LOGTEXT("CLogNotify::Cancel() - end");
167 void CLogNotify::RunL()
169 // RunL is called if the timer has expired
172 LOGTEXT3("CLogNotify::RunL(%d) - client thread is: %S", iStatus.Int(), &iClientThreadName);
176 LOGTEXT("CLogNotify::RunL() - end");
179 void CLogNotify::DoCancel()
181 LOGTEXT2("CLogNotify::DoCancel() - client thread is: %S", &iClientThreadName);
183 // This is what really cancel's us
186 LOGTEXT("CLogNotify::DoCancel() - end");
189 /////////////////////////////////////////////////////////////////////////////////////////
190 /////////////////////////////////////////////////////////////////////////////////////////
191 /////////////////////////////////////////////////////////////////////////////////////////
193 void CLogNotify::CheckForChanges()
195 LOGTEXT4("CLogNotify::CheckForChanges() - iLastCommit = %d, iCommit = %d, client thread name: %S", iLastCommit, iCommit, &iClientThreadName);
197 if (iLastCommit != iCommit)
199 LOGTEXT("CLogNotify::CheckForChanges() - changes detected, attempting to notify client");
200 iLastCommit = iCommit;
201 CompleteClientRequest(RDbNotifier::ECommit);
204 LOGTEXT("CLogNotify::CheckForChanges() - end");
207 void CLogNotify::CompleteClientRequest(TInt aCompletionCode)
209 LOGTEXT3("CLogNotify::CompleteClientRequest() - aCompletionCode = %d, thread: %S", aCompletionCode, &iClientThreadName);
211 if (!iMessagePtr.IsNull())
213 LOGTEXT2("CLogNotify::CompleteClientRequest() - completing outstanding client request status for thread: %S", &iClientThreadName);
214 iMessagePtr.Complete(aCompletionCode);
218 LOGTEXT2("CLogNotify::CompleteClientRequest() - thread %S doesn't have an outstanding notification request", &iClientThreadName);
221 LOGTEXT("CLogNotify::CompleteClientRequest() - end");