|
1 /* |
|
2 * Copyright (c) 2002 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: Implementation of manufacturer parser. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPhoneGsmManufacturerParser.h" |
|
21 #include "CPhoneGsmOptionContainer.h" |
|
22 #include "CPhoneGsmParserResult.h" |
|
23 #include "CPhoneParserFeatures.h" |
|
24 |
|
25 // CONSTANTS |
|
26 const TInt KPhoneManufacturerCodeArrayGanularity = 5; |
|
27 |
|
28 _LIT( KPhoneHashStr, "#" ); |
|
29 #ifdef PHONEPARSER_PARSE_DEBUG_CODE |
|
30 _LIT( KPhoneDebugPrefixStr, "*#74603" ); |
|
31 #endif |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CPhoneGsmManufacturerParser::CPhoneGsmManufacturerParser |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CPhoneGsmManufacturerParser::CPhoneGsmManufacturerParser() |
|
40 { |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CPhoneGsmManufacturerParser::ConstructL |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CPhoneGsmManufacturerParser::ConstructL() |
|
48 { |
|
49 iArray = new ( ELeave ) CCodeArray( |
|
50 KPhoneManufacturerCodeArrayGanularity ); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CPhoneGsmManufacturerParser::NewLC |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CPhoneGsmManufacturerParser* CPhoneGsmManufacturerParser::NewLC() |
|
58 { |
|
59 CPhoneGsmManufacturerParser* self = |
|
60 new ( ELeave ) CPhoneGsmManufacturerParser; |
|
61 |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CPhoneGsmManufacturerParser::~CPhoneGsmManufacturerParser |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CPhoneGsmManufacturerParser::~CPhoneGsmManufacturerParser() |
|
73 { |
|
74 delete iArray; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CPhoneGsmManufacturerParser::AddStringL |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CPhoneGsmManufacturerParser::AddStringL( |
|
82 const TDesC& aString, |
|
83 TInt aFlags, |
|
84 TUint aCommand, |
|
85 TInt aFeatureId ) |
|
86 { |
|
87 TCodeInfo info; |
|
88 info.iString.Set( aString ); |
|
89 info.iFlags = aFlags; |
|
90 info.iCommand = aCommand; |
|
91 info.iFeatureId = aFeatureId; |
|
92 |
|
93 iArray->AppendL( info ); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CPhoneGsmManufacturerParser::ParseL |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 TBool CPhoneGsmManufacturerParser::ParseL( |
|
101 const TDesC& aString, |
|
102 CPhoneGsmParserResult& aResult, |
|
103 CPhoneGsmOptionContainerBase& aOptions ) |
|
104 { |
|
105 TBool result = EFalse; |
|
106 |
|
107 aResult.ClearL(); |
|
108 |
|
109 TInt index; |
|
110 TInt count = iArray->Count(); |
|
111 |
|
112 // Go through all elements. |
|
113 for ( index = 0; index < count; index++ ) |
|
114 { |
|
115 TCodeInfo& info = iArray->At( index ); |
|
116 |
|
117 // Check if string matches to code information. |
|
118 if ( CheckCode( aString, info, aOptions ) ) |
|
119 { |
|
120 // Yes, fill result |
|
121 aResult.SetUid( KPhoneUidManufacturerCode ); |
|
122 aResult.SetAuxInformation( info.iCommand ); |
|
123 result = ETrue; |
|
124 break; |
|
125 } |
|
126 } |
|
127 |
|
128 #ifdef PHONEPARSER_PARSE_DEBUG_CODE |
|
129 if ( !result ) |
|
130 { |
|
131 // Check special debug code. |
|
132 |
|
133 if ( IsPrefixOf( aString, KPhoneDebugPrefixStr ) && |
|
134 IsPostfixOf( aString, KPhoneHashStr ) ) |
|
135 { |
|
136 aResult.SetUid( KPhoneUidManufacturerDebugCode ); |
|
137 aResult.SetAuxInformation( 0 ); |
|
138 aResult.AddParameterL( |
|
139 aString.Mid( |
|
140 KPhoneDebugPrefixStr().Length(), |
|
141 aString.Length() - KPhoneDebugPrefixStr().Length() - 1 ) ); |
|
142 result = ETrue; |
|
143 } |
|
144 } |
|
145 #endif |
|
146 |
|
147 return result; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CPhoneGsmManufacturerParser::CheckCode |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 TBool CPhoneGsmManufacturerParser::CheckCode( |
|
155 const TDesC& aString, |
|
156 const TCodeInfo& aInfo, |
|
157 CPhoneGsmOptionContainerBase& aOptions ) |
|
158 { |
|
159 TInt flags = aInfo.iFlags; |
|
160 |
|
161 if ( !aString.Length() ) |
|
162 { |
|
163 return EFalse; |
|
164 } |
|
165 |
|
166 if ( !CheckSituation( aString, flags, aOptions ) ) |
|
167 { |
|
168 return EFalse; |
|
169 } |
|
170 |
|
171 if ( aInfo.iFeatureId ) |
|
172 { |
|
173 if ( !CPhoneParserFeatures::FeatureSupported( aInfo.iFeatureId ) ) |
|
174 { |
|
175 return EFalse; |
|
176 } |
|
177 } |
|
178 |
|
179 // Check if string is ok. |
|
180 if ( ( flags & EFlagPrefix ) ) |
|
181 { |
|
182 return ( IsPrefixOf( aString, aInfo.iString ) ); |
|
183 } |
|
184 else |
|
185 { |
|
186 return ( aString == aInfo.iString ); |
|
187 } |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CPhoneGsmManufacturerParser::CheckSituation |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 TBool CPhoneGsmManufacturerParser::CheckSituation( |
|
195 const TDesC& aString, |
|
196 TInt aFlags, |
|
197 CPhoneGsmOptionContainerBase& aOptions ) |
|
198 { |
|
199 TBool result = ETrue; |
|
200 |
|
201 // Check if it is send operation or hash check. |
|
202 TBool send = aOptions.FindOptionStatus( KPhoneOptionSend ); |
|
203 |
|
204 TBool isCode = aFlags & EFlagCode; |
|
205 TBool isSend = aFlags & EFlagSend; |
|
206 |
|
207 if ( isCode && send ) |
|
208 { |
|
209 result = EFalse; |
|
210 } |
|
211 else if ( isCode && !send ) |
|
212 { |
|
213 // For code, there must be hash. |
|
214 |
|
215 if ( aString.Right( 1 ) != KPhoneHashStr ) // Compare rightmost characters |
|
216 { |
|
217 result = EFalse; |
|
218 } |
|
219 } |
|
220 |
|
221 if ( isSend && !send ) |
|
222 { |
|
223 result = EFalse; |
|
224 } |
|
225 |
|
226 // Check if phone is in correct state. |
|
227 TBool incall = aOptions.FindOptionStatus( KPhoneOptionInCall ); |
|
228 |
|
229 if ( ( aFlags & EFlagNotInIdle ) && !incall ) |
|
230 { |
|
231 result = EFalse; |
|
232 } |
|
233 |
|
234 if ( ( aFlags & EFlagNotInInCall ) && incall ) |
|
235 { |
|
236 result = EFalse; |
|
237 } |
|
238 |
|
239 return result; |
|
240 } |
|
241 |
|
242 // End of File |
|
243 |