|
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 deligator class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <logwrap.h> |
|
21 #include <logcli.h> |
|
22 #include <logview.h> |
|
23 |
|
24 #include "loggingasyncservice.h" |
|
25 #include "loggingsyncservice.h" |
|
26 #include "loggingevent.h" |
|
27 #include "logiter.h" |
|
28 |
|
29 /** |
|
30 * Default Constructor Method |
|
31 */ |
|
32 |
|
33 CLogSyncService :: CLogSyncService(): CActive(EPriorityStandard) |
|
34 { |
|
35 } |
|
36 |
|
37 |
|
38 /** |
|
39 * Default Destructor |
|
40 */ |
|
41 CLogSyncService :: ~CLogSyncService() |
|
42 { |
|
43 if(this->IsAdded()) |
|
44 { |
|
45 this->Deque() ; |
|
46 } |
|
47 delete iLogViewEvents ; |
|
48 delete iLogViewRecent ; |
|
49 delete iLogClient ; |
|
50 delete iWaitScheduler; |
|
51 iFs.Close() ; |
|
52 } |
|
53 |
|
54 /** |
|
55 * Two phased constructor implementation |
|
56 */ |
|
57 EXPORT_C CLogSyncService* CLogSyncService :: NewL() |
|
58 { |
|
59 CLogSyncService* self = CLogSyncService::NewLC(); |
|
60 CleanupStack::Pop(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 /** |
|
65 * Two phased constructor implementation |
|
66 */ |
|
67 |
|
68 CLogSyncService* CLogSyncService :: NewLC() |
|
69 { |
|
70 CLogSyncService* self = new (ELeave) CLogSyncService(); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 /** |
|
77 * This function constructs the member elements of CLogSyncService Class |
|
78 */ |
|
79 |
|
80 void CLogSyncService :: ConstructL() |
|
81 { |
|
82 User::LeaveIfError(iFs.Connect()); |
|
83 iLogClient = CLogClient::NewL(iFs); |
|
84 iLogViewEvents = CLogViewEvent :: NewL(*iLogClient) ; |
|
85 iLogViewRecent = CLogViewRecent :: NewL(*iLogClient) ; |
|
86 iTaskId = -1 ; |
|
87 iWaitScheduler = new CActiveSchedulerWait(); |
|
88 DoInitialiseL() ; |
|
89 } |
|
90 |
|
91 /** |
|
92 * DoInitialise Method, initalises the members of the class, |
|
93 * and puts the object in ActiveScheduler List |
|
94 */ |
|
95 |
|
96 void CLogSyncService :: DoInitialiseL() |
|
97 { |
|
98 if(!(this->IsAdded())) |
|
99 { |
|
100 CActiveScheduler :: Add (this) ; |
|
101 } |
|
102 } |
|
103 |
|
104 /** |
|
105 * RunL method implementation |
|
106 */ |
|
107 void CLogSyncService :: RunL() |
|
108 { |
|
109 iWaitScheduler->AsyncStop(); |
|
110 } |
|
111 |
|
112 /** |
|
113 * DoCancel Implementation |
|
114 */ |
|
115 void CLogSyncService :: DoCancel() |
|
116 { |
|
117 ; |
|
118 } |
|
119 |
|
120 /** |
|
121 * Reads recent events from the event database |
|
122 * |
|
123 * @param aRecentList, recent event list |
|
124 * @param aFilter, filter for events to appear in the view |
|
125 * returns the ownership handle to Recentevents in the iter |
|
126 */ |
|
127 CLogIter* CLogSyncService :: ReadRecentEventsL( TLogRecentList aRecentList , |
|
128 CLogFilter *aFilter ) |
|
129 { |
|
130 CLogIter *iter = CLogIter :: NewL() ; |
|
131 CLogClient *logcli = CLogClient :: NewL(iter->GetRFs()) ; |
|
132 CLogViewRecent *LogViewRecent = CLogViewRecent :: NewL(*logcli) ; |
|
133 |
|
134 iter->SetLogClient(logcli) ; |
|
135 iter->SetLogRecentView(LogViewRecent) ; |
|
136 iter->SetTaskId(EGetRecent) ; |
|
137 |
|
138 if (LogViewRecent->SetRecentListL(aRecentList, *aFilter, iStatus) ) |
|
139 { |
|
140 // set this active object active to get the events |
|
141 // from the main event database, see RunL() |
|
142 SetActive(); |
|
143 iWaitScheduler->Start() ; |
|
144 |
|
145 //Wrap the LogViewRecent in iter and return the ownership to |
|
146 // the consumer |
|
147 iter->SetRecentView(LogViewRecent) ; |
|
148 } |
|
149 else |
|
150 { |
|
151 delete iter ; |
|
152 iter = NULL ; |
|
153 } |
|
154 return iter ; |
|
155 |
|
156 } |
|
157 |
|
158 |
|
159 /** |
|
160 * Adds a new event to the event database |
|
161 * @param aEvent: Details of the event to be added to the event database |
|
162 */ |
|
163 EXPORT_C TLogId CLogSyncService :: AddL( CLogEvent* aEvent ) |
|
164 { |
|
165 iLogClient->AddEvent( *aEvent , iStatus ) ; |
|
166 SetActive() ; |
|
167 iWaitScheduler->Start() ; |
|
168 |
|
169 if( iStatus.Int() != KRequestPending ) |
|
170 { |
|
171 return aEvent->Id() ; |
|
172 } |
|
173 return iStatus.Int() ; |
|
174 } |
|
175 |
|
176 |
|
177 /** |
|
178 * Deletes a event from the event database |
|
179 * @param aLogId Event id of the event in the database |
|
180 */ |
|
181 EXPORT_C TInt CLogSyncService :: Delete( TLogId aLogId ) |
|
182 { |
|
183 if( aLogId > 0 ) |
|
184 { |
|
185 iLogClient->DeleteEvent(aLogId , iStatus) ; |
|
186 } |
|
187 else |
|
188 { |
|
189 return KErrNotFound; |
|
190 } |
|
191 |
|
192 SetActive() ; |
|
193 iWaitScheduler->Start(); |
|
194 return iStatus.Int() ; |
|
195 } |
|
196 |
|
197 /** |
|
198 * GetList(): Gets the events as specified by filter |
|
199 * |
|
200 * @param aFilter, view filter |
|
201 * Returns the ownership of the iterator for the getlist |
|
202 * result containing the handle to LogviewEvents. |
|
203 */ |
|
204 EXPORT_C CLogIter* CLogSyncService :: GetListL( CLogFilter *aFilter ) |
|
205 { |
|
206 |
|
207 CLogIter *iter = CLogIter :: NewL() ; |
|
208 CLogClient *cli = CLogClient :: NewL(iter->GetRFs()) ; |
|
209 CLogViewEvent* LogviewEvents = CLogViewEvent :: NewL(*cli) ; |
|
210 |
|
211 iter->SetLogClient(cli) ; |
|
212 iter->SetLogViewEvents(LogviewEvents) ; |
|
213 //LogviewEvents->SetFilterL(*aFilter , iStatus) ; |
|
214 iter->SetTaskId(EReadEvents) ; |
|
215 |
|
216 if(LogviewEvents->SetFilterL(*aFilter , iStatus)) |
|
217 { |
|
218 SetActive() ; |
|
219 iWaitScheduler->Start(); |
|
220 iter->SetLogViewEvents(LogviewEvents); |
|
221 return iter ; |
|
222 } |
|
223 else |
|
224 { |
|
225 delete iter; |
|
226 return NULL; |
|
227 } |
|
228 } |
|
229 |
|
230 /** |
|
231 * Gets the details of the event as specified by the |
|
232 * input paramater |
|
233 * |
|
234 * @param aEvent, details of the event to be fetched |
|
235 * returns the owner ship of the iter to the consumer |
|
236 */ |
|
237 CLogIter* CLogSyncService :: GetEventL( CLogEvent *aEvent ) |
|
238 { |
|
239 CLogIter *iter = CLogIter :: NewL() ; |
|
240 |
|
241 iter->SetTaskId(EGetEvent) ; |
|
242 CLogClient *cli = CLogClient :: NewL(iter->GetRFs()) ; |
|
243 iter->SetLogClient(cli) ; |
|
244 cli->GetEvent(*aEvent , iStatus) ; |
|
245 SetActive() ; |
|
246 iWaitScheduler->Start(); |
|
247 |
|
248 if(iStatus.Int() != KErrNone) |
|
249 { |
|
250 delete iter ; |
|
251 return NULL ; |
|
252 } |
|
253 return iter ; |
|
254 } |
|
255 |
|
256 |
|
257 |