24
|
1 |
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// Implements the classes TSAREntry and CSmsSARStore
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include <e32svr.h>
|
|
23 |
|
|
24 |
#include "gsmustor.h"
|
|
25 |
#include "Gsmumain.h"
|
|
26 |
|
|
27 |
const TDriveNumber KStoreDrive = EDriveC;
|
|
28 |
_LIT(KStoreSubDir, "sms\\");
|
|
29 |
|
|
30 |
|
|
31 |
/**
|
|
32 |
* Utility func for cleanup stack - close the filestore and set pointer to NULL
|
|
33 |
*/
|
|
34 |
void CSARStoreCloseObject(TAny* aObj)
|
|
35 |
{
|
|
36 |
LOGGSMU2("WARNING! Hey, CSARStoreCloseObject called by Untrapper! [0x%08x]", aObj);
|
|
37 |
((CSARStore*)aObj)->Revert();
|
|
38 |
}
|
|
39 |
|
|
40 |
//
|
|
41 |
// implementation of TSAREntry
|
|
42 |
//
|
|
43 |
|
|
44 |
|
|
45 |
/**
|
|
46 |
* Constructor
|
|
47 |
*
|
|
48 |
* @capability None
|
|
49 |
*/
|
|
50 |
EXPORT_C TSAREntry::TSAREntry():
|
|
51 |
iReference(0),
|
|
52 |
iTotal(0),
|
|
53 |
iCount(0),
|
|
54 |
iData1(0),
|
|
55 |
iData2(0),
|
|
56 |
iData3(0),
|
|
57 |
iData4(0),
|
|
58 |
iDataStreamId(KNullStreamId),
|
|
59 |
iFlags(0)
|
|
60 |
{
|
|
61 |
} // TSAREntry::TSAREntry
|
|
62 |
|
|
63 |
|
|
64 |
/**
|
|
65 |
* Internalises the object.
|
|
66 |
*
|
|
67 |
* @param aStream Stream to read from
|
|
68 |
* @capability None
|
|
69 |
*/
|
|
70 |
EXPORT_C void TSAREntry::InternalizeL(RReadStream& aStream)
|
|
71 |
{
|
|
72 |
iReference=aStream.ReadInt32L();
|
|
73 |
iTotal=aStream.ReadInt32L();
|
|
74 |
iCount=aStream.ReadInt32L();
|
|
75 |
iData1=aStream.ReadInt32L();
|
|
76 |
iData2=aStream.ReadInt32L();
|
|
77 |
iData3=aStream.ReadInt32L();
|
|
78 |
iData4=aStream.ReadInt32L();
|
|
79 |
aStream >> iDescription1;
|
|
80 |
aStream >> iDescription2;
|
|
81 |
TInt64 time;
|
|
82 |
aStream >> time;
|
|
83 |
iTime=time;
|
|
84 |
aStream >> iDataStreamId;
|
|
85 |
} // TSAREntry::InternalizeL
|
|
86 |
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Externalises the object.
|
|
90 |
*
|
|
91 |
* @param aStream Stream to write to
|
|
92 |
* @capability None
|
|
93 |
*/
|
|
94 |
EXPORT_C void TSAREntry::ExternalizeL(RWriteStream& aStream) const
|
|
95 |
{
|
|
96 |
aStream.WriteInt32L(iReference);
|
|
97 |
aStream.WriteInt32L(iTotal);
|
|
98 |
aStream.WriteInt32L(iCount);
|
|
99 |
aStream.WriteInt32L(iData1);
|
|
100 |
aStream.WriteInt32L(iData2);
|
|
101 |
aStream.WriteInt32L(iData3);
|
|
102 |
aStream.WriteInt32L(iData4);
|
|
103 |
aStream << iDescription1;
|
|
104 |
aStream << iDescription2;
|
|
105 |
aStream << Time().Int64();
|
|
106 |
aStream << iDataStreamId;
|
|
107 |
} // TSAREntry::ExternalizeL
|
|
108 |
|
|
109 |
|
|
110 |
//
|
|
111 |
// implementation of CSARStore
|
|
112 |
//
|
|
113 |
|
|
114 |
|
|
115 |
/**
|
|
116 |
* Opens a specified SAR store.
|
|
117 |
*
|
|
118 |
* A SAR filestore has has three uids, KPermanentFileStoreLayoutUid, KSARStoreUid
|
|
119 |
* (which designates that the file store is a SAR store) and a third UID, that
|
|
120 |
* identifies the particular implementation of CSARStore.
|
|
121 |
*
|
|
122 |
* @param aFullName Name for the segmentation and reassembly filestore
|
|
123 |
* @param aThirdUid Third UID for the filestore.
|
|
124 |
* @capability None
|
|
125 |
*/
|
|
126 |
EXPORT_C void CSARStore::OpenL(const TDesC& aFullName, const TUid& aThirdUid)
|
|
127 |
{
|
|
128 |
#ifdef _SMS_LOGGING_ENABLED
|
|
129 |
TBuf8<80> buf8;
|
|
130 |
buf8.Copy(aFullName);
|
|
131 |
LOGGSMU2("CSARStore::OpenL(): '%S'", &buf8);
|
|
132 |
#endif
|
|
133 |
|
|
134 |
// sanity check
|
|
135 |
__ASSERT_DEBUG(iFileStore==NULL,Panic(KGsmuPanicSARStoreAlreadyOpen));
|
|
136 |
__ASSERT_DEBUG(!iInTransaction, Panic(KGsmuPanicSARStoreTransaction));
|
|
137 |
__ASSERT_DEBUG(iEntryArray.Count()==0,Panic(KGsmuPanicSARStoreEntryArrayNotReset));
|
|
138 |
iFullName.Set(aFullName);
|
|
139 |
iThirdUid = aThirdUid;
|
|
140 |
|
|
141 |
// first opening we have to Internalize
|
|
142 |
DoOpenL();
|
|
143 |
// defect fix for EDNJJUN-4WYJGP
|
|
144 |
// Unable to send sms cause sms*.dat is corrupted
|
|
145 |
TRAPD(ret, InternalizeEntryArrayL());
|
|
146 |
if (ret != KErrNone)
|
|
147 |
{
|
|
148 |
LOGGSMU2("WARNING: InteralizeEntryArrayL left with %d", ret);
|
|
149 |
}
|
|
150 |
|
|
151 |
if(ret == KErrCorrupt || ret == KErrEof || ret == KErrNotFound)
|
|
152 |
{
|
|
153 |
Close(); //because the file is in use
|
|
154 |
User::LeaveIfError(iFs.Delete(iFullName));
|
|
155 |
DoOpenL();
|
|
156 |
}
|
|
157 |
else
|
|
158 |
User::LeaveIfError(ret);
|
|
159 |
} // CSARStore::OpenL
|
|
160 |
|
|
161 |
|
|
162 |
/**
|
|
163 |
* Commits a transaction to the filestore.
|
|
164 |
* @capability None
|
|
165 |
*/
|
|
166 |
EXPORT_C void CSARStore::CommitTransactionL()
|
|
167 |
// This function does the real work of updating the filestore
|
|
168 |
{
|
|
169 |
LOGGSMU4("CSARStore::CommitTransactionL(): this=0x%08X iInTransaction=%d iFileStore=0x%08X",
|
|
170 |
this, iInTransaction, iFileStore);
|
|
171 |
|
|
172 |
__ASSERT_DEBUG(iFileStore!=NULL, Panic(KGsmuPanicSARStoreNotOpen));
|
|
173 |
__ASSERT_DEBUG(iInTransaction, Panic(KGsmuPanicSARStoreTransaction));
|
|
174 |
|
|
175 |
#ifdef _SMS_LOGGING_ENABLED
|
|
176 |
TRAPD(err, DoCommitAndCompactL());
|
|
177 |
if (err != KErrNone)
|
|
178 |
{
|
|
179 |
LOGGSMU2("WARNING! could not CommitL/CompactL due to %d", err);
|
|
180 |
User::Leave(err);
|
|
181 |
}
|
|
182 |
#else
|
|
183 |
DoCommitAndCompactL();
|
|
184 |
#endif
|
|
185 |
|
|
186 |
CleanupStack::Pop(this);
|
|
187 |
iInTransaction = EFalse;
|
|
188 |
|
|
189 |
RemoveDeletedEntries();
|
|
190 |
} // CSARStore::CommitTransactionL
|
|
191 |
|
|
192 |
|
|
193 |
/**
|
|
194 |
* Closes the file store.
|
|
195 |
*
|
|
196 |
* The function deletes the file store object and resets the entry array. It
|
|
197 |
* should be called once when the protocol module is closing down.
|
|
198 |
* @capability None
|
|
199 |
*/
|
|
200 |
EXPORT_C void CSARStore::Close()
|
|
201 |
{
|
|
202 |
#ifdef _SMS_LOGGING_ENABLED
|
|
203 |
TBuf8<80> buf8;
|
|
204 |
buf8.Copy(iFullName);
|
|
205 |
LOGGSMU2("CSARStore::Close(): '%S'", &buf8);
|
|
206 |
#endif
|
|
207 |
|
|
208 |
__ASSERT_DEBUG(!iInTransaction, Panic(KGsmuPanicSARStoreTransaction));
|
|
209 |
|
|
210 |
delete iFileStore;
|
|
211 |
iFileStore=NULL;
|
|
212 |
iEntryArray.Reset();
|
|
213 |
} // CSARStore::Close
|
|
214 |
|
|
215 |
|
|
216 |
/**
|
|
217 |
* Gets a const reference to the entry array.
|
|
218 |
*
|
|
219 |
* @return Entry array
|
|
220 |
* @capability None
|
|
221 |
*/
|
|
222 |
EXPORT_C const CArrayFix<TSAREntry>& CSARStore::Entries() const
|
|
223 |
{
|
|
224 |
return iEntryArray;
|
|
225 |
} // CSARStore::Entries
|
|
226 |
|
|
227 |
|
|
228 |
/**
|
|
229 |
* Purges the reassembly file store.
|
|
230 |
*
|
|
231 |
* After a multipart message, it delete all the old entries.
|
|
232 |
*
|
|
233 |
* Entries will be purged when: 1) The complete message is received; 2) After
|
|
234 |
* aTimerintervalMinutes, if aPurgeIncompletely is false.
|
|
235 |
*
|
|
236 |
* PurgeL() will be called after the booting of the device or when a message
|
|
237 |
* has been received.
|
|
238 |
*
|
|
239 |
* This function opens and closes the file automatically.
|
|
240 |
*
|
|
241 |
* Note: overload function for segmentation store.
|
|
242 |
*
|
|
243 |
* @param aTimeIntervalMinutes Purge time
|
|
244 |
* @param aPurgeIncompleteOnly Purge complete messages flag
|
|
245 |
* @capability None
|
|
246 |
*/
|
|
247 |
EXPORT_C void CSARStore::PurgeL(const TTimeIntervalMinutes& aTimeIntervalMinutes,
|
|
248 |
TBool aPurgeIncompleteOnly)
|
|
249 |
//
|
|
250 |
// TODO ahe - performance filestore / sms
|
|
251 |
// In many cases the files will be opened and closed but no entry will be deleted.
|
|
252 |
// Conclusion:
|
|
253 |
// 1) only open, close, externalize and compact the file when an entry
|
|
254 |
// really shall be deleted
|
|
255 |
// 2) Compact the file after purging, only compact it here
|
|
256 |
// 3) Only purge the segmentation store if the send queue is empty
|
|
257 |
// and only purge the reassembly store when the receiv queue is full
|
|
258 |
//
|
|
259 |
// TODO ahe - for last release -
|
|
260 |
// message can be lost during crash: this issue has to be redesigned but
|
|
261 |
// after the reboot of the device the information in the stores could be lost
|
|
262 |
// due to purging or compacting - a single pdu always gets lost due to not
|
|
263 |
// storing it in the reassembly store.
|
|
264 |
//
|
|
265 |
{
|
|
266 |
LOGGSMU3("CSARStore::PurgeL(): aTimeIntervalMinutes=%d, aPurgeIncompleteOnly=%d",
|
|
267 |
aTimeIntervalMinutes.Int(), aPurgeIncompleteOnly);
|
|
268 |
|
|
269 |
// TODO - flag
|
|
270 |
// we could also save the call of the method from the consruction of the smsprot
|
|
271 |
if( aPurgeIncompleteOnly )
|
|
272 |
return;
|
|
273 |
|
|
274 |
TInt count=iEntryArray.Count();
|
|
275 |
LOGGSMU2("CSARStore::PurgeL(): count=%d", count);
|
|
276 |
|
|
277 |
TTime time;
|
|
278 |
time.UniversalTime();
|
|
279 |
|
|
280 |
// we open the file outside the loop
|
|
281 |
// to save some CPU
|
|
282 |
BeginTransactionLC();
|
|
283 |
for (TInt i=count-1; i>=0; i--)
|
|
284 |
{
|
|
285 |
TSAREntry entry=iEntryArray[i];
|
|
286 |
if (((time>(entry.Time()+aTimeIntervalMinutes)) && !aPurgeIncompleteOnly ))
|
|
287 |
// TODO - flag
|
|
288 |
// check the logic o the aPurgeIncompleteOnly flg
|
|
289 |
// don't purge the store if the entry is complete
|
|
290 |
// entry.IsComplete() )
|
|
291 |
{
|
|
292 |
DoDeleteEntryL(i);
|
|
293 |
}
|
|
294 |
}
|
|
295 |
ExternalizeEntryArrayL();
|
|
296 |
CommitTransactionL();
|
|
297 |
} // CSARStore::PurgeL
|
|
298 |
|
|
299 |
|
|
300 |
/**
|
|
301 |
* Purges the segmentation store.
|
|
302 |
*
|
|
303 |
* This purges the filestore after a multipart message, deleting all the old
|
|
304 |
* entries.
|
|
305 |
*
|
|
306 |
* This function opens and closes the file automatically.
|
|
307 |
*
|
|
308 |
* @param aKSegmentationLifetimeMultiplier The coefficient for calculating whether
|
|
309 |
* a message should be purged
|
|
310 |
* @param aPurgeIncompleteOnly Set to false to purge all entries. Set to true
|
|
311 |
* to purge incomplete messages only.
|
|
312 |
* @capability None
|
|
313 |
*/
|
|
314 |
EXPORT_C void CSARStore::PurgeL(TInt aKSegmentationLifetimeMultiplier,TBool aPurgeIncompleteOnly)
|
|
315 |
{
|
|
316 |
LOGGSMU3("CSARStore::PurgeL(): aKSegmentationLifetimeMultiplier=%d, aPurgeIncompleteOnly=%d",
|
|
317 |
aKSegmentationLifetimeMultiplier, aPurgeIncompleteOnly);
|
|
318 |
|
|
319 |
TInt count=Entries().Count();
|
|
320 |
LOGGSMU2("CSARStore::PurgeL(): count=%d", count);
|
|
321 |
TTime time;
|
|
322 |
time.UniversalTime();
|
|
323 |
|
|
324 |
// we open the file outside the loop
|
|
325 |
// to save some CPU
|
|
326 |
BeginTransactionLC();
|
|
327 |
TInt numDeletedEntry = 0;
|
|
328 |
|
|
329 |
for (TInt i=count-1; i>=0; i--)
|
|
330 |
{
|
|
331 |
const TSmsSegmentationEntry& entry = (const TSmsSegmentationEntry&)Entries()[i];
|
|
332 |
const TTimeIntervalMinutes lifetime((entry.ValidityPeriod()*aKSegmentationLifetimeMultiplier)/1000);
|
|
333 |
//
|
|
334 |
// AEH: Defect fix for EDNPAHN-4WADW3 'Unreliable logging'
|
|
335 |
//
|
|
336 |
// This should solve the problem with agressive PurgeL algorithm
|
|
337 |
// deleting PDUs which are waiting for Status Reports.
|
|
338 |
// Extra bit in TSAREntry indicating Status Reports.
|
|
339 |
// if we don't expect a status report, fake the
|
|
340 |
// number of delivered and failed to be equal
|
|
341 |
// to Total.
|
|
342 |
//
|
|
343 |
|
|
344 |
const TBool have_sr = entry.ExpectStatusReport();
|
|
345 |
|
|
346 |
const TInt deliv_n_failed = have_sr
|
|
347 |
? entry.Delivered() + entry.Failed() // total acked PDUs
|
|
348 |
: entry.Total(); // fake
|
|
349 |
|
|
350 |
if (
|
|
351 |
(entry.IsComplete() && (deliv_n_failed >= entry.Total()))
|
|
352 |
||
|
|
353 |
((time>(entry.Time()+lifetime)) && !aPurgeIncompleteOnly )
|
|
354 |
)
|
|
355 |
{
|
|
356 |
DoDeleteEntryL(i);
|
|
357 |
++numDeletedEntry;
|
|
358 |
}
|
|
359 |
}
|
|
360 |
|
|
361 |
TInt numOldestEntry = 0;
|
|
362 |
if(iMaxmumNumberOfMessagesInSegmentationStore > 0)
|
|
363 |
{
|
|
364 |
while((count - numDeletedEntry) > iMaxmumNumberOfMessagesInSegmentationStore)
|
|
365 |
{ // The number of messages in the store is greater than the allowed number. Find&Delete the oldest one.
|
|
366 |
// If the maximum number of messages is set to o, we don't delete any messages.
|
|
367 |
while (Entries()[numOldestEntry].IsDeleted())
|
|
368 |
{ // Find oldest entry that has not been deleted already
|
|
369 |
++numOldestEntry;
|
|
370 |
}
|
|
371 |
DoDeleteEntryL(numOldestEntry++);
|
|
372 |
++numDeletedEntry;
|
|
373 |
}
|
|
374 |
}
|
|
375 |
|
|
376 |
ExternalizeEntryArrayL();
|
|
377 |
CommitTransactionL();
|
|
378 |
LOGGSMU1("CSmsSegmentationStore::PurgeL End");
|
|
379 |
} // CSARStore::PurgeL
|
|
380 |
|
|
381 |
|
|
382 |
/**
|
|
383 |
* Deletes an entry from the entry array, and externalizes it.
|
|
384 |
*
|
|
385 |
* The file store must be open before calling this function.
|
|
386 |
*
|
|
387 |
* @param aIndex Entry in the SAR store to delete
|
|
388 |
* @capability None
|
|
389 |
*/
|
|
390 |
EXPORT_C void CSARStore::DeleteEntryL(TInt aIndex)
|
|
391 |
{
|
|
392 |
LOGGSMU2("CSARStore::DeleteEntryL(): aIndex=%d", aIndex);
|
|
393 |
|
|
394 |
DoDeleteEntryL(aIndex);
|
|
395 |
ExternalizeEntryArrayL();
|
|
396 |
} // CSARStore::DeleteEntryL
|
|
397 |
|
|
398 |
|
|
399 |
/**
|
|
400 |
* Constructor, initialises class members only.
|
|
401 |
*
|
|
402 |
* @param aFs File system handle
|
|
403 |
* @capability None
|
|
404 |
*/
|
|
405 |
EXPORT_C CSARStore::CSARStore(RFs& aFs)
|
|
406 |
:iFs(aFs)
|
|
407 |
,iEntryArray(8)
|
|
408 |
{
|
|
409 |
} // CSARStore::CSARStore
|
|
410 |
|
|
411 |
|
|
412 |
/**
|
|
413 |
* Destructor. Frees resource.
|
|
414 |
* @capability None
|
|
415 |
*/
|
|
416 |
EXPORT_C CSARStore::~CSARStore()
|
|
417 |
{
|
|
418 |
delete iFileStore;
|
|
419 |
} // CSARStore::CSARStore
|
|
420 |
|
|
421 |
|
|
422 |
/**
|
|
423 |
* Gets a reference to the filestore.
|
|
424 |
*
|
|
425 |
* @return The filestore
|
|
426 |
* @capability None
|
|
427 |
*/
|
|
428 |
EXPORT_C CFileStore& CSARStore::FileStore()
|
|
429 |
{
|
|
430 |
LOGGSMU1("CSARStore::FileStore()");
|
|
431 |
|
|
432 |
__ASSERT_DEBUG(iFileStore!=NULL,Panic(KGsmuPanicSARStoreNotOpen));
|
|
433 |
return *iFileStore;
|
|
434 |
} // CSARStore::FileStore
|
|
435 |
|
|
436 |
|
|
437 |
/**
|
|
438 |
* Gets a (const) reference to the filestore.
|
|
439 |
*
|
|
440 |
* @return The filestore
|
|
441 |
* @capability None
|
|
442 |
*/
|
|
443 |
EXPORT_C const CFileStore& CSARStore::FileStore() const
|
|
444 |
{
|
|
445 |
// Ignore in code coverage - not used in SMS stack.
|
|
446 |
BULLSEYE_OFF
|
|
447 |
LOGGSMU1("CSARStore::FileStore()");
|
|
448 |
__ASSERT_DEBUG(iFileStore!=NULL,Panic(KGsmuPanicSARStoreNotOpen));
|
|
449 |
return *iFileStore;
|
|
450 |
BULLSEYE_RESTORE
|
|
451 |
}
|
|
452 |
|
|
453 |
/**
|
|
454 |
* Adds a new entry to the file store.
|
|
455 |
*
|
|
456 |
* The function appends the new entry to the internal entry array, and then externalises
|
|
457 |
* it.
|
|
458 |
*
|
|
459 |
* The file store must be open before calling this function.
|
|
460 |
*
|
|
461 |
* @param aEntry SAR entry to add
|
|
462 |
* @capability None
|
|
463 |
*/
|
|
464 |
EXPORT_C void CSARStore::AddEntryL(const TSAREntry& aEntry)
|
|
465 |
{
|
|
466 |
LOGGSMU1("CSARStore::AddEntryL()");
|
|
467 |
|
|
468 |
__ASSERT_DEBUG(iFileStore!=NULL,Panic(KGsmuPanicSARStoreNotOpen));
|
|
469 |
__ASSERT_DEBUG(aEntry.DataStreamId()!=KNullStreamId,Panic(KGsmuPanicSAREntryDataStreamIdNotSet));
|
|
470 |
iEntryArray.AppendL(aEntry);
|
|
471 |
iEntryArray[iEntryArray.Count()-1].SetIsAdded(ETrue);
|
|
472 |
ExternalizeEntryArrayL();
|
|
473 |
} // CSARStore::AddEntryL
|
|
474 |
|
|
475 |
|
|
476 |
/**
|
|
477 |
* Changes an entry in the file store - changes it first in the internal
|
|
478 |
* entry array, and then externalizes it.
|
|
479 |
*
|
|
480 |
* The file store must be open before calling this function.
|
|
481 |
*
|
|
482 |
* @param aIndex The index into the SAR store to be changed
|
|
483 |
* @param aNewEntry The new SAR store entry
|
|
484 |
* @capability None
|
|
485 |
*/
|
|
486 |
EXPORT_C void CSARStore::ChangeEntryL(TInt aIndex,const TSAREntry& aNewEntry)
|
|
487 |
{
|
|
488 |
LOGGSMU2("CSARStore::ChangeEntryL(): aIndex=%d", aIndex);
|
|
489 |
|
|
490 |
__ASSERT_DEBUG(iFileStore!=NULL,Panic(KGsmuPanicSARStoreNotOpen));
|
|
491 |
__ASSERT_DEBUG(iEntryArray[aIndex].DataStreamId()==aNewEntry.DataStreamId(),Panic(KGsmuPanicSAREntryDataStreamIdChanged));
|
|
492 |
|
|
493 |
iEntryArray[aIndex].SetIsDeleted(ETrue);
|
|
494 |
iEntryArray.InsertL(aIndex,aNewEntry);
|
|
495 |
iEntryArray[aIndex].SetIsAdded(ETrue);
|
|
496 |
|
|
497 |
ExternalizeEntryArrayL();
|
|
498 |
} // CSARStore::ChangeEntryL
|
|
499 |
|
|
500 |
|
|
501 |
/**
|
|
502 |
* Gets the extra stream ID.
|
|
503 |
*
|
|
504 |
* @return Extra stream ID
|
|
505 |
* @capability None
|
|
506 |
*/
|
|
507 |
EXPORT_C TStreamId CSARStore::ExtraStreamId() const
|
|
508 |
{
|
|
509 |
LOGGSMU1("CSARStore::ExtraStreamId");
|
|
510 |
return iExtraStreamId;
|
|
511 |
} // CSARStore::ExtraStreamId
|
|
512 |
|
|
513 |
|
|
514 |
/**
|
|
515 |
* Sets the extra stream ID - changes it first in the internal
|
|
516 |
* entry array, and then externalizes it.
|
|
517 |
*
|
|
518 |
* You must call Close() when the function returns.
|
|
519 |
*
|
|
520 |
* @param aExtraStreamId Extra stream ID
|
|
521 |
* @capability None
|
|
522 |
*/
|
|
523 |
EXPORT_C void CSARStore::SetExtraStreamIdL(const TStreamId& aExtraStreamId)
|
|
524 |
{
|
|
525 |
LOGGSMU2("CSARStore::SetExtraStreamIdL(): id=%d", aExtraStreamId.Value());
|
|
526 |
|
|
527 |
__ASSERT_DEBUG(iFileStore!=NULL,Panic(KGsmuPanicSARStoreNotOpen));
|
|
528 |
TStreamId streamid=iExtraStreamId;
|
|
529 |
iExtraStreamId=aExtraStreamId;
|
|
530 |
TRAPD(ret, ExternalizeEntryArrayL());
|
|
531 |
if (ret!=KErrNone)
|
|
532 |
{
|
|
533 |
LOGGSMU2("WARNING! CSARStore::DoExternalizeEntryArrayL left with %d", ret);
|
|
534 |
iExtraStreamId=streamid; // Roll back
|
|
535 |
User::Leave(ret); // re-leave to allow caller to also roll back
|
|
536 |
}
|
|
537 |
} // CSARStore::SetExtraStreamIdL
|
|
538 |
|
|
539 |
|
|
540 |
/**
|
|
541 |
* Compacts the file store.
|
|
542 |
*
|
|
543 |
* This is done on every reboot and for every eighth SMS message sent, to keep
|
|
544 |
* the size of the file as low as possible.
|
|
545 |
*
|
|
546 |
* This function opens and closes the file automatically.
|
|
547 |
* @capability None
|
|
548 |
*/
|
|
549 |
EXPORT_C void CSARStore::CompactL()
|
|
550 |
{
|
|
551 |
LOGGSMU1("CSARStore::CompactL Start");
|
|
552 |
__ASSERT_DEBUG(iFileStore!=NULL, Panic(KGsmuPanicSARStoreNotOpen));
|
|
553 |
__ASSERT_DEBUG(iInTransaction, Panic(KGsmuPanicSARStoreTransaction));
|
|
554 |
|
|
555 |
TInt space = iFileStore->CompactL();
|
|
556 |
iFileStore->CommitL();
|
|
557 |
|
|
558 |
LOGGSMU2("CSARStore::CompactL End [space=%d]", space);
|
|
559 |
(void)space;
|
|
560 |
} // CSARStore::CompactL
|
|
561 |
|
|
562 |
|
|
563 |
/**
|
|
564 |
* Sets the SAR store as in-transaction.
|
|
565 |
*
|
|
566 |
* The function checks the validity of the call and leaves KErrAccessDenied if
|
|
567 |
* invalid.
|
|
568 |
* @capability None
|
|
569 |
*/
|
|
570 |
EXPORT_C void CSARStore::BeginTransactionLC()
|
|
571 |
{
|
|
572 |
LOGGSMU4("CSARStore::BeginTransactionLC [this=0x%08X iInTransaction=%d iFileStore=0x%08X]", this, iInTransaction, iFileStore);
|
|
573 |
|
|
574 |
if (iFileStore == NULL || iInTransaction)
|
|
575 |
{
|
|
576 |
LOGGSMU1("WARNING CSARStore::BeginTransactionLC leaving with KErrAccessDenied");
|
|
577 |
User::Leave(KErrAccessDenied);
|
|
578 |
}
|
|
579 |
|
|
580 |
TCleanupItem sarClose(CSARStoreCloseObject, this);
|
|
581 |
CleanupStack::PushL(sarClose);
|
|
582 |
iInTransaction = ETrue;
|
|
583 |
} // CSARStore::BeginTransactionLC
|
|
584 |
|
|
585 |
void CSARStore::Revert()
|
|
586 |
{
|
|
587 |
LOGGSMU3("CSARStore::Revert(): this=0x%08X, iInTransaction=%d",
|
|
588 |
this, iInTransaction);
|
|
589 |
|
|
590 |
__ASSERT_DEBUG(iInTransaction, Panic(KGsmuPanicSARStoreTransaction));
|
|
591 |
|
|
592 |
iFileStore->Revert();
|
|
593 |
iInTransaction = EFalse;
|
|
594 |
ReinstateDeletedEntries();
|
|
595 |
} // CSARStore::Revert
|
|
596 |
|
|
597 |
|
|
598 |
/**
|
|
599 |
* Opens a filestore.
|
|
600 |
*
|
|
601 |
* This is called by OpenL(), and does the work of really opening the file. If
|
|
602 |
* the file is not there, it creates a new one.
|
|
603 |
* @capability None
|
|
604 |
*/
|
|
605 |
EXPORT_C void CSARStore::DoOpenL()
|
|
606 |
{
|
|
607 |
#ifdef _SMS_LOGGING_ENABLED
|
|
608 |
TBuf8<80> buf8;
|
|
609 |
buf8.Copy(iFullName);
|
|
610 |
LOGGSMU3("CSARStore::DoOpenL(): '%S' this=0x%08X", &buf8, this);
|
|
611 |
#endif
|
|
612 |
|
|
613 |
TUidType uidtype(KPermanentFileStoreLayoutUid,KSARStoreUid,iThirdUid);
|
|
614 |
TEntry entry;
|
|
615 |
TInt ret=iFs.Entry(iFullName,entry); // Check file exists
|
|
616 |
if (ret==KErrNone) // File found
|
|
617 |
{
|
|
618 |
if (uidtype!=entry.iType)
|
|
619 |
ret=KErrNotFound;
|
|
620 |
}
|
|
621 |
if (ret==KErrNone) // Filestore found
|
|
622 |
{
|
|
623 |
// using OpenLC puts it on the cleanup stack,
|
|
624 |
// so that the trap handler will close the file
|
|
625 |
// automatically
|
|
626 |
TRAP(ret,(iFileStore=CPermanentFileStore::OpenL(iFs,iFullName,EFileShareExclusive|EFileStream|EFileRead|EFileWrite)));
|
|
627 |
if(ret != KErrNone)
|
|
628 |
{
|
|
629 |
LOGGSMU2("WARNING! CPermanentFileStore::OpenLC left with %d", ret);
|
|
630 |
}
|
|
631 |
}
|
|
632 |
|
|
633 |
if (ret==KErrNoMemory) // Filestore not corrupted
|
|
634 |
{
|
|
635 |
User::Leave(ret);
|
|
636 |
}
|
|
637 |
else if (ret != KErrNone) // The filestore was corrupted or not found, so create a new one
|
|
638 |
{
|
|
639 |
// create a new file and push the close function on the cleanup stack,
|
|
640 |
// so that the trap handler will close the file automatically
|
|
641 |
#ifdef _SMS_LOGGING_ENABLED
|
|
642 |
TBuf8<80> buf8;
|
|
643 |
buf8.Copy(iFullName);
|
|
644 |
LOGGSMU2("CSARStore::DoOpenL(): New file created '%S'", &buf8);
|
|
645 |
#endif
|
|
646 |
TInt kerr(iFs.MkDirAll(iFullName)); //the directory may not exist, So create one.
|
|
647 |
if(kerr != KErrAlreadyExists)
|
|
648 |
{
|
|
649 |
User::LeaveIfError(kerr);
|
|
650 |
}
|
|
651 |
iFileStore=CPermanentFileStore::ReplaceL(iFs, iFullName,EFileShareExclusive|EFileStream|EFileRead|EFileWrite);
|
|
652 |
iFileStore->SetTypeL(uidtype);
|
|
653 |
// the file got lost so we externalize the internal
|
|
654 |
// representation of the data before we continue
|
|
655 |
BeginTransactionLC();
|
|
656 |
ExternalizeEntryArrayL();
|
|
657 |
CommitTransactionL();
|
|
658 |
}
|
|
659 |
|
|
660 |
__ASSERT_DEBUG(iFileStore!=NULL, Panic(KGsmuPanicSARStoreNotOpen));
|
|
661 |
} // CSARStore::DoOpenL
|
|
662 |
|
|
663 |
|
|
664 |
/**
|
|
665 |
* Actually delete an entry in the entry array
|
|
666 |
*/
|
|
667 |
void CSARStore::DoDeleteEntryL(TInt aIndex)
|
|
668 |
{
|
|
669 |
#ifdef _SMS_LOGGING_ENABLED
|
|
670 |
const TSmsSegmentationEntry& entry = (const TSmsSegmentationEntry&)iEntryArray[aIndex];
|
|
671 |
|
|
672 |
LOGGSMU3("CSARStore::DoDeleteEntryL [aIndex=%d Count=%d]",
|
|
673 |
aIndex, iEntryArray.Count());
|
|
674 |
LOGGSMU4("CSARStore::DoDeleteEntryL [aIndex=%d Delivered=%d Failed=%d]",
|
|
675 |
aIndex, entry.Delivered(), entry.Failed());
|
|
676 |
LOGGSMU4("CSARStore::DoDeleteEntryL [aIndex=%d Count=%d Total=%d]",
|
|
677 |
aIndex, entry.Count(), entry.Total());
|
|
678 |
LOGGSMU4("CSARStore::DoDeleteEntryL [aIndex=%d logId=%d StreamId=%d]",
|
|
679 |
aIndex, entry.LogServerId(), entry.DataStreamId().Value());
|
|
680 |
#endif // _SMS_LOGGING_ENABLED
|
|
681 |
|
|
682 |
__ASSERT_DEBUG(iFileStore!=NULL,Panic(KGsmuPanicSARStoreNotOpen));
|
|
683 |
TRAPD(err, iFileStore->DeleteL(iEntryArray[aIndex].DataStreamId()));
|
|
684 |
if(err == KErrNone)
|
|
685 |
{
|
|
686 |
iEntryArray[aIndex].SetIsDeleted(ETrue);
|
|
687 |
}
|
|
688 |
} // CSARStore::DoDeleteEntryL
|
|
689 |
|
|
690 |
|
|
691 |
/**
|
|
692 |
* internalize - read from the file store into RAM
|
|
693 |
*/
|
|
694 |
void CSARStore::InternalizeEntryArrayL()
|
|
695 |
{
|
|
696 |
LOGGSMU1("CSARStore::InternalizeEntryArrayL()");
|
|
697 |
|
|
698 |
__ASSERT_DEBUG(iFileStore!=NULL, Panic(KGsmuPanicSARStoreNotOpen));
|
|
699 |
|
|
700 |
TStreamId headerid=iFileStore->Root();
|
|
701 |
RStoreReadStream stream;
|
|
702 |
stream.OpenLC(*iFileStore,headerid);
|
|
703 |
TInt count=stream.ReadInt32L();
|
|
704 |
for (TInt i=0; i<count; i++)
|
|
705 |
{
|
|
706 |
TSAREntry sarentry;
|
|
707 |
stream >> sarentry;
|
|
708 |
iEntryArray.AppendL(sarentry);
|
|
709 |
}
|
|
710 |
stream >> iExtraStreamId;
|
|
711 |
CleanupStack::PopAndDestroy(); // stream
|
|
712 |
} // CSARStore::InternalizeEntryArrayL
|
|
713 |
|
|
714 |
|
|
715 |
void CSARStore::RemoveDeletedEntries()
|
|
716 |
{
|
|
717 |
LOGGSMU1("CSARStore::RemoveDeletedEntries()");
|
|
718 |
|
|
719 |
TInt count=iEntryArray.Count();
|
|
720 |
while (count--)
|
|
721 |
{
|
|
722 |
TSAREntry& entry = iEntryArray[count];
|
|
723 |
|
|
724 |
if (entry.IsDeleted())
|
|
725 |
iEntryArray.Delete(count);
|
|
726 |
else
|
|
727 |
entry.SetIsAdded(EFalse);
|
|
728 |
}
|
|
729 |
} // CSARStore::RemoveDeletedEntries
|
|
730 |
|
|
731 |
|
|
732 |
void CSARStore::ReinstateDeletedEntries()
|
|
733 |
{
|
|
734 |
LOGGSMU1("CSARStore::ReinstateDeletedEntries()");
|
|
735 |
|
|
736 |
TInt count=iEntryArray.Count();
|
|
737 |
while (count--)
|
|
738 |
{
|
|
739 |
TSAREntry& entry = iEntryArray[count];
|
|
740 |
|
|
741 |
if (entry.IsAdded())
|
|
742 |
iEntryArray.Delete(count);
|
|
743 |
else
|
|
744 |
entry.SetIsDeleted(EFalse);
|
|
745 |
}
|
|
746 |
} // CSARStore::ReinstateDeletedEntries
|
|
747 |
|
|
748 |
|
|
749 |
/**
|
|
750 |
* externalize - read from RAM to the file store
|
|
751 |
*/
|
|
752 |
void CSARStore::ExternalizeEntryArrayL()
|
|
753 |
{
|
|
754 |
__ASSERT_DEBUG(iFileStore!=NULL, Panic(KGsmuPanicSARStoreNotOpen));
|
|
755 |
__ASSERT_DEBUG(iInTransaction, Panic(KGsmuPanicSARStoreTransaction));
|
|
756 |
|
|
757 |
LOGGSMU4("CSARStore::ExternalizeEntryArrayL(): this=0x%08X count=%d headerid=%d]",
|
|
758 |
this, iEntryArray.Count(), iFileStore->Root().Value());
|
|
759 |
|
|
760 |
TStreamId headerid=iFileStore->Root();
|
|
761 |
RStoreWriteStream stream;
|
|
762 |
if (headerid==KNullStreamId)
|
|
763 |
{
|
|
764 |
headerid=stream.CreateLC(*iFileStore);
|
|
765 |
iFileStore->SetRootL(headerid);
|
|
766 |
}
|
|
767 |
else
|
|
768 |
{
|
|
769 |
stream.ReplaceLC(*iFileStore,headerid);
|
|
770 |
}
|
|
771 |
|
|
772 |
TInt count1=iEntryArray.Count();
|
|
773 |
TInt count2=0;
|
|
774 |
TInt i=0;
|
|
775 |
|
|
776 |
for (; i<count1; i++)
|
|
777 |
{
|
|
778 |
if (!iEntryArray[i].IsDeleted())
|
|
779 |
{
|
|
780 |
count2++;
|
|
781 |
}
|
|
782 |
}
|
|
783 |
stream.WriteInt32L(count2);
|
|
784 |
for (i=0; i<count1; i++)
|
|
785 |
{
|
|
786 |
if (!iEntryArray[i].IsDeleted())
|
|
787 |
{
|
|
788 |
stream << iEntryArray[i];
|
|
789 |
}
|
|
790 |
}
|
|
791 |
|
|
792 |
stream << iExtraStreamId;
|
|
793 |
stream.CommitL();
|
|
794 |
CleanupStack::PopAndDestroy(&stream);
|
|
795 |
} // CSARStore::ExternalizeEntryArrayL
|
|
796 |
|
|
797 |
|
|
798 |
/**
|
|
799 |
* called by CloseFile - always do a CommitL
|
|
800 |
* and if the store is of a certains size then
|
|
801 |
* call CompactL also
|
|
802 |
*/
|
|
803 |
void CSARStore::DoCommitAndCompactL()
|
|
804 |
{
|
|
805 |
LOGGSMU1("CSARStore::DoCommitAndCompactL()");
|
|
806 |
|
|
807 |
LOGGSMUTIMESTAMP();
|
|
808 |
iFileStore->CommitL();
|
|
809 |
LOGGSMUTIMESTAMP();
|
|
810 |
|
|
811 |
iCommitCount--;
|
|
812 |
if (iCommitCount < 0)
|
|
813 |
{
|
|
814 |
iCommitCount = KNumStoreCommitsBeforeCompaction;
|
|
815 |
iFileStore->CompactL();
|
|
816 |
iFileStore->CommitL();
|
|
817 |
}
|
|
818 |
} // CSARStore::DoCommitAndCompactL
|
|
819 |
|
|
820 |
|
|
821 |
/**
|
|
822 |
* Returns the private path used to open a store.
|
|
823 |
*
|
|
824 |
* @param aPath The private path of a store.
|
|
825 |
* @capability None
|
|
826 |
*/
|
|
827 |
EXPORT_C void CSARStore::PrivatePath(TDes& aPath)
|
|
828 |
{
|
|
829 |
LOGGSMU1("CSARStore::PrivatePath()");
|
|
830 |
|
|
831 |
TDriveUnit driveUnit(KStoreDrive);
|
|
832 |
TDriveName drive=driveUnit.Name();
|
|
833 |
aPath.Insert(0, drive);
|
|
834 |
//append private path
|
|
835 |
TPath privatePath;
|
|
836 |
iFs.PrivatePath(privatePath);
|
|
837 |
aPath.Append(privatePath);
|
|
838 |
aPath.Append(KStoreSubDir);
|
|
839 |
} // CSARStore::PrivatePath
|