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 |
// Deletes an SMS message present on the ME (Mobile Equipment). AT+CMGD=xx
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "NOTIFY.H"
|
|
19 |
#include "mSMSSTOR.H"
|
|
20 |
#include "mSMSDEL.H"
|
|
21 |
#include "mSLOGGER.H"
|
|
22 |
#include "ATIO.H"
|
|
23 |
#include "Matstd.h"
|
|
24 |
#include "smsbase.H"
|
|
25 |
#include "et_phone_util.h"
|
|
26 |
|
|
27 |
_LIT8(KSmsDeleteCommand,"AT+CMGD=%d\r");
|
|
28 |
|
|
29 |
|
|
30 |
CATSmsStorageDelete* CATSmsStorageDelete::NewL(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals)
|
|
31 |
{
|
|
32 |
CATSmsStorageDelete* self = new(ELeave) CATSmsStorageDelete(aIo, aTelObject, aInit, aPhoneGlobals);
|
|
33 |
CleanupStack::PushL(self);
|
|
34 |
self->ConstructL();
|
|
35 |
CleanupStack::Pop();
|
|
36 |
return self;
|
|
37 |
}
|
|
38 |
|
|
39 |
CATSmsStorageDelete::CATSmsStorageDelete(CATIO* aIo, CTelObject* aTelObject, CATInit* aInit, CPhoneGlobals* aPhoneGlobals)
|
|
40 |
:CATSmsCommands(aIo, aTelObject, aInit, aPhoneGlobals),
|
|
41 |
iCancelled(EFalse),
|
|
42 |
iSmsStore(REINTERPRET_CAST(CMobileSmsStore*, aTelObject))
|
|
43 |
{}
|
|
44 |
|
|
45 |
CATSmsStorageDelete::~CATSmsStorageDelete()
|
|
46 |
{}
|
|
47 |
|
|
48 |
void CATSmsStorageDelete::ConstructL()
|
|
49 |
{
|
|
50 |
CATCommands::ConstructL();
|
|
51 |
}
|
|
52 |
|
|
53 |
void CATSmsStorageDelete::Start(TTsyReqHandle aTsyReqHandle, TAny* aParams)
|
|
54 |
//
|
|
55 |
// Places BufferMarker and then starts the FSM (Finite State Machine).
|
|
56 |
//
|
|
57 |
{
|
|
58 |
__ASSERT_DEBUG(aParams,Panic(EMobileSmsMessagingNullParameter));
|
|
59 |
__ASSERT_DEBUG(aTsyReqHandle!=TSY_HANDLE_INIT_VALUE,Panic(EMobileSmsMessagingNullParameter));
|
|
60 |
|
|
61 |
iReqHandle = aTsyReqHandle;
|
|
62 |
iCancelled=EFalse;
|
|
63 |
iDeleteIndex = *(static_cast<TInt*>(aParams));
|
|
64 |
|
|
65 |
if (ComparePrefMem(iSmsStore->iStoreName))
|
|
66 |
StartDeleteSequence();
|
|
67 |
else //ie: the compared memories are different, must change phone mem to temporary mem
|
|
68 |
{
|
|
69 |
SetCurrentPrefMem(iSmsStore->iStoreName);
|
|
70 |
iState = EATWaitForSendingPrefMemComplete;
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
void CATSmsStorageDelete::StartDeleteSequence()
|
|
75 |
{
|
|
76 |
iTxBuffer.Format(KSmsDeleteCommand,iDeleteIndex); // Delete Command as per ETSI std (GSM 07.05, May 1996)
|
|
77 |
iIo->Write(this, iTxBuffer);
|
|
78 |
iIo->SetTimeOut(this, 5000);
|
|
79 |
iState = EATWaitForSendingDeleteComplete;
|
|
80 |
}
|
|
81 |
|
|
82 |
void CATSmsStorageDelete::EventSignal(TEventSource aSource)
|
|
83 |
//
|
|
84 |
// FSM for GSmsStorageDelete
|
|
85 |
//
|
|
86 |
{
|
|
87 |
LOGTEXT2(_L8("CATSmsStorageDelete:\tiState = %D"), iState);
|
|
88 |
if (aSource == ETimeOutCompletion)
|
|
89 |
{
|
|
90 |
LOGTEXT(_L8("CATSmsStorageDelete:\tTimeout error during Sms Delete"));
|
|
91 |
iIo->WriteAndTimerCancel(this);
|
|
92 |
if ((iState != EATWaitForPrefMemResponse)&&(!ComparePrefMem(iSmsStore->iStoreName)))
|
|
93 |
iPhoneGlobals->iPhonePrefMem = iSmsStore->iStoreName;
|
|
94 |
Complete(KErrTimedOut);
|
|
95 |
return;
|
|
96 |
} //if
|
|
97 |
|
|
98 |
switch(iState)
|
|
99 |
{
|
|
100 |
// the following 2 cases deal with changing to the client's preferred memory, if the situation arrises
|
|
101 |
// there are also two cases at the end of this state machine (EventSignal) that change the settings back
|
|
102 |
// to the original configuration.
|
|
103 |
case EATWaitForSendingPrefMemComplete:
|
|
104 |
__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
|
|
105 |
iIo->WriteAndTimerCancel(this);
|
|
106 |
StandardWriteCompletionHandler(aSource, 5);
|
|
107 |
iState = EATWaitForPrefMemResponse;
|
|
108 |
break;
|
|
109 |
|
|
110 |
case EATWaitForPrefMemResponse:
|
|
111 |
__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
|
|
112 |
{
|
|
113 |
iIo->WriteAndTimerCancel(this);
|
|
114 |
TInt pos=iIo->BufferFindF(KCPMSResponseString);
|
|
115 |
RemoveStdExpectStrings();
|
|
116 |
if (pos == KErrNotFound)
|
|
117 |
{
|
|
118 |
Complete(pos, aSource);
|
|
119 |
return;
|
|
120 |
}
|
|
121 |
LOGTEXT(_L8("CATSmsStorageDelete:\tPhones's preferred memory successfully set to client's preferred memory"));
|
|
122 |
iPhoneGlobals->iPhonePrefMem=iSmsStore->iStoreName;
|
|
123 |
if (!iCancelled)
|
|
124 |
StartDeleteSequence();
|
|
125 |
else
|
|
126 |
{
|
|
127 |
Complete(KErrCancel, aSource);
|
|
128 |
}
|
|
129 |
}
|
|
130 |
break;
|
|
131 |
|
|
132 |
// The next 2 cases deal with deleting....
|
|
133 |
|
|
134 |
case EATWaitForSendingDeleteComplete:
|
|
135 |
{
|
|
136 |
__ASSERT_ALWAYS(aSource == EWriteCompletion, Panic(EATCommand_IllegalCompletionWriteExpected));
|
|
137 |
iIo->WriteAndTimerCancel(this);
|
|
138 |
StandardWriteCompletionHandler(aSource,5);
|
|
139 |
AddCmsErrorExpectString();
|
|
140 |
iState=EATWaitForOKResponseComplete;
|
|
141 |
}
|
|
142 |
break;
|
|
143 |
|
|
144 |
case EATWaitForOKResponseComplete:
|
|
145 |
__ASSERT_ALWAYS(aSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
|
|
146 |
{
|
|
147 |
iIo->WriteAndTimerCancel(this);
|
|
148 |
TInt ret=ValidateExpectStringsWithCmsError();
|
|
149 |
RemoveCmsErrorExpectString();
|
|
150 |
RemoveStdExpectStrings();
|
|
151 |
// Delete has completed - hopefully successfully!
|
|
152 |
Complete(ret,aSource);
|
|
153 |
}
|
|
154 |
break;
|
|
155 |
|
|
156 |
default:
|
|
157 |
break;
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
|
|
162 |
void CATSmsStorageDelete::Stop(TTsyReqHandle aTsyReqHandle)
|
|
163 |
{
|
|
164 |
__ASSERT_ALWAYS(aTsyReqHandle == iReqHandle, Panic(EIllegalTsyReqHandle));
|
|
165 |
LOGTEXT(_L8("CATSmsStorageDelete:\tCancel called."));
|
|
166 |
// Wait for convenient place in FSM to cancel
|
|
167 |
iCancelled=ETrue;
|
|
168 |
}
|
|
169 |
|
|
170 |
|
|
171 |
void CATSmsStorageDelete::Complete(TInt aError)
|
|
172 |
{
|
|
173 |
Complete(aError, EReadCompletion);
|
|
174 |
}
|
|
175 |
|
|
176 |
void CATSmsStorageDelete::Complete(TInt aError, TEventSource aSource)
|
|
177 |
{
|
|
178 |
iIo->RemoveExpectStrings(this);
|
|
179 |
iOKExpectString=NULL;
|
|
180 |
iErrorExpectString=NULL;
|
|
181 |
|
|
182 |
//
|
|
183 |
// Call our base classes Complete so that
|
|
184 |
// we allow it do what ever it needs to do.
|
|
185 |
CATCommands::Complete(aError,aSource);
|
|
186 |
|
|
187 |
if (iReqHandle != 0 )
|
|
188 |
iTelObject->ReqCompleted(iReqHandle, aError);
|
|
189 |
|
|
190 |
if (aSource == EWriteCompletion)
|
|
191 |
iIo->Read();
|
|
192 |
|
|
193 |
iState = EATNotInProgress;
|
|
194 |
}
|
|
195 |
|
|
196 |
void CATSmsStorageDelete::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
|
|
197 |
{
|
|
198 |
if (iState!=EATNotInProgress)
|
|
199 |
{
|
|
200 |
iIo->WriteAndTimerCancel(this);
|
|
201 |
iOKExpectString=NULL;
|
|
202 |
iErrorExpectString=NULL;
|
|
203 |
iTelObject->ReqCompleted(iReqHandle, aStatus);
|
|
204 |
iState = EATNotInProgress;
|
|
205 |
}
|
|
206 |
}
|
|
207 |
|
|
208 |
TInt CATSmsStorageDelete::ValidateExpectStringsWithCmsError()
|
|
209 |
//
|
|
210 |
// Check for "ERROR" or "+CMS ERROR:" expect strings
|
|
211 |
// This would be the place to add more intelligent processing of the +CMS ERROR: xxx
|
|
212 |
// response. At the moment this is rather crude. "+CMS ERROR: 300" translates to a ME error
|
|
213 |
// which should not set aRetry, whereas a "+CMS ERROR: <anything>" might translate
|
|
214 |
// to a PDU error.
|
|
215 |
//
|
|
216 |
{
|
|
217 |
TInt ret(KErrNone);
|
|
218 |
if((iIo->FoundChatString()==iErrorExpectString)||
|
|
219 |
(iIo->FoundChatString()==iCmsExpectString))
|
|
220 |
{
|
|
221 |
LOGTEXT(_L8("CATSmsStorageDelete:\tSMS Delete error detected."));
|
|
222 |
ret=KErrGeneral;
|
|
223 |
}
|
|
224 |
return ret;
|
|
225 |
}
|
|
226 |
|