|
1 /** |
|
2 * ==================================================================== |
|
3 * logengine.cpp |
|
4 * Copyright (c) 2006-2007 Nokia Corporation |
|
5 * |
|
6 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
7 * you may not use this file except in compliance with the License. |
|
8 * You may obtain a copy of the License at |
|
9 * |
|
10 * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 * |
|
12 * Unless required by applicable law or agreed to in writing, software |
|
13 * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 * See the License for the specific language governing permissions and |
|
16 * limitations under the License. |
|
17 * ==================================================================== |
|
18 */ |
|
19 // |
|
20 #include "logengine.h" |
|
21 // |
|
22 // |
|
23 // |
|
24 CLogEngine::CLogEngine(CEventArray& aEventArray) : CActive(CActive::EPriorityStandard), iEventArray(aEventArray) |
|
25 { |
|
26 // |
|
27 } |
|
28 void CLogEngine::ConstructL(TInt aDirection, TUid aType) |
|
29 { |
|
30 // |
|
31 //Connect to the file server. |
|
32 User::LeaveIfError(iFs.Connect()); |
|
33 //Check if Log Engine available - |
|
34 //NOTE: potentially dangerous if CLogWrapper closes the RFs? |
|
35 CLogWrapper* iLogWrapper = CLogWrapper::NewL(iFs, 0); |
|
36 if (!iLogWrapper->ClientAvailable()) |
|
37 { |
|
38 //Get out... as the Log API is not supported. |
|
39 User::Leave(KErrNotSupported); |
|
40 } |
|
41 delete iLogWrapper; |
|
42 //Setup LOG elements. |
|
43 iLogClient = CLogClient::NewL(iFs); |
|
44 iLogView = CLogViewEvent::NewL(*iLogClient); |
|
45 iLogFilter = CLogFilter::NewL(); |
|
46 //Setup filter (call logs handled by default). |
|
47 SetLogFilter(aDirection, aType); |
|
48 //Create active scheduler waiting. |
|
49 iWait = new (ELeave) CActiveSchedulerWait; |
|
50 //Add to the active scheduler |
|
51 CActiveScheduler::Add(this); |
|
52 } |
|
53 CLogEngine* CLogEngine::NewL(CEventArray& aEventArray, TInt aDirection, TUid aType) |
|
54 { |
|
55 // |
|
56 CLogEngine* self = CLogEngine::NewLC(aEventArray, aDirection, aType); |
|
57 CleanupStack::Pop(self); |
|
58 return self; |
|
59 } |
|
60 CLogEngine* CLogEngine::NewLC(CEventArray& aEventArray, TInt aDirection, TUid aType) |
|
61 { |
|
62 // |
|
63 CLogEngine* self = new (ELeave) CLogEngine(aEventArray); |
|
64 CleanupStack::PushL(self); |
|
65 self->ConstructL(aDirection, aType); |
|
66 return self; |
|
67 } |
|
68 CLogEngine::~CLogEngine() |
|
69 { |
|
70 // |
|
71 //Cancel all outstanding active object calls. |
|
72 Cancel(); |
|
73 // |
|
74 if (iWait) { delete iWait; } |
|
75 if (iLogView) { delete iLogView; } |
|
76 if (iLogClient) { delete iLogClient; } |
|
77 if (iLogFilter) { delete iLogFilter; } |
|
78 |
|
79 iFs.Close(); |
|
80 } |
|
81 void CLogEngine::SetLogFilter(TInt aDirection, TUid aType) |
|
82 { |
|
83 // Find from the log engine, the string for the given direction resource |
|
84 TBuf<64> direction; |
|
85 iLogClient->GetString(direction, aDirection); |
|
86 // Set the direction to be filtered |
|
87 iLogFilter->SetDirection(direction); |
|
88 iLogFilter->SetEventType(aType); |
|
89 } |
|
90 void CLogEngine::StartL() |
|
91 { |
|
92 // |
|
93 if (iLogView->SetFilterL(*iLogFilter, iStatus)) |
|
94 { |
|
95 // if there are events in the filtered view |
|
96 // issue the asynchronous request |
|
97 SetActive(); |
|
98 //Wait for the last log entry. |
|
99 iWait->Start(); |
|
100 } |
|
101 //Change state. |
|
102 iEngineState = ECreate; |
|
103 } |
|
104 void CLogEngine::DoCancel() |
|
105 { |
|
106 //Stop waiting for the result. |
|
107 iWait->AsyncStop(); |
|
108 } |
|
109 void CLogEngine::RunL() |
|
110 { |
|
111 // |
|
112 if (iStatus != KErrNone) |
|
113 { |
|
114 // if there has been a problem inform the observer. |
|
115 iWait->AsyncStop(); |
|
116 return; |
|
117 } |
|
118 // |
|
119 switch (iEngineState) |
|
120 { |
|
121 case ECreate: |
|
122 { |
|
123 // The filtered view has been successfully created |
|
124 // so issue a request to go to the first event |
|
125 iLogView->FirstL(iStatus); |
|
126 if (iLogView->CountL() > 0) |
|
127 { |
|
128 iEngineState = EAddEntry; |
|
129 SetActive(); |
|
130 } |
|
131 else |
|
132 { |
|
133 //Done as the initially logs were cleared... |
|
134 Cancel(); |
|
135 iWait->AsyncStop(); |
|
136 } |
|
137 break; |
|
138 } |
|
139 case EAddEntry: |
|
140 { |
|
141 // Add the current event to the array of events |
|
142 const CLogEvent& event = iLogView->Event(); |
|
143 iEventArray.AddEntryL(event); |
|
144 // Are there any more entries |
|
145 if (iLogView->NextL(iStatus)) |
|
146 { |
|
147 // if there is another entry, issue the request |
|
148 // to move to the next entry. |
|
149 SetActive(); |
|
150 } |
|
151 else |
|
152 { |
|
153 // |
|
154 Cancel(); |
|
155 iWait->AsyncStop(); |
|
156 } |
|
157 break; |
|
158 } |
|
159 default: |
|
160 break; |
|
161 } |
|
162 } |
|
163 TInt CLogEngine::RunError(TInt aError) |
|
164 { |
|
165 // |
|
166 iWait->AsyncStop(); |
|
167 return aError; |
|
168 } |