1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Handles the commands "AT+CLAC?" and "AT+CLAC" |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "lclistallcmd.h" |
|
19 #include "debug.h" |
|
20 |
|
21 const TInt KCrLfLength = 2; // CR+LF |
|
22 const TInt KOkReplyLength = 6; // CR+LF+"OK"+CR+LF |
|
23 |
|
24 _LIT8( KClacCmd, "AT+CLAC" ); |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // Two-phased constructor. |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CLcListAllCmd* CLcListAllCmd::NewL( MLcCustomPlugin* aCallback ) |
|
31 { |
|
32 CLcListAllCmd* self = new (ELeave) CLcListAllCmd( aCallback ); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Destructor. |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CLcListAllCmd::~CLcListAllCmd() |
|
44 { |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CLcListAllCmd::CLcListAllCmd |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CLcListAllCmd::CLcListAllCmd( MLcCustomPlugin* aCallback ) : |
|
52 iCallback( aCallback ) |
|
53 { |
|
54 iCmdHandlerType = ECmdHandlerTypeUndefined; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CLcListAllCmd::ConstructL |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 void CLcListAllCmd::ConstructL() |
|
62 { |
|
63 if ( !iCallback ) |
|
64 { |
|
65 User::Leave( KErrGeneral ); |
|
66 } |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // Checks command types |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 TBool CLcListAllCmd::CheckCommand( const TDesC8& aCmd ) |
|
74 { |
|
75 TRACE_FUNC_ENTRY |
|
76 // The AT+CLAC command supports two types: base and test |
|
77 iCmdHandlerType = iCallback->CheckCommandType( KClacCmd, aCmd ); |
|
78 if ( iCmdHandlerType==ECmdHandlerTypeBase || |
|
79 iCmdHandlerType==ECmdHandlerTypeTest ) |
|
80 { |
|
81 iDetectedCmd = EDetectedCmdCLAC; |
|
82 TRACE_FUNC_EXIT |
|
83 return ETrue; |
|
84 } |
|
85 TRACE_FUNC_EXIT |
|
86 return EFalse; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // Reports the support status of an AT command. This is a synchronous API. |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 TBool CLcListAllCmd::IsCommandSupported( const TDesC8& aCmd ) |
|
94 { |
|
95 TRACE_FUNC_ENTRY |
|
96 // Set all to undefined if either the command or its type is unknown |
|
97 // HandleCommand() should be round only when both are set |
|
98 TBool cmdUnderstood = CheckCommand( aCmd ); |
|
99 if ( cmdUnderstood ) |
|
100 { |
|
101 TRACE_FUNC_EXIT |
|
102 return ETrue; |
|
103 } |
|
104 iCmdHandlerType = ECmdHandlerTypeUndefined; |
|
105 iDetectedCmd = EDetectedCmdUndefined; |
|
106 TRACE_FUNC_EXIT |
|
107 return EFalse; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // Handles an AT command. Cancelling of the pending request is done by |
|
112 // HandleCommandCancel(). The implementation in the extension plugin should |
|
113 // be asynchronous. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void CLcListAllCmd::HandleCommand( const TDesC8& /*aCmd*/, |
|
117 RBuf8& /*aReply*/, |
|
118 TBool aReplyNeeded ) |
|
119 { |
|
120 TRACE_FUNC_ENTRY |
|
121 if ( !aReplyNeeded ) |
|
122 { |
|
123 TRACE_FUNC_EXIT |
|
124 return; |
|
125 } |
|
126 if ( iCmdHandlerType == ECmdHandlerTypeTest ) |
|
127 { |
|
128 iCallback->CreateReplyAndComplete( EReplyTypeOk ); |
|
129 TRACE_FUNC_EXIT |
|
130 return; |
|
131 } |
|
132 // Else here means ECmdHandlerTypeBase |
|
133 // First check the quiet mode and verbose mode. |
|
134 // These are handled in CreateReplyAndComplete() |
|
135 TInt retTemp; |
|
136 TBool quietMode = EFalse; |
|
137 retTemp = iCallback->GetModeValue( EModeTypeQuiet, quietMode ); |
|
138 if ( retTemp != KErrNone ) |
|
139 { |
|
140 iCallback->CreateReplyAndComplete( EReplyTypeError ); |
|
141 TRACE_FUNC_EXIT |
|
142 return; |
|
143 } |
|
144 RBuf8 reply; |
|
145 if ( quietMode ) |
|
146 { |
|
147 iCallback->CreateReplyAndComplete( EReplyTypeOther, reply ); |
|
148 reply.Close(); |
|
149 TRACE_FUNC_EXIT |
|
150 return; |
|
151 } |
|
152 TBool error = CreateSupportedList( reply ); |
|
153 if ( error ) |
|
154 { |
|
155 iCallback->CreateReplyAndComplete( EReplyTypeError ); |
|
156 reply.Close(); |
|
157 TRACE_FUNC_EXIT |
|
158 return; |
|
159 } |
|
160 RBuf8 okReply; |
|
161 iCallback->CreateOkOrErrorReply( okReply, ETrue ); |
|
162 reply.Append( okReply ); |
|
163 okReply.Close(); |
|
164 iCallback->CreateReplyAndComplete( EReplyTypeOther, reply ); |
|
165 reply.Close(); |
|
166 TRACE_FUNC_EXIT |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // Cancels a pending HandleCommand request. |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CLcListAllCmd::HandleCommandCancel() |
|
174 { |
|
175 TRACE_FUNC_ENTRY |
|
176 TRACE_FUNC_EXIT |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // Creates a linearized list of supported commands |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 TBool CLcListAllCmd::CreateSupportedList( RBuf8& aReply ) |
|
184 { |
|
185 TRACE_FUNC_ENTRY |
|
186 // First get the unsorted list from ATEXT |
|
187 RPointerArray<HBufC8> commands; |
|
188 iCallback->GetSupportedCommands( commands ); |
|
189 // Next linearize the list for a reply |
|
190 if ( commands.Count() <= 0 ) |
|
191 { |
|
192 commands.Close(); |
|
193 TRACE_FUNC_EXIT |
|
194 return EFalse; |
|
195 } |
|
196 TInt i; |
|
197 TInt linearSize = KOkReplyLength; |
|
198 TInt count = commands.Count(); |
|
199 for ( i=0; i<count; i++ ) |
|
200 { |
|
201 linearSize += (*commands[i]).Length(); |
|
202 if ( i < count-1 ) |
|
203 { |
|
204 linearSize += KCrLfLength; |
|
205 } |
|
206 } |
|
207 linearSize += KCrLfLength; |
|
208 // Now we have the length of the linear region, |
|
209 // use that to create the reply |
|
210 TChar carriageReturn; |
|
211 TChar lineFeed; |
|
212 TInt retTemp; |
|
213 retTemp = aReply.Create( linearSize ); |
|
214 retTemp |= iCallback->GetCharacterValue( ECharTypeCR, carriageReturn ); |
|
215 retTemp |= iCallback->GetCharacterValue( ECharTypeLF, lineFeed ); |
|
216 if ( retTemp != KErrNone ) |
|
217 { |
|
218 commands.ResetAndDestroy(); |
|
219 commands.Close(); |
|
220 TRACE_FUNC_EXIT |
|
221 return ETrue; |
|
222 } |
|
223 for ( i=0; i<count; i++ ) |
|
224 { |
|
225 aReply.Append( *commands[i] ); |
|
226 if ( i < count-1 ) |
|
227 { |
|
228 aReply.Append( carriageReturn ); |
|
229 aReply.Append( lineFeed ); |
|
230 } |
|
231 } |
|
232 aReply.Append( carriageReturn ); |
|
233 aReply.Append( lineFeed ); |
|
234 // Delete the array as it is no longer needed |
|
235 commands.ResetAndDestroy(); |
|
236 commands.Close(); |
|
237 TRACE_FUNC_EXIT |
|
238 return EFalse; |
|
239 } |
|