|
1 /* |
|
2 * Copyright (c) 2002 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 "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: |
|
15 * Messaging Centre application's engine class that reads events from |
|
16 * log DB. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 |
|
24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
25 #include <logfilterandeventconstants.hrh> |
|
26 #endif |
|
27 #include <coemain.h> // for CCoeEnv |
|
28 #include <logview.h> // CLogViewEvent |
|
29 #include "DllMain.h" // panic function |
|
30 #include "MceLogEngineReader.h" |
|
31 #include <LogsApiConsts.h> |
|
32 |
|
33 // ================= MEMBER FUNCTIONS ======================= |
|
34 |
|
35 CMceLogEngineReader::CMceLogEngineReader( |
|
36 CMceLogEngine* aObserver) |
|
37 : CActive(EPriorityStandard), |
|
38 iObserver(aObserver) |
|
39 { |
|
40 } |
|
41 |
|
42 CMceLogEngineReader* CMceLogEngineReader::NewL( |
|
43 CMceLogEngine* aObserver) |
|
44 { |
|
45 CMceLogEngineReader* self = new (ELeave) CMceLogEngineReader(aObserver); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop(); |
|
49 return self; |
|
50 } |
|
51 |
|
52 void CMceLogEngineReader::ConstructL() |
|
53 { |
|
54 User::LeaveIfError(iFsSession.Connect()); |
|
55 iLogClient = CLogClient::NewL(iFsSession); |
|
56 iLogViewEvent = CLogViewEvent::NewL(*iLogClient, *this); |
|
57 SetSpecialFilterL(); |
|
58 CActiveScheduler::Add(this); |
|
59 } |
|
60 |
|
61 CMceLogEngineReader::~CMceLogEngineReader() |
|
62 { |
|
63 Cancel(); |
|
64 |
|
65 delete iLogViewEvent; |
|
66 delete iLogClient; |
|
67 |
|
68 iFsSession.Close(); |
|
69 |
|
70 if (iFilterList) |
|
71 { |
|
72 iFilterList->ResetAndDestroy(); |
|
73 delete iFilterList; |
|
74 } |
|
75 } |
|
76 |
|
77 |
|
78 void CMceLogEngineReader::StartReadingL() |
|
79 { |
|
80 Cancel(); |
|
81 iEventCounter = 0; |
|
82 iEventsInView = 0; |
|
83 iArrayReset = EFalse; |
|
84 |
|
85 if( iLogViewEvent->SetFilterL(*iFilterList, iStatus) ) |
|
86 { |
|
87 iReaderState = ESettingFilter; |
|
88 SetActive(); |
|
89 } |
|
90 else if( iObserver ) |
|
91 { |
|
92 iObserver->ResetArray(); |
|
93 iObserver->ReadEventsCompletedL(); |
|
94 } |
|
95 } |
|
96 |
|
97 |
|
98 void CMceLogEngineReader::DoCancel() |
|
99 { |
|
100 /// cancel filter setting or event reading |
|
101 iLogViewEvent->Cancel(); |
|
102 } |
|
103 |
|
104 TInt CMceLogEngineReader::RunError(TInt aError) |
|
105 { |
|
106 if( aError == KErrAccessDenied ) |
|
107 { |
|
108 return KErrNone; |
|
109 } |
|
110 else |
|
111 { |
|
112 return aError; |
|
113 } |
|
114 } |
|
115 |
|
116 |
|
117 void CMceLogEngineReader::RunL() |
|
118 { |
|
119 CLogEvent* event; |
|
120 |
|
121 if (iStatus != KErrNone) |
|
122 { |
|
123 // reading entries failed somehow. |
|
124 iObserver->ReadEventsCompletedL( EFalse ); |
|
125 } |
|
126 else |
|
127 { |
|
128 switch (iReaderState) |
|
129 { |
|
130 /// filter setting asyncronous request completed |
|
131 case ESettingFilter: |
|
132 |
|
133 if (iLogViewEvent->CountL() == 0) |
|
134 { |
|
135 iObserver->ResetArray(); |
|
136 iObserver->ReadEventsCompletedL(); |
|
137 } |
|
138 else |
|
139 { |
|
140 /// start first event reading asyncronous request |
|
141 iReaderState = EReadingEntry; |
|
142 iLogViewEvent->FirstL(iStatus); |
|
143 SetActive(); |
|
144 } |
|
145 break; |
|
146 |
|
147 /// event reading asyncronous request completed |
|
148 case EReadingEntry: |
|
149 |
|
150 if( ! iArrayReset ) |
|
151 { |
|
152 iArrayReset = ETrue; |
|
153 iObserver->ResetArray(); |
|
154 } |
|
155 |
|
156 event = CLogEvent::NewL(); |
|
157 CleanupStack::PushL( event ); |
|
158 event->CopyL(iLogViewEvent->Event()); |
|
159 |
|
160 iEventsInView++; |
|
161 |
|
162 if( event->Number().Length() || event->RemoteParty().Length() ) |
|
163 { |
|
164 iObserver->AddEventToListL( event ); |
|
165 CleanupStack::Pop(); // event |
|
166 iEventCounter++; |
|
167 } |
|
168 else |
|
169 { |
|
170 CleanupStack::PopAndDestroy(); // event |
|
171 } |
|
172 |
|
173 if ( iEventsInView < iLogViewEvent->CountL() && |
|
174 iEventCounter < KMceLogEngFetchLimit ) |
|
175 { |
|
176 /// read next event |
|
177 iLogViewEvent->NextL( iStatus ); |
|
178 SetActive(); |
|
179 } |
|
180 else |
|
181 { |
|
182 /// inform observer, that reading is done |
|
183 iObserver->ReadEventsCompletedL(); |
|
184 } |
|
185 break; |
|
186 |
|
187 default: |
|
188 break; |
|
189 |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 |
|
195 void CMceLogEngineReader::SetSpecialFilterL() |
|
196 { |
|
197 /// create filter array to pass through only |
|
198 /// events needed in Delivery Report |
|
199 |
|
200 CLogFilter* filter; |
|
201 |
|
202 if( iFilterList ) |
|
203 { |
|
204 iFilterList->ResetAndDestroy(); |
|
205 delete iFilterList; |
|
206 iFilterList = NULL; |
|
207 } |
|
208 iFilterList = new (ELeave) CLogFilterList(); |
|
209 |
|
210 /// Direction: OUT |
|
211 TLogString inOutName; |
|
212 iLogClient->GetString(inOutName, R_LOG_DIR_OUT); |
|
213 filter = CLogFilter::NewL(); |
|
214 CleanupStack::PushL( filter ); |
|
215 filter->SetDirection(inOutName); |
|
216 filter->SetFlags( KLogEventRead ); |
|
217 filter->SetNullFields( ELogFlagsField ); |
|
218 iFilterList->AppendL(filter); |
|
219 CleanupStack::Pop(); //filter |
|
220 |
|
221 /// Event Type: SMS |
|
222 filter = CLogFilter::NewL(); |
|
223 CleanupStack::PushL( filter ); |
|
224 filter->SetEventType(KLogShortMessageEventTypeUid); |
|
225 iFilterList->AppendL(filter); |
|
226 CleanupStack::Pop(); //filter |
|
227 |
|
228 /// Event Type: MMS |
|
229 filter = CLogFilter::NewL(); |
|
230 CleanupStack::PushL( filter ); |
|
231 filter->SetEventType( KLogsEngMmsEventTypeUid ); |
|
232 iFilterList->AppendL(filter); |
|
233 CleanupStack::Pop(); //filter |
|
234 |
|
235 /// Status: Pending |
|
236 TLogString pending; |
|
237 iLogClient->GetString(pending, R_LOG_DEL_PENDING); |
|
238 filter = CLogFilter::NewL(); |
|
239 CleanupStack::PushL( filter ); |
|
240 filter->SetStatus( pending ); |
|
241 iFilterList->AppendL(filter); |
|
242 CleanupStack::Pop(); //filter |
|
243 |
|
244 /// Status: Delivered |
|
245 TLogString done; |
|
246 iLogClient->GetString(done, R_LOG_DEL_DONE); |
|
247 filter = CLogFilter::NewL(); |
|
248 CleanupStack::PushL( filter ); |
|
249 filter->SetStatus( done ); |
|
250 iFilterList->AppendL(filter); |
|
251 CleanupStack::Pop(); //filter |
|
252 |
|
253 /// Status: Failed |
|
254 TLogString failed; |
|
255 iLogClient->GetString(failed, R_LOG_DEL_FAILED); |
|
256 filter = CLogFilter::NewL(); |
|
257 CleanupStack::PushL( filter ); |
|
258 filter->SetStatus( failed ); |
|
259 iFilterList->AppendL(filter); |
|
260 CleanupStack::Pop(); //filter |
|
261 |
|
262 /// Event Type: MMS |
|
263 /// Status: Read |
|
264 filter = CLogFilter::NewL(); |
|
265 CleanupStack::PushL( filter ); |
|
266 filter->SetEventType( KLogsEngMmsEventTypeUid ); |
|
267 filter->SetStatus( KLogsMsgReadText ); |
|
268 iFilterList->AppendL( filter ); |
|
269 CleanupStack::Pop(); //filter |
|
270 |
|
271 } |
|
272 |
|
273 void CMceLogEngineReader::HandleLogViewChangeEventAddedL( |
|
274 TLogId /*aId*/, |
|
275 TInt /*aViewIndex*/, |
|
276 TInt /*aChangeIndex*/, |
|
277 TInt /*aTotalChangeCount*/ ) |
|
278 { |
|
279 StartReadingL(); |
|
280 } |
|
281 |
|
282 void CMceLogEngineReader::HandleLogViewChangeEventChangedL( |
|
283 TLogId /*aId*/, |
|
284 TInt /*aViewIndex*/, |
|
285 TInt /*aChangeIndex*/, |
|
286 TInt /*aTotalChangeCount*/ ) |
|
287 { |
|
288 StartReadingL(); |
|
289 } |
|
290 |
|
291 void CMceLogEngineReader::HandleLogViewChangeEventDeletedL( |
|
292 TLogId /*aId*/, |
|
293 TInt /*aViewIndex*/, |
|
294 TInt /*aChangeIndex*/, |
|
295 TInt /*aTotalChangeCount*/ ) |
|
296 { |
|
297 StartReadingL(); |
|
298 } |
|
299 |
|
300 void CMceLogEngineReader::ClearDrListL() |
|
301 { |
|
302 __ASSERT_DEBUG( iLogViewEvent, LogsEnginePanic( ELogsEnginePanicPreCond ) ); |
|
303 iLogViewEvent->SetFlagsL( KLogEventRead ); |
|
304 StartReadingL(); |
|
305 } |
|
306 |
|
307 // End of file |