|
1 /* |
|
2 * Copyright (c) 2006 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: AlwaysOnline server command parser |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 |
|
22 #include "AOCommandParser.h" |
|
23 #include "AlwaysOnlineManagerLogging.h" |
|
24 |
|
25 // EXTERNAL DATA STRUCTURES |
|
26 // EXTERNAL FUNCTION PROTOTYPES |
|
27 // CONSTANTS |
|
28 _LIT8( KAOCmdEnd, ":AOCmdEnd" ); |
|
29 _LIT8( KColon, ":" ); |
|
30 _LIT8( KProgressFormat, "AOCmdStart:*:*:AOCmdEnd" ); |
|
31 const TInt KAOStartTagLength = 11; |
|
32 const TInt KAOColonHex = 0x3A; |
|
33 // MACROS |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 // MODULE DATA STRUCTURES |
|
36 // LOCAL FUNCTION PROTOTYPES |
|
37 // FORWARD DECLARATIONS |
|
38 |
|
39 // ============================ MEMBER FUNCTIONS =============================== |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // CAOCommandParser::CAOCommandParser() |
|
43 // ---------------------------------------------------------------------------- |
|
44 // |
|
45 CAOCommandParser::CAOCommandParser() |
|
46 { |
|
47 KAOMANAGER_LOGGER_FN1("CAOCommandParser::CAOCommandParser()"); |
|
48 KAOMANAGER_LOGGER_FN2("CAOCommandParser::CAOCommandParser()"); |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // CAOCommandParser::~CAOCommandParser() |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 CAOCommandParser::~CAOCommandParser() |
|
56 { |
|
57 delete iProgress; |
|
58 iProgress = NULL; |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // CAOCommandParser::ConstructL() |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 void CAOCommandParser::ConstructL( const TDesC8& aProgress ) |
|
66 { |
|
67 iProgress = aProgress.AllocL(); |
|
68 } |
|
69 |
|
70 // ---------------------------------------------------------------------------- |
|
71 // CAOCommandParser::NewL() |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 CAOCommandParser* CAOCommandParser::NewL( const TDesC8& aProgress ) |
|
75 { |
|
76 CAOCommandParser* self = NewLC( aProgress ); |
|
77 CleanupStack::Pop( self ); |
|
78 |
|
79 return self; |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------------------------------- |
|
83 // CAOCommandParser::NewLC() |
|
84 // ---------------------------------------------------------------------------- |
|
85 // |
|
86 CAOCommandParser* CAOCommandParser::NewLC( const TDesC8& aProgress ) |
|
87 { |
|
88 CAOCommandParser* self = new ( ELeave ) CAOCommandParser(); |
|
89 CleanupStack::PushL( self ); |
|
90 self->ConstructL( aProgress ); |
|
91 |
|
92 return self; |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CAOCommandParser::Parse() |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 TAOParserErrors CAOCommandParser::Parse() |
|
100 { |
|
101 KAOMANAGER_LOGGER_FN1("CAOCommandParser::Parse()"); |
|
102 |
|
103 TAOParserErrors error = EAOParserNoError; |
|
104 |
|
105 // Is the format correct? |
|
106 TInt idx = iProgress->Match( KProgressFormat ); |
|
107 |
|
108 KAOMANAGER_LOGGER_WRITE_FORMAT8("CAlwaysOnlineManager::HandleOpCompletion() : result: %S", iProgress); |
|
109 |
|
110 if ( idx != KErrNotFound ) // Was format correct? |
|
111 { |
|
112 KAOMANAGER_LOGGER_WRITE("CAOCommandParser::Parse() Format is correct"); |
|
113 |
|
114 // Received progress: |
|
115 // "AOCmdStart:<UID of plugin>:<command enumeration>:<result>:AOCmdEnd |
|
116 TInt endTagIdx = iProgress->Find( KAOCmdEnd ); |
|
117 TPtrC8 endBuf( iProgress->Mid( |
|
118 KAOStartTagLength, |
|
119 endTagIdx - KAOStartTagLength ) ); |
|
120 |
|
121 // Now it should be like: |
|
122 // <UID of plugin>:<command enumeration>:<result> |
|
123 ParseUID( endBuf ); |
|
124 ParseCommand( endBuf ); |
|
125 ParseResult( endBuf ); |
|
126 } |
|
127 else |
|
128 { |
|
129 KAOMANAGER_LOGGER_WRITE("CAOCommandParser::Parse() Unknown format"); |
|
130 error = EAOParserUnknownFormat; |
|
131 } |
|
132 |
|
133 KAOMANAGER_LOGGER_FN2("CAOCommandParser::CAOCommandParser()"); |
|
134 |
|
135 return error; |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------------------------------- |
|
139 // CAOCommandParser::ParseUID() |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 void CAOCommandParser::ParseUID( TDesC8& aEndBuf ) |
|
143 { |
|
144 TInt idx = aEndBuf.Find( KColon ); |
|
145 TPtrC8 uidBuf( aEndBuf.Left( idx ) ); |
|
146 |
|
147 TLex8 uidLex( uidBuf ); |
|
148 TInt id; |
|
149 uidLex.Val( id ); |
|
150 iUid = TUid::Uid( id ); |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // CAOCommandParser::ParseCommand() |
|
155 // ---------------------------------------------------------------------------- |
|
156 // |
|
157 void CAOCommandParser::ParseCommand( TDesC8& aEndBuf ) |
|
158 { |
|
159 TInt idx = aEndBuf.Find( KColon ); |
|
160 TChar colonChar( KAOColonHex ); |
|
161 TInt secondColonIdx = aEndBuf.LocateReverse( colonChar ); |
|
162 // Jump over colon characters |
|
163 idx++; |
|
164 secondColonIdx++; |
|
165 TPtrC8 cmdBuf( aEndBuf.Mid( idx, secondColonIdx - idx ) ); |
|
166 |
|
167 TLex8 cmdLex( cmdBuf ); |
|
168 cmdLex.Val( iCommand ); |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CAOCommandParser::ParseResul() |
|
173 // ---------------------------------------------------------------------------- |
|
174 // |
|
175 void CAOCommandParser::ParseResult( TDesC8& aEndBuf ) |
|
176 { |
|
177 TInt idx = aEndBuf.Find( KColon ); |
|
178 TChar colonChar( KAOColonHex ); |
|
179 TInt secondColonIdx = aEndBuf.LocateReverse( colonChar ); |
|
180 // Jump over colon characters |
|
181 idx++; |
|
182 secondColonIdx++; |
|
183 |
|
184 TPtrC8 resultBuf ( aEndBuf.Right( aEndBuf.Length() - secondColonIdx ) ); |
|
185 iResult = resultBuf.Left( iResult.MaxLength() ); |
|
186 } |
|
187 |
|
188 // ---------------------------------------------------------------------------- |
|
189 // CAOCommandParser::Uid() |
|
190 // ---------------------------------------------------------------------------- |
|
191 // |
|
192 const TUid& CAOCommandParser::Uid() |
|
193 { |
|
194 return iUid; |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // CAOCommandParser::Command() |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 TInt CAOCommandParser::Command() |
|
202 { |
|
203 return iCommand; |
|
204 } |
|
205 |
|
206 // ---------------------------------------------------------------------------- |
|
207 // CAOCommandParser::Result() |
|
208 // ---------------------------------------------------------------------------- |
|
209 // |
|
210 const TDes8& CAOCommandParser::Result( ) |
|
211 { |
|
212 return iResult; |
|
213 } |
|
214 |
|
215 // End of File |