|
1 /* |
|
2 * Copyright (c) 2007-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 "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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <centralrepository.h> |
|
20 |
|
21 #include "voipeventlogengine.h" |
|
22 #include "voipeventlogconstants.h" |
|
23 #include "voiperrorentry.h" |
|
24 #include "voipeventloglogger.h" // For logging |
|
25 |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // Constructor |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CVoipEventLogEngine::CVoipEventLogEngine() |
|
34 { |
|
35 } |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // Constructor |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 void CVoipEventLogEngine::ConstructL() |
|
43 { |
|
44 VELLOGSTRING( "CVoipEventLogEngine::ConstructL() - IN" ); |
|
45 iRepository = CRepository::NewL( KCRUidVoIPEventLog ); |
|
46 |
|
47 TInt err = iSemaphore.OpenGlobal( KVoIPEventLogSemaphore ); |
|
48 if ( err != KErrNone ) |
|
49 { |
|
50 User::LeaveIfError( iSemaphore.CreateGlobal( KVoIPEventLogSemaphore, 1 ) ); |
|
51 } |
|
52 |
|
53 |
|
54 VELLOGSTRING( "CVoipEventLogEngine::ConstructL() - OUT" ); |
|
55 } |
|
56 |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // Constructor |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CVoipEventLogEngine* CVoipEventLogEngine::NewL() |
|
63 { |
|
64 CVoipEventLogEngine* self = CVoipEventLogEngine::NewLC(); |
|
65 CleanupStack::Pop( self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Constructor |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CVoipEventLogEngine* CVoipEventLogEngine::NewLC() |
|
75 { |
|
76 CVoipEventLogEngine* self = new( ELeave ) CVoipEventLogEngine; |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 return self; |
|
80 } |
|
81 |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // Destructor |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CVoipEventLogEngine::~CVoipEventLogEngine() |
|
88 { |
|
89 VELLOGSTRING( "CVoipEventLogEngine::~CVoipEventLogEngine() - IN" ); |
|
90 |
|
91 delete iRepository; |
|
92 |
|
93 iSemaphore.Close(); |
|
94 |
|
95 VELLOGSTRING( "CVoipEventLogEngine::~CVoipEventLogEngine() - OUT" ); |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // release semaphore, this function is used in custom cleanup |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 void CVoipEventLogEngine::ReleaseSemaphore( TAny* aEngine ) |
|
103 { |
|
104 ASSERT ( aEngine ); |
|
105 CVoipEventLogEngine* engine = static_cast<CVoipEventLogEngine*>( aEngine ); |
|
106 engine->DoReleaseSemaphore(); |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // release semaphore |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 void CVoipEventLogEngine::DoReleaseSemaphore() |
|
114 { |
|
115 iSemaphore.Signal(); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // Begins transaction in repository. |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CVoipEventLogEngine::BeginTransactionLC() |
|
123 { |
|
124 VELLOGSTRING( "CVoipEventLogEngine::BeginTransaction() - IN" ); |
|
125 |
|
126 iSemaphore.Wait(); |
|
127 TCleanupItem cleanup( CVoipEventLogEngine::ReleaseSemaphore, this ); |
|
128 CleanupStack::PushL( cleanup ); |
|
129 |
|
130 User::LeaveIfError( iRepository->StartTransaction( CRepository::EReadWriteTransaction ) ); |
|
131 |
|
132 iRepository->CleanupRollbackTransactionPushL(); // if leave happens, only roll back, no delete |
|
133 |
|
134 VELLOGSTRING( "CVoipEventLogEngine::BeginTransaction() - OUT" ); |
|
135 |
|
136 } |
|
137 |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // Commits changes in repository. |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void CVoipEventLogEngine::CommitTransactionL() |
|
144 { |
|
145 VELLOGSTRING( |
|
146 "CVoipEventLogEngine::CommitTransactionL() - IN" ); |
|
147 |
|
148 TUint32 temp; |
|
149 User::LeaveIfError( iRepository->CommitTransaction( temp ) ); |
|
150 |
|
151 iSemaphore.Signal(); |
|
152 |
|
153 CleanupStack::Pop( 2 ); // semaphore and repository |
|
154 |
|
155 VELLOGSTRING( "CVoipEventLogEngine::CommitTransaction() - OUT" ); |
|
156 |
|
157 } |
|
158 |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // Generate time stamp with current time |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 void CVoipEventLogEngine::GenerateTimeStampL( TDes& aTimeStamp) const |
|
165 { |
|
166 TTime now; |
|
167 now.HomeTime(); |
|
168 now.FormatL( aTimeStamp, KVoIPTimeStampFormat ); |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // Get latest index number |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 TInt CVoipEventLogEngine::GetLatestIndexL() |
|
176 { |
|
177 TInt latestIndex( 0 ); |
|
178 User::LeaveIfError( iRepository->Get( KVELLatestErrorIndexKey, latestIndex ) ); |
|
179 |
|
180 return latestIndex; |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // Get new index number |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 TInt CVoipEventLogEngine::GetNewIndexL() |
|
188 { |
|
189 TInt latestIndex = GetLatestIndexL(); |
|
190 TInt maxCount = GetMaxErrorCountL(); |
|
191 TInt newIndex = latestIndex + 1; |
|
192 if( newIndex >= maxCount ) |
|
193 { |
|
194 newIndex = newIndex - maxCount; |
|
195 } |
|
196 |
|
197 return newIndex; |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // Get maximum error count |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 TInt CVoipEventLogEngine::GetMaxErrorCountL() |
|
205 { |
|
206 TInt count( 0 ); |
|
207 User::LeaveIfError( iRepository->Get( KVELMaxErrorCountKey, count ) ); |
|
208 |
|
209 return count; |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // Writes an error data to event log |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 void CVoipEventLogEngine::WriteErrorL( const CVoipErrorEntry& aErrorEntry ) |
|
217 { |
|
218 if( aErrorEntry.ErrorText().Length() > NCentralRepositoryConstants::KMaxBinaryLength ) |
|
219 { |
|
220 User::Leave( KErrArgument ); |
|
221 } |
|
222 |
|
223 TInt newIndex = GetNewIndexL(); |
|
224 TBuf<KTimeStampStrLen> timeStamp; |
|
225 GenerateTimeStampL( timeStamp ); |
|
226 |
|
227 // error code |
|
228 TUint32 key = newIndex + KSPColumnErrorCode; |
|
229 User::LeaveIfError( iRepository->Set( key, aErrorEntry.ErrorCode() ) ); |
|
230 |
|
231 // error text |
|
232 key += KColumnIncrement; |
|
233 User::LeaveIfError( iRepository->Set( key, aErrorEntry.ErrorText() ) ); |
|
234 |
|
235 // time stamp |
|
236 key += KColumnIncrement; |
|
237 User::LeaveIfError( iRepository->Set( key, timeStamp ) ); |
|
238 |
|
239 // save newIndex to latest index |
|
240 User::LeaveIfError( iRepository->Set( KVELLatestErrorIndexKey, newIndex ) ); |
|
241 |
|
242 // save new count to cenrep |
|
243 TInt count( 0 ); |
|
244 |
|
245 User::LeaveIfError( iRepository->Get( KVELErrorCountKey, count ) ); |
|
246 if( count < GetMaxErrorCountL() ) |
|
247 { |
|
248 count++; |
|
249 User::LeaveIfError( iRepository->Set( KVELErrorCountKey, count ) ); |
|
250 } |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------------------------- |
|
254 // Reads error count from the log |
|
255 // --------------------------------------------------------------------------- |
|
256 // |
|
257 void CVoipEventLogEngine::ErrorCountL( TInt& aCount ) |
|
258 { |
|
259 User::LeaveIfError( iRepository->Get( KVELErrorCountKey, aCount ) ); |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // Reset voip errors log history. |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 TInt CVoipEventLogEngine::ResetLogHistory() |
|
267 { |
|
268 TInt retValue = iRepository->Reset(); |
|
269 return retValue; |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // Reads an error informaiton from the log |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 void CVoipEventLogEngine::ReadErrorL( TInt aIndex, CVoipErrorEntry& aErrorEntry ) |
|
277 { |
|
278 TInt count( 0 ); |
|
279 ErrorCountL( count ); |
|
280 |
|
281 if( aIndex > count - 1 ) |
|
282 { |
|
283 User::Leave( KErrNotFound ); |
|
284 } |
|
285 |
|
286 TInt latestIndex = GetLatestIndexL(); |
|
287 TInt index = latestIndex - aIndex; |
|
288 if( index < 0 ) |
|
289 { |
|
290 index += count; |
|
291 } |
|
292 |
|
293 // error code |
|
294 TUint32 key = index + KSPColumnErrorCode; |
|
295 TInt errorCode; |
|
296 User::LeaveIfError( iRepository->Get( key, errorCode ) ); |
|
297 aErrorEntry.SetErrorCode( errorCode ); |
|
298 |
|
299 // error text |
|
300 HBufC* errorText = HBufC::NewLC( NCentralRepositoryConstants::KMaxBinaryLength ); |
|
301 TPtr ptrErrorText = errorText->Des(); |
|
302 key += KColumnIncrement; |
|
303 User::LeaveIfError( iRepository->Get( key, ptrErrorText ) ); |
|
304 |
|
305 // error timestamp |
|
306 HBufC* timeStamp = HBufC::NewLC( KTimeStampStrLen ); |
|
307 TPtr ptrTimeStamp = timeStamp->Des(); |
|
308 key += KColumnIncrement; |
|
309 User::LeaveIfError( iRepository->Get( key, ptrTimeStamp ) ); |
|
310 |
|
311 // set new data to aErrorEntry |
|
312 User::LeaveIfError( aErrorEntry.SetErrorText( *errorText ) ); |
|
313 User::LeaveIfError( aErrorEntry.SetTimeStamp( *timeStamp ) ); |
|
314 |
|
315 CleanupStack::PopAndDestroy( 2, errorText ); |
|
316 |
|
317 } |
|
318 |