123 // ----------------------------------------------------------------------------- |
121 // ----------------------------------------------------------------------------- |
124 // |
122 // |
125 void CPsmSession::ServiceL( const RMessage2& aMessage ) |
123 void CPsmSession::ServiceL( const RMessage2& aMessage ) |
126 { |
124 { |
127 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ServiceL()" ) ) ); |
125 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ServiceL()" ) ) ); |
128 |
|
129 TRAPD( error, DispatchL( aMessage ) ); |
|
130 |
|
131 // Complete message with error code if there were errors |
|
132 if ( KErrNone != error ) |
|
133 { |
|
134 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ServiceL() - Error: %i" ), error ) ); |
|
135 aMessage.Complete( error ); |
|
136 } |
|
137 |
|
138 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ServiceL - return" ) ) ); |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CPsmSession::DispatchL |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 void CPsmSession::DispatchL( const RMessage2& aMessage ) |
|
146 { |
|
147 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::DispatchL()" ) ) ); |
|
148 |
|
149 switch ( aMessage.Function() ) |
126 switch ( aMessage.Function() ) |
150 { |
127 { |
151 case EPsmServerNotifyModeChange: // For power save mode change |
128 case EPsmServerNotifyModeChange: // For power save mode change |
152 { |
129 { |
153 TInt mode = aMessage.Int0(); |
130 TInt mode = aMessage.Int0(); |
154 if ( !iNotifyModeMessage ) |
131 if ( !iNotifyModeMessage ) |
155 { |
132 { |
156 // Create message wrapper if not yet created |
133 // Create message wrapper if not yet created |
157 iNotifyModeMessage = CPsmMessage::NewL( iPsmManager ); |
134 CPsmMessage* notifyModeMessage = CPsmMessage::NewL( iPsmManager ); |
158 iPsmManager.RegisterObserver( iNotifyModeMessage ); |
135 CleanupStack::PushL(notifyModeMessage); |
159 } |
136 iPsmManager.RegisterObserverL( notifyModeMessage ); |
160 |
137 CleanupStack::Pop(notifyModeMessage); |
161 // Check that mode to be set is valid, otherwise error code. |
138 iNotifyModeMessage = notifyModeMessage; |
162 if( mode == iPsmManager.SettingsProvider().Mode() ) |
139 } |
|
140 |
|
141 //Check whether the mode is already set . |
|
142 TInt cenrepMode( 0 ); |
|
143 CRepository* cenrep = CRepository::NewLC( KCRUidPowerSaveMode ); |
|
144 User::LeaveIfError(cenrep->Get( KPsmCurrentMode, cenrepMode )); |
|
145 CleanupStack::PopAndDestroy( cenrep ); |
|
146 // Check that mode to be set is valid, otherwise error code. |
|
147 if( mode == cenrepMode ) |
163 { |
148 { |
164 User::Leave( KErrAlreadyExists ); |
149 User::Leave( KErrAlreadyExists ); |
165 } |
150 } |
166 |
151 |
167 if( ( mode > EPsmsrvPartialMode ) || ( mode < EPsmsrvModeNormal ) ) |
152 if( ( mode > EPsmsrvPartialMode ) || ( mode < EPsmsrvModeNormal ) ) |
245 } |
227 } |
246 // Complete message |
228 // Complete message |
247 aMessage.Complete( KErrNone ); |
229 aMessage.Complete( KErrNone ); |
248 break; |
230 break; |
249 } |
231 } |
|
232 #ifdef _DEBUG |
|
233 case EDebugHeapMark: |
|
234 { |
|
235 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession - EDebugMarkHeap: Alloc Cells: %d."), User::CountAllocCells())); |
|
236 __UHEAP_MARK; |
|
237 aMessage.Complete(KErrNone); |
|
238 break; |
|
239 } |
|
240 |
|
241 case EDebugHeapMarkEnd: |
|
242 { |
|
243 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession - EDebugMarkHeapEnd: Alloc Cells: %d."), User::CountAllocCells())); |
|
244 if ( iNotifyModeMessage ) |
|
245 { |
|
246 // Unregister observer from manager |
|
247 iPsmManager.UnregisterObserver( iNotifyModeMessage ); |
|
248 // Compress the observer array |
|
249 iPsmManager.CompressModeObserversArray(); |
|
250 // Finally delete message |
|
251 delete iNotifyModeMessage; |
|
252 iNotifyModeMessage = NULL; |
|
253 } |
|
254 iPsmManager.ClosePluginLoader(); |
|
255 __UHEAP_MARKEND; |
|
256 aMessage.Complete(KErrNone); |
|
257 break; |
|
258 } |
|
259 |
|
260 case EDebugSetHeapFailure: |
|
261 { |
|
262 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession - EDebugSetHeapFailure: Value of Failure Rate: %d."), aMessage.Int0())); |
|
263 __UHEAP_SETFAIL(RAllocator::EFailNext,aMessage.Int0()); |
|
264 aMessage.Complete(KErrNone); |
|
265 break; |
|
266 } |
|
267 |
|
268 case EDebugHeapReset: |
|
269 { |
|
270 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession - EDebugHeapReset "))); |
|
271 __UHEAP_RESET; |
|
272 aMessage.Complete(KErrNone); |
|
273 break; |
|
274 } |
|
275 #endif |
250 default: |
276 default: |
251 { |
277 { |
252 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ServiceL() - unknown request: %i - ERROR" ), aMessage.Function() ) ); |
278 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ServiceL() - unknown request: %i - ERROR" ), aMessage.Function() ) ); |
253 User::Leave( KErrUnknown ); |
279 User::Leave( KErrUnknown ); |
254 } |
280 } |
255 } |
281 } |
256 |
282 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ServiceL - return" ) ) ); |
257 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::DispatchL - return" ) ) ); |
283 } |
258 } |
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CPsmSession::ServiceError |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 void CPsmSession::ServiceError(const RMessage2 &aMessage, TInt aError) |
|
290 { |
|
291 // Complete message with error code if there were errors |
|
292 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ServiceError() - Error: %i" ), aError ) ); |
|
293 if (iNotifyModeMessage && (aMessage.Handle() == iNotifyModeMessage->MessageHandle()) ) |
|
294 { |
|
295 iNotifyModeMessage->Complete( aError ); |
|
296 } |
|
297 else |
|
298 { |
|
299 aMessage.Complete( aError ); |
|
300 } |
|
301 } |
|
302 |
259 |
303 |
260 // ----------------------------------------------------------------------------- |
304 // ----------------------------------------------------------------------------- |
261 // CPsmSession::HandleSettingsRequestL |
305 // CPsmSession::HandleSettingsRequestL |
262 // ----------------------------------------------------------------------------- |
306 // ----------------------------------------------------------------------------- |
263 // |
307 // |
264 void CPsmSession::HandleSettingsRequestL( const RMessage2& aMessage ) |
308 void CPsmSession::HandleSettingsRequestL( const RMessage2& aMessage ) |
265 { |
309 { |
266 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL()" ) ) ); |
310 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL()" ) ) ); |
267 |
311 |
|
312 RConfigInfoArray configArray; |
|
313 CleanupClosePushL(configArray); |
268 // read config array from message |
314 // read config array from message |
269 ReadConfigArrayL( iConfigArray, aMessage ); |
315 ReadConfigArrayL( configArray, aMessage ); |
270 // Get storage UID |
316 // Get storage UID |
271 TUint32 storage = aMessage.Int2(); |
317 TUint32 storage = aMessage.Int2(); |
272 |
318 |
273 TInt err( KErrNone ); |
319 TInt err( KErrNone ); |
274 |
320 |
275 if ( aMessage.Function() == EPsmServerBackupSettings ) |
321 switch ( aMessage.Function() ) |
276 { |
322 { |
277 iPsmManager.SettingsProvider().BackupSettingsL( iConfigArray, storage ); |
323 case EPsmServerBackupSettings: // For server backup settings |
278 } |
324 { |
279 else |
325 iPsmManager.SettingsProvider().BackupSettingsL( configArray, storage ); |
280 { |
326 break; |
281 if ( aMessage.Function() == EPsmServerGetSettings ) |
327 } |
282 { |
328 case EPsmServerGetSettings: // For getting server settingspower save mode change |
283 iPsmManager.SettingsProvider().GetSettingsL( iConfigArray, storage ); |
329 { |
284 } |
330 iPsmManager.SettingsProvider().GetSettingsL( configArray, storage ); |
285 else |
331 // check whether the configArray is empty before writing the value back to message. |
286 { |
332 if(configArray.Count() > 0) |
287 // EPsmServerChangeSettings |
333 { |
288 iPsmManager.SettingsProvider().BackupAndGetSettingsL( iConfigArray, storage ); |
334 // write changed values back to message |
289 } |
335 TInt arraySize( configArray.Count() * sizeof( TPsmsrvConfigInfo ) ); |
290 |
336 TPtr8 arrayPtr( reinterpret_cast<TUint8*>(&configArray[0]), arraySize, arraySize ); |
291 // We have to write changed values back to message |
337 err = aMessage.Write( 0, arrayPtr ); |
292 TInt arraySize( iConfigArray.Count() * sizeof( TPsmsrvConfigInfo ) ); |
338 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL - New data wrote to message: %i" ), err ) ); |
293 TPtr8 arrayPtr( reinterpret_cast<TUint8*>(&iConfigArray[0]), arraySize, arraySize ); |
339 } |
294 err = aMessage.Write( 0, arrayPtr ); |
340 else |
295 ERROR_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL - New data wrote to message: %i" ), err ) ); |
341 { |
|
342 ERROR_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL - Config Array is Empty" )) ); |
|
343 } |
|
344 break; |
|
345 } |
|
346 case EPsmServerChangeSettings: // For changing the settings |
|
347 { |
|
348 // We have to write changed values back to message |
|
349 iPsmManager.SettingsProvider().BackupAndGetSettingsL( configArray, storage ); |
|
350 // We have to write changed values back to message |
|
351 TInt arraySize( configArray.Count() * sizeof( TPsmsrvConfigInfo ) ); |
|
352 TPtr8 arrayPtr( reinterpret_cast<TUint8*>(&configArray[0]), arraySize, arraySize ); |
|
353 err = aMessage.Write( 0, arrayPtr ); |
|
354 ERROR_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL - New data wrote to message: %i" ), err ) ); |
|
355 break; |
|
356 } |
|
357 default: |
|
358 { |
|
359 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL() - unknown request: %i - ERROR" ), aMessage.Function() ) ); |
|
360 User::Leave( KErrUnknown ); |
|
361 } |
296 } |
362 } |
297 // Complete message before destroying local config array |
363 // Complete message before destroying local config array |
298 aMessage.Complete( err ); |
364 aMessage.Complete( err ); |
|
365 |
|
366 CleanupStack::PopAndDestroy(&configArray); |
|
367 |
299 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL - return" ) ) ); |
368 COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL - return" ) ) ); |
300 } |
369 } |
301 |
370 |
302 // ----------------------------------------------------------------------------- |
371 // ----------------------------------------------------------------------------- |
303 // CPsmSession::ReadConfigArrayL |
372 // CPsmSession::ReadConfigArrayL |