0
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-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 the License "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 |
|
|
20 |
// EXTERNAL RESOURCES
|
|
21 |
|
|
22 |
// Include Files
|
|
23 |
#include <ctsy/rmmcustomapi.h>
|
|
24 |
#include "cmmsmscache.h"
|
|
25 |
#include "tsylogger.h"
|
|
26 |
#include "tisi.h"
|
|
27 |
#include <smsisi.h>
|
|
28 |
#include "osttracedefinitions.h"
|
|
29 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
30 |
#include "cmmsmscachetraces.h"
|
|
31 |
#endif
|
|
32 |
|
|
33 |
// External Data Structures
|
|
34 |
// none
|
|
35 |
|
|
36 |
// External Function Prototypes
|
|
37 |
// none
|
|
38 |
|
|
39 |
// LOCAL CONSTANTS AND MACROS
|
|
40 |
// none
|
|
41 |
|
|
42 |
// MODULE DATA STRUCTURES
|
|
43 |
|
|
44 |
// Local Data Structures
|
|
45 |
// none
|
|
46 |
|
|
47 |
// Local Function Prototypes
|
|
48 |
// none
|
|
49 |
|
|
50 |
// LOCAL FUNCTIONS
|
|
51 |
// none
|
|
52 |
|
|
53 |
// MEMBER FUNCTIONS
|
|
54 |
|
|
55 |
//=============================================================================
|
|
56 |
|
|
57 |
// -----------------------------------------------------------------------------
|
|
58 |
// CMmSmsCache::CMmSmsCache
|
|
59 |
// Creates new CMmSmsCache object
|
|
60 |
// -----------------------------------------------------------------------------
|
|
61 |
//
|
|
62 |
CMmSmsCache::CMmSmsCache()
|
|
63 |
{
|
|
64 |
TFLOGSTRING("TSY: CMmSmsCache::CMmSmsCache");
|
|
65 |
OstTrace0( TRACE_NORMAL, CMMSMSCACHE_CMMSMSCACHE, "CMmSmsCache::CMmSmsCache" );
|
|
66 |
Reset();
|
|
67 |
// If SIM is offline,then won't get
|
|
68 |
// sim ready completion and cache error state stays as
|
|
69 |
// KErrNotFound. If user accesses SIM SMS --> immediate complete
|
|
70 |
// with KErrNotFound
|
|
71 |
SetStatus( KErrNotFound );
|
|
72 |
}
|
|
73 |
|
|
74 |
// -----------------------------------------------------------------------------
|
|
75 |
// CMmSmsCache::~CMmSmsCache
|
|
76 |
// delete CMmSmsCache
|
|
77 |
// -----------------------------------------------------------------------------
|
|
78 |
//
|
|
79 |
CMmSmsCache::~CMmSmsCache()
|
|
80 |
{
|
|
81 |
TFLOGSTRING("TSY: CMmSmsCache::~CMmSmsCache");
|
|
82 |
OstTrace0( TRACE_NORMAL, DUP1_CMMSMSCACHE_CMMSMSCACHE, "CMmSmsCache::~CMmSmsCache" );
|
|
83 |
Reset();
|
|
84 |
}
|
|
85 |
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
// CMmSmsCache::Reset
|
|
88 |
// reset cache to not ready state
|
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
//
|
|
91 |
void CMmSmsCache::Reset()
|
|
92 |
{
|
|
93 |
TFLOGSTRING("TSY: CMmSmsCache::Reset");
|
|
94 |
OstTrace0( TRACE_NORMAL, CMMSMSCACHE_RESET, "CMmSmsCache::Reset" );
|
|
95 |
|
|
96 |
iError = KErrNotReady;
|
|
97 |
iDeleteLocation = 0;
|
|
98 |
|
|
99 |
for ( TInt i = 0; i < iElements.Count(); i++ )
|
|
100 |
{
|
|
101 |
delete iElements[i];
|
|
102 |
iElements[i] = NULL;
|
|
103 |
}
|
|
104 |
iElements.Reset();
|
|
105 |
}
|
|
106 |
|
|
107 |
// -----------------------------------------------------------------------------
|
|
108 |
// CMmSmsCache::UsedEntries
|
|
109 |
// get the number of used entries from cache
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
TInt CMmSmsCache::UsedEntries()
|
|
113 |
{
|
|
114 |
TFLOGSTRING("TSY: CMmSmsCache::UsedEntries");
|
|
115 |
OstTrace0( TRACE_NORMAL, CMMSMSCACHE_USEDENTRIES, "CMmSmsCache::UsedEntries" );
|
|
116 |
TInt count( 0 );
|
|
117 |
for ( TInt i = 0; i < iElements.Count(); i++ )
|
|
118 |
{
|
|
119 |
if ( iElements[i] )
|
|
120 |
{
|
|
121 |
count++;
|
|
122 |
}
|
|
123 |
}
|
|
124 |
return count;
|
|
125 |
}
|
|
126 |
|
|
127 |
// -----------------------------------------------------------------------------
|
|
128 |
// CMmSmsCache::TotalEntries
|
|
129 |
// get the total number of entries in SIM
|
|
130 |
// -----------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
TInt CMmSmsCache::TotalEntries()
|
|
133 |
{
|
|
134 |
TFLOGSTRING2("TSY: CMmSmsCache::TotalEntries: %d",iElements.Count());
|
|
135 |
OstTrace1( TRACE_NORMAL, CMMSMSCACHE_TOTALENTRIES, "CMmSmsCache::TotalEntries;iElements.Count=%d", iElements.Count() );
|
|
136 |
return iElements.Count();
|
|
137 |
}
|
|
138 |
|
|
139 |
// -----------------------------------------------------------------------------
|
|
140 |
// CMmSmsCache::Status
|
|
141 |
// Returns cache status, this can be KErrNotReady (cache is being read)
|
|
142 |
// KErrNone (cache is ok and can be used)
|
|
143 |
// any other (cache is in error state and is unusable)
|
|
144 |
// -----------------------------------------------------------------------------
|
|
145 |
//
|
|
146 |
TInt CMmSmsCache::Status()
|
|
147 |
{
|
|
148 |
TFLOGSTRING("TSY: CMmSmsCache::Status");
|
|
149 |
OstTrace0( TRACE_NORMAL, CMMSMSCACHE_STATUS, "CMmSmsCache::Status" );
|
|
150 |
return iError;
|
|
151 |
}
|
|
152 |
|
|
153 |
// -----------------------------------------------------------------------------
|
|
154 |
// CMmSmsCache::SetStatus
|
|
155 |
// set cache error state
|
|
156 |
// -----------------------------------------------------------------------------
|
|
157 |
//
|
|
158 |
void CMmSmsCache::SetStatus( TInt aError )
|
|
159 |
{
|
|
160 |
TFLOGSTRING2("TSY: CMmSmsCache::SetStatus %d", aError);
|
|
161 |
OstTrace1( TRACE_NORMAL, CMMSMSCACHE_SETSTATUS, "CMmSmsCache::SetStatus;aError=%d", aError );
|
|
162 |
iError = aError;
|
|
163 |
}
|
|
164 |
|
|
165 |
// -----------------------------------------------------------------------------
|
|
166 |
// CMmSmsCache::SetTotalEntriesL
|
|
167 |
// initialize cache to contain aTotal number of empty entries
|
|
168 |
// it is assumed that cache is Reset before call to this..
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
void CMmSmsCache::SetTotalEntriesL( TInt aTotal )
|
|
172 |
{
|
|
173 |
TFLOGSTRING2("TSY: CMmSmsCache::SetTotalEntriesL %d", aTotal);
|
|
174 |
OstTrace1( TRACE_NORMAL, CMMSMSCACHE_SETTOTALENTRIESL, "CMmSmsCache::SetTotalEntriesL;aTotal=%d", aTotal );
|
|
175 |
|
|
176 |
RMobileSmsStore::TMobileGsmSmsEntryV1* element = NULL;
|
|
177 |
for ( TInt i = 0; i < aTotal; i++ )
|
|
178 |
{
|
|
179 |
iElements.AppendL( element );
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
|
183 |
// -----------------------------------------------------------------------------
|
|
184 |
// CMmSmsCache::AddEntryL
|
|
185 |
// adds new entry to cache, if the cause of isi msg is not
|
|
186 |
// ok, then we add just a null pointer (to save space)
|
|
187 |
// returns true if element was cache and false
|
|
188 |
// if cache location is empty
|
|
189 |
// -----------------------------------------------------------------------------
|
|
190 |
//
|
|
191 |
TBool CMmSmsCache::AddEntryL(
|
|
192 |
const RMobileSmsStore::TMobileGsmSmsEntryV1* aEntry,
|
|
193 |
const TUint8 aRecordId )
|
|
194 |
{
|
|
195 |
TFLOGSTRING("TSY: CMmSmsCache::AddEntryL");
|
|
196 |
OstTrace0( TRACE_NORMAL, CMMSMSCACHE_ADDENTRYL, "CMmSmsCache::AddEntryL" );
|
|
197 |
|
|
198 |
if ( 0 < iElements.Count() )
|
|
199 |
{
|
|
200 |
delete iElements[aRecordId - 1];
|
|
201 |
iElements[aRecordId - 1] = NULL;
|
|
202 |
}
|
|
203 |
|
|
204 |
// If the location is non-empty (filled with 0xFF (3GPP TS 31.102
|
|
205 |
// 4.2.25 EFSMS (Short messages)))
|
|
206 |
|
|
207 |
if ( EMPTY_LOCATION != aEntry->iMsgStatus )
|
|
208 |
{
|
|
209 |
// Make a copy of the received SIM SMS.
|
|
210 |
// Reserve heap memory; can leave if out of mem.
|
|
211 |
RMobileSmsStore::TMobileGsmSmsEntryV1* tmpBuf =
|
|
212 |
new( ELeave ) RMobileSmsStore::TMobileGsmSmsEntryV1;
|
|
213 |
*tmpBuf = *aEntry;
|
|
214 |
// copy data
|
|
215 |
iElements[aRecordId - 1] = tmpBuf;
|
|
216 |
|
|
217 |
return ETrue;
|
|
218 |
}
|
|
219 |
return EFalse;
|
|
220 |
}
|
|
221 |
|
|
222 |
// -----------------------------------------------------------------------------
|
|
223 |
// CMmSmsCache::GetEntry
|
|
224 |
// get entry from cache, returns null if cache doesn't c;ontain
|
|
225 |
// valid entry in the given location location range is in range
|
|
226 |
// [1... max sim sms slots]
|
|
227 |
// -----------------------------------------------------------------------------
|
|
228 |
//
|
|
229 |
RMobileSmsStore::TMobileGsmSmsEntryV1* CMmSmsCache::GetEntry( TInt aLocation )
|
|
230 |
{
|
|
231 |
TFLOGSTRING2("TSY: CMmSmsCache::GetEntry - location: %d", aLocation);
|
|
232 |
OstTrace1( TRACE_NORMAL, CMMSMSCACHE_GETENTRY, "CMmSmsCache::GetEntry;aLocation=%d", aLocation );
|
|
233 |
RMobileSmsStore::TMobileGsmSmsEntryV1* smsData = NULL;
|
|
234 |
if ( aLocation <= iElements.Count() && aLocation >= 1 )
|
|
235 |
{
|
|
236 |
if ( iElements[aLocation-1] )
|
|
237 |
{
|
|
238 |
RMobileSmsStore::TMobileGsmSmsEntryV1* tempHBuf(
|
|
239 |
iElements[aLocation-1] );
|
|
240 |
smsData = tempHBuf;
|
|
241 |
}
|
|
242 |
}
|
|
243 |
return smsData;
|
|
244 |
}
|
|
245 |
|
|
246 |
// -----------------------------------------------------------------------------
|
|
247 |
// CMmSmsCache::FirstFreeLocation
|
|
248 |
// return first free location in range [1... max sim sms slots]
|
|
249 |
// or zero if no free slots are found
|
|
250 |
// -----------------------------------------------------------------------------
|
|
251 |
//
|
|
252 |
TUint CMmSmsCache::FirstFreeLocation()
|
|
253 |
{
|
|
254 |
TFLOGSTRING("TSY: CMmSmsCache::FirstFreeLocation");
|
|
255 |
OstTrace0( TRACE_NORMAL, CMMSMSCACHE_FIRSTFREELOCATION, "CMmSmsCache::FirstFreeLocation" );
|
|
256 |
TInt location( 0 );
|
|
257 |
for ( TInt i = 0; i < iElements.Count(); i++ )
|
|
258 |
{
|
|
259 |
if ( !iElements[i] )
|
|
260 |
{
|
|
261 |
location = i + 1;
|
|
262 |
i = iElements.Count(); // exit loop
|
|
263 |
}
|
|
264 |
}
|
|
265 |
TFLOGSTRING2("TSY: CMmSmsCache::FirstFreeLocation - found location: %d", location);
|
|
266 |
OstTrace0( TRACE_NORMAL, DUP1_CMMSMSCACHE_FIRSTFREELOCATION, "CMmSmsCache::FirstFreeLocation" );
|
|
267 |
return location;
|
|
268 |
}
|
|
269 |
|
|
270 |
// -----------------------------------------------------------------------------
|
|
271 |
// CMmSmsCache::SetDeleteLocation
|
|
272 |
// set the location to delete by Delete()
|
|
273 |
// -----------------------------------------------------------------------------
|
|
274 |
//
|
|
275 |
void CMmSmsCache::SetDeleteLocation( TInt aLocation )
|
|
276 |
{
|
|
277 |
TFLOGSTRING2("TSY: CMmSmsCache::SetDeleteLocation %d", aLocation);
|
|
278 |
OstTrace1( TRACE_NORMAL, CMMSMSCACHE_SETDELETELOCATION, "CMmSmsCache::SetDeleteLocation;aLocation=%d", aLocation );
|
|
279 |
iDeleteLocation = aLocation;
|
|
280 |
}
|
|
281 |
|
|
282 |
// -----------------------------------------------------------------------------
|
|
283 |
// CMmSmsCache::Delete
|
|
284 |
// if flush location is set, then flush it
|
|
285 |
// -----------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
void CMmSmsCache::Delete()
|
|
288 |
{
|
|
289 |
TFLOGSTRING("TSY: CMmSmsCache::Delete");
|
|
290 |
OstTrace0( TRACE_NORMAL, CMMSMSCACHE_DELETE, "CMmSmsCache::Delete" );
|
|
291 |
if ( iDeleteLocation!=0 )
|
|
292 |
{
|
|
293 |
Delete( iDeleteLocation );
|
|
294 |
iDeleteLocation = NULL;
|
|
295 |
}
|
|
296 |
}
|
|
297 |
|
|
298 |
// -----------------------------------------------------------------------------
|
|
299 |
// CMmSmsCache::Delete
|
|
300 |
// Delete an element from cache
|
|
301 |
// -----------------------------------------------------------------------------
|
|
302 |
//
|
|
303 |
void CMmSmsCache::Delete( TInt aLocation )
|
|
304 |
{
|
|
305 |
TFLOGSTRING2("TSY: CMmSmsCache::Delete %d", aLocation);
|
|
306 |
OstTrace1( TRACE_NORMAL, DUP1_CMMSMSCACHE_DELETE, "CMmSmsCache::Delete;aLocation=%d", aLocation );
|
|
307 |
|
|
308 |
if ( aLocation <= iElements.Count() && aLocation >= 1 )
|
|
309 |
{
|
|
310 |
delete iElements[aLocation-1];
|
|
311 |
iElements[aLocation-1] = NULL;
|
|
312 |
}
|
|
313 |
}
|
|
314 |
|
|
315 |
// -----------------------------------------------------------------------------
|
|
316 |
// CMmSmsCache::DeleteAll
|
|
317 |
// empty all of cache
|
|
318 |
// -----------------------------------------------------------------------------
|
|
319 |
//
|
|
320 |
void CMmSmsCache::DeleteAll()
|
|
321 |
{
|
|
322 |
TFLOGSTRING("TSY: CMmSmsCache::DeleteAll");
|
|
323 |
OstTrace0( TRACE_NORMAL, CMMSMSCACHE_DELETEALL, "CMmSmsCache::DeleteAll" );
|
|
324 |
for ( TInt i = 0; i < iElements.Count(); i++ )
|
|
325 |
{
|
|
326 |
delete iElements[i];
|
|
327 |
iElements[i] = NULL;
|
|
328 |
}
|
|
329 |
}
|
|
330 |
|
|
331 |
// End of File
|