|
1 /* |
|
2 * Copyright (c) 2007-2007 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: CCenRepAttributes class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <cfdefinitions.h> |
|
20 #include <cfcontextsourcesetting.h> |
|
21 #include <cfcontextsourcesettingarray.h> |
|
22 |
|
23 #include "cenrepattributes.h" |
|
24 #include "cenreptrace.h" |
|
25 |
|
26 // Capabilities |
|
27 _LIT_SECURITY_POLICY_PASS( KCenRepSourceInteractionSec ); |
|
28 |
|
29 // ======== LOCAL FUNCTIONS ========= |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 CCenRepAttributes::~CCenRepAttributes() |
|
34 { |
|
35 FUNC_LOG; |
|
36 // Delete context |
|
37 delete iContext; |
|
38 } |
|
39 |
|
40 CCenRepAttributes::CCenRepAttributes( |
|
41 MCFContextInterface& aCF, |
|
42 CCFContextSourceSettingArray& aSettings ) : |
|
43 iSettings( aSettings ), |
|
44 iCF( aCF ) |
|
45 { |
|
46 FUNC_LOG; |
|
47 } |
|
48 |
|
49 //---------------------------------------------------------------------------- |
|
50 // CCenRepAttributes::ConvertToHex |
|
51 //---------------------------------------------------------------------------- |
|
52 // |
|
53 TInt CCenRepAttributes::ConvertToHex( const TDesC& aString, TUint32& aValue ) |
|
54 { |
|
55 FUNC_LOG; |
|
56 |
|
57 const TUint KLimit = 0xffffffff; |
|
58 _LIT( KHexPattern, "0x*" ); |
|
59 TInt err = KErrNotFound; |
|
60 |
|
61 if ( err != aString.Match( KHexPattern ) ) |
|
62 { |
|
63 TLex lex( aString ); |
|
64 |
|
65 // Get rid of '0x' |
|
66 const TInt incAmount( 2 ); |
|
67 lex.Inc( incAmount ); |
|
68 err = lex.BoundedVal( aValue, EHex, KLimit ); |
|
69 } |
|
70 |
|
71 return err; |
|
72 } |
|
73 |
|
74 //---------------------------------------------------------------------------- |
|
75 // CCenRepAttributes::ConvertToInt |
|
76 //---------------------------------------------------------------------------- |
|
77 // |
|
78 TInt CCenRepAttributes::ConvertToInt( const TDesC& aString, TInt& aValue ) const |
|
79 { |
|
80 FUNC_LOG; |
|
81 |
|
82 TInt err = KErrNone; |
|
83 |
|
84 TLex lex( aString ); |
|
85 |
|
86 if( lex.Val( aValue ) != KErrNone ) |
|
87 { |
|
88 err = KErrNotFound; |
|
89 } |
|
90 |
|
91 return err; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CCenRepAttributes::InitCenRepKeyL |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 TUint32 CCenRepAttributes::InitCenRepKeyL( TInt aIndex ) |
|
99 { |
|
100 FUNC_LOG; |
|
101 |
|
102 TUint32 cenRepKey = 0; |
|
103 |
|
104 iParamArray = iSettings.Item( aIndex ).Parameters(); |
|
105 const RKeyValueArray& attrArray = iSettings.Item( aIndex ).Attributes(); |
|
106 |
|
107 iParamCount = iParamArray.Count(); |
|
108 |
|
109 // Check attributes |
|
110 TInt attrCount = attrArray.Count(); |
|
111 |
|
112 DefineContext(); |
|
113 |
|
114 // Find given key |
|
115 for( TInt i = 0; i < attrCount; i++ ) |
|
116 { |
|
117 // Currently only interested given parameter key |
|
118 if ( attrArray[i]->Key().CompareF( KKey ) == KErrNone ) |
|
119 { |
|
120 TInt err = ConvertToHex( attrArray[i]->Value(), cenRepKey ); |
|
121 User::LeaveIfError( err ); |
|
122 } |
|
123 } |
|
124 return cenRepKey; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CCenRepAttributes::DefineContext |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CCenRepAttributes::DefineContext() |
|
132 { |
|
133 FUNC_LOG; |
|
134 |
|
135 TPtrC value( KNullDesC ); |
|
136 TPtrC key( KNullDesC ); |
|
137 |
|
138 TPtrC conTypePtr ( KNullDesC ); |
|
139 TPtrC conSourcePtr ( KNullDesC ); |
|
140 |
|
141 |
|
142 for( TInt i = 0; i < iParamCount; i++ ) |
|
143 { |
|
144 const RKeyValueArray& paramAttr = iParamArray[i]->Attributes(); |
|
145 TInt paramAttrCount = paramAttr.Count(); |
|
146 for( TInt j = 0; j < paramAttrCount; j++ ) |
|
147 { |
|
148 key.Set( paramAttr[j]->Key() ); |
|
149 value.Set( paramAttr[j]->Value() ); |
|
150 |
|
151 // Check ContextSource |
|
152 if ( key.CompareF( KContextSource ) == KErrNone ) |
|
153 { |
|
154 conSourcePtr.Set( value ); |
|
155 } |
|
156 |
|
157 // Check ContextType |
|
158 else if ( key.CompareF( KContextType ) == KErrNone ) |
|
159 { |
|
160 conTypePtr.Set( value); |
|
161 } |
|
162 } |
|
163 iCF.DefineContext( conSourcePtr, |
|
164 conTypePtr, |
|
165 KCenRepSourceInteractionSec ); |
|
166 } |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CCenRepAttributes::PublishContext |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CCenRepAttributes::PublishContext() |
|
174 { |
|
175 FUNC_LOG; |
|
176 |
|
177 RThread thread; |
|
178 iCF.PublishContext( *iContext, thread ); |
|
179 thread.Close(); |
|
180 } |