sysstatemgmt/systemstatemgr/ssm/src/ssmswppolicycli.cpp
changeset 0 4e1aa6a622a0
child 64 61992147389a
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2008-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 "ssmswppolicycli.h"
       
    17 #include "ssmswppolicysrv.h"
       
    18 #include "ssmswppolicyconst.h"
       
    19 #include "ssmdebug.h"
       
    20 
       
    21 /**
       
    22  Constructs the client-side ssmswppolicy server session.
       
    23 */
       
    24 RSsmSwpPolicySession::RSsmSwpPolicySession()
       
    25 	: RSessionBase(), iVersion(KSsmSwpPolicyCliVersionMajor, KSsmSwpPolicyCliVersionMinor, KSsmSwpPolicyCliVersionBuild)
       
    26 	{
       
    27 	} //lint !e1401 not initialized by constructor (iSpare)
       
    28 	
       
    29 /**
       
    30  Connects to the ssmswppolicy server. If the server is not found, this function will attempt to start it
       
    31  and retry connecting to it.
       
    32 
       
    33 @leave KErrNoMemory if no memory.
       
    34 */
       
    35 void RSsmSwpPolicySession::ConnectL()
       
    36 	{
       
    37 	// Guard against multiple calls.
       
    38 	if(KNullHandle != iHandle)
       
    39 		{
       
    40 		DEBUGPRINT1(_L("RSsmSwpPolicySession: Client already has a Connected session"));
       
    41 		User::Leave(KErrAlreadyExists);
       
    42 		}
       
    43 
       
    44 	const TInt err = CreateSession(KSsmSwpPolicySrvName, iVersion, KSsmSwpPolicySrvMsgSlots);
       
    45 	if((KErrNotFound == err) || (KErrServerTerminated == err))
       
    46 		{
       
    47 		User::LeaveIfError(CSsmSwpPolicyServer::StartSsmSwpPolicySrv(KSsmSwpPolicySrvName));
       
    48 		User::LeaveIfError(CreateSession(KSsmSwpPolicySrvName, iVersion, KSsmSwpPolicySrvMsgSlots));
       
    49 		DEBUGPRINT1(_L("RSsmSwpPolicySession Connect Completed with KErrNone"));
       
    50 		}
       
    51 	else
       
    52 		{
       
    53 		DEBUGPRINT2(_L("RSsmSwpPolicySession Connect Completed with %d"), err);
       
    54 		User::LeaveIfError(err);
       
    55 		}
       
    56 	}
       
    57 
       
    58 #ifdef TEST_SSM_SERVER
       
    59 /**
       
    60  For testing purposes
       
    61  Connects to ssmswppolicy server with the specified name. If the server is not found, this function will attempt to start it
       
    62  and retry connecting to it.
       
    63  
       
    64 @param aServerName The name of the ssmswppolicy server to connect to
       
    65 @leave KErrNoMemory if no memory.
       
    66 */
       
    67 void RSsmSwpPolicySession::ConnectL(const TDesC& aServerName)
       
    68 	{
       
    69 	// Guard against multiple calls.
       
    70 	if(KNullHandle != iHandle)
       
    71 		{
       
    72 		User::Leave(KErrAlreadyExists);
       
    73 		}
       
    74 
       
    75 	const TInt err = CreateSession(aServerName, iVersion, KSsmSwpPolicySrvMsgSlots);
       
    76 	if((KErrNotFound == err) || (KErrServerTerminated == err))
       
    77 		{
       
    78 		User::LeaveIfError(CSsmSwpPolicyServer::StartSsmSwpPolicySrv(aServerName));
       
    79 		User::LeaveIfError(CreateSession(aServerName, iVersion, KSsmSwpPolicySrvMsgSlots));
       
    80 		DEBUGPRINT1(_L("RSsmSwpPolicySession Connect Completed with KErrNone"));
       
    81 		}
       
    82 	else
       
    83 		{
       
    84 		DEBUGPRINT2(_L("RSsmSwpPolicySession Connect Completed with %d"), err);
       
    85 		User::LeaveIfError(err);
       
    86 		}
       
    87 	}
       
    88 #endif	// TEST_SSM_SERVER
       
    89 
       
    90 /**
       
    91 Closes the RSession handle.
       
    92 */
       
    93 void RSsmSwpPolicySession::Close()
       
    94 	{
       
    95 	RSessionBase::Close();
       
    96 	}
       
    97 
       
    98 /**
       
    99 Sets the swppolicy dll handle and initializes the swppolicy. The policyhandle which is loaded in 
       
   100 swppolicyresovler is passed to the swppolicyserver, where it is used to open the handle to swppolicy
       
   101 and forward the calls from policy frame to the swppolicy.
       
   102 
       
   103 @param aPolicyHandle The swppolicy policyhandle
       
   104 @param aStatus		 Request Status
       
   105 */
       
   106 void RSsmSwpPolicySession::CallSetDllHandleAndInitialize(TInt aPolicyHandle, TRequestStatus& aStatus)
       
   107 	{
       
   108 	DEBUGPRINT1(_L("RSsmSwpPolicySession: Sets the swppolicy Dll Hanlde and Initializes it"));
       
   109 	SendReceive(ESsmPolicySrvSetSwpPolicyDllHandleAndInitialize, TIpcArgs(aPolicyHandle), aStatus);
       
   110 	}
       
   111 
       
   112 /**
       
   113 Cancels the Initialization of the swppolicy, if any Initialization request is pending.
       
   114 @return KErrNone, if successful; otherwise one of the other system-wide error codes. 
       
   115 */
       
   116 TInt RSsmSwpPolicySession::CallInitializeCancel()
       
   117 	{
       
   118 	DEBUGPRINT1(_L("RSsmSwpPolicySession: Cancel Initialization of the swp policy"));
       
   119 	return (SendReceive(ESsmPolicySrvInitializeCancel));
       
   120 	}
       
   121 
       
   122 /**
       
   123 Prepares the commandlist in swppolicy
       
   124 @param aSwp		Swp value
       
   125 @param aStatus	Request Status 
       
   126 */
       
   127 void RSsmSwpPolicySession::CallPrepareCommandList(const TSsmSwp& aSwp, TRequestStatus& aStatus)
       
   128 	{
       
   129 	DEBUGPRINT1(_L("RSsmSwpPolicySession: Call Prepare command list in swppolicy"));
       
   130 	const TPckgC<TSsmSwp> swpBuf(aSwp);
       
   131 	SendReceive(ESsmPolicySrvPrepareCommandList, TIpcArgs(&swpBuf), aStatus);
       
   132 	}
       
   133 
       
   134 /**
       
   135 Cancels the preparation of the commandlist, if any preparecommandlist request is pending.
       
   136 @return KErrNone, if successful; otherwise one of the other system-wide error codes. 
       
   137 */
       
   138 TInt RSsmSwpPolicySession::CallPrepareCommandListCancel()
       
   139 	{
       
   140 	DEBUGPRINT1(_L("RSsmSwpPolicySession: Cancel prepare command list in swppolicy"));
       
   141 	return (SendReceive(ESsmPolicySrvPrepareCommandListCancel));
       
   142 	}
       
   143 
       
   144 /**
       
   145 Returns the commandlist to the client from swppolicy.
       
   146 @return A pointer to commandlist
       
   147 */
       
   148 CSsmCommandList* RSsmSwpPolicySession::CallCommandListL()
       
   149 	{
       
   150 	// Ensure any memory that might already have been allocated is disposed of. 
       
   151 	// Transfer the streamed cmd list from the CBuf.
       
   152 	RBuf8 cmdListBuf;
       
   153 	cmdListBuf.CreateL(KSsmSwpPolicyStreamBufMaxSize);
       
   154 	CleanupClosePushL(cmdListBuf);
       
   155 
       
   156 	TInt err = SendReceive(ESsmPolicySrvCommandList, TIpcArgs(&cmdListBuf));
       
   157 	DEBUGPRINT2(_L("RSsmSwpPolicySession: CallCommandList completed with %d"), err);
       
   158 
       
   159 	CSsmCommandList* cmdList = NULL;
       
   160 
       
   161 	if(err == KErrNone)
       
   162 		{
       
   163 		// Supply RBuf to the readstream. Stream and reconstruct the command list.
       
   164 		RDesReadStream readStream(cmdListBuf);
       
   165 		CleanupClosePushL(readStream);
       
   166 		cmdList = CSsmCommandList::NewLC();
       
   167 		cmdList->InternalizeL( readStream);
       
   168 		CleanupStack::Pop(cmdList);
       
   169 		CleanupStack::PopAndDestroy(&readStream);
       
   170 		}
       
   171 
       
   172 	CleanupStack::PopAndDestroy(&cmdListBuf);
       
   173 	return cmdList;
       
   174 	}
       
   175 
       
   176 /*
       
   177 Handles the value returned by Cle.
       
   178 @param aSwp			swp value
       
   179 @param aError		Error returned by cle as result of the command execution
       
   180 @param aSeverity	Severity of the command
       
   181 @param aStatus		Request Status
       
   182 */
       
   183 void RSsmSwpPolicySession::CallHandleCleReturnValue(const TSsmSwp& aSwp, TInt aError, TInt aSeverity, TRequestStatus& aStatus)
       
   184 	{
       
   185 	const TPckgC<TSsmSwp> swpBuf(aSwp);
       
   186 	DEBUGPRINT1(_L("RSsmSwpPolicySession: Call HandleCleReturn Value of the swppolicy"));
       
   187 	SendReceive(ESsmPolicySrvHandleCleReturnValue, TIpcArgs(&swpBuf, aError, aSeverity), aStatus);
       
   188 	}
       
   189 
       
   190 /**
       
   191 Cancels the HandleCleReturnValue, if any HandleCleReturnValue request is pending.
       
   192 @return KErrNone, if successful; otherwise one of the other system-wide error codes. 
       
   193 */
       
   194 TInt RSsmSwpPolicySession::CallHandleCleReturnValueCancel()
       
   195 	{
       
   196 	DEBUGPRINT1(_L("RSsmSwpPolicySession: Cancel Call HandleCleReturn Value of the swppolicy"));
       
   197 	return (SendReceive(ESsmPolicySrvHandleCleReturnValueCancel));
       
   198 	}
       
   199 
       
   200 
       
   201 
       
   202 	
       
   203