|
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: CCenRepHandler class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <centralrepository.h> |
|
20 #include <cfcontextsourcesetting.h> |
|
21 #include <cfcontextsourcesettingarray.h> |
|
22 |
|
23 #include "cenrephandler.h" |
|
24 #include "cenrepattributesmasked.h" |
|
25 #include "cenrepattributesnonmasked.h" |
|
26 #include "cenreptrace.h" |
|
27 // #include "cenrepsourceplugintester.h" |
|
28 |
|
29 // ======== LOCAL FUNCTIONS ========= |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 CCenRepHandler* CCenRepHandler::NewL( |
|
34 MCFContextInterface& aCF, |
|
35 CCFContextSourceSettingArray& aSettings, |
|
36 TInt aIndex) |
|
37 { |
|
38 FUNC_LOG; |
|
39 |
|
40 CCenRepHandler* self = new (ELeave) CCenRepHandler(); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL( aCF, aSettings, aIndex); |
|
43 CleanupStack::Pop( self ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 void CCenRepHandler::ConstructL( MCFContextInterface& aCF, |
|
48 CCFContextSourceSettingArray& aSettings, |
|
49 TInt aIndex ) |
|
50 { |
|
51 FUNC_LOG; |
|
52 |
|
53 TUid repositoryUid = TUid::Null(); |
|
54 TUint32 repositoryInt( 0 ); |
|
55 |
|
56 const RKeyValueArray& attrArray = aSettings.Item( aIndex ).Attributes(); |
|
57 TInt attrCount = attrArray.Count(); |
|
58 |
|
59 // Find attribute values |
|
60 for( TInt i = 0; i < attrCount; i++ ) |
|
61 { |
|
62 if ( attrArray[i]->Key().CompareF( KUID ) == KErrNone ) |
|
63 { |
|
64 TInt err = CCenRepAttributes::ConvertToHex( attrArray[i]->Value(), |
|
65 repositoryInt ); |
|
66 User::LeaveIfError( err ); |
|
67 repositoryUid = TUid::Uid( repositoryInt ); |
|
68 } |
|
69 else if ( attrArray[i]->Key().CompareF( KMode ) == KErrNone ) |
|
70 { |
|
71 if ( attrArray[i]->Value().CompareF( KMasked ) == KErrNone ) |
|
72 { |
|
73 iCenRepAttributes = CCenRepAttributesMasked::NewL( aCF, aSettings ); |
|
74 } |
|
75 else if ( attrArray[i]->Value().CompareF( KNonMasked ) == KErrNone ) |
|
76 { |
|
77 iCenRepAttributes = CCenRepAttributesNonMasked::NewL( aCF, aSettings ); |
|
78 } |
|
79 else |
|
80 { |
|
81 User::Leave( KErrNotSupported ); |
|
82 } |
|
83 iKey = iCenRepAttributes->InitCenRepKeyL( aIndex ); |
|
84 } |
|
85 } |
|
86 |
|
87 iCrep = CRepository::NewL( repositoryUid ); |
|
88 |
|
89 QueryAndUpdateContext(); |
|
90 |
|
91 // Test |
|
92 |
|
93 /* |
|
94 iTester = CCenRepSourcePluginTester::NewL( this ); |
|
95 iTester->StartTimer(); |
|
96 */ |
|
97 |
|
98 TInt err = iCrep->NotifyRequest( iKey, iStatus ); |
|
99 if( err == KErrNone ) |
|
100 { |
|
101 SetActive(); |
|
102 } |
|
103 } |
|
104 |
|
105 CCenRepHandler::CCenRepHandler(): |
|
106 CActive( CActive::EPriorityStandard ) |
|
107 { |
|
108 FUNC_LOG; |
|
109 |
|
110 CActiveScheduler::Add( this ); |
|
111 } |
|
112 |
|
113 CCenRepHandler::~CCenRepHandler() |
|
114 { |
|
115 FUNC_LOG; |
|
116 |
|
117 Cancel(); |
|
118 delete iCenRepAttributes; |
|
119 delete iCrep; |
|
120 // delete iTester; |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CCenRepHandler::RunL |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void CCenRepHandler::RunL() |
|
128 { |
|
129 FUNC_LOG; |
|
130 |
|
131 TInt err( KErrGeneral ); |
|
132 |
|
133 // Test |
|
134 /* |
|
135 vvalue = 0x1; |
|
136 iCenRepAttributes->UpdateContext( vvalue ); |
|
137 |
|
138 vvalue = 0xb; |
|
139 iCenRepAttributes->UpdateContext( vvalue ); |
|
140 */ |
|
141 // End of test |
|
142 |
|
143 TInt tmpStat = iStatus.Int(); |
|
144 INFO_1( "CCenRepHandler::RunL: iStatus == %d", tmpStat ); |
|
145 |
|
146 if ( tmpStat > 0 ) |
|
147 { |
|
148 QueryAndUpdateContext(); |
|
149 err = iCrep->NotifyRequest( iKey, iStatus ); |
|
150 } |
|
151 else |
|
152 { |
|
153 err = iCrep->NotifyRequest( iKey, iStatus ); |
|
154 } |
|
155 |
|
156 INFO_1( "Error code of Central Repository NotifyRequest access: %d", err ); |
|
157 |
|
158 if ( err != KErrAlreadyExists ) |
|
159 { |
|
160 User::LeaveIfError( err ); |
|
161 } |
|
162 |
|
163 SetActive(); |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CCenRepHandler::RunError |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 TInt CCenRepHandler::RunError( TInt aError ) |
|
171 { |
|
172 FUNC_LOG; |
|
173 |
|
174 INFO_1( "CCenRepHandler::RunError: aError == %d", aError ); |
|
175 |
|
176 // Avoid Panic in CActiveScheduler |
|
177 aError = KErrNone; |
|
178 |
|
179 return aError; |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CCenRepHandler::DoCancel |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CCenRepHandler::DoCancel() |
|
187 { |
|
188 FUNC_LOG; |
|
189 |
|
190 iCrep->NotifyCancel( iKey ); |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // CCenRepHandler::QueryAndUpdateContext |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 void CCenRepHandler::QueryAndUpdateContext() |
|
198 { |
|
199 FUNC_LOG; |
|
200 |
|
201 TInt value( 0 ); |
|
202 |
|
203 TInt err = iCrep->Get( iKey, value ); |
|
204 |
|
205 INFO_1( "Error code of Central Repository get access: %d", err ); |
|
206 |
|
207 if( err == KErrNone ) |
|
208 { |
|
209 TRAPD( updateErr, iCenRepAttributes->UpdateContextL( value ) ); |
|
210 |
|
211 INFO_1( "Leave code of CenRepAttributes->UpdateContextL: %d", updateErr ); |
|
212 |
|
213 updateErr = updateErr; // Make compiler happy |
|
214 } |
|
215 } |