os/persistentdata/loggingservices/eventlogger/LogServ/src/LogServViewWindowFetcher.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 "LogServViewWindowFetcher.h"
19 #include "logservpanic.h"
20 #include "LogServView.h"
23 const TInt KLogViewWindowTransferBufferGranularity = 500;
26 /////////////////////////////////////////////////////////////////////////////////////////
27 // -----> CLogServViewWindowFetcher (source)
28 /////////////////////////////////////////////////////////////////////////////////////////
30 CLogServViewWindowFetcher::CLogServViewWindowFetcher(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority)
31 : CLogActive(aPriority), iDatabase(aDatabase)
35 CLogServViewWindowFetcher::~CLogServViewWindowFetcher()
43 void CLogServViewWindowFetcher::ConstructL()
45 iBuffer = CBufFlat::NewL(KLogViewWindowTransferBufferGranularity);
46 iEvent = CLogEvent::NewL();
47 iGetEvent = CLogGetEvent::NewL(iDatabase, Priority());
50 CLogServViewWindowFetcher* CLogServViewWindowFetcher::NewL(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority)
52 CLogServViewWindowFetcher* self = new(ELeave) CLogServViewWindowFetcher(aDatabase, aPriority);
53 CleanupStack::PushL(self);
55 CleanupStack::Pop(self);
59 /////////////////////////////////////////////////////////////////////////////////////////
60 /////////////////////////////////////////////////////////////////////////////////////////
61 /////////////////////////////////////////////////////////////////////////////////////////
63 void CLogServViewWindowFetcher::StartL(TRequestStatus& aStatus, const CLogServViewBase& aView, const TLogTransferWindow& aWindow, const RMessage2& aMessage)
65 __ASSERT_ALWAYS(iState == EStateIdle, Panic(ELogViewWindowFetcherBadState));
74 iState = EStateStarting;
79 /////////////////////////////////////////////////////////////////////////////////////////
80 /////////////////////////////////////////////////////////////////////////////////////////
81 /////////////////////////////////////////////////////////////////////////////////////////
83 void CLogServViewWindowFetcher::DoRunL()
85 const TInt error = iStatus.Int();
86 User::LeaveIfError(error);
91 GetNextEventL(iWindowIndex);
92 iState = EStateContinuing;
94 case EStateContinuing:
98 __ASSERT_ALWAYS(0, Panic(ELogViewWindowFetcherBadState2));
103 void CLogServViewWindowFetcher::ProcessEventL()
105 // Try and write the event to the buffer
106 const TInt sizeBefore = iBuffer->Size();
107 RBufWriteStream stream(*iBuffer, iBuffer->Size());
109 const TInt sizeAfter = iBuffer->Size();
111 TBool moreToFetch = EFalse;
113 const TInt numberToFetch = iWindow.Range();
114 if (sizeAfter > iWindow.iBufferSize)
116 //The client buffer size is too small. It should be increased, if the client wants
117 //to get the server data.
118 //The server sets iServerDataSize data member with the minimal size which the client
119 //side buffer should have - sizeAfter.
120 TPtrC8 ptr(reinterpret_cast <TUint8*> (&iWindow), sizeof(iWindow));
121 iWindow.iServerDataSize = sizeAfter;
122 iMessage->WriteL(2, ptr);
124 iBuffer->ResizeL(sizeBefore);
125 iWindowIndex -= 1; // we didn't get this event
127 else if (iWindowIndex+1 < numberToFetch)
129 GetNextEventL(iWindowIndex+1);
135 // Write whatever we have back to the client's address space
136 TPtr8 pBuffer(iBuffer->Ptr(0));
137 iMessage->WriteL(3, pBuffer);
142 void CLogServViewWindowFetcher::DoCancel()
147 // Nothing to do, completed our own request status
149 case EStateContinuing:
153 __ASSERT_ALWAYS(0, Panic(ELogViewWindowFetcherBadState3));
156 CLogActive::DoCancel();
159 void CLogServViewWindowFetcher::DoComplete(TInt& aCompletionCode)
161 // Indicates to the client side how many records we retrieved.
162 if (aCompletionCode == KErrNone)
163 aCompletionCode = iWindowIndex+1;
168 /////////////////////////////////////////////////////////////////////////////////////////
169 /////////////////////////////////////////////////////////////////////////////////////////
170 /////////////////////////////////////////////////////////////////////////////////////////
172 void CLogServViewWindowFetcher::GetNextEventL(TInt aWindowIndex)
174 const TInt index = iWindow.iLower + aWindowIndex;
175 const TInt viewCount = iView->Count();
178 ::PanicClientL(*iMessage, ELogViewBadWindow);
180 else if (index >= viewCount)
182 // View is still catching up with changes which have been made in the server?
183 CLogEvent* event = CLogEvent::NewL();
187 iWindowIndex = aWindowIndex;
191 const TLogId id = iView->At(index);
193 iGetEvent->StartL(*iEvent, iStatus, *iMessage);
194 iWindowIndex = aWindowIndex;
199 void CLogServViewWindowFetcher::CompleteRequest()
201 TRequestStatus* status = &iStatus;
202 User::RequestComplete(status, KErrNone);