sysstatemgmt/systemstatemgr/ssm/src/ssmswppolicyframe.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 <e32cmn.h>
       
    17 
       
    18 #include <ssm/ssmswp.h>
       
    19 #include "ssmswppolicyframe.h"
       
    20 
       
    21 #include "ssmdebug.h"
       
    22 #include "ssmserverpanic.h"
       
    23 #include "ssmswppolicyproxy.h"
       
    24 
       
    25 
       
    26 /**
       
    27 signature of expected DLL factory function
       
    28 */
       
    29 typedef MSsmSwpPolicy*(*TFuncSwpNewL)(void);
       
    30 
       
    31 /**
       
    32 Trivial constructor
       
    33 */
       
    34 CSsmSwpPolicyFrame::CSsmSwpPolicyFrame()
       
    35 	{
       
    36 	}
       
    37 
       
    38 /**
       
    39 Static method to create a new frame and instantiate a policy using the
       
    40 supplied factory method
       
    41 
       
    42 @param aNewLFunc - a factory method that creates a new policy
       
    43                    (the frame takes ownership)
       
    44 @return a new frame object that encapsulates a valid policy
       
    45 */
       
    46 CSsmSwpPolicyFrame* CSsmSwpPolicyFrame::NewL(TLibraryFunction aNewLFunc)
       
    47 	{
       
    48 	CSsmSwpPolicyFrame* self = new (ELeave) CSsmSwpPolicyFrame();
       
    49 	CleanupStack::PushL (self);
       
    50 	self->ConstructL (aNewLFunc);
       
    51 	CleanupStack::Pop (self);
       
    52 	return self;
       
    53 	}
       
    54 
       
    55 /**
       
    56 Construct the frame and create the policy
       
    57 
       
    58 @param aNewLFunc - a factory method that creates a new policy
       
    59 @return a new frame object that encapsulates a valid policy
       
    60 */
       
    61 void CSsmSwpPolicyFrame::ConstructL(TLibraryFunction aNewLFunc)
       
    62 	{
       
    63 	TFuncSwpNewL newL = reinterpret_cast<TFuncSwpNewL>( aNewLFunc );
       
    64 	iSwpPolicy = newL ();
       
    65 #ifdef _DEBUG
       
    66 	if(!iSwpPolicy)
       
    67 		{
       
    68 		DEBUGPRINT1(_L("First function in Swp Policy DLL didn't create a new instance"));
       
    69 		}
       
    70 #endif
       
    71 	SSMLOGLEAVEIFNULL(iSwpPolicy);
       
    72 	}
       
    73 
       
    74 /**
       
    75 Destroy the owned policy and release the library (if available).
       
    76 */
       
    77 CSsmSwpPolicyFrame::~CSsmSwpPolicyFrame()
       
    78 	{
       
    79 	//Let the derived implementation handle its own destruction
       
    80 	if(iSwpPolicy)
       
    81 		{
       
    82 		iSwpPolicy->Release();
       
    83 		iSwpPolicy = NULL;
       
    84 		iLibrary.Close(); // release the dll
       
    85 		}
       
    86 	}
       
    87 
       
    88 /**
       
    89 Return the swp key that this frame is associated with
       
    90 
       
    91 @return this frame's swp value
       
    92 
       
    93 */
       
    94 TUint CSsmSwpPolicyFrame::SwpKey() const
       
    95 	{
       
    96 	return iSwpKey;
       
    97 	}
       
    98 
       
    99 /**
       
   100 Set the swp key that this frame is associated with
       
   101 
       
   102 @param a valid swp key that matches the loaded policy
       
   103 
       
   104 */
       
   105 void CSsmSwpPolicyFrame::SetSwpKey(TUint aKey)
       
   106 	{
       
   107 	iSwpKey = aKey;
       
   108 	}  //lint !e1746 Suppress parameter 'aKey' could be made const reference
       
   109 
       
   110 /**
       
   111  Takes ownership of open handle
       
   112  */
       
   113 void CSsmSwpPolicyFrame::SetLibrary(const RLibrary& aLibrary)
       
   114 	{
       
   115 	iLibrary = aLibrary;
       
   116 	}
       
   117 
       
   118 void CSsmSwpPolicyFrame::SetSsmSwpPolicySession(CSsmSwpPolicyCliSession* aSsmSwpPolicySession)
       
   119 	{
       
   120 	iSsmSwpPolicySession = aSsmSwpPolicySession;
       
   121 	}
       
   122 
       
   123 /**
       
   124 Accessor to the policy's asynchronous Initialize method
       
   125 
       
   126 @param aStatus to inform the caller of completion.
       
   127 Note: the possible values for the completion status are defined by the policy method
       
   128 
       
   129 */
       
   130 void CSsmSwpPolicyFrame::CallInitialize(TRequestStatus& aStatus)
       
   131 	{
       
   132 	__ASSERT_DEBUG(NULL != iSwpPolicy, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError1));
       
   133 	__ASSERT_DEBUG(NULL != iSsmSwpPolicySession, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError18));
       
   134 
       
   135 	// lazy initialisation
       
   136 	// if initialization is already called then we are simply completing the request with KErrNone.
       
   137 	if (!iInitializeCalled)
       
   138 		{
       
   139 		iSsmSwpPolicySession->CallSetDllHandleAndInitialize(iLibrary.Handle(), aStatus);
       
   140 		iInitializeCalled = ETrue;
       
   141 		iInternalState = EWaitForPrepare;
       
   142 		}
       
   143 	else // complete
       
   144 		{
       
   145 		DEBUGPRINT1(_L("SwpPolicy is already initialized"));
       
   146 		TRequestStatus* status = &aStatus;
       
   147 		User::RequestComplete (status, KErrNone);
       
   148 		}
       
   149 	}
       
   150 
       
   151 /**
       
   152 Accessor to the policy's synchronous Cancel method
       
   153 
       
   154 */
       
   155 TInt CSsmSwpPolicyFrame::CallInitializeCancel()
       
   156 	{
       
   157 	__ASSERT_DEBUG(NULL != iSwpPolicy, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError15));
       
   158 	__ASSERT_DEBUG(NULL != iSsmSwpPolicySession, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError22));
       
   159 
       
   160 	TInt err = KErrNone;
       
   161 	if (iInitializeCalled)
       
   162 		{
       
   163 		err = iSsmSwpPolicySession->CallInitializeCancel();
       
   164 		iInternalState = EWaitForPrepare;
       
   165 		}
       
   166 	return err;
       
   167 	}
       
   168 
       
   169 /**
       
   170 Accessor to the policy's synchronous TransitionAllowed method
       
   171 
       
   172 @param aSwp swp value to interrogate
       
   173 @param aMessage Contains information about the requesting client process.
       
   174 @return the response to the query
       
   175 */
       
   176 MSsmSwpPolicy::TResponse CSsmSwpPolicyFrame::CallTransitionAllowed(const TSsmSwp& aSwp, const RMessagePtr2& aMessage)
       
   177 	{
       
   178 	// CallTransitionAllowed can be called at any time as long as the object has been initialised
       
   179 	__ASSERT_DEBUG(NULL != iSwpPolicy, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError3));
       
   180 	__ASSERT_DEBUG(iInitializeCalled, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError4));
       
   181 
       
   182 	MSsmSwpPolicy::TResponse response = MSsmSwpPolicy::ENotAllowed;
       
   183 
       
   184 	// Since this is a synchronous call we are not using iSsmSwpPolicySession
       
   185 	// for enquiring about response returned from TransitionAllowed.
       
   186 	if (iInitializeCalled)
       
   187 		{
       
   188 		response = iSwpPolicy->TransitionAllowed(aSwp, aMessage);
       
   189 		}
       
   190 	return response;
       
   191 	}
       
   192 
       
   193 /**
       
   194 Accessor to the policy's asynchronous PrepareCommandList method
       
   195 
       
   196 @param aSwp swp value to interrogate
       
   197 @param aStatus to inform the caller of completion
       
   198 Note: the possible values for the completion status are defined by the policy method
       
   199 
       
   200 */
       
   201 void CSsmSwpPolicyFrame::CallPrepareCommandList(const TSsmSwp& aSwp, TRequestStatus& aStatus)
       
   202 	{
       
   203 	__ASSERT_DEBUG(EWaitForPrepare == iInternalState || EWaitForCommandListExecution == iInternalState, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError5));
       
   204 	__ASSERT_DEBUG(aSwp.Key() == iSwpKey, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError6));
       
   205 
       
   206 	__ASSERT_DEBUG(NULL != iSwpPolicy, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError7));
       
   207 	__ASSERT_DEBUG(NULL != iSsmSwpPolicySession, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError19));
       
   208 	__ASSERT_DEBUG(iInitializeCalled, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError8));
       
   209 
       
   210 	// if initialization is not called then we are simply completing the request with KErrNone.
       
   211 	if (iInitializeCalled)
       
   212 		{
       
   213 		iSsmSwpPolicySession->CallPrepareCommandList(aSwp, aStatus);
       
   214 		iInternalState = EWaitForGet;
       
   215 		}
       
   216 	else // complete
       
   217 		{
       
   218 		DEBUGPRINT1(_L("SwpPolicy is not initialized"));
       
   219 		TRequestStatus* status = &aStatus;
       
   220 		User::RequestComplete (status, KErrNone);
       
   221 		}
       
   222 
       
   223 	} //lint !e1746 Suppress parameter 'aSwp' could be made const reference
       
   224 
       
   225 /**
       
   226 Accessor to the policy's synchronous Cancel method
       
   227 
       
   228 */
       
   229 TInt CSsmSwpPolicyFrame::CallPrepareCommandListCancel()
       
   230 	{
       
   231 	__ASSERT_DEBUG(NULL != iSwpPolicy, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError16));
       
   232 	__ASSERT_DEBUG(NULL != iSsmSwpPolicySession, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError23));
       
   233 
       
   234 	TInt err = KErrNone;
       
   235 	// iSsmSwpPolicySession is the session with ssmswppolicycli
       
   236 	if (iInitializeCalled)
       
   237 		{
       
   238 		err = iSsmSwpPolicySession->CallPrepareCommandListCancel();
       
   239 		iInternalState = EWaitForPrepare;
       
   240 		}
       
   241 	return err;
       
   242 	}
       
   243 
       
   244 /**
       
   245 Accessor to the policy's synchronous CommandList method
       
   246 
       
   247 @return a valid command list for execution or NULL
       
   248 
       
   249 */
       
   250 CSsmCommandList* CSsmSwpPolicyFrame::CallCommandList()
       
   251 	{
       
   252 	__ASSERT_DEBUG(EWaitForGet == iInternalState, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError9));
       
   253 	__ASSERT_DEBUG(NULL != iSwpPolicy, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError10));
       
   254 	__ASSERT_DEBUG(NULL != iSsmSwpPolicySession, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError20));
       
   255 	__ASSERT_DEBUG(iInitializeCalled, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError11));
       
   256 
       
   257 	CSsmCommandList* list=  NULL;
       
   258 	if (iInitializeCalled)
       
   259 		{
       
   260 		list = iSsmSwpPolicySession->CallCommandList();
       
   261 		iInternalState = EWaitForCommandListExecution;
       
   262 		}
       
   263 	return list;
       
   264 	}
       
   265 
       
   266 /**
       
   267 Accessor to the policy's asynchronous HandleCleReturnValue method
       
   268 
       
   269 @param TInt the value returned by the CLE
       
   270 @param aStatus to inform the caller of completion
       
   271 Note: the possible values for the completion status are defined by the policy method
       
   272 
       
   273 */
       
   274 void CSsmSwpPolicyFrame::CallHandleCleReturnValue(const TSsmSwp& aSwp, TInt aError, TInt aSeverity, TRequestStatus& aStatus)
       
   275 	{
       
   276 	__ASSERT_DEBUG(EWaitForCommandListExecution == iInternalState, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError12));
       
   277 	__ASSERT_DEBUG(NULL != iSwpPolicy, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError13));
       
   278 	__ASSERT_DEBUG(NULL != iSsmSwpPolicySession, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError21));
       
   279 	__ASSERT_DEBUG(iInitializeCalled, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError14));
       
   280 
       
   281 	// If initialization is not called then we are simply completing the request with KErrNone.
       
   282 	if (iInitializeCalled)
       
   283 		{
       
   284 		iSsmSwpPolicySession->CallHandleCleReturnValue(aSwp, aError, aSeverity, aStatus);
       
   285 		iInternalState = EWaitForPrepare;
       
   286 		}
       
   287 	else // complete
       
   288 		{
       
   289 		DEBUGPRINT1(_L("SwpPolicy is not initialized"));
       
   290 		TRequestStatus* status = &aStatus;
       
   291 		User::RequestComplete(status, KErrNone);
       
   292 		}
       
   293 	}
       
   294 
       
   295 /**
       
   296 Accessor to the policy's synchronous Cancel method
       
   297 
       
   298 */
       
   299 TInt CSsmSwpPolicyFrame::CallHandleCleReturnValueCancel()
       
   300 	{
       
   301 	__ASSERT_DEBUG(EWaitForPrepare == iInternalState, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError17));
       
   302 	__ASSERT_DEBUG(NULL != iSwpPolicy, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError2));
       
   303 	__ASSERT_DEBUG(NULL != iSsmSwpPolicySession, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError24));
       
   304 	__ASSERT_DEBUG(iInitializeCalled, PanicNow(KPanicSysStateMgr,ESwpPolicyFrameError14));
       
   305 
       
   306 	TInt err = iSsmSwpPolicySession->CallHandleCleReturnValueCancel();
       
   307 	iInternalState = EWaitForPrepare;
       
   308 	return err;
       
   309 	}