sysstatemgmt/systemstatemgr/cle/src/clecli.cpp
changeset 0 4e1aa6a622a0
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 "clecli.h"
       
    17 #include "clesrv.h"
       
    18 
       
    19 /**
       
    20  Construct the client-side CLE session.
       
    21 
       
    22 */
       
    23 RCleSession::RCleSession()
       
    24 : RSessionBase(),iVersion( KCleCliVersionMajor, KCleCliVersionMinor, KCleCliVersionBuild )
       
    25 	{
       
    26 	} //lint !e1401 not initialized by constructor (iSpare)
       
    27 
       
    28 
       
    29 	
       
    30 /**
       
    31  Connect to the CLE server. If the server is not found, this function will attempt to start it
       
    32  and retry connecting to it.
       
    33 
       
    34 @leave KErrNoMemory if no memory.
       
    35 @leave One of the system-wide error codes.
       
    36 */
       
    37 void RCleSession::ConnectL()
       
    38 	{
       
    39 	// Guard against multiple calls.
       
    40 	if( KNullHandle != iHandle )
       
    41 		{
       
    42 		User::Leave( KErrAlreadyExists );
       
    43 		}
       
    44 
       
    45 	const TInt err = CreateSession(KCleSrvName, iVersion, KCleSrvMsgSlots);
       
    46 	if( (KErrNotFound == err) || (KErrServerTerminated == err) )
       
    47 		{
       
    48 		User::LeaveIfError( CCleServer::StartCleSrv(KCleSrvName) );
       
    49 		User::LeaveIfError( CreateSession(KCleSrvName, iVersion, KCleSrvMsgSlots) );
       
    50 		}
       
    51 	else
       
    52 		{
       
    53 		User::LeaveIfError( err );
       
    54 		}	
       
    55 	}
       
    56 	
       
    57 /**
       
    58  Connect to the CLE server with the specified name. If the server is not found, this function will attempt to start it
       
    59  and retry connecting to it.
       
    60  
       
    61 @param aServerName The name of the CLE server to connect to
       
    62 @leave KErrNoMemory if no memory.
       
    63 @leave One of the system-wide error codes.
       
    64 */
       
    65 void RCleSession::ConnectL(const TDesC& aServerName)
       
    66 	{
       
    67 	// Guard against multiple calls.
       
    68 	if( KNullHandle != iHandle )
       
    69 		{
       
    70 		User::Leave( KErrAlreadyExists );
       
    71 		}
       
    72 
       
    73 	const TInt err = CreateSession(aServerName, iVersion, KCleSrvMsgSlots);
       
    74 	if( (KErrNotFound == err) || (KErrServerTerminated == err) )
       
    75 		{
       
    76 		User::LeaveIfError( CCleServer::StartCleSrv(aServerName) );
       
    77 		User::LeaveIfError( CreateSession(aServerName, iVersion, KCleSrvMsgSlots) );
       
    78 		}
       
    79 	else
       
    80 		{
       
    81 		User::LeaveIfError( err );
       
    82 		}	
       
    83 	}	
       
    84 	
       
    85 void RCleSession::Close()
       
    86 	{
       
    87 	// Guard against illegal operations if non-open.
       
    88 	if( Handle() )
       
    89 		{
       
    90 		ExecuteCommandListCancel();
       
    91 		}
       
    92 	RSessionBase::Close();
       
    93 	}
       
    94 
       
    95 
       
    96 /**
       
    97   Sends the pointer of the command list to the CLE server for reconstruction and execution 
       
    98   of the commands.
       
    99   The system currently only supports one call per client session. 
       
   100 
       
   101   @param aCmdList A constructed command list to be passed to the CLE server for execution.
       
   102   @param aStatus The TRequestStatus is completed by server-side code when
       
   103   all commands in a list have been initiated. KErrNone if list execution is successful. A system-wide error code 
       
   104   in case of error. KErrCancel if a call is made to ExecuteCommandListCancel() during list processing. 
       
   105   
       
   106 */
       
   107  void RCleSession::ExecuteCommandList( const CSsmCommandList& aCmdList, TRequestStatus& aStatus ,TCmdErrorSeverity& /*aSeverity*/)
       
   108 	{
       
   109 	TRequestStatus* clientStatus = &aStatus;
       
   110 	
       
   111 	if( aCmdList.Count() == 0 )
       
   112 		{
       
   113 		// Empty cmd list? Notify the client benignly and don't bother the server.
       
   114 		User::RequestComplete( clientStatus, KErrArgument );
       
   115 		
       
   116 		return;
       
   117 		}
       
   118 
       
   119 	if( !Handle() )
       
   120 		{
       
   121 		// Suggests that a call to ConnectL() might have been overlooked.
       
   122 		User::RequestComplete( clientStatus, KErrDisconnected );
       
   123 		
       
   124 		return;
       
   125 		}
       
   126 	TIpcArgs args( &aCmdList );
       
   127     SendReceive( ECleSrvExecuteCmdList, args, aStatus );
       
   128 	}
       
   129 
       
   130 
       
   131 
       
   132 /**
       
   133  Cancels a currently executing command list.
       
   134  
       
   135  @see ExecuteCommandList()
       
   136 
       
   137 */	
       
   138 void RCleSession::ExecuteCommandListCancel()
       
   139 	{
       
   140 	
       
   141 	if( Handle() )
       
   142 		{
       
   143 		SendReceive( ECleSrvExecuteCmdListCancel );
       
   144 		}
       
   145 	
       
   146 	}