5
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Implements logging SAPI async class.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "loggingasyncservice.h"
|
|
20 |
#include "loggingevent.h"
|
|
21 |
#include "loggingfilter.h"
|
|
22 |
#include "logiter.h"
|
|
23 |
|
|
24 |
/**
|
|
25 |
* Default Constructor Method
|
|
26 |
*/
|
|
27 |
CLogAsyncService :: CLogAsyncService(): CActive(EPriorityStandard)
|
|
28 |
{
|
|
29 |
iTransId=0;
|
|
30 |
}
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Default Destructor
|
|
34 |
*/
|
|
35 |
CLogAsyncService :: ~CLogAsyncService()
|
|
36 |
{
|
|
37 |
Cancel();
|
|
38 |
delete iLogClient ;
|
|
39 |
iFs.Close() ;
|
|
40 |
}
|
|
41 |
|
|
42 |
/**
|
|
43 |
* NewL() Constructs the ClogAsync object
|
|
44 |
*/
|
|
45 |
EXPORT_C CLogAsyncService* CLogAsyncService :: NewL( MLoggingCallback* aCallback )
|
|
46 |
{
|
|
47 |
CLogAsyncService* self = CLogAsyncService::NewLC( aCallback );
|
|
48 |
CleanupStack :: Pop( self ) ;
|
|
49 |
return self;
|
|
50 |
}
|
|
51 |
|
|
52 |
/**
|
|
53 |
* NewLC Two phase constructor implementation
|
|
54 |
*/
|
|
55 |
CLogAsyncService* CLogAsyncService :: NewLC( MLoggingCallback* aCallback )
|
|
56 |
{
|
|
57 |
CLogAsyncService* self = new((ELeave)) CLogAsyncService() ;
|
|
58 |
CleanupStack :: PushL(self) ;
|
|
59 |
self->ConstructL(aCallback) ;
|
|
60 |
return self ;
|
|
61 |
}
|
|
62 |
|
|
63 |
/**
|
|
64 |
* ConstructL, Constructs Members of AsyncService Class
|
|
65 |
*/
|
|
66 |
void CLogAsyncService :: ConstructL( MLoggingCallback* aCallback )
|
|
67 |
{
|
|
68 |
User::LeaveIfError(iFs.Connect());
|
|
69 |
iLogClient = CLogClient::NewL(iFs);
|
|
70 |
iCallback = aCallback;
|
|
71 |
iIter = NULL ;
|
|
72 |
iTask = ESleep;
|
|
73 |
DoInitialiseL() ;
|
|
74 |
}
|
|
75 |
|
|
76 |
/**
|
|
77 |
* DoInitalise, Initalises the Members of AsyncService Class
|
|
78 |
*/
|
|
79 |
void CLogAsyncService :: DoInitialiseL()
|
|
80 |
{
|
|
81 |
CActiveScheduler :: Add(this) ;
|
|
82 |
}
|
|
83 |
|
|
84 |
/**
|
|
85 |
* RunL Method .
|
|
86 |
*/
|
|
87 |
void CLogAsyncService :: RunL()
|
|
88 |
{
|
|
89 |
TRAP_IGNORE(RunCmdL());
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* RunCmdL Method implementation, revices Notifications of completed
|
|
94 |
* Async services: Add , Delete and GetEvent requests
|
|
95 |
*/
|
|
96 |
void CLogAsyncService :: RunCmdL()
|
|
97 |
{
|
|
98 |
switch( iTask )
|
|
99 |
{
|
|
100 |
case EAddEvent:
|
|
101 |
{
|
|
102 |
CLogIter *iter = CLogIter :: NewL() ;
|
|
103 |
iter->SetEventL(iUpdatedEvent) ;
|
|
104 |
delete iUpdatedEvent ;
|
|
105 |
iUpdatedEvent = NULL ;
|
|
106 |
iCallback->HandleNotifyL(iTransId ,iStatus.Int() , iter ) ;
|
|
107 |
iter = NULL;
|
|
108 |
iTask = ESleep;
|
|
109 |
this->Deque();
|
|
110 |
break;
|
|
111 |
}
|
|
112 |
|
|
113 |
case EDeleteEvent:
|
|
114 |
{
|
|
115 |
iCallback->HandleNotifyL( iTransId, iStatus.Int(), NULL ) ;
|
|
116 |
iTask = ESleep;
|
|
117 |
this->Deque();
|
|
118 |
break;
|
|
119 |
}
|
|
120 |
|
|
121 |
case EReadEvents :
|
|
122 |
{
|
|
123 |
iIter->SetTaskId(EReadEvents) ;
|
|
124 |
iCallback->HandleNotifyL( iTransId, KErrNone, iIter ) ;
|
|
125 |
iIter = NULL ;
|
|
126 |
iTask = ESleep;
|
|
127 |
break;
|
|
128 |
}
|
|
129 |
|
|
130 |
case EGetRecent:
|
|
131 |
{
|
|
132 |
iIter->SetTaskId(EGetRecent) ;
|
|
133 |
iCallback->HandleNotifyL( iTransId ,KErrNone, iIter ) ;
|
|
134 |
iIter = NULL ;
|
|
135 |
iTask = ESleep;
|
|
136 |
break;
|
|
137 |
}
|
|
138 |
|
|
139 |
case EGetEvent :
|
|
140 |
{
|
|
141 |
iIter->SetEventL( iUpdatedEvent ) ;
|
|
142 |
iIter->SetTaskId( EGetEvent ) ;
|
|
143 |
delete iUpdatedEvent ;
|
|
144 |
iUpdatedEvent = NULL ;
|
|
145 |
|
|
146 |
if( iStatus.Int() != KErrNone )
|
|
147 |
{
|
|
148 |
delete iIter;
|
|
149 |
iIter = NULL ;
|
|
150 |
}
|
|
151 |
|
|
152 |
iCallback->HandleNotifyL(iTransId , KErrNone, iIter) ;
|
|
153 |
iIter = NULL ;
|
|
154 |
iTask = ESleep;
|
|
155 |
break ;
|
|
156 |
}
|
|
157 |
case ENotification:
|
|
158 |
{
|
|
159 |
NotifyUpdates( iTransId, iInterval );
|
|
160 |
iCallback->HandleNotifyL( iTransId, KErrNone , NULL ) ;
|
|
161 |
break;
|
|
162 |
}
|
|
163 |
|
|
164 |
case EErrorEvent:
|
|
165 |
{
|
|
166 |
delete iIter;
|
|
167 |
iIter = NULL ;
|
|
168 |
iCallback->HandleNotifyL( iTransId ,KErrNone, iIter ) ;
|
|
169 |
iTask = ESleep;
|
|
170 |
break;
|
|
171 |
}
|
|
172 |
|
|
173 |
case ESleep:
|
|
174 |
default:
|
|
175 |
{
|
|
176 |
break ;
|
|
177 |
}
|
|
178 |
|
|
179 |
}
|
|
180 |
}
|
|
181 |
|
|
182 |
/**
|
|
183 |
* Do Cancel Method for cancelling the outstanding async requests
|
|
184 |
*/
|
|
185 |
void CLogAsyncService :: DoCancel()
|
|
186 |
{
|
|
187 |
switch(iTask)
|
|
188 |
{
|
|
189 |
case EAddEvent:
|
|
190 |
{
|
|
191 |
iLogClient->Cancel();
|
|
192 |
break;
|
|
193 |
}
|
|
194 |
|
|
195 |
case EDeleteEvent:
|
|
196 |
{
|
|
197 |
iLogClient->Cancel();
|
|
198 |
break;
|
|
199 |
}
|
|
200 |
case EGetRecent:
|
|
201 |
case EGetEvent:
|
|
202 |
case EErrorEvent:
|
|
203 |
case EReadEvents :
|
|
204 |
{
|
|
205 |
delete iIter ;
|
|
206 |
break;
|
|
207 |
}
|
|
208 |
case ENotification:
|
|
209 |
{
|
|
210 |
iLogClient->NotifyChangeCancel() ;
|
|
211 |
break ;
|
|
212 |
}
|
|
213 |
case ESleep:
|
|
214 |
default:
|
|
215 |
{
|
|
216 |
break;
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
iCallback->CancelNotifyL( iTransId );
|
|
221 |
|
|
222 |
if(iUpdatedEvent)
|
|
223 |
{
|
|
224 |
delete iUpdatedEvent ;
|
|
225 |
iUpdatedEvent = NULL ;
|
|
226 |
}
|
|
227 |
|
|
228 |
}
|
|
229 |
|
|
230 |
/**
|
|
231 |
* AddEvent, adds an event to event database asynchronously
|
|
232 |
* @param aEvent, details of the event to be added to database
|
|
233 |
*/
|
|
234 |
EXPORT_C void CLogAsyncService :: AddL( TUint aTransId ,CLogEvent* aEvent )
|
|
235 |
|
|
236 |
{
|
|
237 |
if(!iUpdatedEvent)
|
|
238 |
{
|
|
239 |
iUpdatedEvent = CLogsEvent :: NewL() ;
|
|
240 |
}
|
|
241 |
iUpdatedEvent->Copy(aEvent);
|
|
242 |
iLogClient->AddEvent(*(iUpdatedEvent->getEvent()) , iStatus);
|
|
243 |
iTransId = aTransId ;
|
|
244 |
SetActive() ;
|
|
245 |
iTask = EAddEvent;
|
|
246 |
}
|
|
247 |
|
|
248 |
/**
|
|
249 |
* Deletes a event from the event database
|
|
250 |
* @param aLogId Event id of the event in the database
|
|
251 |
* @param aFilter, search criteria for this event in event database
|
|
252 |
*/
|
|
253 |
void CLogAsyncService :: Delete( TUint aTransId , TLogId aLogId )
|
|
254 |
{
|
|
255 |
iLogClient->DeleteEvent(aLogId , iStatus) ;
|
|
256 |
iTransId = aTransId ;
|
|
257 |
SetActive() ;
|
|
258 |
iTask = EDeleteEvent;
|
|
259 |
}
|
|
260 |
|
|
261 |
/**
|
|
262 |
* Gets eventList asynchronously
|
|
263 |
* @param aFilter: Event filter for querying the event database
|
|
264 |
* @param aCallback: callback address
|
|
265 |
*/
|
|
266 |
void CLogAsyncService :: GetListL( TUint aTransId ,CLogFilter *aFilter )
|
|
267 |
{
|
|
268 |
if(!iIter)
|
|
269 |
{
|
|
270 |
iIter = CLogIter :: NewL() ;
|
|
271 |
}
|
|
272 |
|
|
273 |
CLogClient *cli = CLogClient :: NewL(iIter->GetRFs()) ;
|
|
274 |
CLogViewEvent *events = CLogViewEvent :: NewL(*cli) ;
|
|
275 |
|
|
276 |
iIter->SetLogViewEvents( events ) ;
|
|
277 |
iIter->SetLogClient( cli ) ;
|
|
278 |
|
|
279 |
if( events->SetFilterL( *aFilter, iStatus ) )
|
|
280 |
{
|
|
281 |
iTask = EReadEvents ;
|
|
282 |
iTransId = aTransId ;
|
|
283 |
SetActive() ;
|
|
284 |
}
|
|
285 |
else //case where the setFilter fails but for the uniformity of the
|
|
286 |
//behaviour of this API for all the inputs.. we are artificially
|
|
287 |
//simulalting asyc behaviour to report the error to the user
|
|
288 |
//as the other internal apis used in this command gives the error
|
|
289 |
//in the callback i.e.., asycn error only
|
|
290 |
{
|
|
291 |
iIter->SetTaskId( EReadEvents ) ;
|
|
292 |
iTask = EErrorEvent;
|
|
293 |
iTransId = aTransId ;
|
|
294 |
iStatus = KRequestPending;
|
|
295 |
SetActive();
|
|
296 |
TRequestStatus* temp = &iStatus;
|
|
297 |
User::RequestComplete( temp, KErrNone );
|
|
298 |
}
|
|
299 |
}
|
|
300 |
/**
|
|
301 |
* Reads recent events from the database aysnchronously
|
|
302 |
*
|
|
303 |
* @param Transaction id of the async event
|
|
304 |
* @param RecentList
|
|
305 |
* @param Filter for events to appear in the view.
|
|
306 |
*/
|
|
307 |
TBool CLogAsyncService :: ReadRecentEventsL( TUint aTransId ,
|
|
308 |
TLogRecentList aList ,
|
|
309 |
const CLogFilter *aFilter )
|
|
310 |
{
|
|
311 |
if(!iIter)
|
|
312 |
{
|
|
313 |
iIter = CLogIter :: NewL() ;
|
|
314 |
}
|
|
315 |
CLogClient *cli = CLogClient :: NewL(iIter->GetRFs()) ;
|
|
316 |
CLogViewRecent *LogViewRecent = CLogViewRecent :: NewL(*cli) ;
|
|
317 |
iIter->SetLogRecentView( LogViewRecent ) ;
|
|
318 |
iIter->SetLogClient( cli ) ;
|
|
319 |
|
|
320 |
if(LogViewRecent->SetRecentListL(aList, *aFilter, iStatus))
|
|
321 |
{
|
|
322 |
// set this active object active to get the events
|
|
323 |
// from the main event database, see RunL()
|
|
324 |
iTransId = aTransId ;
|
|
325 |
iTask = EGetRecent;
|
|
326 |
SetActive();
|
|
327 |
}
|
|
328 |
else
|
|
329 |
{
|
|
330 |
iIter->SetTaskId(EGetEvent) ;
|
|
331 |
iTask = EErrorEvent;
|
|
332 |
iTransId = aTransId ;
|
|
333 |
iStatus = KRequestPending;
|
|
334 |
SetActive();
|
|
335 |
TRequestStatus* temp = &iStatus;
|
|
336 |
User::RequestComplete( temp, KErrNone );
|
|
337 |
}
|
|
338 |
return ETrue ;
|
|
339 |
|
|
340 |
}
|
|
341 |
|
|
342 |
/**
|
|
343 |
* Notifies the updates happening to the log database
|
|
344 |
*/
|
|
345 |
void CLogAsyncService :: NotifyUpdates( TUint aTransId ,TTimeIntervalMicroSeconds32 aDelay )
|
|
346 |
{
|
|
347 |
iLogClient->NotifyChange( aDelay , iStatus ) ;
|
|
348 |
iTask = ENotification ;
|
|
349 |
iTransId = aTransId ;
|
|
350 |
SetActive() ;
|
|
351 |
}
|
|
352 |
|
|
353 |
/**
|
|
354 |
* Gets the details of the event as specified by the input
|
|
355 |
* paramater asynchronously
|
|
356 |
*
|
|
357 |
* @param, Transaction id of this event
|
|
358 |
* @param , Details of the event to be fetched from the database
|
|
359 |
*/
|
|
360 |
void CLogAsyncService :: GetEventL( TUint aTransId, CLogEvent* aEvent )
|
|
361 |
{
|
|
362 |
if( !iUpdatedEvent )
|
|
363 |
{
|
|
364 |
iUpdatedEvent = CLogsEvent :: NewL() ;
|
|
365 |
}
|
|
366 |
|
|
367 |
iUpdatedEvent->SetEvent(*aEvent) ;
|
|
368 |
iLogClient->GetEvent(*(iUpdatedEvent->getEvent()) , iStatus) ;
|
|
369 |
|
|
370 |
if( !iIter )
|
|
371 |
{
|
|
372 |
iIter = CLogIter :: NewL() ;
|
|
373 |
}
|
|
374 |
iTransId = aTransId ;
|
|
375 |
iTask = EGetEvent ;
|
|
376 |
SetActive() ;
|
|
377 |
}
|
|
378 |
|
|
379 |
|