os/persistentdata/loggingservices/eventlogger/LogServ/src/LogServViewChangeManager.cpp
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 "LogServViewChangeManager.h"
18 #include "logservpanic.h"
19 #include "LogServDatabaseChangeInterface.h"
22 const TInt KLogServViewChangeDefinitionGranularity = 10;
23 const TInt KLogServViewChangeQueueGranularity = 3;
24 const TInt KLogServViewChangeBufferGranularity = 40;
27 /////////////////////////////////////////////////////////////////////////////////////////
28 // -----> CLogServViewChangeManager (source)
29 /////////////////////////////////////////////////////////////////////////////////////////
31 CLogServViewChangeManager::CLogServViewChangeManager(MLogServDatabaseChangeInterface& aChangeInterface)
32 : iChangeInterface(aChangeInterface), iPendingChanges(KLogServViewChangeQueueGranularity)
36 CLogServViewChangeManager::~CLogServViewChangeManager()
38 delete iTransientChangeDefinition;
40 iPendingChanges.ResetAndDestroy();
41 iPendingChanges.Close();
44 void CLogServViewChangeManager::ConstructL()
46 iTransientChangeDefinition = CLogChangeDefinition::NewL(KLogServViewChangeDefinitionGranularity);
49 CLogServViewChangeManager* CLogServViewChangeManager::NewL(MLogServDatabaseChangeInterface& aChangeInterface)
51 CLogServViewChangeManager* self = new(ELeave) CLogServViewChangeManager(aChangeInterface);
52 CleanupStack::PushL(self);
54 CleanupStack::Pop(self);
58 /////////////////////////////////////////////////////////////////////////////////////////
59 /////////////////////////////////////////////////////////////////////////////////////////
60 /////////////////////////////////////////////////////////////////////////////////////////
62 void CLogServViewChangeManager::ChangeTransactionPrepare()
64 iTransientChangeDefinition->Reset();
67 void CLogServViewChangeManager::ChangeTransactionSubmitL(TLogId aId, TLogDatabaseChangeType aType, TInt aViewIndex)
69 iTransientChangeDefinition->AddL(aId, aType, aViewIndex);
72 void CLogServViewChangeManager::ChangeTransactionCommitL()
74 // We can only tell the client-side view change observer about the changes if:
76 // (2) we actually have something to tell the client views (some changes)
77 // (3) we have an outstanding client-side change message pointer
79 const TInt count = iTransientChangeDefinition->Count();
82 // Do we have any existing pending changes? We can't alter the contents of the
83 // first pending change, since the client may already be preparing a client-side
84 // buffer of the requisite size. We can, however, combine the 2nd batch of changes
85 // with this new set so there is less IPC required (although more memory).
86 const TInt pendingChangeCount = iPendingChanges.Count();
87 if (pendingChangeCount >= 2)
89 CLogChangeDefinition* changeDef = CLogChangeDefinition::NewL();
90 CleanupStack::PushL(changeDef);
92 CBufBase* buffer = iPendingChanges[1];
93 RBufReadStream readStream(*buffer);
95 readStream >> *changeDef;
98 TLogId logId = KLogNullId;
99 TLogDatabaseChangeType type = ELogChangeTypeUndefined;
102 for(TInt i=0; i<count; i++)
104 type = iTransientChangeDefinition->At(i, logId, viewIndex);
105 changeDef->AddL(logId, type, viewIndex);
108 // Write the whole lot out again
109 buffer->Delete(0, buffer->Size());
111 RBufWriteStream writeStream(*buffer);
112 writeStream << *changeDef;
114 CleanupStack::PopAndDestroy(changeDef);
118 CBufBase* buffer = CBufFlat::NewL(KLogServViewChangeBufferGranularity);
119 CleanupStack::PushL(buffer);
121 // Externalize changes
122 RBufWriteStream stream(*buffer);
123 stream << *iTransientChangeDefinition;
127 User::LeaveIfError(iPendingChanges.Append(buffer));
128 CleanupStack::Pop(buffer);
131 // Notify if necessary - handles (3) implicitly
136 iTransientChangeDefinition->Reset();
139 /////////////////////////////////////////////////////////////////////////////////////////
140 /////////////////////////////////////////////////////////////////////////////////////////
141 /////////////////////////////////////////////////////////////////////////////////////////
143 void CLogServViewChangeManager::DeliverChangesL(const RMessage2& aMessage)
145 if (iPendingChanges.Count())
147 CBufBase* headItem = iPendingChanges[0];
149 const TInt expectedChangesSize = aMessage.Int1();
150 const TPtr8 pBufferContents(headItem->Ptr(0));
152 // Check buffer size is as we expect
153 if (expectedChangesSize != pBufferContents.Size())
154 ::PanicClientL(aMessage, ELogViewBadClientSideChangeBufferSize);
157 // Write back to client-side
158 aMessage.WriteL(2, pBufferContents);
161 iPendingChanges.Remove(0);
166 ::PanicClientL(aMessage, ELogViewNoPendingChangesToDeliver);
169 /////////////////////////////////////////////////////////////////////////////////////////
170 /////////////////////////////////////////////////////////////////////////////////////////
171 /////////////////////////////////////////////////////////////////////////////////////////
173 void CLogServViewChangeManager::RequestChangeNotifications(const RMessage2& aMessage)
175 if (iClientSideChangeMessage == RMessagePtr2())
177 // Notify if we have any cached changes...
178 iClientSideChangeMessage = aMessage;
182 PanicClient(aMessage, ELogViewChangeRequestAlreadyIssued);
185 void CLogServViewChangeManager::RequestChangeNotificationsCancel()
187 if (iClientSideChangeMessage != RMessagePtr2())
188 CompleteClientChangeMessage(KErrCancel);
190 // Zap all the pending changes too
191 iPendingChanges.ResetAndDestroy();
192 iPendingChanges.GranularCompress();
195 /////////////////////////////////////////////////////////////////////////////////////////
196 /////////////////////////////////////////////////////////////////////////////////////////
197 /////////////////////////////////////////////////////////////////////////////////////////
199 void CLogServViewChangeManager::NotifyClient()
201 const TInt count = iPendingChanges.Count();
202 if (iClientSideChangeMessage != RMessagePtr2() && count)
204 CBufBase* headItem = iPendingChanges[0];
205 const TInt messageSize = headItem->Size();
206 CompleteClientChangeMessage(messageSize);
210 void CLogServViewChangeManager::CompleteClientChangeMessage(TInt aCompletionCode)
212 __ASSERT_ALWAYS(iClientSideChangeMessage != RMessagePtr2(), Panic(ELogViewNoClientChangeMessageOutstanding));
213 iClientSideChangeMessage.Complete(aCompletionCode);