|
1 /* |
|
2 * Copyright (c) 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: Power save mode client class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <psmsrvdomaincrkeys.h> |
|
21 #include <centralrepository.h> |
|
22 #include "psmsettingsimpl.h" |
|
23 #include "psmtrace.h" |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CPsmSettingsImpl::~CPsmSettingsImpl |
|
27 // Constructor. |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CPsmSettingsImpl::~CPsmSettingsImpl() |
|
31 { |
|
32 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::~CPsmSettingsImpl()" ) ) ); |
|
33 if ( iOwnSession ) |
|
34 { |
|
35 iPsmServer.Close(); |
|
36 } |
|
37 |
|
38 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::~CPsmSettingsImpl() - return" ) ) ); |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CPsmSettingsImpl::CPsmSettingsImpl |
|
43 // Constructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CPsmSettingsImpl::CPsmSettingsImpl() |
|
47 { |
|
48 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::CPsmSettingsImpl()" ) ) ); |
|
49 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::CPsmSettingsImpl() - return" ) ) ); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CPsmSettingsImpl::ConstructL |
|
54 // Two-phased constructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CPsmSettingsImpl::ConstructL() |
|
58 { |
|
59 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::ConstructL()" ) ) ); |
|
60 User::LeaveIfError( iPsmServer.Connect() ); |
|
61 iOwnSession = ETrue; |
|
62 |
|
63 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::ConstructL - return" ) ) ); |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CPsmSettingsImpl::CPsmSettingsImpl |
|
68 // Constructor. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CPsmSettingsImpl::CPsmSettingsImpl( RPsmServer& aPsmServer ) : |
|
72 iPsmServer( aPsmServer ) |
|
73 { |
|
74 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::CPsmSettingsImpl()" ) ) ); |
|
75 iOwnSession = EFalse; |
|
76 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::CPsmSettingsImpl() - return" ) ) ); |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CPsmSettingsImpl::BackupAndGetSettings |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 TInt CPsmSettingsImpl::BackupAndGetSettings( |
|
84 RConfigInfoArray& aPsmConfigArray, const TUint32 aRepository ) |
|
85 { |
|
86 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::BackupAndGetSettings()" ) ) ); |
|
87 return HandleSettingsRequest( aPsmConfigArray, aRepository, EPsmServerChangeSettings ); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CPsmSettingsImpl::GetSettings |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 TInt CPsmSettingsImpl::GetSettings( |
|
95 RConfigInfoArray& aPsmConfigArray, const TUint32 aRepository ) |
|
96 { |
|
97 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::GetSettings()" ) ) ); |
|
98 return HandleSettingsRequest( aPsmConfigArray, aRepository, EPsmServerGetSettings ); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CPsmSettingsImpl::BackupSettings |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 TInt CPsmSettingsImpl::BackupSettings( |
|
106 RConfigInfoArray& aPsmConfigArray, const TUint32 aRepository ) |
|
107 { |
|
108 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::BackupSettings()" ) ) ); |
|
109 return HandleSettingsRequest( aPsmConfigArray, aRepository, EPsmServerBackupSettings ); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CPsmSettingsImpl::GetCurrentMode |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 TInt CPsmSettingsImpl::GetCurrentMode( TInt& aMode ) |
|
117 { |
|
118 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::GetCurrentMode()" ) ) ); |
|
119 |
|
120 TInt errorCode( KErrNone ); |
|
121 CRepository* cenrep = NULL; |
|
122 |
|
123 TRAP_IGNORE( cenrep = CRepository::NewL( KCRUidPowerSaveMode ) ); |
|
124 |
|
125 if ( cenrep ) |
|
126 { |
|
127 errorCode = cenrep->Get( KPsmCurrentMode, aMode ); |
|
128 delete cenrep; |
|
129 cenrep = NULL; |
|
130 } |
|
131 else |
|
132 { |
|
133 errorCode = KErrNoMemory; |
|
134 } |
|
135 |
|
136 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::GetCurrentMode - Mode: %i" ), aMode ) ); |
|
137 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::GetCurrentMode - return: %i" ), errorCode ) ); |
|
138 return errorCode; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CPsmSettingsImpl::HandleSettingsRequest |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 TInt CPsmSettingsImpl::HandleSettingsRequest( |
|
146 RConfigInfoArray& aPsmConfigArray, |
|
147 const TUint32 aRepository, |
|
148 const TPsmServerRequest aRequest ) |
|
149 { |
|
150 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::HandleSettingsRequest()" ) ) ); |
|
151 |
|
152 TInt configCount( aPsmConfigArray.Count() ); |
|
153 TInt err( KErrNone ); |
|
154 |
|
155 RConfigInfoArray configArray; |
|
156 |
|
157 TRAP( err, |
|
158 for( TInt i = 0; i < configCount; i++ ) |
|
159 { |
|
160 // RArray::Append might not work correctly, have to use AppendL |
|
161 configArray.AppendL( aPsmConfigArray[i] ); |
|
162 } ); // End of TRAP |
|
163 |
|
164 if ( KErrNone == err ) |
|
165 { |
|
166 TInt arraySize( configCount * sizeof( TPsmsrvConfigInfo ) ); |
|
167 TPtr8 arrayPtr( ( TUint8* ) &configArray[0], arraySize, arraySize ); |
|
168 |
|
169 // Create IPC arguments. First is array, second is item count in array and third is repository |
|
170 TIpcArgs args = TIpcArgs( &arrayPtr, configCount, aRepository ); |
|
171 |
|
172 // Send message to server side |
|
173 err = iPsmServer.SendReceiveSync( aRequest, args ); |
|
174 |
|
175 if ( err == KErrNone && EPsmServerBackupSettings != aRequest ) // Copy configs info to aPsmConfigArray |
|
176 { |
|
177 // Same configs already exists in both arrays, just update values |
|
178 UpdateConfigArray( aPsmConfigArray, configArray ); |
|
179 } |
|
180 } |
|
181 |
|
182 configArray.Reset(); |
|
183 configArray.Close(); |
|
184 |
|
185 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::HandleSettingsRequest - return: %i" ), err ) ); |
|
186 return err; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CPsmSettingsImpl::UpdateConfigArray |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CPsmSettingsImpl::UpdateConfigArray( RConfigInfoArray& aTargetArray, |
|
194 RConfigInfoArray& aSourceArray ) |
|
195 { |
|
196 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::UpdateConfigArray()" ) ) ); |
|
197 |
|
198 for ( TInt i = 0; aTargetArray.Count() != i; i++ ) |
|
199 { |
|
200 TBool found = EFalse; |
|
201 TPsmsrvConfigInfo& targetInfo = aTargetArray[i]; |
|
202 |
|
203 for ( TInt a = 0; !found && aSourceArray.Count() != a; a++ ) |
|
204 { |
|
205 TPsmsrvConfigInfo& sourceInfo = aSourceArray[a]; |
|
206 |
|
207 // check keys |
|
208 if ( sourceInfo.iConfigId == targetInfo.iConfigId && |
|
209 sourceInfo.iConfigType == targetInfo.iConfigType ) |
|
210 { |
|
211 // Add blocked information |
|
212 targetInfo.iBlocked = sourceInfo.iBlocked; |
|
213 |
|
214 // correct config found, update value |
|
215 switch ( targetInfo.iConfigType ) |
|
216 { |
|
217 case EConfigTypeInt: |
|
218 { |
|
219 targetInfo.iIntValue = sourceInfo.iIntValue; |
|
220 break; |
|
221 } |
|
222 case EConfigTypeReal: |
|
223 { |
|
224 targetInfo.iRealValue = sourceInfo.iRealValue; |
|
225 break; |
|
226 } |
|
227 case EConfigTypeBuf: |
|
228 { |
|
229 targetInfo.iDesValue.Copy( sourceInfo.iDesValue ); |
|
230 break; |
|
231 } |
|
232 default: |
|
233 { |
|
234 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::UpdateConfigArray() - Unknown type" ) ) ); |
|
235 } |
|
236 } |
|
237 // No need to loop config array anymore with this set element |
|
238 found = ETrue; |
|
239 } |
|
240 } |
|
241 } |
|
242 |
|
243 COMPONENT_TRACE( ( _L( "PSM Client - CPsmSettingsImpl::UpdateConfigArray() - return" ) ) ); |
|
244 } |
|
245 |
|
246 // End of file |