|
1 // Copyright (c) 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 // @file atsmsstorereadall.cpp |
|
15 // This contains CAtSmsStoreReadAll which is used to read all messages |
|
16 // |
|
17 |
|
18 //system include |
|
19 #include <ctsy/ltsy/cctsydispatchercallback.h> |
|
20 |
|
21 //user include |
|
22 #include "mslogger.h" |
|
23 #include "atsmsstorereadall.h" |
|
24 #include "smsatutil.h" |
|
25 |
|
26 //constant defination |
|
27 _LIT8(KSmsReadCommand,"AT+CMGR=%d\r"); |
|
28 _LIT8(KCMGRResponseString,"+CMGR:"); |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CAtSmsStoreReadAll::CAtSmsStoreReadAll |
|
32 // other items were commented in a header |
|
33 // --------------------------------------------------------------------------- |
|
34 CAtSmsStoreReadAll::CAtSmsStoreReadAll(CGlobalPhonemanager& aGloblePhone, |
|
35 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
36 :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback) |
|
37 { |
|
38 LOGTEXT(_L8("CAtSmsStoreReadAll::CAtSmsStoreReadAll called")); |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CAtSmsStoreReadAll::~CAtSmsStoreReadAll |
|
43 // other items were commented in a header |
|
44 // --------------------------------------------------------------------------- |
|
45 CAtSmsStoreReadAll::~CAtSmsStoreReadAll() |
|
46 { |
|
47 LOGTEXT(_L8("CAtSmsStoreReadAll::~CAtSmsStoreReadAll called")); |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CAtSmsStoreReadAll::NewLC |
|
52 // other items were commented in a header |
|
53 // --------------------------------------------------------------------------- |
|
54 CAtSmsStoreReadAll* CAtSmsStoreReadAll::NewLC(CGlobalPhonemanager& aGloblePhone, |
|
55 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
56 { |
|
57 CAtSmsStoreReadAll* self = new (ELeave)CAtSmsStoreReadAll( aGloblePhone,aCtsyDispatcherCallback ); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CAtSmsStoreReadAll::NewL |
|
65 // other items were commented in a header |
|
66 // --------------------------------------------------------------------------- |
|
67 CAtSmsStoreReadAll* CAtSmsStoreReadAll::NewL(CGlobalPhonemanager& aGloblePhone, |
|
68 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
69 { |
|
70 CAtSmsStoreReadAll* self=CAtSmsStoreReadAll::NewLC( aGloblePhone,aCtsyDispatcherCallback ); |
|
71 CleanupStack::Pop(self); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CAtSmsStoreReadAll::ConstructL |
|
77 // other items were commented in a header |
|
78 // --------------------------------------------------------------------------- |
|
79 void CAtSmsStoreReadAll::ConstructL() |
|
80 { |
|
81 CAtCommandBase::ConstructL(); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CAtSmsStoreRead::StartRequest |
|
86 // other items were commented in a header |
|
87 // --------------------------------------------------------------------------- |
|
88 void CAtSmsStoreReadAll::StartRequest() |
|
89 { |
|
90 iIndex = 1; |
|
91 ExecuteCommand(); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CAtSmsStoreReadAll::ExecuteCommand |
|
96 // other items were commented in a header |
|
97 // --------------------------------------------------------------------------- |
|
98 void CAtSmsStoreReadAll::ExecuteCommand() |
|
99 { |
|
100 LOGTEXT(_L8("CAtSmsStoreReadAll::ExecuteCommand callded")); |
|
101 ReadMessage(); |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CAtSmsStoreReadAll::ReadMessage |
|
106 // other items were commented in a header |
|
107 // --------------------------------------------------------------------------- |
|
108 void CAtSmsStoreReadAll::ReadMessage() |
|
109 { |
|
110 LOGTEXT(_L8("CAtSmsStoreReadAll::ReadMessage callded")); |
|
111 iTxBuffer.Zero(); |
|
112 iTxBuffer.Format(KSmsReadCommand,iIndex); |
|
113 Write(); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CAtSmsStoreReadAll::EventSignal |
|
118 // other items were commented in a header |
|
119 // --------------------------------------------------------------------------- |
|
120 void CAtSmsStoreReadAll::EventSignal(TAtEventSource aEventSource, TInt aStatus) |
|
121 { |
|
122 LOGTEXT3(_L8("CAtSmsStoreReadAll::EventSignal aStatus=%D iSource=%D"), |
|
123 aStatus,aEventSource); |
|
124 if(aStatus == KErrNone) |
|
125 { |
|
126 if((aEventSource == EWriteCompletion)) |
|
127 { |
|
128 LOGTEXT(_L8("CAtSmsStoreRead::EventSignal,EWriteCompletion!")); |
|
129 return; |
|
130 } |
|
131 aStatus = iError; |
|
132 } |
|
133 |
|
134 if(iIndex < iPhoneGlobals.iStoreTotal) |
|
135 { |
|
136 iCtsyDispatcherCallback.CallbackPhonebookSmsStoreReadAllComp(aStatus,iSmsData,iIndex,ETrue,EFalse); |
|
137 iIndex++; |
|
138 ReadMessage(); |
|
139 } |
|
140 else |
|
141 { |
|
142 //Handle last message |
|
143 Complete(); |
|
144 iPhoneGlobals.iEventSignalActive = EFalse; |
|
145 iCtsyDispatcherCallback.CallbackPhonebookSmsStoreReadAllComp(aStatus,iSmsData,iIndex,EFalse,EFalse); |
|
146 } |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CAtSmsStoreReadAll::ParseResponseL |
|
151 // other items were commented in a header |
|
152 // --------------------------------------------------------------------------- |
|
153 void CAtSmsStoreReadAll::ParseResponseL(const TDesC8& /*aResponseBuf*/) |
|
154 { |
|
155 /** |
|
156 * Response:+CMGR:<stat>,[<alpha>],<length><CR><LF><pdu> |
|
157 */ |
|
158 iError = KErrNone; |
|
159 RArray<TPtrC8> array; |
|
160 CleanupClosePushL(array); |
|
161 iParser->ParseRespondedBuffer(array,Buffer()); |
|
162 if(array[0].MatchF(KAnyATCommand)!=KErrNotFound) |
|
163 { |
|
164 array.Remove(0); |
|
165 } |
|
166 TInt count = array.Count(); |
|
167 #ifdef _DEBUG |
|
168 for( TInt i=0;i<count;i++ ) |
|
169 { |
|
170 LOGTEXT3(_L8("CAtSmsStoreReadAll::ParseResponseL\tarray[%d]=%S"),i,&array[i]); |
|
171 } |
|
172 #endif |
|
173 if (count <= 1) |
|
174 { |
|
175 CleanupStack::PopAndDestroy(); |
|
176 iError = KErrNotFound; |
|
177 return; |
|
178 } |
|
179 if(array[0].MatchF(KCMGRResponseString)==KErrNotFound) |
|
180 { |
|
181 LOGTEXT(_L8("CAtSmsStoreReadAll::ParseResponseL\tFound +CMGR String!")); |
|
182 CleanupStack::PopAndDestroy(); |
|
183 iError = KErrNotFound; |
|
184 return; |
|
185 } |
|
186 // parse the message status |
|
187 TLex8 lex(array[1]); |
|
188 TUint16 val; |
|
189 TInt ret=lex.Val(val,EDecimal); |
|
190 if(ret!=KErrNone) |
|
191 { |
|
192 CleanupStack::PopAndDestroy(); |
|
193 iError = ret; |
|
194 return; |
|
195 } |
|
196 iSmsData.iMessageStatus = val; |
|
197 |
|
198 //parse the message length |
|
199 TLex8 lex1(array[3]); |
|
200 TUint msgLength; |
|
201 ret=lex1.Val(msgLength,EDecimal); |
|
202 if(ret!=KErrNone) |
|
203 { |
|
204 CleanupStack::PopAndDestroy(); |
|
205 iError = ret; |
|
206 return; |
|
207 } |
|
208 LOGTEXT2(_L8("CAtSmsStoreReadAll::ParseResponseL\tMessage Length=%d"),msgLength); |
|
209 TBuf8<KMaxAsciiPduLength> pdu; //Binary Message pdu |
|
210 SmsAtUtil::ConvertAsciiToBinary(array[4],pdu); |
|
211 TPtrC8 pduPtr(pdu); |
|
212 |
|
213 RMobilePhone::TMobileAddress gsmServiceCentre; //messages's SCA |
|
214 if (msgLength*2 < array[4].Length()) |
|
215 { |
|
216 // There is an SCA prepended so remove this and store it in iGsmServiceCentre |
|
217 SmsAtUtil::ReadAndRemoveAddressFromPdu(pduPtr,gsmServiceCentre); |
|
218 } |
|
219 iSmsData.iSmsMsg = pduPtr; |
|
220 iSmsData.iServiceCentre = gsmServiceCentre.iTelNumber; |
|
221 iSmsData.iMobileScNPI = gsmServiceCentre.iNumberPlan; |
|
222 iSmsData.iMobileScTON = gsmServiceCentre.iTypeOfNumber; |
|
223 LOGTEXT2(_L8("CAtSmsStoreReadAll::ParseResponseL\tMessage Status=%d"), |
|
224 iSmsData.iMessageStatus); |
|
225 LOGTEXT3(_L8("CAtSmsStoreReadAll::ParseResponseL\tSmsMsg=%S, ServiceCentre=%S"), |
|
226 &iSmsData.iSmsMsg, &iSmsData.iServiceCentre); |
|
227 CleanupStack::PopAndDestroy(&array); |
|
228 } |
|
229 |
|
230 //End of file |