|
1 /* |
|
2 * Copyright (c) 2002-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: Implements Configuration File Parser Interface. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "acc_debug.h" |
|
22 #include "AccPolAccessoryPolicy.h" |
|
23 #include "AccPolGenericIDAccessor.h" |
|
24 #include "AccPolicyDB.h" |
|
25 #include "AccPolNameValueArraySerial.h" |
|
26 #include "AccClientServerMessages.h" |
|
27 #include <AccConfigFileParser.h> |
|
28 #include <AccConGenericID.h> |
|
29 #include <s32mem.h> |
|
30 |
|
31 // EXTERNAL DATA STRUCTURES |
|
32 |
|
33 // EXTERNAL FUNCTION PROTOTYPES |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt KAccConfigMaxCapabilityGroups = 64; |
|
37 |
|
38 // MACROS |
|
39 |
|
40 // LOCAL CONSTANTS AND MACROS |
|
41 |
|
42 // MODULE DATA STRUCTURES |
|
43 |
|
44 // LOCAL FUNCTION PROTOTYPES |
|
45 |
|
46 // FORWARD DECLARATIONS |
|
47 |
|
48 // ============================= LOCAL FUNCTIONS =============================== |
|
49 |
|
50 // ============================ MEMBER FUNCTIONS =============================== |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CAccConfigFileParser::ParseSubblocks |
|
54 // Detecting subblocks and store them to destination array |
|
55 // (other items were commented in a header). |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void CAccConfigFileParser::ParseSubblocks( const TUint64& aVal, |
|
59 RArray<TUint64>& aCaps ) |
|
60 { |
|
61 COM_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::ParseSubblocks()" ); |
|
62 |
|
63 TUint64 sum( 0 ); |
|
64 TUint64 curVal( 1 ); |
|
65 TInt curBit( 0 ); |
|
66 |
|
67 do { |
|
68 COM_TRACE_4( "[AccFW:SrvUtil] CAccConfigFileParser::(Cap) Binary for this roundtrip is HI:0x%x LO:0x%x, total sum is HI:0x%x LO:0x%x", I64HIGH( curVal ), I64LOW( curVal ), I64HIGH( sum ), I64LOW( sum ) ); |
|
69 COM_TRACE_2( "[AccFW:SrvUtil] CAccConfigFileParser::(Cap) & HI:0x%x LO:0x%x", I64HIGH( curVal & aVal ), I64LOW( curVal & aVal ) ); |
|
70 |
|
71 // Check if this subblock is defined in SB-def block |
|
72 if ( ( curVal & aVal ) == curVal ) |
|
73 { |
|
74 COM_TRACE_2( "[AccFW:SrvUtil] CAccConfigFileParser::(Cap) MATCH! HI:0x%x LO:0x%x", I64HIGH( curVal ), I64LOW( curVal ) ); |
|
75 aCaps.Append( curVal ); // Append to found caps array |
|
76 sum += curVal; |
|
77 } |
|
78 curBit++; |
|
79 curVal = 2 * curVal; |
|
80 } |
|
81 while ( sum < aVal && curBit < KAccConfigMaxCapabilityGroups ); |
|
82 |
|
83 COM_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::ParseSubblocks - return void" ); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CAccConfigFileParser::ParseNames |
|
88 // Detect all subblock names and append them to the gicen array. |
|
89 // (other items were commented in a header). |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CAccConfigFileParser::ParseNames( const TUint32& aVal, |
|
93 RArray<TUint32>& aNames ) |
|
94 { |
|
95 COM_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::ParseNames()" ); |
|
96 TUint32 sum( 0 ); |
|
97 TUint32 curVal( 1 ); |
|
98 TInt curBit( 0 ); |
|
99 |
|
100 do { |
|
101 COM_TRACE_2( "[AccFW:SrvUtil] CAccConfigFileParser::ParseNames Binary for this roundtrip is 0x%x, total sum is 0x%x", curVal, sum ); |
|
102 COM_TRACE_1( "[AccFW:SrvUtil] CAccConfigFileParser::ParseNames & 0x%x", curVal & aVal ); |
|
103 // Check if this subblock is defined in SB-def block |
|
104 |
|
105 if ( ( curVal & aVal ) == curVal ) |
|
106 { |
|
107 COM_TRACE_1( "[AccFW:SrvUtil] (Name) MATCH! 0x%x",curVal ); |
|
108 aNames.Append( curVal ); // Append to found caps array |
|
109 sum += curVal; |
|
110 } |
|
111 curBit++; |
|
112 curVal = 2 * curVal; |
|
113 } |
|
114 while ( sum < aVal && curBit < KAccConfigMaxCapabilityGroups ); |
|
115 |
|
116 COM_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::ParseNames - return void" ); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CAccConfigFileParser::CAccConfigFileParser |
|
121 // C++ default constructor can NOT contain any code, that |
|
122 // might leave. |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 CAccConfigFileParser::CAccConfigFileParser() |
|
126 { |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CAccConfigFileParser::ConstructL |
|
131 // Symbian 2nd phase constructor can leave. |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CAccConfigFileParser::ConstructL( const TDesC& /*aConfFileName*/ ) |
|
135 { |
|
136 COM_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::ConstructL()" ); |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CAccConfigFileParser::NewL |
|
141 // Two-phased constructor. |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 EXPORT_C CAccConfigFileParser* CAccConfigFileParser::NewL( |
|
145 const TDesC& aConfFileName ) |
|
146 { |
|
147 API_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::NewL()" ); |
|
148 CAccConfigFileParser* self = new( ELeave ) CAccConfigFileParser; |
|
149 |
|
150 CleanupStack::PushL( self ); |
|
151 self->ConstructL( aConfFileName ); |
|
152 CleanupStack::Pop( self ); |
|
153 |
|
154 API_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::NewL - return" ); |
|
155 return self; |
|
156 } |
|
157 |
|
158 // Destructor |
|
159 EXPORT_C CAccConfigFileParser::~CAccConfigFileParser() |
|
160 { |
|
161 API_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::~CAccConfigFileParser()" ); |
|
162 |
|
163 API_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::~CAccConfigFileParser - return" ); |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CAccConfigFileParser::FindL |
|
168 // Find a matching Generic ID for Hardware Device ID. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 EXPORT_C void CAccConfigFileParser::ParseGenericIDL( |
|
172 CAccConGenericID* const aGenericID, |
|
173 const TAccPolGIDHeader& aGenericIDHeader, |
|
174 const RArray<TAccPolNameValueRecord>& aNameValueArray ) |
|
175 { |
|
176 |
|
177 __ASSERT_DEBUG( aGenericID, User::Invariant() ); |
|
178 |
|
179 TAccPolGenericID genericID = aGenericID->GenericID(); |
|
180 |
|
181 TAccPolGenericIDAccessor::SetFeatureAttributeL( genericID, |
|
182 KAccPolDTDeviceType, |
|
183 aGenericIDHeader.iAccessoryDeviceType ); |
|
184 TAccPolGenericIDAccessor::SetFeatureAttributeL( genericID, |
|
185 KAccPolPCPhysicalConnection, |
|
186 aGenericIDHeader.iPhysicalConnection ); |
|
187 TAccPolGenericIDAccessor::SetFeatureAttributeL( genericID, |
|
188 KAccPolAPApplicationProtocol, |
|
189 aGenericIDHeader.iApplicationProtocol ); |
|
190 TAccPolGenericIDAccessor::SetFeatureAttributeL( genericID, |
|
191 KAccPolSBCapabilities, |
|
192 aGenericIDHeader.iCapabilitiesSubblocks ); |
|
193 TAccPolGenericIDAccessor::SetHWModelID( genericID, aGenericIDHeader.iHWModelID ); |
|
194 TAccPolGenericIDAccessor::SetHWDeviceID( genericID, |
|
195 aGenericIDHeader.iHWDeviceID ); |
|
196 TAccPolGenericIDAccessor::SetDeviceAddress( genericID, |
|
197 aGenericIDHeader.iDeviceAddress ); |
|
198 |
|
199 if ( aGenericIDHeader.iDBID > 0 ) |
|
200 { |
|
201 TAccPolGenericIDAccessor::SetDBID( genericID, aGenericIDHeader.iDBID ); |
|
202 } |
|
203 else |
|
204 { |
|
205 TAccPolGenericIDAccessor::SetDBID( genericID, KAccSrvGenerateGID); |
|
206 } |
|
207 |
|
208 TAccPolGenericIDAccessor::SetGenericIDStaticAttributes( aGenericID, genericID ); |
|
209 |
|
210 RBufWriteStream wStrm; |
|
211 |
|
212 // Externalize to CAccConGenericID |
|
213 (void) wStrm.Open( *TAccPolGenericIDAccessor::NameValueBuf (aGenericID ) ); |
|
214 wStrm.PushL(); |
|
215 TAccPolNameValueArraySerial::ExternalizeL( aNameValueArray, wStrm ); |
|
216 wStrm.CommitL(); |
|
217 wStrm.Close(); |
|
218 wStrm.Pop(); |
|
219 |
|
220 #ifdef _DEBUG |
|
221 TBuf8<KTraceMaxSize> b; |
|
222 TInt size( TAccPolGenericIDAccessor::NameValueBuf (aGenericID )->Size() ); |
|
223 if( size > KTraceMaxSize ) |
|
224 { |
|
225 size = KTraceMaxSize;//COM_TRACE_RAW_1 supports KTraceMaxSize |
|
226 } |
|
227 TAccPolGenericIDAccessor::NameValueBuf (aGenericID )->Read( 0, b, size ); |
|
228 TBuf<KTraceMaxSize> c; |
|
229 b.Copy( c ); |
|
230 COM_TRACE_RAW_1( " ", c ); |
|
231 #endif // _DEBUG |
|
232 |
|
233 // Internalize to the local variable |
|
234 /* RArray<TAccPolNameValueRecord> nameValueArray; |
|
235 RBufReadStream rStrm; |
|
236 rStrm.Open( *TAccPolGenericIDAccessor::NameValueBuf (aGenericID ) ); |
|
237 rStrm.PushL(); |
|
238 TAccPolNameValueArraySerial::InternalizeL( rStrm, nameValueArray ); |
|
239 rStrm.Close(); |
|
240 rStrm.Pop(); |
|
241 */ |
|
242 } |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CAccConfigFileParser::FindL |
|
246 // Find a matching Generic ID for Hardware Device ID. |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 EXPORT_C void CAccConfigFileParser::FindL( CAccConGenericID* const aGenericID, |
|
250 TUint64 aHWDeviceID, |
|
251 const TDesC& aHWModelID ) |
|
252 { |
|
253 API_TRACE_2( "[AccFW:SrvUtil] CAccConfigFileParser::FindL(Device HI:0x%x LO:0x%x)", I64HIGH( aHWDeviceID ), I64LOW( aHWDeviceID ) ); |
|
254 |
|
255 CAccPolAccessoryPolicy* accPolicy = CAccPolAccessoryPolicy::NewL( NULL ); |
|
256 // This is not used in ParseGenericIDContent since last parameter is not EAccRule |
|
257 TBuf8<1> nullGidInt; |
|
258 |
|
259 CleanupStack::PushL( accPolicy ); |
|
260 accPolicy->ParseGenericIDContentL( |
|
261 aGenericID, |
|
262 aHWDeviceID, |
|
263 aHWModelID, |
|
264 nullGidInt, // We don't have GID integer |
|
265 EAccUnknown ); // unknown type. accPolicy does not use this value in search |
|
266 |
|
267 CleanupStack::PopAndDestroy( accPolicy ); |
|
268 |
|
269 API_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser:::FindL - return void" ); |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CAccConfigFileParser::bitNumber |
|
274 // Find a bit from aBitmask. |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 TInt CAccConfigFileParser::BitNumber( TUint64 aBitmask ) |
|
278 { |
|
279 API_TRACE_2( "[AccFW:SrvUtil] CAccConfigFileParser::BitNumber(HI:0x%x LO:0x%x)", I64HIGH( aBitmask ), I64LOW( aBitmask ) ); |
|
280 |
|
281 #ifdef _DEBUG |
|
282 |
|
283 _LIT( KZeroBitNumber, "ZeroBitNumber" ); |
|
284 |
|
285 if ( !aBitmask ) |
|
286 { |
|
287 COM_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::BitNumber - Panics now" ); |
|
288 User::Panic( KZeroBitNumber, KErrArgument ); |
|
289 } |
|
290 |
|
291 #endif // _DEBUG |
|
292 |
|
293 TInt curBit(-1); |
|
294 while( ( aBitmask>> ++curBit ) > 1 ) |
|
295 |
|
296 API_TRACE_1( "[AccFW:SrvUtil] CAccConfigFileParser::BitNumber - return %d", curBit ); |
|
297 return curBit; |
|
298 } |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // CAccConfigFileParser::FindL |
|
302 // Find a matching Generic ID for Hardware Device ID. |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 EXPORT_C void CAccConfigFileParser::FindL( TAccPolGenericID& /*aGenericID*/, |
|
306 TUint64 /*aHWDeviceID*/, |
|
307 const TDesC& /*aHWModelID*/ ) |
|
308 { |
|
309 API_TRACE_( "[AccFW:SrvUtil] CAccConfigFileParser::FindL() - KErrNotSupported"); |
|
310 User::Leave( KErrNotSupported ); |
|
311 } |
|
312 |
|
313 // End of File |