testexecmgmt/ucc/Source/Uccs.v2/ServiceStubs/HostExecute/CHostExecuteStub.cpp
changeset 0 3da2a79470a7
equal deleted inserted replaced
-1:000000000000 0:3da2a79470a7
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   
       
    15 * System Includes
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include <assert.h>
       
    23 
       
    24 
       
    25 /*******************************************************************************
       
    26  *
       
    27  * Local Includes
       
    28  *
       
    29  ******************************************************************************/
       
    30 #include "strncpynt.h"
       
    31 #include "CHostExecuteStub.h"
       
    32 #include "CCHostexecute.h"
       
    33 #include "../../Core/UCCS_ServiceValues.h"
       
    34 #include "../../Core/UCCS_ErrorCodes.h"
       
    35 
       
    36 
       
    37 /*******************************************************************************
       
    38  *
       
    39  * Definitions
       
    40  *
       
    41  ******************************************************************************/
       
    42 
       
    43 /*******************************************************************************
       
    44  *
       
    45  * Macro Functions
       
    46  *
       
    47  ******************************************************************************/
       
    48 																		
       
    49 /*******************************************************************************
       
    50  *
       
    51  * Constructor / Destructor
       
    52  *
       
    53  ******************************************************************************/
       
    54 CHostExecuteStub::CHostExecuteStub()
       
    55 {
       
    56 	iClientHostExecute = new CCHostexecute();
       
    57 	assert( iClientHostExecute != NULL );
       
    58 }
       
    59 
       
    60 
       
    61 CHostExecuteStub::~CHostExecuteStub()
       
    62 {
       
    63 	delete iClientHostExecute;
       
    64 }
       
    65 
       
    66 
       
    67 /*******************************************************************************
       
    68  *
       
    69  * Startup / Shutdown
       
    70  *
       
    71  ******************************************************************************/
       
    72 int CHostExecuteStub::StartUccsService( char *aHostName,  int *aErrorCode, int *aUnused )
       
    73 {
       
    74 	int client_stub_error;
       
    75 	
       
    76 	// check params
       
    77 	assert( aHostName != NULL );
       
    78 	assert( aErrorCode != NULL );
       
    79 	*aErrorCode = 0;
       
    80 	
       
    81 	// connect to the remote service
       
    82 	client_stub_error = iClientHostExecute->Connect( aHostName );
       
    83 
       
    84 	// return the result
       
    85 	return client_stub_error;
       
    86 }
       
    87 
       
    88 
       
    89 int CHostExecuteStub::StopUccsService( int *aErrorCode, int *aUnused )
       
    90 {
       
    91 	int client_stub_error;
       
    92 
       
    93 	// check params
       
    94 	assert( aErrorCode != NULL );
       
    95 	*aErrorCode = 0;
       
    96 
       
    97 	// shutdown the stub -- force it to close
       
    98 	client_stub_error = iClientHostExecute->Disconnect();
       
    99 	
       
   100 	// done
       
   101 	return client_stub_error;
       
   102 }
       
   103 
       
   104 
       
   105 /*******************************************************************************
       
   106  *
       
   107  * IssueCommand
       
   108  *
       
   109  ******************************************************************************/
       
   110 CDataRecord* CHostExecuteStub::IssueCommand( CDataRecord* aRequest )
       
   111 {
       
   112 	int i, err, client_stub_error, method_id = -1;
       
   113 	char *tmp_string;
       
   114 	CDataRecord *request_reply;
       
   115 
       
   116 	TStartupInfo sarg_startup_info;
       
   117 	int rv_integer, sarg_integer;
       
   118 	TExecuteRequest sarg_execute_request;
       
   119 	TExecuteResult rv_execute_result;
       
   120 	TComponentList rv_component_list;
       
   121 
       
   122 	// check params
       
   123 	assert( aRequest != NULL );
       
   124 
       
   125 	// create a standard reply 
       
   126 	request_reply = CreateBaseReply( aRequest );
       
   127 	assert( request_reply != NULL );
       
   128 
       
   129 	// get and check the method_id
       
   130 	err = request_reply->GetFieldAsInt( "METHODID", &method_id );
       
   131 	if( method_id == -1 ) {
       
   132 		UpdateCompletionCode( request_reply, ERR_INVALID_METHOD );
       
   133 		return request_reply;
       
   134 	}
       
   135 
       
   136 	// now dispatch and call the appropriate method
       
   137 	switch( method_id ) {
       
   138 
       
   139 	// ss_startuprpcservice
       
   140 	case 1:
       
   141 
       
   142 		// extract the parameters
       
   143 		sarg_startup_info.iEmpty = 0;
       
   144 
       
   145 		// make the call and update the return value
       
   146 		client_stub_error = iClientHostExecute->ss_startuprpcservice( sarg_startup_info, &rv_integer );
       
   147 		UpdateCompletionCode( request_reply, client_stub_error );		
       
   148 		if( client_stub_error != ERR_NONE ) {
       
   149 			break;
       
   150 		}
       
   151 
       
   152 		// set any return information
       
   153 		request_reply->NewField( "RESULT", rv_integer );
       
   154 		break;
       
   155 
       
   156 	// sc_shutdownrpcservice
       
   157 	case 2: 
       
   158 		
       
   159 		// extract the parameters
       
   160 		GETINTEGERARGUMENT( "FORCE", &sarg_integer, 1, 1, aRequest, request_reply );
       
   161 		
       
   162 		// make the call and update the return value
       
   163 		client_stub_error = iClientHostExecute->sc_shutdownrpcservice( sarg_integer, &rv_integer );
       
   164 		UpdateCompletionCode( request_reply, client_stub_error );
       
   165 		if( client_stub_error != ERR_NONE ) {
       
   166 			break;
       
   167 		}
       
   168 
       
   169 		// set the return values
       
   170 		request_reply->NewField( "RESULT", rv_integer );
       
   171 		break;
       
   172 
       
   173 	// list_devices
       
   174 	case 30:
       
   175 
       
   176 		// make the call and update the return value
       
   177 		client_stub_error = iClientHostExecute->list_devices( &rv_component_list );
       
   178 		UpdateCompletionCode( request_reply, client_stub_error );
       
   179 		if( client_stub_error != ERR_NONE ) {
       
   180 			break;
       
   181 		}
       
   182 
       
   183 		// set the return values
       
   184 		request_reply->NewField( "PROCESSCOUNT", rv_component_list.TComponentList_len );
       
   185 		for( i = 0; i < rv_component_list.TComponentList_len; i++ ) {
       
   186 			AddIteratedIntegerFieldName( "PID", i, (rv_component_list.TComponentList_val)[i], request_reply );
       
   187 		}
       
   188 		break;		
       
   189 
       
   190 	// st_executecommand
       
   191 	case 3:
       
   192 
       
   193 		// extract the parameters
       
   194 		GETSTRINGARGUMENT( "COMMAND", &tmp_string, 1, 0, aRequest, request_reply );
       
   195 		STRNCPY_NULL_TERMINATE( sarg_execute_request.iCommandLine, tmp_string, MAXCOMMANDLINE );
       
   196 		GETINTEGERARGUMENT( "TIMEOUT", &(sarg_execute_request.iTimeout), 2, 0, aRequest, request_reply );
       
   197 		GETINTEGERARGUMENT( "GETSTDOUT", &(sarg_execute_request.iRecordStandardOut), 3, 1, aRequest, request_reply );
       
   198 		GETINTEGERARGUMENT( "GETSTDERR", &(sarg_execute_request.iRecordStandartError), 4, 1, aRequest, request_reply );
       
   199 
       
   200 		// make the call and update the return value
       
   201 		client_stub_error = iClientHostExecute->st_executecommand( sarg_execute_request, &rv_execute_result );
       
   202 		UpdateCompletionCode( request_reply, client_stub_error );
       
   203 		if( client_stub_error != ERR_NONE ) {
       
   204 			break;
       
   205 		}
       
   206 
       
   207 		// extract the parameters
       
   208 		request_reply->NewField( "RESULT", rv_execute_result.iResult );
       
   209 		request_reply->NewField( "RESULT_DETAIL", rv_execute_result.iErrorCode );
       
   210 		request_reply->NewField( "RESULT_SYSTEM_ERROR", rv_execute_result.iErrorDetail );
       
   211 		request_reply->NewField( "PROCESS_EXIT_REASON", rv_execute_result.iProcessExitReason );
       
   212 		request_reply->NewField( "PROCESS_EXIT_DETAIL", rv_execute_result.iProcessExitDetail );
       
   213 		request_reply->NewField( "STANDARD_OUTPUT_LENGTH", rv_execute_result.iStandardOut.TVarData_len );
       
   214 		request_reply->NewField( "STANDARD_OUTPUT", rv_execute_result.iStandardOut.TVarData_val );
       
   215 		request_reply->NewField( "STANDARD_ERROR_LENGTH", rv_execute_result.iStandardError.TVarData_len );
       
   216 		request_reply->NewField( "STANDARD_ERROR", rv_execute_result.iStandardError.TVarData_val );
       
   217 		break;
       
   218 
       
   219 	// Any other method id results in an invalid method id result
       
   220 	default:
       
   221 		UpdateCompletionCode( request_reply, ERR_INVALID_METHOD );
       
   222 		break;
       
   223 	}
       
   224 
       
   225 	// everything should be handled above 
       
   226 	return request_reply;
       
   227 }
       
   228 
       
   229 
       
   230 /*******************************************************************************
       
   231  *
       
   232  * GetStatus()
       
   233  *
       
   234  ******************************************************************************/
       
   235 int CHostExecuteStub::GetStatus()
       
   236 {
       
   237 	assert( !"GetStatus() - is not implemented" );
       
   238 	return -1;
       
   239 }
       
   240 
       
   241 
       
   242 /*******************************************************************************
       
   243  *
       
   244  * GetLastRPCError()
       
   245  *
       
   246  ******************************************************************************/
       
   247 char *CHostExecuteStub::GetLastRPCError( int *aIntError )
       
   248 {
       
   249 	return iClientHostExecute->GetLastRPCError( aIntError );
       
   250 }