sysstatemgmt/systemstatemgr/ssm/src/ssmsession.cpp
changeset 0 4e1aa6a622a0
child 59 0f7422b6b602
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <ssm/ssmstatemanager.h>
       
    17 #include "ssmserver.h"
       
    18 #include "ssmsession.h"
       
    19 #include "ssmclisrv.h"
       
    20 #include "ssmdebug.h"
       
    21 
       
    22 CSsmSession::~CSsmSession( )
       
    23 	{
       
    24 	}
       
    25 
       
    26 CSsmSession::CSsmSession( )
       
    27 	{
       
    28 	}
       
    29 
       
    30 CSsmSession* CSsmSession::NewL( )
       
    31 	{
       
    32 	CSsmSession* session = new(ELeave) CSsmSession();
       
    33 	return session;
       
    34 	}
       
    35 
       
    36 void CSsmSession::ServiceL(const RMessage2& aMessage)
       
    37 	{
       
    38 	switch( aMessage.Function() )
       
    39 		{
       
    40 		case ERequestStateTransition:
       
    41 			{
       
    42 			TSsmState newState;
       
    43 			newState.SetFromInt(aMessage.Int0());
       
    44 			const TInt reason = aMessage.Int1();
       
    45 #ifdef _DEBUG
       
    46 			TSsmStateName name = newState.Name();
       
    47 			DEBUGPRINT2(_L("SysStateSession received new request: ERequestStateTransition %S"), &name);
       
    48 #endif
       
    49 			SsmServer()->RequestStateTransitionL(newState, reason, aMessage);
       
    50 			break;
       
    51 			} //lint !e529 'name' not subsequently referenced in release builds
       
    52 
       
    53 		case ERequestStateTransitionCancel:
       
    54 			DEBUGPRINT1(_L ("SysStateSession received new request: ERequestStateTransitionCancel"));
       
    55 			aMessage.Complete (KErrNone);
       
    56 			SsmServer()->RequestStateTransitionCancel(this);
       
    57 			break;
       
    58 
       
    59 		case ERequestSwpChange:
       
    60 			{
       
    61 			const TUint swpKey = {aMessage.Int0()};
       
    62 			const TSsmSwp newSwpValue(swpKey, aMessage.Int1());
       
    63 			DEBUGPRINT3(_L ("SysStateSession received new request: ERequestSwpChange %x : %d"), newSwpValue.Key(), newSwpValue.Value());
       
    64 			SsmServer()->RequestSwpChangeL(newSwpValue, aMessage);
       
    65 			break;
       
    66 			}
       
    67 
       
    68 		case ERequestSwpChangeCancel:
       
    69 			{
       
    70 			DEBUGPRINT1(_L ("SysStateSession received new request: ERequestSwpChangeCancel"));
       
    71 			aMessage.Complete (KErrNone);
       
    72 			SsmServer()->RequestSwpChangeCancel(this);
       
    73 			break;
       
    74 			}
       
    75 	
       
    76 		case ERequestRegisterSwpMapping:
       
    77 			{
       
    78 			DEBUGPRINT1(_L ("SysStateSession received new request: ERequestRegisterSwpMapping"));
       
    79 			const TUint swpKey = {aMessage.Int0()};
       
    80 			const TInt deslen = aMessage.GetDesLengthL(1);
       
    81 			RBuf filename;
       
    82 			filename.Create(deslen);
       
    83 			filename.CleanupClosePushL();
       
    84 			aMessage.ReadL(1, filename);
       
    85 			SsmServer()->RequestRegisterSwpMappingL(swpKey, filename);
       
    86 			CleanupStack::PopAndDestroy(&filename);
       
    87 			aMessage.Complete(KErrNone);
       
    88 			break;
       
    89 			}
       
    90 			
       
    91 		case ERequestMarkHeap:
       
    92 			{
       
    93 			#ifdef _DEBUG
       
    94 			__UHEAP_MARK;
       
    95 			DEBUGPRINT2(_L("CSsmSession - EDebugMarkHeap: Alloc Cells: %d."), User::CountAllocCells());
       
    96 			#endif
       
    97 			aMessage.Complete(KErrNone);
       
    98 			break;
       
    99 			}
       
   100 			
       
   101 		case ERequestMarkHeapEnd:
       
   102 			{
       
   103 			#ifdef _DEBUG
       
   104 			//Type of cleanup required.Passed from the test case
       
   105 			TInt aCleanup = (aMessage.Int0());
       
   106 			//Deletes the data members of the transition engine which are on the heap
       
   107 			//This is done to ensure that each test cleans up after itself
       
   108 			switch(aCleanup)
       
   109 				{
       
   110 				case ENoCleanup:
       
   111 					{
       
   112 					//No cleanup required
       
   113 					break;
       
   114 					}
       
   115 				case EDoCleanup:
       
   116 					{
       
   117 					//Cleanup both  state transition engine and swp request handler
       
   118 					SsmServer()->DoCleanupStateTransitionEngine();
       
   119 					SsmServer()->DoCleanupSwpRequestHandler();
       
   120 					break;
       
   121 					}
       
   122 				case ECleanupStateTransitionEngineOnly:
       
   123 					{
       
   124 					//cleanup only state transition engine
       
   125 					SsmServer()->DoCleanupStateTransitionEngine();
       
   126 					break;
       
   127 					}
       
   128 				case ECleanupSwpRequestHandlerOnly:
       
   129 					{
       
   130 					//cleanup only the swp request handler
       
   131 					SsmServer()->DoCleanupSwpRequestHandler();
       
   132 					break;
       
   133 					}
       
   134 				default:
       
   135 					{
       
   136 					break;
       
   137 					}
       
   138 				}				
       
   139 			DEBUGPRINT2(_L("CSsmSession - EDebugMarkHeapEndC: Alloc Cells: %d."), User::CountAllocCells());
       
   140 			__UHEAP_MARKEND;
       
   141 			
       
   142 			#endif
       
   143 			aMessage.Complete(KErrNone);
       
   144 			break;
       
   145 			}	
       
   146 		case ERequestDeRegisterSwpMapping:
       
   147 			{
       
   148 			#ifdef _DEBUG
       
   149 			DEBUGPRINT1(_L ("SysStateSession received new request: ERequestDeRegisterSwpMapping"));
       
   150 			const TUint swpKey = {aMessage.Int0()};
       
   151 			const TInt length = aMessage.GetDesLengthL(1);
       
   152 			RBuf filename;
       
   153 			filename.Create(length);
       
   154 			filename.CleanupClosePushL();
       
   155 			aMessage.ReadL(1, filename);
       
   156 			SsmServer()->RequestDeRegisterSwpMappingL(swpKey, filename);
       
   157 			CleanupStack::PopAndDestroy(&filename);
       
   158 			#endif
       
   159 			aMessage.Complete(KErrNone);
       
   160 			break;
       
   161 			}	
       
   162 		default:
       
   163 			{
       
   164 			DEBUGPRINT2(_L ("SysStateSession received unknown request %d. PolicyServer configuration must be wrong."), aMessage.Function());
       
   165 			aMessage.Complete(KErrNotSupported);
       
   166 			break;
       
   167 			}
       
   168 		}
       
   169 	}
       
   170 
       
   171 void CSsmSession::ServiceError(const RMessage2 &aMessage, TInt aError )
       
   172 	{
       
   173 	DEBUGPRINT2(_L ("SysStateSession: ServiceError %d"), aError);
       
   174 	CSession2::ServiceError(aMessage, aError);
       
   175 	}
       
   176 
       
   177 /**
       
   178  CSsmSession::SsmServer() returns a pointer to the server object
       
   179  */
       
   180 CSsmServer* CSsmSession::SsmServer( ) const
       
   181 	{
       
   182 	return static_cast<CSsmServer*> (const_cast<CServer2*> (Server()));
       
   183 	}