sysstatemgmt/systemstatemgr/ssm/src/ssmswprequesthandler.cpp
changeset 0 4e1aa6a622a0
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/ssmswppolicy.h>
       
    17 
       
    18 #include "ssmdebug.h"
       
    19 #include "ssmserverpanic.h"
       
    20 #include "ssmswprequesthandler.h"
       
    21 #include "ssmswptransitionscheduler.h"
       
    22 #include "ssmswptransitionengine.h"
       
    23 #include "ssmswppolicyresolverproxy.h"
       
    24 #include "ssmswppolicyframe.h"
       
    25 
       
    26 
       
    27 //
       
    28 // Creation and Construction methods
       
    29 //
       
    30 
       
    31 /**
       
    32 @leave 	One of the system-wide error codes.
       
    33 @return A newly created CSsmSwpRequestHandler
       
    34 */
       
    35 CSsmSwpRequestHandler* CSsmSwpRequestHandler::NewL( )
       
    36 	{
       
    37 	CSsmSwpRequestHandler* self = NewLC ( );
       
    38 	CleanupStack::Pop (self );
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 /**
       
    43 @leave One of the system-wide error codes.
       
    44 @return A newly created CSsmSwpRequestHandler on the cleanup stack
       
    45 */
       
    46 CSsmSwpRequestHandler* CSsmSwpRequestHandler::NewLC( )
       
    47 	{
       
    48 	CSsmSwpRequestHandler* self = new (ELeave) CSsmSwpRequestHandler();
       
    49 	CleanupStack::PushL (self );
       
    50 	self->ConstructL ( );
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 /**
       
    55 Empty constructor
       
    56 */
       
    57 CSsmSwpRequestHandler::CSsmSwpRequestHandler() : iPerformCommandListValidation(ETrue)
       
    58 	{
       
    59 	}
       
    60 
       
    61 /**
       
    62  Construct transition scheduler
       
    63 
       
    64  @leave	One of the system-wide error codes.
       
    65  */
       
    66 void CSsmSwpRequestHandler::ConstructL( )
       
    67 	{
       
    68 	iSwpTransitionScheduler = CSsmSwpTransitionScheduler::NewL ( );
       
    69 	}
       
    70 
       
    71 /**
       
    72 Empty destructor
       
    73 */
       
    74 CSsmSwpRequestHandler::~CSsmSwpRequestHandler( )
       
    75 	{
       
    76 	delete iSwpTransitionScheduler;
       
    77 	}
       
    78 
       
    79 //
       
    80 // Public API methods
       
    81 //
       
    82 
       
    83 void CSsmSwpRequestHandler::SetSwpHandlerMonitor(MSwpHandlerMonitor* aMonitor)
       
    84 	{
       
    85 	iSwpHandlerMonitor = aMonitor;
       
    86 	}
       
    87 
       
    88 void CSsmSwpRequestHandler::SetSwpPolicyResolverProxy(MSsmSwpPolicyResolverProxy* aPolicyResolverProxy)
       
    89 	{
       
    90 	iSwpPolicyResolverProxy = aPolicyResolverProxy;
       
    91 	}
       
    92 
       
    93 void CSsmSwpRequestHandler::SetCleSessionProxy(MCleSessionProxy* aCleSessionProxy)
       
    94 	{
       
    95 	iCleSessionProxy = aCleSessionProxy;
       
    96 	}
       
    97 
       
    98 void CSsmSwpRequestHandler::PerformCommandListValidation(TBool aSetting)
       
    99 	{
       
   100 	iPerformCommandListValidation = aSetting;
       
   101 #ifdef _DEBUG
       
   102 	if(iPerformCommandListValidation)
       
   103 		{
       
   104 		DEBUGPRINT1(_L("Turning on State command list validation"));
       
   105 		}
       
   106 	else
       
   107 		{
       
   108 		DEBUGPRINT1(_L("Turning off State command list validation"));
       
   109 		}
       
   110 #endif
       
   111 	}
       
   112 
       
   113 /**
       
   114 Receives a swp request and handles it synchronously
       
   115 
       
   116 @param aRequest An swp change request
       
   117 @leave One of the system-wide error codes.
       
   118 */
       
   119 void CSsmSwpRequestHandler::SubmitRequestL(const TSsmSwp& aRequest )
       
   120 	{
       
   121 	__ASSERT_DEBUG(NULL != iSwpTransitionScheduler, PanicNow(KPanicSysStateMgr,ESwpRequestHandlerError1));
       
   122 	DoSubmitRequestL (aRequest, NULL );
       
   123 	}
       
   124 
       
   125 /**
       
   126 Receives a swp request and handles it asynchronously
       
   127 
       
   128 @param aRequest An swp change request
       
   129 @param aMessage Client message  to complete
       
   130 @leave One of the system-wide error codes.
       
   131 */
       
   132 void CSsmSwpRequestHandler::SubmitRequestL(const TSsmSwp& aRequest,
       
   133 		const RMessage2& aMessage )
       
   134 	{
       
   135 	__ASSERT_DEBUG(NULL != iSwpTransitionScheduler, PanicNow(KPanicSysStateMgr,ESwpRequestHandlerError2));
       
   136 	DoSubmitRequestL (aRequest, &aMessage );
       
   137 	}
       
   138 
       
   139 /**
       
   140  Cancel all running and queued requests
       
   141  */
       
   142 void CSsmSwpRequestHandler::Cancel(CSession2* aSession)
       
   143 	{
       
   144 	__ASSERT_DEBUG(NULL != iSwpTransitionScheduler, PanicNow(KPanicSysStateMgr,ESwpRequestHandlerError3));
       
   145 	iSwpTransitionScheduler->Cancel(aSession);
       
   146 	}
       
   147 
       
   148 //
       
   149 // Private methods
       
   150 //
       
   151 
       
   152 /**
       
   153 Resolve the policy for the swp value
       
   154 Set up the engine ready for running
       
   155 Add the engine to the scheduler
       
   156 
       
   157 @param aRequest An swp change request
       
   158 @leave KErrNotFound If swp value is not registered
       
   159 @leave Or one of the system-wide error codes
       
   160 */
       
   161 
       
   162 void CSsmSwpRequestHandler::DoSubmitRequestL(const TSsmSwp& aRequest, const RMessage2* aMessage)
       
   163 	{
       
   164 	__ASSERT_DEBUG(NULL != iSwpPolicyResolverProxy, PanicNow(KPanicSysStateMgr,ESwpRequestHandlerError4));
       
   165 	__ASSERT_DEBUG(NULL != iCleSessionProxy, PanicNow(KPanicSysStateMgr,ESwpRequestHandlerError5));
       
   166 
       
   167 	NotifyRequestMade (aRequest );
       
   168 
       
   169 	// get the policy
       
   170 	CSsmSwpPolicyFrame* policyFrame = iSwpPolicyResolverProxy->GetSwpPolicyL(aRequest);
       
   171 	SSMLOGLEAVEIFNULL(policyFrame);
       
   172 	CleanupStack::PushL(policyFrame);
       
   173 
       
   174 	// Create an engine
       
   175 	CSsmSwpTransitionEngine* engine = CSsmSwpTransitionEngine::NewL (aRequest);
       
   176 	engine->SetCleSessionProxy(iCleSessionProxy);
       
   177 	engine->SetSwpPolicyFrame(policyFrame); // and take ownership
       
   178 	CleanupStack::Pop (policyFrame ); // engine takes ownership
       
   179 	CleanupStack::PushL (engine);
       
   180 
       
   181 	engine->PerformCommandListValidation(iPerformCommandListValidation);
       
   182 
       
   183 	iSwpTransitionScheduler->SubmitL (engine ); // scheduler takes ownership
       
   184 	CleanupStack::Pop (engine );
       
   185 
       
   186 	engine->SetClientMessage (aMessage ); // client wants to be notified
       
   187 	}
       
   188 
       
   189 //
       
   190 //Event notification interface
       
   191 //
       
   192 
       
   193 /**
       
   194 Flag request made
       
   195 
       
   196 @param aRequest Value of swp request
       
   197 */
       
   198 void CSsmSwpRequestHandler::NotifyRequestMade(const TSsmSwp& aRequest )
       
   199 	{
       
   200 	if (NULL != iSwpHandlerMonitor )
       
   201 		{
       
   202 		iSwpHandlerMonitor->SwpRequestMade (aRequest );
       
   203 		}
       
   204 	}
       
   205 /**
       
   206  * Used only for testing purposes
       
   207  * Cleans up the Transition Scheduler
       
   208  */
       
   209 #ifdef _DEBUG
       
   210 void CSsmSwpRequestHandler::CleanupSwpTransitionScheduler()
       
   211 	{
       
   212 	iSwpTransitionScheduler->CleanupIndividualSchedulerArray();
       
   213 	}
       
   214 #endif