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 atcommandbase.cpp |
|
15 // This contains CAtCommandBase which is the base class for AT command |
|
16 // |
|
17 |
|
18 // user include |
|
19 #include "mslogger.h" |
|
20 #include "atcommandbase.h" |
|
21 #include "commengine.h" |
|
22 #include "atmanager.h" |
|
23 #include "stringparser.h" |
|
24 #include "atcommandexecuteobserver.h" |
|
25 #include "activecommandstore.h" |
|
26 #include "atswitchonlinemode.h" |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // CAtCommandBase::~CAtCommandBase |
|
30 // other items were commented in a header |
|
31 // --------------------------------------------------------------------------- |
|
32 CAtCommandBase::~CAtCommandBase() |
|
33 { |
|
34 iExpectingArray.Close(); |
|
35 |
|
36 delete iParser; |
|
37 iParser = NULL; |
|
38 |
|
39 if(iATSwitchOnLineMode) |
|
40 { |
|
41 delete iATSwitchOnLineMode; |
|
42 iATSwitchOnLineMode = NULL; |
|
43 } |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CAtCommandBase::AtType |
|
48 // other items were commented in a header |
|
49 // --------------------------------------------------------------------------- |
|
50 TLtsyATCommandType CAtCommandBase::AtType() |
|
51 { |
|
52 return iAtType; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CAtCommandBase::CAtCommandBase |
|
57 // other items were commented in a header |
|
58 // --------------------------------------------------------------------------- |
|
59 CAtCommandBase::CAtCommandBase(CGlobalPhonemanager& aGloblePhone, |
|
60 CCtsyDispatcherCallback& aCtsyDispatcherCallback) |
|
61 :CRequestBase(aGloblePhone), |
|
62 iCtsyDispatcherCallback(aCtsyDispatcherCallback) |
|
63 |
|
64 { |
|
65 LOGTEXT(_L8("[Ltsy] Starting CAtCommandBase::CAtCommandBase()")); |
|
66 |
|
67 iAtType = ELtsyAt_User_NotUse; |
|
68 |
|
69 iWriteTimeOut = KLtsyDefaultWriteTimeOut; |
|
70 iReadTimeOut = KLtsyDefaultReadTimeOut; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CAtCommandBase::ConstructL |
|
75 // other items were commented in a header |
|
76 // --------------------------------------------------------------------------- |
|
77 void CAtCommandBase::ConstructL() |
|
78 { |
|
79 iParser = new (ELeave) CRespondBufParser; |
|
80 iAtCommandObserver = NULL; |
|
81 //Add OK and ERROR expecting string |
|
82 iExpectingArray.AppendL(KLtsyOkString()); |
|
83 iExpectingArray.AppendL(KLtsyErrorString()); |
|
84 iExpectingArray.AppendL(KLtsyCmeErrorString()); |
|
85 |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CAtCommandBase::AddExpectStringL |
|
90 // other items were commented in a header |
|
91 // --------------------------------------------------------------------------- |
|
92 void CAtCommandBase::AddExpectStringL(const TDesC8& aExpectStr) |
|
93 { |
|
94 iExpectingArray.AppendL(aExpectStr); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CAtCommandBase::RemoveAllExpectString |
|
99 // other items were commented in a header |
|
100 // --------------------------------------------------------------------------- |
|
101 void CAtCommandBase::RemoveAllExpectString() |
|
102 { |
|
103 iExpectingArray.Reset(); |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CAtCommandBase::RemoveExpectString |
|
108 // other items were commented in a header |
|
109 // --------------------------------------------------------------------------- |
|
110 void CAtCommandBase::RemoveExpectString(const TDesC8& aExpectStr) |
|
111 { |
|
112 TBool found(ETrue); |
|
113 TInt count = iExpectingArray.Count(); |
|
114 |
|
115 for (TInt n = 0; found && n < count; n++) |
|
116 { |
|
117 if (iExpectingArray[n].Compare(aExpectStr) == 0) |
|
118 { |
|
119 iExpectingArray.Remove(n); |
|
120 iExpectingArray.Compress(); |
|
121 found = EFalse; |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CAtCommandBase::MatchExpectString |
|
128 // other items were commented in a header |
|
129 // --------------------------------------------------------------------------- |
|
130 TBool CAtCommandBase::MatchExpectString(const TDesC8& aReadLine) |
|
131 { |
|
132 TInt count = iExpectingArray.Count(); |
|
133 LOGTEXT2(_L8("[Ltsy] count = %d"), count); |
|
134 for (TInt n = 0; n < count; n++) |
|
135 { |
|
136 if (aReadLine.Match(iExpectingArray[n]) == 0) |
|
137 { |
|
138 return ETrue; |
|
139 } |
|
140 } |
|
141 if(aReadLine.Length()< KLtsyGenericBufferSize) |
|
142 { |
|
143 iNoMatchedLastLine.Copy(aReadLine); |
|
144 } |
|
145 return EFalse; |
|
146 } |
|
147 // --------------------------------------------------------------------------- |
|
148 // CAtCommandBase::SetAtCommandObserver |
|
149 // other items were commented in a header |
|
150 // --------------------------------------------------------------------------- |
|
151 void CAtCommandBase::SetAtCommandObserver(MAtCommandExecuteObserver* aAtCommandObserver) |
|
152 { |
|
153 iAtCommandObserver = aAtCommandObserver; |
|
154 } |
|
155 // --------------------------------------------------------------------------- |
|
156 // CAtCommandBase::RemoveAtCommandObserver |
|
157 // other items were commented in a header |
|
158 // --------------------------------------------------------------------------- |
|
159 void CAtCommandBase::RemoveAtCommandObserver() |
|
160 { |
|
161 iAtCommandObserver = NULL; |
|
162 } |
|
163 // --------------------------------------------------------------------------- |
|
164 // CAtCommandBase::GenericEventSignal |
|
165 // other items were commented in a header |
|
166 // --------------------------------------------------------------------------- |
|
167 void CAtCommandBase::GenericEventSignal(TAtEventSource aEventSource, TInt aStatus) |
|
168 { |
|
169 LOGTEXT(_L8("[Ltsy] Starting CAtCommandBase::GenericEventSignal()")); |
|
170 if(iAtCommandObserver) |
|
171 { |
|
172 iAtCommandObserver->AtCommandExecuteComplete(aEventSource, aStatus); |
|
173 } |
|
174 else |
|
175 { |
|
176 EventSignal(aEventSource, aStatus); |
|
177 } |
|
178 if((aEventSource == EWriteCompletion) && (aStatus == KErrNone)) |
|
179 { |
|
180 StartTimer(iReadTimeOut); |
|
181 } |
|
182 LOGTEXT(_L8("[Ltsy] End CAtCommandBase::GenericEventSignal()")); |
|
183 } |
|
184 // --------------------------------------------------------------------------- |
|
185 // CAtCommandBase::Write |
|
186 // other items were commented in a header |
|
187 // --------------------------------------------------------------------------- |
|
188 void CAtCommandBase::Write() |
|
189 { |
|
190 LOGTEXT(_L8("[Ltsy] Starting CAtCommandBase::Write()")); |
|
191 if(iPhoneGlobals.iPhoneStatus.iMode==RPhone::EModeOnlineData) |
|
192 { |
|
193 if(!iATSwitchOnLineMode) |
|
194 { |
|
195 TRAPD(ret,iATSwitchOnLineMode = CATSwitchOnLineMode::NewL(iPhoneGlobals,iCtsyDispatcherCallback)); |
|
196 if(ret!=KErrNone) |
|
197 { |
|
198 EventSignal(EWriteCompletion,ret); |
|
199 return; |
|
200 } |
|
201 } |
|
202 iATSwitchOnLineMode->StartSwitchOnLineMode(this,iAtCommandObserver); |
|
203 } |
|
204 else |
|
205 { |
|
206 ClearBuffer(); |
|
207 iPhoneGlobals.iAtManager->SetSolicitedAtCommand(this); |
|
208 iPhoneGlobals.iCommEngine->CommWrite(iTxBuffer); |
|
209 StartTimer(iWriteTimeOut); |
|
210 } |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CAtCommandBase::SetTimeOut |
|
215 // other items were commented in a header |
|
216 // --------------------------------------------------------------------------- |
|
217 void CAtCommandBase::SetTimeOut(TInt aWriteTimeOut, TInt aReadTimeOut) |
|
218 { |
|
219 iWriteTimeOut = aWriteTimeOut; |
|
220 iReadTimeOut = aReadTimeOut; |
|
221 } |
|
222 |
|
223 //--------------------------------------------------------------------------- |
|
224 // CAtCommandBase::SetTimeOut |
|
225 // other items were commented in a header |
|
226 // --------------------------------------------------------------------------- |
|
227 void CAtCommandBase::StartTimer(const TInt aTimeOut) |
|
228 { |
|
229 iPhoneGlobals.iCommEngine->StartTimer(aTimeOut); |
|
230 } |
|
231 |
|
232 //--------------------------------------------------------------------------- |
|
233 // CAtCommandBase::StopTimer |
|
234 // other items were commented in a header |
|
235 // --------------------------------------------------------------------------- |
|
236 void CAtCommandBase::StopTimer() |
|
237 { |
|
238 iPhoneGlobals.iCommEngine->StopTimer(); |
|
239 } |
|
240 |
|
241 //--------------------------------------------------------------------------- |
|
242 // CAtCommandBase::Buffer |
|
243 // other items were commented in a header |
|
244 // --------------------------------------------------------------------------- |
|
245 TPtrC8 CAtCommandBase::Buffer() const |
|
246 { |
|
247 return iPhoneGlobals.iCommEngine->GetStringParse()->Buffer(); |
|
248 } |
|
249 |
|
250 //--------------------------------------------------------------------------- |
|
251 // CAtCommandBase::CurrentLine |
|
252 // other items were commented in a header |
|
253 // --------------------------------------------------------------------------- |
|
254 TPtrC8 CAtCommandBase::CurrentLine() const |
|
255 { |
|
256 return iPhoneGlobals.iCommEngine->GetStringParse()->CurrentLine(); |
|
257 } |
|
258 //--------------------------------------------------------------------------- |
|
259 // CAtCommandBase::PrecedingLine |
|
260 // other items were commented in a header |
|
261 // --------------------------------------------------------------------------- |
|
262 TPtrC8 CAtCommandBase::PrecedingLine() const |
|
263 { |
|
264 return iNoMatchedLastLine; |
|
265 } |
|
266 //--------------------------------------------------------------------------- |
|
267 // CAtCommandBase::ClearBuffer |
|
268 // other items were commented in a header |
|
269 // --------------------------------------------------------------------------- |
|
270 void CAtCommandBase::ClearBuffer() |
|
271 { |
|
272 iPhoneGlobals.iCommEngine->GetStringParse()->ClearBuffer(); |
|
273 } |
|
274 |
|
275 //--------------------------------------------------------------------------- |
|
276 // CAtCommandBase::ClearCurrentLine |
|
277 // other items were commented in a header |
|
278 // --------------------------------------------------------------------------- |
|
279 void CAtCommandBase::ClearCurrentLine() |
|
280 { |
|
281 iPhoneGlobals.iCommEngine->GetStringParse()->ClearCurrentLine(); |
|
282 } |
|
283 |
|
284 //--------------------------------------------------------------------------- |
|
285 // CAtCommandBase::Complete |
|
286 // other items were commented in a header |
|
287 // --------------------------------------------------------------------------- |
|
288 void CAtCommandBase::Complete() |
|
289 { |
|
290 (iPhoneGlobals.iAtManager->GetActiveCommandStore())->RemoveActiveAtCommand(this); |
|
291 StopTimer(); |
|
292 ClearBuffer(); |
|
293 } |
|
294 |
|
295 //--------------------------------------------------------------------------- |
|
296 // CAtCommandBase::CancelCommand |
|
297 // other items were commented in a header |
|
298 // --------------------------------------------------------------------------- |
|
299 void CAtCommandBase::CancelCommand() |
|
300 { |
|
301 |
|
302 } |
|
303 |
|
304 //--------------------------------------------------------------------------- |
|
305 // CAtCommandBase::ParseResponseL |
|
306 // other items were commented in a header |
|
307 // --------------------------------------------------------------------------- |
|
308 void CAtCommandBase::ParseResponseL(const TDesC8& /*aResponseBuf*/) |
|
309 { |
|
310 LOGTEXT(_L8("[Ltsy] Starting CAtCommandBase::ParseResponseL()")); |
|
311 } |
|
312 |
|
313 void CAtCommandBase::EventSignal(TAtEventSource /*aEventSource*/, TInt /*aStatus*/) |
|
314 { |
|
315 |
|
316 } |
|
317 //--------------------------------------------------------------------------- |
|
318 // CAtCommandBase::AddUnsolicitedAtCommand |
|
319 // other items were commented in a header |
|
320 // --------------------------------------------------------------------------- |
|
321 void CAtCommandBase::AddUnsolicitedAtCommand() |
|
322 { |
|
323 iPhoneGlobals.iAtManager->GetActiveCommandStore()->AddUnsolicitedAtCommand(this); |
|
324 } |
|
325 //--------------------------------------------------------------------------- |
|
326 // CAtCommandBase::RemoveAtCommand |
|
327 // other items were commented in a header |
|
328 // --------------------------------------------------------------------------- |
|
329 void CAtCommandBase::RemoveAtCommand() |
|
330 { |
|
331 iPhoneGlobals.iAtManager->GetActiveCommandStore()->RemoveActiveAtCommand(this); |
|
332 } |
|
333 // End of file |
|