66
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: missed alarm store class description
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
//Include files
|
|
21 |
|
|
22 |
#include "missedalarmstore.h"
|
|
23 |
#include "missedalarm.h"
|
|
24 |
#include "missedalarmstoreconstants.h"
|
|
25 |
#include "alarmenginesdebug.h"
|
|
26 |
|
|
27 |
// ----------------------------------------------------------------------------
|
|
28 |
// CMissedAlarmStore::NewLc
|
|
29 |
// 1st phase of construction
|
|
30 |
// ----------------------------------------------------------------------------
|
|
31 |
//
|
|
32 |
EXPORT_C CMissedAlarmStore* CMissedAlarmStore::NewLC()
|
|
33 |
{
|
|
34 |
TRACE_ENTRY_POINT;
|
|
35 |
|
|
36 |
CMissedAlarmStore* self = new (ELeave) CMissedAlarmStore();
|
|
37 |
CleanupStack::PushL(self);
|
|
38 |
|
|
39 |
TRACE_EXIT_POINT;
|
|
40 |
return self;
|
|
41 |
}
|
|
42 |
|
|
43 |
// ----------------------------------------------------------------------------
|
|
44 |
// CMissedAlarmStore::NewL
|
|
45 |
// 1st phase of construction
|
|
46 |
// ----------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
EXPORT_C CMissedAlarmStore* CMissedAlarmStore::NewL(CRepository& aRepository)
|
|
49 |
{
|
|
50 |
TRACE_ENTRY_POINT;
|
|
51 |
|
|
52 |
CMissedAlarmStore* self=new (ELeave) CMissedAlarmStore(aRepository);
|
|
53 |
CleanupStack::PushL(self);
|
|
54 |
self->ConstructL();
|
|
55 |
CleanupStack::Pop(self);
|
|
56 |
|
|
57 |
TRACE_EXIT_POINT;
|
|
58 |
return self;
|
|
59 |
}
|
|
60 |
|
|
61 |
// ----------------------------------------------------------------------------
|
|
62 |
// CMissedAlarmStore::~CMissedAlarmStore
|
|
63 |
// Class destructor.Frees all resources used by this class
|
|
64 |
// ----------------------------------------------------------------------------
|
|
65 |
CMissedAlarmStore::~CMissedAlarmStore()
|
|
66 |
{
|
|
67 |
TRACE_ENTRY_POINT;
|
|
68 |
|
|
69 |
if(iRepository)
|
|
70 |
{
|
|
71 |
delete iRepository;
|
|
72 |
iRepository = NULL;
|
|
73 |
}
|
|
74 |
|
|
75 |
TRACE_EXIT_POINT;
|
|
76 |
}
|
|
77 |
|
|
78 |
// ----------------------------------------------------------------------------
|
|
79 |
// CMissedAlarmStore::CMissedAlarmStore
|
|
80 |
// Default constructor
|
|
81 |
// ----------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
CMissedAlarmStore::CMissedAlarmStore()
|
|
84 |
{
|
|
85 |
TRACE_ENTRY_POINT;
|
|
86 |
|
|
87 |
TRAP_IGNORE(iRepository = CRepository::NewL(KUidRepository));
|
|
88 |
|
|
89 |
TRACE_EXIT_POINT;
|
|
90 |
}
|
|
91 |
|
|
92 |
// ----------------------------------------------------------------------------
|
|
93 |
// CMissedAlarmStore::CMissedAlarmStore
|
|
94 |
// Default constructor
|
|
95 |
// ----------------------------------------------------------------------------
|
|
96 |
//
|
|
97 |
CMissedAlarmStore::CMissedAlarmStore(CRepository& aRepository)
|
|
98 |
: iRepository(&aRepository)
|
|
99 |
{
|
|
100 |
TRACE_ENTRY_POINT;
|
|
101 |
TRACE_EXIT_POINT;
|
|
102 |
}
|
|
103 |
|
|
104 |
// ----------------------------------------------------------------------------
|
|
105 |
// CMissedAlarmStore::ConstructL
|
|
106 |
// Second stage constructor
|
|
107 |
// ----------------------------------------------------------------------------
|
|
108 |
//
|
|
109 |
void CMissedAlarmStore::ConstructL()
|
|
110 |
{
|
|
111 |
TRACE_ENTRY_POINT;
|
|
112 |
TRACE_EXIT_POINT;
|
|
113 |
}
|
|
114 |
|
|
115 |
// ----------------------------------------------------------------------------
|
|
116 |
// CMissedAlarmStore::AddL
|
|
117 |
// Add the list of CMissedAlarm in the Central Repository.
|
|
118 |
// ----------------------------------------------------------------------------
|
|
119 |
//
|
|
120 |
EXPORT_C void CMissedAlarmStore::AddL(RPointerArray<CMissedAlarm>& aMissedAlarmList)
|
|
121 |
{
|
|
122 |
TRACE_ENTRY_POINT;
|
|
123 |
|
|
124 |
TUint count = aMissedAlarmList.Count();
|
|
125 |
for( TUint i = 0; i < count; i++)
|
|
126 |
{
|
|
127 |
CMissedAlarm& missedalarm = *(aMissedAlarmList[i]);
|
|
128 |
SetL( missedalarm.iLuid, missedalarm.iInstanceTime, missedalarm.iCalFileName );
|
|
129 |
}
|
|
130 |
|
|
131 |
TRACE_EXIT_POINT;
|
|
132 |
}
|
|
133 |
|
|
134 |
// ----------------------------------------------------------------------------
|
|
135 |
// CMissedAlarmStore::GetL
|
|
136 |
// Gets the list of CMissedAlarm from the Central Repository.
|
|
137 |
// ----------------------------------------------------------------------------
|
|
138 |
//
|
|
139 |
EXPORT_C void CMissedAlarmStore::GetL(RPointerArray<CMissedAlarm> &aArray)
|
|
140 |
{
|
|
141 |
TRACE_ENTRY_POINT;
|
|
142 |
|
|
143 |
RArray<TUint32> foundIds;
|
|
144 |
TUint32 key;
|
|
145 |
TInt err = 0;
|
|
146 |
CMissedAlarm *missedalarm = NULL;
|
|
147 |
TReal instanceTime;
|
|
148 |
TInt luid;
|
|
149 |
TBuf<256> calFileName;
|
|
150 |
err = iRepository->FindL( KLuidPartialKey, KLuidMask, foundIds);
|
|
151 |
|
|
152 |
TUint count = foundIds.Count();
|
|
153 |
if( count && KErrNone == err)
|
|
154 |
{
|
|
155 |
for(TUint32 i =0; i < count; i++)
|
|
156 |
{
|
|
157 |
key = foundIds[i];
|
|
158 |
err = iRepository->Get( key, luid);
|
|
159 |
if( KErrNone == err )
|
|
160 |
{
|
|
161 |
err = iRepository->Get( key | KTTimeShift, instanceTime );
|
|
162 |
if( KErrNone == err )
|
|
163 |
{
|
|
164 |
err = iRepository->Get( key | KCalFileNameShift, calFileName );
|
|
165 |
if( KErrNone == err )
|
|
166 |
{
|
|
167 |
missedalarm = CMissedAlarm::NewL( luid,
|
|
168 |
TTime(TInt64(instanceTime)), calFileName );
|
|
169 |
CleanupStack::PushL( missedalarm );
|
|
170 |
aArray.Append( missedalarm );
|
|
171 |
CleanupStack::Pop(missedalarm );
|
|
172 |
}
|
|
173 |
}
|
|
174 |
}
|
|
175 |
}
|
|
176 |
}
|
|
177 |
foundIds.Reset();
|
|
178 |
TRACE_EXIT_POINT;
|
|
179 |
}
|
|
180 |
|
|
181 |
// ----------------------------------------------------------------------------
|
|
182 |
// CMissedAlarmStore::RemoveAllL
|
|
183 |
// Removes all the entries from the central repository.
|
|
184 |
// ----------------------------------------------------------------------------
|
|
185 |
//
|
|
186 |
EXPORT_C void CMissedAlarmStore::RemoveAllL()
|
|
187 |
{
|
|
188 |
TRACE_ENTRY_POINT;
|
|
189 |
|
|
190 |
RArray<TUint32> foundIds;
|
|
191 |
TUint32 key;
|
|
192 |
TInt err = 0;
|
|
193 |
err = iRepository->FindL( KLuidPartialKey, KLuidMask, foundIds);
|
|
194 |
|
|
195 |
TUint count = foundIds.Count();
|
|
196 |
if( count && KErrNone == err)
|
|
197 |
{
|
|
198 |
for(TInt i =0; i < count; i++)
|
|
199 |
{
|
|
200 |
key = foundIds[i];
|
|
201 |
iRepository->Delete(key);
|
|
202 |
iRepository->Delete(key | KTTimeShift);
|
|
203 |
iRepository->Delete(key | KCalFileNameShift);
|
|
204 |
}
|
|
205 |
}
|
|
206 |
foundIds.Reset();
|
|
207 |
|
|
208 |
TRACE_EXIT_POINT;
|
|
209 |
}
|
|
210 |
|
|
211 |
// ----------------------------------------------------------------------------
|
|
212 |
// CMissedAlarmStore::RemoveL
|
|
213 |
// Removes an entry from the central repository.
|
|
214 |
// ----------------------------------------------------------------------------
|
|
215 |
//
|
|
216 |
EXPORT_C void CMissedAlarmStore::RemoveL( CMissedAlarm& aMissedAlarm )
|
|
217 |
{
|
|
218 |
TRACE_ENTRY_POINT;
|
|
219 |
|
|
220 |
RArray<TUint32> foundIds;
|
|
221 |
TUint32 key;
|
|
222 |
TInt err = 0;
|
|
223 |
err = iRepository->FindEqL( KLuidPartialKey, KLuidMask,
|
|
224 |
aMissedAlarm.iLuid, foundIds );
|
|
225 |
|
|
226 |
TUint count = foundIds.Count();
|
|
227 |
TBool remAllLUids = EFalse;
|
|
228 |
if( count && KErrNone == err)
|
|
229 |
{
|
|
230 |
TReal instTime;
|
|
231 |
TReal aInstTime = TReal( (aMissedAlarm.iInstanceTime).Int64());
|
|
232 |
TBuf<256> calFileName;
|
|
233 |
for( TUint j = 0; j < count; j++ )
|
|
234 |
{
|
|
235 |
key = foundIds[j];
|
|
236 |
err = iRepository->Get( key | KTTimeShift, instTime );
|
|
237 |
|
|
238 |
if( remAllLUids ||
|
|
239 |
( KErrNone == err && aInstTime == instTime ))
|
|
240 |
{
|
|
241 |
err = iRepository->Get( key | KCalFileNameShift, calFileName );
|
|
242 |
if( KErrNone == err && !aMissedAlarm.iCalFileName.CompareF( calFileName ) )
|
|
243 |
{
|
|
244 |
DeleteEntryAndReArrangeL( key );
|
|
245 |
foundIds.Reset();
|
|
246 |
return;
|
|
247 |
}
|
|
248 |
}
|
|
249 |
}
|
|
250 |
}
|
|
251 |
foundIds.Reset();
|
|
252 |
|
|
253 |
TRACE_EXIT_POINT;
|
|
254 |
}
|
|
255 |
|
|
256 |
// ----------------------------------------------------------------------------
|
|
257 |
// CMissedAlarmStore::CountL
|
|
258 |
// Counts the number of entries in the central repository.
|
|
259 |
// ----------------------------------------------------------------------------
|
|
260 |
//
|
|
261 |
EXPORT_C void CMissedAlarmStore::CountL(TUint32 &aCount)
|
|
262 |
{
|
|
263 |
TRACE_ENTRY_POINT;
|
|
264 |
|
|
265 |
RArray<TUint32> foundIds;
|
|
266 |
TInt err = 0;
|
|
267 |
err = iRepository->FindL( KLuidPartialKey, KLuidMask, foundIds);
|
|
268 |
|
|
269 |
if( KErrAbort == err || KErrPermissionDenied == err )
|
|
270 |
{
|
|
271 |
User::Leave( err );
|
|
272 |
}
|
|
273 |
|
|
274 |
aCount = foundIds.Count();
|
|
275 |
foundIds.Reset();
|
|
276 |
|
|
277 |
TRACE_EXIT_POINT;
|
|
278 |
}
|
|
279 |
|
|
280 |
// ----------------------------------------------------------------------------
|
|
281 |
// CMissedAlarmStore::SetL
|
|
282 |
// Add the single entry in the Central Repository.
|
|
283 |
// ----------------------------------------------------------------------------
|
|
284 |
//
|
|
285 |
void CMissedAlarmStore::SetL( const TInt aLuid, const TTime aInstanceTime, const TDesC& aCalFileName)
|
|
286 |
{
|
|
287 |
TRACE_ENTRY_POINT;
|
|
288 |
|
|
289 |
TUint32 keyId;
|
|
290 |
RArray<TUint32> foundIds;
|
|
291 |
TInt err = 0;
|
|
292 |
err = iRepository->FindEqL( KLuidPartialKey, KLuidMask, aLuid, foundIds );
|
|
293 |
|
|
294 |
TUint32 count = foundIds.Count();
|
|
295 |
TReal istTime;
|
|
296 |
TBuf<256> calFileName;
|
|
297 |
|
|
298 |
for( TUint32 j = 0; j < count; j++ )
|
|
299 |
{
|
|
300 |
TUint32 val = foundIds[j];
|
|
301 |
err = iRepository->Get( foundIds[j] | KTTimeShift, istTime );
|
|
302 |
if( KErrNone == err && TReal( aInstanceTime.Int64()) == istTime )
|
|
303 |
{
|
|
304 |
err = iRepository->Get( foundIds[j] | KCalFileNameShift, calFileName );
|
|
305 |
if( KErrNone == err && !calFileName.CompareF( aCalFileName ) )
|
|
306 |
{
|
|
307 |
//entryexists = ETrue;
|
|
308 |
foundIds.Reset();
|
|
309 |
return;
|
|
310 |
}
|
|
311 |
}
|
|
312 |
}
|
|
313 |
foundIds.Reset();
|
|
314 |
|
|
315 |
CountL(count);
|
|
316 |
TUint32 key = count;
|
|
317 |
if( count >= KMaxKeys )
|
|
318 |
{
|
|
319 |
DeleteEntryAndReArrangeL(0);
|
|
320 |
key = KMaxKeys - 1;
|
|
321 |
}
|
|
322 |
|
|
323 |
// Begin read write transaction
|
|
324 |
err = iRepository->StartTransaction(CRepository::EReadWriteTransaction);
|
|
325 |
|
|
326 |
// perform some write operations
|
|
327 |
err = iRepository->Create(key, aLuid);
|
|
328 |
|
|
329 |
err = iRepository->Create(key | KTTimeShift, TReal( aInstanceTime.Int64()) );
|
|
330 |
|
|
331 |
err = iRepository->Create(key | KCalFileNameShift, aCalFileName );
|
|
332 |
|
|
333 |
err = iRepository->CommitTransaction( keyId );
|
|
334 |
if (err != KErrNone)
|
|
335 |
{
|
|
336 |
iRepository->FailTransaction();
|
|
337 |
}
|
|
338 |
|
|
339 |
TRACE_EXIT_POINT;
|
|
340 |
}
|
|
341 |
|
|
342 |
// ----------------------------------------------------------------------------
|
|
343 |
// CMissedAlarmStore::DeleteEntryAndReArrangeL
|
|
344 |
// Delete old entry and insert new entry when the missed alarms count is more
|
|
345 |
// than 10 entries
|
|
346 |
// ----------------------------------------------------------------------------
|
|
347 |
//
|
|
348 |
void CMissedAlarmStore::DeleteEntryAndReArrangeL(TInt aDeletedIndex)
|
|
349 |
{
|
|
350 |
TRACE_ENTRY_POINT;
|
|
351 |
|
|
352 |
TInt err;
|
|
353 |
TUint32 keyInfo;
|
|
354 |
TUint32 count = 0;
|
|
355 |
CountL(count);
|
|
356 |
err = iRepository->StartTransaction(CRepository::EReadWriteTransaction);
|
|
357 |
iRepository->CleanupCancelTransactionPushL();
|
|
358 |
TInt idx = 0;
|
|
359 |
for( idx = aDeletedIndex; idx < KMaxKeys-1 && idx < count-1; idx++ )
|
|
360 |
{
|
|
361 |
// Move the key to the target position
|
|
362 |
iRepository->Delete( idx );
|
|
363 |
iRepository->Delete( idx | KTTimeShift );
|
|
364 |
iRepository->Delete( idx | KCalFileNameShift );
|
|
365 |
err = User::LeaveIfError(iRepository->Move(idx+1, idx, 0xFFFFFFFF, keyInfo));
|
|
366 |
err = User::LeaveIfError(iRepository->Move((idx+1) | KTTimeShift,
|
|
367 |
idx | KTTimeShift, 0xFFFFFFFF, keyInfo));
|
|
368 |
err = User::LeaveIfError(iRepository->Move((idx+1) | KCalFileNameShift,
|
|
369 |
idx | KCalFileNameShift, 0xFFFFFFFF, keyInfo));
|
|
370 |
}
|
|
371 |
iRepository->Delete( idx );
|
|
372 |
iRepository->Delete( idx | KTTimeShift );
|
|
373 |
iRepository->Delete( idx | KCalFileNameShift );
|
|
374 |
CleanupStack::Pop(); // transaction
|
|
375 |
err = iRepository->CommitTransaction(keyInfo);
|
|
376 |
|
|
377 |
User::LeaveIfError(err);
|
|
378 |
|
|
379 |
TRACE_EXIT_POINT;
|
|
380 |
}
|
|
381 |
|
|
382 |
// End of file
|