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 atphbkgetphonestoreinfo.cpp |
|
15 // This contains CAtPhbkGetPhoneStoreInfo which is used to get phonebook information |
|
16 // |
|
17 |
|
18 //system include |
|
19 #include <ctsy/ltsy/cctsydispatchercallback.h> |
|
20 #include <etelmm.h> |
|
21 |
|
22 //user include |
|
23 #include "atphbkgetphonestoreinfo.h" |
|
24 #include "mslogger.h" |
|
25 #include "ltsycommondefine.h" |
|
26 |
|
27 //constant defination |
|
28 _LIT8(KSetPhoneStore,"AT+CPBS=\"%S\"\r"); |
|
29 _LIT8(KGetPhoneStoreInfo,"AT+CPBS?\r"); |
|
30 _LIT8(KCPBSResponseString,"+CPBS:"); |
|
31 _LIT8(KAdnPhonebook,"SM"); |
|
32 _LIT8(KFdnPhonebook,"FD"); |
|
33 _LIT8(KGetPrefMemCommand,"AT+CPMS?\r"); |
|
34 _LIT8(KCPMSResponseString,"+CPMS:"); |
|
35 |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // CAtPhbkGetPhoneStoreInfo::CAtPhbkGetPhoneStoreInfo |
|
39 // other items were commented in a header |
|
40 // --------------------------------------------------------------------------- |
|
41 CAtPhbkGetPhoneStoreInfo::CAtPhbkGetPhoneStoreInfo(CGlobalPhonemanager& aGloblePhone, |
|
42 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
43 :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback) |
|
44 { |
|
45 LOGTEXT(_L8("CAtPhbkGetPhoneStoreInfo::CAtPhbkGetPhoneStoreInfo called")); |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CAtPhbkGetPhoneStoreInfo::~CAtPhbkGetPhoneStoreInfo |
|
50 // other items were commented in a header |
|
51 // --------------------------------------------------------------------------- |
|
52 CAtPhbkGetPhoneStoreInfo::~CAtPhbkGetPhoneStoreInfo() |
|
53 { |
|
54 LOGTEXT(_L8("CAtPhbkGetPhoneStoreInfo::~CAtPhbkGetPhoneStoreInfo called")); |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CAtPhbkGetPhoneStoreInfo::NewLC |
|
59 // other items were commented in a header |
|
60 // --------------------------------------------------------------------------- |
|
61 CAtPhbkGetPhoneStoreInfo* CAtPhbkGetPhoneStoreInfo::NewLC(CGlobalPhonemanager& aGloblePhone, |
|
62 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
63 { |
|
64 CAtPhbkGetPhoneStoreInfo* self = new (ELeave)CAtPhbkGetPhoneStoreInfo(aGloblePhone, |
|
65 aCtsyDispatcherCallback); |
|
66 CleanupStack::PushL(self); |
|
67 self->ConstructL(); |
|
68 return self; |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CAtPhbkGetPhoneStoreInfo::NewL |
|
73 // other items were commented in a header |
|
74 // --------------------------------------------------------------------------- |
|
75 CAtPhbkGetPhoneStoreInfo* CAtPhbkGetPhoneStoreInfo::NewL(CGlobalPhonemanager& aGloblePhone, |
|
76 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
77 { |
|
78 CAtPhbkGetPhoneStoreInfo* self=CAtPhbkGetPhoneStoreInfo::NewLC(aGloblePhone, |
|
79 aCtsyDispatcherCallback); |
|
80 CleanupStack::Pop(self); |
|
81 return self; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CAtPhbkGetPhoneStoreInfo::ConstructL |
|
86 // other items were commented in a header |
|
87 // --------------------------------------------------------------------------- |
|
88 void CAtPhbkGetPhoneStoreInfo::ConstructL() |
|
89 { |
|
90 CAtCommandBase::ConstructL(); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CAtPhbkGetPhoneStoreInfo::SetPhoneStoreParam |
|
95 // other items were commented in a header |
|
96 // --------------------------------------------------------------------------- |
|
97 void CAtPhbkGetPhoneStoreInfo::SetPhoneStoreParam(const TDesC& aStoreName) |
|
98 { |
|
99 iStoreName = aStoreName; |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CAtPhbkGetPhoneStoreInfo::StartRequest |
|
104 // other items were commented in a header |
|
105 // --------------------------------------------------------------------------- |
|
106 void CAtPhbkGetPhoneStoreInfo::StartRequest() |
|
107 { |
|
108 if( iStoreName.CompareF(KETelIccSmsStore) == KErrNone) |
|
109 { |
|
110 iState = ESetIccSmsStore; |
|
111 iTxBuffer.Zero(); |
|
112 iTxBuffer.Copy(KGetPrefMemCommand); |
|
113 Write(); |
|
114 } |
|
115 else |
|
116 { |
|
117 ExecuteCommand(); |
|
118 } |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CAtPhbkGetPhoneStoreInfo::ExecuteCommand |
|
123 // other items were commented in a header |
|
124 // --------------------------------------------------------------------------- |
|
125 void CAtPhbkGetPhoneStoreInfo::ExecuteCommand() |
|
126 { |
|
127 LOGTEXT(_L8("CAtPhbkGetPhoneStoreInfo::ExecuteCommand called")); |
|
128 iState = ESetPhoneStore; |
|
129 TPtrC8 storeName; |
|
130 iTxBuffer.Zero(); |
|
131 if( iStoreName.CompareF(KETelIccFdnPhoneBook) == KErrNone ) |
|
132 { |
|
133 storeName.Set(KFdnPhonebook); |
|
134 } |
|
135 else if( iStoreName.CompareF(KETelIccAdnPhoneBook) == KErrNone) |
|
136 { |
|
137 storeName.Set(KAdnPhonebook); |
|
138 } |
|
139 iTxBuffer.Format(KSetPhoneStore,&storeName); |
|
140 Write(); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CAtPhbkGetPhoneStoreInfo::EventSignal |
|
145 // other items were commented in a header |
|
146 // --------------------------------------------------------------------------- |
|
147 void CAtPhbkGetPhoneStoreInfo::EventSignal(TAtEventSource aEventSource, TInt aStatus) |
|
148 { |
|
149 LOGTEXT3(_L8("CAtPhbkGetPhoneStoreInfo::EventSignal aStatus=%D iSource=%D"),aStatus,aEventSource); |
|
150 |
|
151 if(aStatus != KErrNone) |
|
152 { |
|
153 Complete(); |
|
154 iPhoneGlobals.iEventSignalActive = EFalse; |
|
155 iCtsyDispatcherCallback.CallbackPhonebookGetPhoneStoreInfoComp(aStatus,iPhoneStoreInfo); |
|
156 } |
|
157 else |
|
158 { |
|
159 if( aEventSource == EWriteCompletion ) |
|
160 { |
|
161 LOGTEXT(_L8("CAtPhbkGetPhoneStoreInfo::EventSignal,EWriteCompletion!")); |
|
162 if( iState == ESetPhoneStore ) |
|
163 { |
|
164 iState = ESetPhoneStoreComplete; |
|
165 } |
|
166 else if( iState == EGetPhoneStoreInfo ) |
|
167 { |
|
168 iState = EGetPhoneStoreInfoComplete; |
|
169 } |
|
170 else if( iState ==ESetIccSmsStore ) |
|
171 { |
|
172 iState = ESetIccSmsStoreComplete; |
|
173 } |
|
174 } |
|
175 else |
|
176 { |
|
177 LOGTEXT(_L8("CAtPhbkGetPhoneStoreInfo::EventSignal,EReadCompletion!")); |
|
178 if( iState == ESetPhoneStoreComplete ) |
|
179 { |
|
180 Complete(); |
|
181 iPhoneGlobals.iEventSignalActive = EFalse; |
|
182 if(iError == KErrNone) |
|
183 { |
|
184 iState = EGetPhoneStoreInfo; |
|
185 GetPhoneStoreInfo(); |
|
186 } |
|
187 else |
|
188 { |
|
189 iCtsyDispatcherCallback.CallbackPhonebookGetPhoneStoreInfoComp(iError,iPhoneStoreInfo); |
|
190 } |
|
191 } |
|
192 else if( iState == EGetPhoneStoreInfoComplete ) |
|
193 { |
|
194 iPhoneStoreInfo.iName = iStoreName; |
|
195 Complete(); |
|
196 iPhoneGlobals.iEventSignalActive = EFalse; |
|
197 iCtsyDispatcherCallback.CallbackPhonebookGetPhoneStoreInfoComp(iError,iPhoneStoreInfo); |
|
198 } |
|
199 else if( iState == ESetIccSmsStoreComplete) |
|
200 { |
|
201 iPhoneStoreInfo.iName = iStoreName; |
|
202 Complete(); |
|
203 iPhoneGlobals.iEventSignalActive = EFalse; |
|
204 iCtsyDispatcherCallback.CallbackPhonebookGetPhoneStoreInfoComp(iError,iPhoneStoreInfo); |
|
205 } |
|
206 } |
|
207 } |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // CAtPhbkGetPhoneStoreInfo::GetPhoneStoreInfo |
|
212 // other items were commented in a header |
|
213 // --------------------------------------------------------------------------- |
|
214 void CAtPhbkGetPhoneStoreInfo::GetPhoneStoreInfo() |
|
215 { |
|
216 LOGTEXT(_L8("CAtPhbkGetPhoneStoreInfo::GetPhoneStoreInfo callded")); |
|
217 iPhoneGlobals.iEventSignalActive = ETrue; |
|
218 iTxBuffer.Zero(); |
|
219 iTxBuffer.Copy(KGetPhoneStoreInfo); |
|
220 Write(); |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------------------------- |
|
224 // CAtPhbkGetPhoneStoreInfo::ParseResponseL |
|
225 // other items were commented in a header |
|
226 // --------------------------------------------------------------------------- |
|
227 void CAtPhbkGetPhoneStoreInfo::ParseResponseL(const TDesC8& /*aResponseBuf*/) |
|
228 { |
|
229 if( iState == ESetPhoneStoreComplete ) |
|
230 { |
|
231 if (CurrentLine().Match(KLtsyOkString) == 0) |
|
232 { |
|
233 iError = KErrNone; |
|
234 } |
|
235 else |
|
236 { |
|
237 iError = KErrGeneral; |
|
238 } |
|
239 } |
|
240 else if( iState == EGetPhoneStoreInfoComplete ) |
|
241 { |
|
242 /** |
|
243 * Here is an Example |
|
244 * +CPBS: "SM",6,250 |
|
245 * ADN phonebook is selected,6 locations are used and |
|
246 * total 250 locations are available |
|
247 */ |
|
248 iError = KErrNone; |
|
249 RArray<TPtrC8> array; |
|
250 CleanupClosePushL(array); |
|
251 iParser->ParseRespondedBuffer(array,Buffer()); |
|
252 //remove AT+CPBS |
|
253 if(array[0].MatchF(KAnyATCommand) != KErrNotFound) |
|
254 { |
|
255 array.Remove(0); |
|
256 } |
|
257 TInt count = array.Count(); |
|
258 #ifdef _DEBUG |
|
259 for( TInt i=0;i<count;i++ ) |
|
260 { |
|
261 LOGTEXT3(_L8("CAtPhbkGetPhoneStoreInfo::ParseResponseL\tarray[%d]=%S"), |
|
262 i,&array[i]); |
|
263 } |
|
264 #endif |
|
265 if (count <= 1) |
|
266 { |
|
267 CleanupStack::PopAndDestroy(); |
|
268 iError = KErrNotFound; |
|
269 return; |
|
270 } |
|
271 if(array[0].MatchF(KCPBSResponseString) == KErrNotFound) |
|
272 { |
|
273 CleanupStack::PopAndDestroy(); |
|
274 iError = KErrNotFound; |
|
275 return; |
|
276 } |
|
277 |
|
278 //parse used |
|
279 TLex8 lex(array[2]); |
|
280 TUint16 val; |
|
281 TInt ret = lex.Val(val,EDecimal); |
|
282 if(ret != KErrNone) |
|
283 { |
|
284 CleanupStack::PopAndDestroy(); |
|
285 iError = ret; |
|
286 return; |
|
287 } |
|
288 iPhoneStoreInfo.iUsedEntries = val; |
|
289 |
|
290 //parse total |
|
291 TLex8 lex1(array[3]); |
|
292 ret = lex1.Val(val,EDecimal); |
|
293 if(ret != KErrNone) |
|
294 { |
|
295 CleanupStack::PopAndDestroy(); |
|
296 iError = ret; |
|
297 return; |
|
298 } |
|
299 iPhoneStoreInfo.iTotalEntries = val; |
|
300 iPhoneStoreInfo.iType = RMobilePhoneStore::EPhoneBookStore; |
|
301 LOGTEXT3(_L8("CAtPhbkGetPhoneStoreInfo::ParseResponseL\tPreferred store used=%d, total=%d"), |
|
302 iPhoneStoreInfo.iUsedEntries,iPhoneStoreInfo.iTotalEntries); |
|
303 CleanupStack::PopAndDestroy(&array); |
|
304 } |
|
305 else |
|
306 { |
|
307 /** |
|
308 * Parse result of AT+CPMS? |
|
309 * Response:+CPMS:<mem1>,<used1>,<total1>,<mem2>,<used2>,<total2> |
|
310 * Here only the first mem is used. mem1 is SM |
|
311 */ |
|
312 iError = KErrNone; |
|
313 RArray<TPtrC8> array; |
|
314 CleanupClosePushL(array); |
|
315 iParser->ParseRespondedBuffer(array,Buffer()); |
|
316 if(array[0].MatchF(KAnyATCommand) != KErrNotFound) |
|
317 { |
|
318 array.Remove(0); |
|
319 } |
|
320 TInt Count = array.Count(); |
|
321 if (Count <= 1) |
|
322 { |
|
323 CleanupStack::PopAndDestroy(); |
|
324 iError = KErrNotFound; |
|
325 return; |
|
326 } |
|
327 if(array[0].MatchF(KCPMSResponseString) == KErrNotFound) |
|
328 { |
|
329 CleanupStack::PopAndDestroy(); |
|
330 iError = KErrNotFound; |
|
331 return; |
|
332 } |
|
333 //parse name |
|
334 TPtrC8 name(array[1]); |
|
335 |
|
336 //parse used |
|
337 TLex8 lex(array[2]); |
|
338 TUint16 val; |
|
339 TInt ret = lex.Val(val,EDecimal); |
|
340 if(ret != KErrNone) |
|
341 { |
|
342 CleanupStack::PopAndDestroy(); |
|
343 iError = ret; |
|
344 return; |
|
345 } |
|
346 iPhoneStoreInfo.iUsedEntries = val; |
|
347 |
|
348 //parse total |
|
349 TLex8 lex1(array[3]); |
|
350 ret = lex1.Val(val,EDecimal); |
|
351 if(ret != KErrNone) |
|
352 { |
|
353 CleanupStack::PopAndDestroy(); |
|
354 iError = ret; |
|
355 return; |
|
356 } |
|
357 iPhoneStoreInfo.iTotalEntries = val; |
|
358 iPhoneStoreInfo.iType = RMobilePhoneStore::EShortMessageStore; |
|
359 LOGTEXT3(_L8("CAtPhbkGetPhoneStoreInfo::ParseResponseL\tPreferred store used=%d, total=%d"), |
|
360 iPhoneStoreInfo.iUsedEntries,iPhoneStoreInfo.iTotalEntries); |
|
361 CleanupStack::PopAndDestroy(&array); |
|
362 } |
|
363 } |
|
364 |
|
365 //End of file |
|