|
1 /* |
|
2 * |
|
3 * Copyright (c) <2010> Comarch S.A. and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 * This component and the accompanying materials are made available |
|
6 * under the terms of the License "Eclipse Public License v1.0" |
|
7 * which accompanies this distribution, and is available |
|
8 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 * |
|
10 * Original Contributors: |
|
11 * Comarch S.A. - original contribution. |
|
12 * |
|
13 * Contributors: |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <badesca.h> |
|
20 |
|
21 #include "hspcommand.h" |
|
22 #include "debug.h" |
|
23 |
|
24 TATParam::TATParam( const TDesC8& aValue ) |
|
25 |
|
26 { |
|
27 iValue.Copy( aValue ); |
|
28 } |
|
29 |
|
30 const TDesC8& TATParam::Des() const |
|
31 { |
|
32 return iValue; |
|
33 } |
|
34 |
|
35 TInt TATParam::IntL() const |
|
36 { |
|
37 TLex8 lex( iValue ); |
|
38 TInt res = KErrNotFound; |
|
39 User::LeaveIfError( lex.Val( res ) ); |
|
40 |
|
41 return res; |
|
42 |
|
43 } |
|
44 |
|
45 CHsHSPCommand* CHsHSPCommand::NewL() |
|
46 { |
|
47 CHsHSPCommand *self = CHsHSPCommand::NewLC(); |
|
48 CleanupStack::Pop( self ); |
|
49 |
|
50 return self; |
|
51 } |
|
52 |
|
53 CHsHSPCommand* CHsHSPCommand::NewLC() |
|
54 { |
|
55 |
|
56 CHsHSPCommand *self = new ( ELeave ) CHsHSPCommand(); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 CHsHSPCommand::~CHsHSPCommand() |
|
63 { |
|
64 iParams.Close(); |
|
65 iModeDes.Close(); |
|
66 iParamsDes.Close(); |
|
67 iTypeDes.Close(); |
|
68 } |
|
69 |
|
70 TInt CHsHSPCommand::SetType( const THsHSPCommandType aType ) |
|
71 { |
|
72 iType = aType; |
|
73 |
|
74 switch ( iType ) |
|
75 { |
|
76 case EHSPCmdRING: |
|
77 iTypeDes.Copy( KHsHSPRINGCommand ); |
|
78 break; |
|
79 case EHSPCmdVGS: |
|
80 iTypeDes.Copy( KHsHSPVGSCommand ); |
|
81 break; |
|
82 case EHSPCmdVGM: |
|
83 iTypeDes.Copy( KHsHSPVGMCommand ); |
|
84 break; |
|
85 case EHSPCmdCKPD: |
|
86 iTypeDes.Copy( KHsHSPCKPDCommand ); |
|
87 break; |
|
88 default: |
|
89 return KErrArgument; |
|
90 |
|
91 } |
|
92 return KErrNone; |
|
93 } |
|
94 |
|
95 TInt CHsHSPCommand::SetMode( const THsHSPCommandMode aMode ) |
|
96 { |
|
97 iMode = aMode; |
|
98 switch ( iMode ) |
|
99 { |
|
100 case ECmdModeRead: |
|
101 iModeDes.Copy( KHsHSPATReadModeDes ); |
|
102 break; |
|
103 case ECmdModeWrite: |
|
104 iModeDes.Copy( KHsHSPATWriteModeDes ); |
|
105 break; |
|
106 case ECmdModeTest: |
|
107 iModeDes.Copy( KHsHSPATTestModeDes ); |
|
108 break; |
|
109 case ECmdModeNormal: |
|
110 iModeDes.Copy( KNullDesC8 ); |
|
111 break; |
|
112 case ECmdModeOther: |
|
113 iModeDes.Copy( KNullDesC8 ); |
|
114 break; |
|
115 default: |
|
116 return KErrArgument; |
|
117 } |
|
118 |
|
119 return KErrNone; |
|
120 } |
|
121 |
|
122 TInt CHsHSPCommand::SetParams( const RATParamArray& aParams ) |
|
123 { |
|
124 TRACE_FUNC_ENTRY |
|
125 |
|
126 TInt res = KErrNone; |
|
127 if ( aParams.Count() > 0 ) |
|
128 { |
|
129 iParams.Reset(); |
|
130 iParams = aParams; |
|
131 |
|
132 for ( TInt i = 0; i < iParams.Count() - 1; i++ ) |
|
133 { |
|
134 |
|
135 iParamsDes.Append( iParams[i].Des() ); |
|
136 iParamsDes.Append( KHsHSPParamsSeparator ); |
|
137 } |
|
138 |
|
139 iParamsDes.Append( iParams[iParams.Count() - 1].Des() ); |
|
140 |
|
141 } |
|
142 else |
|
143 res = KErrArgument; |
|
144 |
|
145 TRACE_FUNC_EXIT |
|
146 return res; |
|
147 } |
|
148 |
|
149 void CHsHSPCommand::SetSource( const TBool aFromAG ) |
|
150 { |
|
151 iFromAG = aFromAG; |
|
152 } |
|
153 |
|
154 void CHsHSPCommand::ToDes8( TDes8& aBuf ) const |
|
155 { |
|
156 |
|
157 if ( iMode == ECmdModeNormal ) |
|
158 { |
|
159 aBuf.Copy( KHsHSPCommandPrefix ); |
|
160 aBuf.Append( iTypeDes ); |
|
161 aBuf.Append( KHsHSPCommandSuffix ); |
|
162 } |
|
163 |
|
164 else if ( iType != EHSPCmdUnknown ) |
|
165 { |
|
166 aBuf.Copy( KHsHSPCommandPrefix ); |
|
167 aBuf.Append( iTypeDes ); |
|
168 aBuf.Append( iModeDes ); |
|
169 aBuf.Append( iParamsDes ); |
|
170 aBuf.Append( KHsHSPCommandSuffix ); |
|
171 } |
|
172 else |
|
173 { |
|
174 aBuf.Zero(); |
|
175 } |
|
176 |
|
177 TRACE_INFO((_L8("COMMAND TO DES: %S"),&aBuf)); |
|
178 } |
|
179 |
|
180 THsHSPCommandType CHsHSPCommand::Type() const |
|
181 { |
|
182 return iType; |
|
183 } |
|
184 |
|
185 THsHSPCommandMode CHsHSPCommand::Mode() const |
|
186 { |
|
187 return iMode; |
|
188 } |
|
189 |
|
190 TBool CHsHSPCommand::FromAG() const |
|
191 { |
|
192 return iFromAG; |
|
193 } |
|
194 |
|
195 const RATParamArray CHsHSPCommand::Params() const |
|
196 { |
|
197 return iParams; |
|
198 } |
|
199 |
|
200 void CHsHSPCommand::CopyL( const CHsHSPCommand* aCmdFrom, CHsHSPCommand& aCmdTo ) |
|
201 { |
|
202 aCmdTo.iMode = aCmdFrom->iMode; |
|
203 aCmdTo.iType = aCmdFrom->iType; |
|
204 |
|
205 aCmdTo.iParams.Reset(); |
|
206 for ( TInt i = 0; i < aCmdFrom->iParams.Count(); i++ ) |
|
207 { |
|
208 aCmdTo.iParams.AppendL( aCmdFrom->iParams[i] ); |
|
209 } |
|
210 |
|
211 aCmdTo.iFromAG = aCmdFrom->iFromAG; |
|
212 |
|
213 aCmdTo.iModeDes.Copy( aCmdFrom->iModeDes ); |
|
214 aCmdTo.iTypeDes.Copy( aCmdFrom->iTypeDes ); |
|
215 aCmdTo.iParamsDes.Copy( aCmdFrom->iParamsDes ); |
|
216 |
|
217 } |
|
218 |
|
219 CHsHSPCommand::CHsHSPCommand() : |
|
220 iType( EHSPCmdUnknown ), iParams( KParamArrayGranularity ) |
|
221 { |
|
222 |
|
223 } |
|
224 |
|
225 void CHsHSPCommand::ConstructL() |
|
226 { |
|
227 iModeDes.CreateL( KModeDesMaxLength ); |
|
228 iTypeDes.CreateL( KTypeDesMaxLength ); |
|
229 iParamsDes.CreateL( KParamsDesMaxLength ); |
|
230 |
|
231 } |