os/persistentdata/loggingservices/eventlogger/LogCli/src/LogViewWindowFetcher.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 "LogViewWindowFetcher.h"
22 #include "logservcli.h"
25 const TInt KLogSizeOfEventGuess = 200;
26 const TInt KLogWindowFetchBufferGranularity = KLogSizeOfEventGuess * 2;
27 const TInt KLogWindowFetchBufferMinimumBufferSize = 4;
30 /////////////////////////////////////////////////////////////////////////////////////////
31 // -----> CLogViewWindowFetcher (source)
32 /////////////////////////////////////////////////////////////////////////////////////////
34 CLogViewWindowFetcher::CLogViewWindowFetcher(RLogSession& aSession, TLogViewId aViewId, MLogViewWindowFetcherObserver& aObserver, TInt aPriority)
35 : CActive(aPriority), iSession(aSession), iViewId(aViewId), iObserver(aObserver), iBufferPointer(NULL, 0)
37 CActiveScheduler::Add(this);
38 iData().iOperationType = ELogOperationViewWindowFetch;
41 CLogViewWindowFetcher::~CLogViewWindowFetcher()
48 void CLogViewWindowFetcher::ConstructL()
50 iBuffer = CBufFlat::NewL(KLogWindowFetchBufferGranularity);
53 /////////////////////////////////////////////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////////////////////////////
55 /////////////////////////////////////////////////////////////////////////////////////////
57 void CLogViewWindowFetcher::PrepareToFetchWindowL(const TLogWindowAndCursor& aRequestedWindow)
59 iRequestedWindow = aRequestedWindow;
60 iRequestedWindow.iValid = EFalse;
61 iWindowReq = iRequestedWindow; // Initialise window
62 // Setup the buffer so that its the right size to receive the events
63 const TInt range = Max(1, iRequestedWindow.iUpper - iRequestedWindow.iLower + 1);
64 const TInt size = KLogSizeOfEventGuess * range;
65 iBuffer->ResizeL(size);
66 iBufferPointer.Set(iBuffer->Ptr(0));
68 iFetchWindowData().iBufferSize = size;
71 void CLogViewWindowFetcher::Start(TRequestStatus& aObserver)
73 iObserverRequestStatus = &aObserver;
74 *iObserverRequestStatus = KRequestPending;
75 if (iRequestedWindow.Range())
76 Fetch(iRequestedWindow);
80 iRequestedWindow.NormalizeWindowAndCursor();
81 User::RequestComplete(iObserverRequestStatus, KErrNone);
85 void CLogViewWindowFetcher::SilentCancel()
87 if (iObserverRequestStatus)
88 User::RequestComplete(iObserverRequestStatus, KErrNone);
93 /////////////////////////////////////////////////////////////////////////////////////////
94 /////////////////////////////////////////////////////////////////////////////////////////
95 /////////////////////////////////////////////////////////////////////////////////////////
97 void CLogViewWindowFetcher::RunL()
99 const TInt sentByServer = iStatus.Int();
100 User::LeaveIfError(sentByServer);
101 //The server has completed the operation without any error, but there is no returned data
102 //(sentByServer == 0). Then the client has to check if iFetchWindowData().iServerDataSize
103 //data member is set, which means that the server wants to send more data than the client
104 //side buffer can accept. The client has to increase the buffer size and then execute
105 //the operation again.
106 TInt newSize = iFetchWindowData().iServerDataSize;
107 //newSize was initialized, so iFetchWindowData().iServerDataSize can be set to 0.
108 iFetchWindowData().iServerDataSize = 0;
109 if(sentByServer == 0 && newSize > 0)
111 iBuffer->ResizeL(newSize);
112 iBufferPointer.Set(iBuffer->Ptr(0));
113 iFetchWindowData().iBufferSize = newSize;
114 //The operation will be executed again later - see "Fetch(iWindowReq)" call.
116 RBufReadStream stream(*iBuffer);
117 for(TInt i=0; i<sentByServer; i++)
119 // Give the event to the observer
120 CLogEvent* event = CLogEvent::NewL();
121 CleanupStack::PushL(event);
124 iObserver.HandleFetchedWindowItemL(i, event);
125 CleanupStack::Pop(event);
128 // Do we need to fetch the next batch?
129 iWindowReq.iLower += sentByServer; // the lower array index for next request
131 if(iWindowReq.iLower <= iWindowReq.iUpper)
139 iBuffer->ResizeL(KLogWindowFetchBufferMinimumBufferSize);
140 iRequestedWindow.iValid = ETrue;
141 CompleteObserver(KErrNone);
145 void CLogViewWindowFetcher::DoCancel()
147 if (iData().iOperationId > 0)
149 const TInt errorIgnored = iSession.Send(ELogOperationCancel, TIpcArgs(&iData));
152 iData().iOperationId = KLogNullOperationId;
155 CompleteObserver(KErrCancel);
158 TInt CLogViewWindowFetcher::RunError(TInt aError)
160 CompleteObserver(aError);
164 /////////////////////////////////////////////////////////////////////////////////////////
165 /////////////////////////////////////////////////////////////////////////////////////////
166 /////////////////////////////////////////////////////////////////////////////////////////
168 void CLogViewWindowFetcher::Fetch(const TLogWindow& aWindow)
170 iFetchWindowData().iLower = aWindow.iLower;
171 iFetchWindowData().iUpper = aWindow.iUpper;
173 iData().iOperationId = iSession.AllocateIdOperation();
175 iSession.Send(ELogViewOperationInitiate, TIpcArgs(&iData,iViewId,&iFetchWindowData,&iBufferPointer), iStatus);
179 void CLogViewWindowFetcher::CompleteObserver(TInt aError)
181 if (iObserverRequestStatus)
182 User::RequestComplete(iObserverRequestStatus, aError);