24
|
1 |
// Copyright (c) 1997-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 |
// Retrieves information on ME <mem1>, <mem2> storage slots (total, used) ....AT+CPMS?
|
|
15 |
// Also tracks the number of preferred memories.
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "NOTIFY.H"
|
|
20 |
#include "mSMSMESS.H"
|
|
21 |
#include "mSMSMEM.H"
|
|
22 |
#include "mSLOGGER.H"
|
|
23 |
#include "ATIO.H"
|
|
24 |
#include "ATINIT.H"
|
|
25 |
#include "mSMSSTOR.H"
|
|
26 |
|
|
27 |
_LIT8(KOpenBracketCharacter,"(");
|
|
28 |
_LIT8(KCloseBracketCharacter,")");
|
|
29 |
|
|
30 |
|
|
31 |
CATSmsMemoryStorage* CATSmsMemoryStorage::NewL (CATIO* aIo, CTelObject* aTelObject, CATInit* aInit,
|
|
32 |
CPhoneGlobals* aGsmStatus)
|
|
33 |
{
|
|
34 |
CATSmsMemoryStorage* self = new (ELeave) CATSmsMemoryStorage(aIo, aTelObject, aInit, aGsmStatus);
|
|
35 |
CleanupStack::PushL(self);
|
|
36 |
self->ConstructL();
|
|
37 |
CleanupStack::Pop();
|
|
38 |
return self;
|
|
39 |
}
|
|
40 |
|
|
41 |
CATSmsMemoryStorage::CATSmsMemoryStorage(CATIO* aIo, CTelObject* aTelObject,
|
|
42 |
CATInit* aInit, CPhoneGlobals* aGsmStatus)
|
|
43 |
:CATSmsCommands(aIo, aTelObject, aInit, aGsmStatus),
|
|
44 |
iSmsStore(REINTERPRET_CAST(CMobileSmsStore*,aTelObject)),
|
|
45 |
iCancelled(EFalse)
|
|
46 |
{}
|
|
47 |
|
|
48 |
void CATSmsMemoryStorage::ConstructL()
|
|
49 |
{
|
|
50 |
CATCommands::ConstructL();
|
|
51 |
iClientPreferredMem = 1;
|
|
52 |
}
|
|
53 |
|
|
54 |
CATSmsMemoryStorage::~CATSmsMemoryStorage()
|
|
55 |
{}
|
|
56 |
|
|
57 |
void CATSmsMemoryStorage::Start(TTsyReqHandle aTsyReqHandle, TAny* aParams)
|
|
58 |
//
|
|
59 |
// Start function called by CMobileSmsMessaging::GetMessageStoreInfo
|
|
60 |
//
|
|
61 |
{
|
|
62 |
iReqHandle = aTsyReqHandle;
|
|
63 |
iCancelled=EFalse;
|
|
64 |
if (aParams)
|
|
65 |
iInfoPckg=static_cast<RMobilePhoneStore::TMobilePhoneStoreInfoV1Pckg*>(aParams);
|
|
66 |
|
|
67 |
if (ComparePrefMem(iPeekPrevStorage[iClientPreferredMem].iStoreName))
|
|
68 |
{
|
|
69 |
// no need to set preferred memory as correct one is selected already
|
|
70 |
iTxBuffer.Copy(KGetPrefMemTestCommand); // Preferred Memory Storage cmd. ETSI std GSM 07.05, May 1996
|
|
71 |
iIo->Write(this, iTxBuffer);
|
|
72 |
iIo->SetTimeOut(this, 5000);
|
|
73 |
iState = EATWaitForSendingCPMSRequestComplete;
|
|
74 |
}
|
|
75 |
else //ie: the compared memories are different, must change phone mem to temporary mem
|
|
76 |
{
|
|
77 |
iRequestedMem=iPeekPrevStorage[iClientPreferredMem].iStoreName;
|
|
78 |
SetCurrentPrefMem(iRequestedMem);
|
|
79 |
iState = EATWaitForSettingMem;
|
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
void CATSmsMemoryStorage::StartGetInfo(TTsyReqHandle aTsyReqHandle, TAny* aParams)
|
|
84 |
//
|
|
85 |
// Start function called by CMobileSmsStore::GetInfo
|
|
86 |
//
|
|
87 |
{
|
|
88 |
LOGTEXT(_L8("CATSmsMemoryStorage:\tClient has called a GetInfo"));
|
|
89 |
iReqHandle = aTsyReqHandle;
|
|
90 |
iCancelled=EFalse;
|
|
91 |
|
|
92 |
if (aParams)
|
|
93 |
iInfoPckg=static_cast<RMobilePhoneStore::TMobilePhoneStoreInfoV1Pckg*>(aParams);
|
|
94 |
|
|
95 |
if (ComparePrefMem(iSmsStore->iStoreName))
|
|
96 |
{
|
|
97 |
// no need to set preferred memory as correct one is selected already
|
|
98 |
iTxBuffer.Copy(KGetPrefMemTestCommand); // Preferred Memory Storage cmd. ETSI std GSM 07.05, May 1996
|
|
99 |
iIo->Write(this, iTxBuffer);
|
|
100 |
iIo->SetTimeOut(this, 5000);
|
|
101 |
iState = EATWaitForSendingCPMSRequestComplete;
|
|
102 |
}
|
|
103 |
else
|
|
104 |
{
|
|
105 |
iRequestedMem=iSmsStore->iStoreName;
|
|
106 |
SetCurrentPrefMem(iRequestedMem);
|
|
107 |
iState = EATWaitForSettingMem;
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
|
|
112 |
void CATSmsMemoryStorage::EventSignal(TEventSource aSource)
|
|
113 |
//
|
|
114 |
// Finite State Machine for handling events from the comm port
|
|
115 |
//
|
|
116 |
{
|
|
117 |
LOGTEXT2(_L8("CATSmsMemoryStorage:\tiState = %D"), iState);
|
|
118 |
if (aSource == ETimeOutCompletion)
|
|
119 |
{
|
|
120 |
LOGTEXT(_L8("CATSmsMemoryStorage:\tTimeout Error during AT+CPMS query of ME"));
|
|
121 |
iPhoneGlobals->iPhoneStatus.iModemDetected = RPhone::EDetectedNotPresent;
|
|
122 |
Complete(KErrTimedOut, aSource);
|
|
123 |
return;
|
|
124 |
}
|
|
125 |
|
|
126 |
|
|
127 |
TInt ret(KErrNone);
|
|
128 |
|
|
129 |
switch (iState)
|
|
130 |
{
|
|
131 |
case EATWaitForSettingMem:
|
|
132 |
iIo->WriteAndTimerCancel(this);
|
|
133 |
StandardWriteCompletionHandler(aSource, 5);
|
|
134 |
iState = EATWaitForSettingMemComplete;
|
|
135 |
break;
|
|
136 |
|
|
137 |
case EATWaitForSettingMemComplete:
|
|
138 |
__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
|
|
139 |
|
|
140 |
iIo->WriteAndTimerCancel(this);
|
|
141 |
ret=ValidateExpectString();
|
|
142 |
if (ret==KErrNone)
|
|
143 |
{
|
|
144 |
iPhoneGlobals->iPhonePrefMem=iRequestedMem;
|
|
145 |
if (iCancelled)
|
|
146 |
Complete(KErrCancel, aSource);
|
|
147 |
else
|
|
148 |
{
|
|
149 |
iTxBuffer.Copy(KGetPrefMemTestCommand); // Preferred Memory Storage cmd. ETSI std GSM 07.05, May 1996
|
|
150 |
iIo->Write(this, iTxBuffer);
|
|
151 |
iIo->SetTimeOut(this, 5000);
|
|
152 |
iState = EATWaitForSendingCPMSRequestComplete;
|
|
153 |
}
|
|
154 |
}
|
|
155 |
else
|
|
156 |
Complete(ret, aSource);
|
|
157 |
break;
|
|
158 |
|
|
159 |
case EATWaitForSendingCPMSRequestComplete:
|
|
160 |
iIo->WriteAndTimerCancel(this);
|
|
161 |
StandardWriteCompletionHandler(aSource,5);
|
|
162 |
iState = EATWaitForCPMSResponseComplete;
|
|
163 |
break;
|
|
164 |
|
|
165 |
case EATWaitForCPMSResponseComplete:
|
|
166 |
__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
|
|
167 |
iIo->WriteAndTimerCancel(this);
|
|
168 |
TRAPD(ret2, CPMSResponseL());
|
|
169 |
Complete(ret2,aSource);
|
|
170 |
break;
|
|
171 |
|
|
172 |
default: // Catches illegal states
|
|
173 |
LOGTEXT2(_L8("CATSmsMemoryStorage:\tiIllegal State = %D"), iState);
|
|
174 |
break;
|
|
175 |
}
|
|
176 |
}
|
|
177 |
|
|
178 |
void CATSmsMemoryStorage::CPMSResponseL()
|
|
179 |
//
|
|
180 |
// Parse result of AT+CPMS? ....used by GetMessageStoreInfo()
|
|
181 |
//
|
|
182 |
{
|
|
183 |
ParseBufferLC();
|
|
184 |
RemoveUnsolicitedStrings(); // Removes any unsolicited strings
|
|
185 |
CATParamListEntry* entry;
|
|
186 |
TDblQueIter<CATParamListEntry> iter(iRxResults);
|
|
187 |
|
|
188 |
// +CPMS: <mem1>,<used1>,<total1>,<mem2>,<used2>,<total2>,<mem3>,<used3>,<total3>
|
|
189 |
// but we don't care after <total1>
|
|
190 |
|
|
191 |
entry = iter++;
|
|
192 |
if (!entry || entry->iResultPtr != KCPMSResponseString)
|
|
193 |
User::Leave(KErrNotFound);
|
|
194 |
|
|
195 |
entry = iter++;
|
|
196 |
TPtrC8 name(entry->iResultPtr);
|
|
197 |
entry=iter++;
|
|
198 |
TInt used = CATParamListEntry::EntryValL(entry);
|
|
199 |
entry=iter++;
|
|
200 |
TInt total = CATParamListEntry::EntryValL(entry);
|
|
201 |
|
|
202 |
RMobilePhoneStore::TMobilePhoneStoreInfoV1& storeInfo = (*iInfoPckg)();
|
|
203 |
|
|
204 |
storeInfo.iType=RMobilePhoneStore::EShortMessageStore;
|
|
205 |
storeInfo.iUsedEntries=used;
|
|
206 |
storeInfo.iTotalEntries=total;
|
|
207 |
|
|
208 |
if (name == KMEStorage)
|
|
209 |
storeInfo.iName=KETelMeSmsStore;
|
|
210 |
else if (name == KSMStorage)
|
|
211 |
storeInfo.iName=KETelIccSmsStore;
|
|
212 |
else if (name == KMTStorage)
|
|
213 |
storeInfo.iName=KETelCombinedSmsStore;
|
|
214 |
else
|
|
215 |
User::Leave(KErrGeneral);
|
|
216 |
|
|
217 |
storeInfo.iCaps=SMSStoreCaps(storeInfo.iName);
|
|
218 |
|
|
219 |
LOGTEXT3(_L8("CPMSResponseL\tPreferred store used=%d, total=%d"), used, total);
|
|
220 |
CleanupStack::PopAndDestroy();
|
|
221 |
}
|
|
222 |
|
|
223 |
void CATSmsMemoryStorage::EnumerateCPMSResponseL()
|
|
224 |
//
|
|
225 |
// Parse result of AT+CPMS=?
|
|
226 |
//
|
|
227 |
{
|
|
228 |
TInt count;
|
|
229 |
for (count = 0; count < KStorageArraySize ; count++)
|
|
230 |
{
|
|
231 |
iPeekPrevStorage[count].iStoreName.Zero();
|
|
232 |
iPeekPrevStorage[count].iMems = 0;
|
|
233 |
}
|
|
234 |
iStoreCounter = 0;
|
|
235 |
|
|
236 |
ParseBufferLC(ETrue); // we need the list separators
|
|
237 |
RemoveUnsolicitedStrings(); // Ensure we remove any unsolicited messages
|
|
238 |
CATParamListEntry* entry;
|
|
239 |
TDblQueIter<CATParamListEntry> iter(iRxResults);
|
|
240 |
|
|
241 |
// +CPMS: (list of supported mem1), (list of supported mem2), (list of supported mem3)
|
|
242 |
|
|
243 |
entry=iter++;
|
|
244 |
if (entry==NULL || entry->iResultPtr != KCPMSResponseString)
|
|
245 |
User::Leave(KErrGeneral);
|
|
246 |
|
|
247 |
TUint32 memtype = KMemTypeReadAndDeleted;
|
|
248 |
TInt listCounter = 0;
|
|
249 |
|
|
250 |
while (entry = iter++, entry != NULL)
|
|
251 |
{
|
|
252 |
TPtrC8 param(entry->iResultPtr);
|
|
253 |
if (param == KOpenBracketCharacter)
|
|
254 |
{
|
|
255 |
if (listCounter>2)
|
|
256 |
User::Leave(KErrGeneral);
|
|
257 |
continue;
|
|
258 |
}
|
|
259 |
if (param == KCloseBracketCharacter)
|
|
260 |
{
|
|
261 |
listCounter++;
|
|
262 |
memtype <<= 1;
|
|
263 |
continue;
|
|
264 |
}
|
|
265 |
// Should be a known mem type
|
|
266 |
if (param == KMTStorage)
|
|
267 |
continue; // Ignore MT storage
|
|
268 |
if (param != KBMStorage &&
|
|
269 |
param != KMEStorage &&
|
|
270 |
param != KSMStorage &&
|
|
271 |
param != KTAStorage)
|
|
272 |
{
|
|
273 |
continue;
|
|
274 |
}
|
|
275 |
for (count = 0 ; count < iStoreCounter ; count++)
|
|
276 |
{
|
|
277 |
if (param == iPeekPrevStorage[count].iStoreName)
|
|
278 |
break;
|
|
279 |
}
|
|
280 |
if (count == iStoreCounter) // ie: The current <mem> being looked at (param) has not been seen before
|
|
281 |
{
|
|
282 |
iPeekPrevStorage[count].iStoreName = param;
|
|
283 |
iStoreCounter++;
|
|
284 |
}
|
|
285 |
iPeekPrevStorage[count].iMems |= memtype;
|
|
286 |
}
|
|
287 |
CleanupStack::PopAndDestroy();
|
|
288 |
LOGTEXT2(_L8("CATSmsMemoryStorage\t%d memory stores found"), iStoreCounter);
|
|
289 |
for (count=0; count<iStoreCounter; count++)
|
|
290 |
{
|
|
291 |
LOGTEXT3(_L8("CATSmsMemoryStorage\t\tStore %S supports %x"),
|
|
292 |
&iPeekPrevStorage[count].iStoreName, iPeekPrevStorage[count].iMems);
|
|
293 |
}
|
|
294 |
}
|
|
295 |
|
|
296 |
TInt CATSmsMemoryStorage::GetNumberOfMessageStores()
|
|
297 |
//
|
|
298 |
// Returns to client, the number of different message stores (mem1, mem2 etc)
|
|
299 |
//
|
|
300 |
{
|
|
301 |
return iStoreCounter;
|
|
302 |
}
|
|
303 |
|
|
304 |
TInt CATSmsMemoryStorage::WhichPreferredMem(TInt aIndex)
|
|
305 |
//
|
|
306 |
// Information from Client, telling TSY which is the preferred memory.
|
|
307 |
//
|
|
308 |
{
|
|
309 |
TInt ret(KErrNone);
|
|
310 |
|
|
311 |
iClientPreferredMem = aIndex;
|
|
312 |
if (iClientPreferredMem > (iStoreCounter - 1))
|
|
313 |
ret=KErrNotSupported;
|
|
314 |
|
|
315 |
return ret;
|
|
316 |
}
|
|
317 |
|
|
318 |
void CATSmsMemoryStorage::Stop(TTsyReqHandle aTsyReqHandle)
|
|
319 |
//
|
|
320 |
// Attempts to halt the process
|
|
321 |
//
|
|
322 |
{
|
|
323 |
__ASSERT_ALWAYS(aTsyReqHandle == iReqHandle,Panic(EIllegalTsyReqHandle));
|
|
324 |
LOGTEXT(_L8("CATSmsMemoryStorage:\tCancelling Command"));
|
|
325 |
|
|
326 |
LOGTEXT2(_L8("Current state TSY is cancelling from %d"), iState);
|
|
327 |
// Wait for convenient place in state machine to cancel
|
|
328 |
iCancelled=ETrue;
|
|
329 |
}
|
|
330 |
|
|
331 |
void CATSmsMemoryStorage::Complete(TInt aError)
|
|
332 |
{
|
|
333 |
Complete(aError,EReadCompletion);
|
|
334 |
}
|
|
335 |
|
|
336 |
void CATSmsMemoryStorage::Complete(TInt aError,TEventSource aSource)
|
|
337 |
{
|
|
338 |
iIo->WriteAndTimerCancel(this);
|
|
339 |
iIo->RemoveExpectStrings(this);
|
|
340 |
iOKExpectString = NULL;
|
|
341 |
iErrorExpectString = NULL;
|
|
342 |
CATCommands::Complete(aError,aSource);
|
|
343 |
iTelObject->ReqCompleted(iReqHandle, aError);
|
|
344 |
if (aSource==EWriteCompletion)
|
|
345 |
iIo->Read();
|
|
346 |
iState = EATNotInProgress;
|
|
347 |
}
|
|
348 |
|
|
349 |
void CATSmsMemoryStorage::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
|
|
350 |
{
|
|
351 |
if (iState!=EATNotInProgress)
|
|
352 |
{
|
|
353 |
iIo->WriteAndTimerCancel(this);
|
|
354 |
iTelObject->ReqCompleted(iReqHandle, aStatus);
|
|
355 |
iState = EATNotInProgress;
|
|
356 |
}
|
|
357 |
}
|
|
358 |
|
|
359 |
void CATSmsMemoryStorage::CopyDataFromCATInit(CATInit* aInit)
|
|
360 |
//
|
|
361 |
// CATInit creates a separate instance of CATSmsMemoryStorage and uses this to get
|
|
362 |
// enumeratestore info during initialisation of the TSY. CMobileSmsMessaging creates another
|
|
363 |
// instance of CATSmsMemoryStorage, but this new instance requires a lot of the information
|
|
364 |
// contained within the CATInit instance. Due to iTelObject problems, we can't just do
|
|
365 |
// a iATSmsMemoryStorage = iInit->iEnumerate; during the ConstructL() of CMobileSmsMessaging.
|
|
366 |
//
|
|
367 |
{
|
|
368 |
iStoreCounter = aInit->iEnumerate->iStoreCounter;
|
|
369 |
for (TInt i = 0; i < KStorageArraySize ; i++)
|
|
370 |
iPeekPrevStorage[i] = aInit->iEnumerate->iPeekPrevStorage[i];
|
|
371 |
}
|
|
372 |
|
|
373 |
void CATSmsMemoryStorage::GetPrefMemL()
|
|
374 |
//
|
|
375 |
// Parse result of AT+CPMS?
|
|
376 |
// this will allocate the phone's pref'd memory to the iPhoneGlobals->iPhonePrefMem local storage.
|
|
377 |
//
|
|
378 |
{
|
|
379 |
ParseBufferLC();
|
|
380 |
RemoveUnsolicitedStrings(); // Removes any unsolicited strings
|
|
381 |
CATParamListEntry* entry;
|
|
382 |
TDblQueIter<CATParamListEntry> iter(iRxResults);
|
|
383 |
|
|
384 |
// +CPMS: <mem1>,<used1>,<total1>,<mem2>,<used2>,<total2>,<mem3>,<used3>,<total3>
|
|
385 |
|
|
386 |
entry = iter++;
|
|
387 |
if (entry==NULL || entry->iResultPtr != KCPMSResponseString)
|
|
388 |
User::Leave(KErrNotFound);
|
|
389 |
|
|
390 |
entry = iter++;
|
|
391 |
if (entry==NULL ||
|
|
392 |
(entry->iResultPtr != KBMStorage &&
|
|
393 |
entry->iResultPtr != KMEStorage &&
|
|
394 |
entry->iResultPtr != KSMStorage &&
|
|
395 |
entry->iResultPtr != KTAStorage))
|
|
396 |
{
|
|
397 |
User::Leave(KErrNotFound);
|
|
398 |
}
|
|
399 |
|
|
400 |
iPhoneGlobals->iPhonePrefMem = entry->iResultPtr;
|
|
401 |
|
|
402 |
LOGTEXT2(_L8("CATSmsMemoryStorage:\tPreferred Memory %S"), &iPhoneGlobals->iPhonePrefMem);
|
|
403 |
CleanupStack::PopAndDestroy();
|
|
404 |
}
|
|
405 |
|
|
406 |
TInt CATSmsMemoryStorage::SMSStoreCaps(TDes& aName)
|
|
407 |
/**
|
|
408 |
* This method returns the capabilities for a specific SMS store.
|
|
409 |
*/
|
|
410 |
{
|
|
411 |
TInt caps = 0;
|
|
412 |
|
|
413 |
if ((aName.CompareF(KETelMeSmsStore)==KErrNone) ||
|
|
414 |
(aName.CompareF(KETelIccSmsStore)==KErrNone))
|
|
415 |
{
|
|
416 |
caps |= RMobileSmsStore::KCapsUnreadMessages;
|
|
417 |
caps |= RMobileSmsStore::KCapsReadMessages;
|
|
418 |
caps |= RMobileSmsStore::KCapsUnsentMessages;
|
|
419 |
caps |= RMobileSmsStore::KCapsSentMessages;
|
|
420 |
caps |= RMobileSmsStore::KCapsGsmMessages;
|
|
421 |
caps |= RMobilePhoneStore::KCapsIndividualEntry;
|
|
422 |
caps |= RMobilePhoneStore::KCapsReadAccess;
|
|
423 |
caps |= RMobilePhoneStore::KCapsWriteAccess;
|
|
424 |
return caps;
|
|
425 |
}
|
|
426 |
return caps; // If the store was not found zero is returned
|
|
427 |
}
|