|
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 "LogViewWindowFetcher.h" |
|
17 |
|
18 // System includes |
|
19 #include <s32mem.h> |
|
20 |
|
21 // User includes |
|
22 #include "logservcli.h" |
|
23 |
|
24 // Constants |
|
25 const TInt KLogSizeOfEventGuess = 200; |
|
26 const TInt KLogWindowFetchBufferGranularity = KLogSizeOfEventGuess * 2; |
|
27 const TInt KLogWindowFetchBufferMinimumBufferSize = 4; |
|
28 |
|
29 |
|
30 ///////////////////////////////////////////////////////////////////////////////////////// |
|
31 // -----> CLogViewWindowFetcher (source) |
|
32 ///////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
34 CLogViewWindowFetcher::CLogViewWindowFetcher(RLogSession& aSession, TLogViewId aViewId, MLogViewWindowFetcherObserver& aObserver, TInt aPriority) |
|
35 : CActive(aPriority), iSession(aSession), iViewId(aViewId), iObserver(aObserver), iBufferPointer(NULL, 0) |
|
36 { |
|
37 CActiveScheduler::Add(this); |
|
38 iData().iOperationType = ELogOperationViewWindowFetch; |
|
39 } |
|
40 |
|
41 CLogViewWindowFetcher::~CLogViewWindowFetcher() |
|
42 { |
|
43 Cancel(); |
|
44 // |
|
45 delete iBuffer; |
|
46 } |
|
47 |
|
48 void CLogViewWindowFetcher::ConstructL() |
|
49 { |
|
50 iBuffer = CBufFlat::NewL(KLogWindowFetchBufferGranularity); |
|
51 } |
|
52 |
|
53 ///////////////////////////////////////////////////////////////////////////////////////// |
|
54 ///////////////////////////////////////////////////////////////////////////////////////// |
|
55 ///////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
57 void CLogViewWindowFetcher::PrepareToFetchWindowL(const TLogWindowAndCursor& aRequestedWindow) |
|
58 { |
|
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)); |
|
67 // |
|
68 iFetchWindowData().iBufferSize = size; |
|
69 } |
|
70 |
|
71 void CLogViewWindowFetcher::Start(TRequestStatus& aObserver) |
|
72 { |
|
73 iObserverRequestStatus = &aObserver; |
|
74 *iObserverRequestStatus = KRequestPending; |
|
75 if (iRequestedWindow.Range()) |
|
76 Fetch(iRequestedWindow); |
|
77 else |
|
78 { |
|
79 // Nothing to fetch |
|
80 iRequestedWindow.NormalizeWindowAndCursor(); |
|
81 User::RequestComplete(iObserverRequestStatus, KErrNone); |
|
82 } |
|
83 } |
|
84 |
|
85 void CLogViewWindowFetcher::SilentCancel() |
|
86 { |
|
87 if (iObserverRequestStatus) |
|
88 User::RequestComplete(iObserverRequestStatus, KErrNone); |
|
89 Cancel(); |
|
90 } |
|
91 |
|
92 |
|
93 ///////////////////////////////////////////////////////////////////////////////////////// |
|
94 ///////////////////////////////////////////////////////////////////////////////////////// |
|
95 ///////////////////////////////////////////////////////////////////////////////////////// |
|
96 |
|
97 void CLogViewWindowFetcher::RunL() |
|
98 { |
|
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) |
|
110 { |
|
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. |
|
115 } |
|
116 RBufReadStream stream(*iBuffer); |
|
117 for(TInt i=0; i<sentByServer; i++) |
|
118 { |
|
119 // Give the event to the observer |
|
120 CLogEvent* event = CLogEvent::NewL(); |
|
121 CleanupStack::PushL(event); |
|
122 // |
|
123 stream >> *event; |
|
124 iObserver.HandleFetchedWindowItemL(i, event); |
|
125 CleanupStack::Pop(event); |
|
126 } |
|
127 |
|
128 // Do we need to fetch the next batch? |
|
129 iWindowReq.iLower += sentByServer; // the lower array index for next request |
|
130 |
|
131 if(iWindowReq.iLower <= iWindowReq.iUpper) |
|
132 { |
|
133 // Fetch some more |
|
134 Fetch(iWindowReq); |
|
135 } |
|
136 else |
|
137 { |
|
138 // All done? |
|
139 iBuffer->ResizeL(KLogWindowFetchBufferMinimumBufferSize); |
|
140 iRequestedWindow.iValid = ETrue; |
|
141 CompleteObserver(KErrNone); |
|
142 } |
|
143 } |
|
144 |
|
145 void CLogViewWindowFetcher::DoCancel() |
|
146 { |
|
147 if (iData().iOperationId > 0) |
|
148 { |
|
149 const TInt errorIgnored = iSession.Send(ELogOperationCancel, TIpcArgs(&iData)); |
|
150 (void) errorIgnored; |
|
151 // |
|
152 iData().iOperationId = KLogNullOperationId; |
|
153 } |
|
154 |
|
155 CompleteObserver(KErrCancel); |
|
156 } |
|
157 |
|
158 TInt CLogViewWindowFetcher::RunError(TInt aError) |
|
159 { |
|
160 CompleteObserver(aError); |
|
161 return KErrNone; |
|
162 } |
|
163 |
|
164 ///////////////////////////////////////////////////////////////////////////////////////// |
|
165 ///////////////////////////////////////////////////////////////////////////////////////// |
|
166 ///////////////////////////////////////////////////////////////////////////////////////// |
|
167 |
|
168 void CLogViewWindowFetcher::Fetch(const TLogWindow& aWindow) |
|
169 { |
|
170 iFetchWindowData().iLower = aWindow.iLower; |
|
171 iFetchWindowData().iUpper = aWindow.iUpper; |
|
172 // |
|
173 iData().iOperationId = iSession.AllocateIdOperation(); |
|
174 // |
|
175 iSession.Send(ELogViewOperationInitiate, TIpcArgs(&iData,iViewId,&iFetchWindowData,&iBufferPointer), iStatus); |
|
176 SetActive(); |
|
177 } |
|
178 |
|
179 void CLogViewWindowFetcher::CompleteObserver(TInt aError) |
|
180 { |
|
181 if (iObserverRequestStatus) |
|
182 User::RequestComplete(iObserverRequestStatus, aError); |
|
183 } |