testexecmgmt/ucc/Source/HostExecuteSimple/CSvcHostexecute.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 * This file was autogenerated by rpcgen, but should be modified by the developer.
       
    16 * Make sure you don't use the -component_mod flag in future or this file will be overwritten.
       
    17 * Tue Oct 28 10:15:13 2003
       
    18 * System Includes
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #include <stdio.h>
       
    26 #include <errno.h>
       
    27 
       
    28 
       
    29 /****************************************************************************************
       
    30  * 
       
    31  * Local Includes
       
    32  * 
       
    33  ***************************************************************************************/
       
    34 #include "CSvcHostexecute.h"
       
    35 #include "hostexecute.h"
       
    36 #include "../ProcessLibrary/proclib.h"
       
    37 #include "../include/standard_service_manager.h"
       
    38 #include "../include/strncpynt.h"
       
    39 
       
    40 
       
    41 /****************************************************************************************
       
    42  * 
       
    43  * File-scope variables
       
    44  * 
       
    45  ***************************************************************************************/
       
    46 static CComponentManager<CSHostexecute> *iComponentManager;
       
    47 
       
    48 
       
    49 /****************************************************************************************
       
    50  * 
       
    51  * Implementation
       
    52  * 
       
    53  ***************************************************************************************/
       
    54 
       
    55 
       
    56 /****************************************************************************************
       
    57  * 
       
    58  * PUBLIC: GetInstanceKeyFromArgs
       
    59  * 
       
    60  ***************************************************************************************/
       
    61 int CSvcHostexecute::GetInstanceKeyFromArgs( int aMethod, void *aArgs )
       
    62 {
       
    63 	// this method should never be called
       
    64 	assert( !"NOT IMPLEMENTED" );
       
    65 	return ERR_NONE;
       
    66 }
       
    67 
       
    68 
       
    69 /****************************************************************************************
       
    70  * 
       
    71  * PUBLIC: SetError
       
    72  * 
       
    73  ***************************************************************************************/
       
    74 int CSvcHostexecute::SetError( int aMethod, void *aArgs, int aError )
       
    75 {
       
    76 	int rv = ERR_NONE;
       
    77 	TExecuteResult *rv_execute_result;
       
    78 	TComponentList *rv_component_list;
       
    79 
       
    80 	switch( aMethod ) {
       
    81 
       
    82 	// TComponentList
       
    83 	case LIST_DEVICES:
       
    84 		SET_LIST_ERROR_CODE( TComponentList, rv_component_list );
       
    85 		break;
       
    86 
       
    87 	// TExecuteResult
       
    88 	case ST_EXECUTECOMMAND:
       
    89 		rv_execute_result = (TExecuteResult*)aArgs;
       
    90 		if( (rv_execute_result->iStandardOut).TVarData_val != NULL ) {
       
    91 			free( (rv_execute_result->iStandardOut).TVarData_val );
       
    92 			(rv_execute_result->iStandardOut).TVarData_val = NULL;
       
    93 			(rv_execute_result->iStandardOut).TVarData_len = 0;
       
    94 		}
       
    95 		if( (rv_execute_result->iStandardError).TVarData_val != NULL ) {
       
    96 			free( (rv_execute_result->iStandardError).TVarData_val );
       
    97 			(rv_execute_result->iStandardError).TVarData_val = NULL;
       
    98 			(rv_execute_result->iStandardError).TVarData_len = 0;
       
    99 		}
       
   100 		memset( rv_execute_result, 0, sizeof(TExecuteResult) );
       
   101 		rv_execute_result->iResult = aError;
       
   102 		break;
       
   103 
       
   104 	// Error
       
   105 	default:
       
   106 		rv = ERR_INVALID_METHOD;
       
   107 		break;
       
   108 	}
       
   109 	return rv;
       
   110 }
       
   111 
       
   112 
       
   113 /****************************************************************************************
       
   114  * 
       
   115  * PUBLIC: GetError
       
   116  * 
       
   117  ***************************************************************************************/
       
   118 int CSvcHostexecute::GetError( int aMethod, void *aArgs )
       
   119 {
       
   120 	// this method should never be called
       
   121 	assert( !"NOT IMPLEMENTED" );
       
   122 	return ERR_NONE;
       
   123 }
       
   124 
       
   125 
       
   126 /****************************************************************************************
       
   127  * 
       
   128  * PUBLIC: StartRPCService
       
   129  * 
       
   130  ***************************************************************************************/
       
   131 int CSvcHostexecute::StartRPCService( CComponentManager<CSHostexecute> *aComponentManager, TStartupInfo *aArg )
       
   132 {
       
   133 	assert( iComponentManager == NULL );
       
   134 	iComponentManager = aComponentManager;
       
   135 	return ERR_NONE;
       
   136 }
       
   137 
       
   138 
       
   139 /****************************************************************************************
       
   140  * 
       
   141  * PUBLIC: StopRPCService
       
   142  * 
       
   143  ***************************************************************************************/
       
   144 int CSvcHostexecute::StopRPCService()
       
   145 {
       
   146 	iComponentManager = NULL;
       
   147 	return ERR_NONE;
       
   148 }
       
   149 
       
   150 
       
   151 /****************************************************************************************
       
   152  * 
       
   153  * PUBLIC: st_executecommand
       
   154  * 
       
   155  ***************************************************************************************/
       
   156 TExecuteResult CSvcHostexecute::st_executecommand( TExecuteRequest aArgs )
       
   157 {
       
   158 	TExecuteResult rv;
       
   159 	int errcode;
       
   160 	CAProcess process;
       
   161 	TCAProcessError perr;
       
   162 	TProcessExitReason preason;
       
   163 	string *standardout = NULL, *standarderror = NULL;
       
   164 
       
   165 	// init the rv
       
   166 	memset( &rv, 0, sizeof(rv) );
       
   167 	rv.iResult = ERR_NONE;
       
   168 
       
   169 	// get the buffers
       
   170 	if( aArgs.iRecordStandardOut != 0 ) {
       
   171 		standardout = new string();
       
   172 		assert( standardout != NULL );
       
   173 	} 
       
   174 	if( aArgs.iRecordStandartError != 0 ) {
       
   175 		standarderror = new string();
       
   176 		assert( standarderror != NULL );
       
   177 	}
       
   178 
       
   179 	// execute the process - return any errors
       
   180 	perr = process.Execute( aArgs.iCommandLine, &errcode, aArgs.iTimeout, standardout, standarderror );
       
   181 	if( perr != CAE_NONE ) {
       
   182 		rv.iResult = ERR_EXECUTE_PROCESS_ERROR;
       
   183 		rv.iErrorCode = (int)perr;
       
   184 		rv.iErrorDetail = errno;
       
   185 	}
       
   186 
       
   187 	// save any output
       
   188 	if( (standardout != NULL) && (standardout->length() > 0) ) {
       
   189 		rv.iStandardOut.TVarData_val = (char*)malloc( standardout->length() + 1 );
       
   190 		rv.iStandardOut.TVarData_len = standardout->length() + 1;
       
   191 		STRNCPY_NULL_TERMINATE( rv.iStandardOut.TVarData_val, standardout->c_str(), standardout->length() + 1 );
       
   192 	}
       
   193 	if( (standarderror != NULL) && (standarderror->length() > 0) ) {
       
   194 		rv.iStandardError.TVarData_val = (char*)malloc( standarderror->length() + 1 );
       
   195 		rv.iStandardError.TVarData_len = standarderror->length() + 1;
       
   196 		STRNCPY_NULL_TERMINATE( rv.iStandardError.TVarData_val, standarderror->c_str(), standarderror->length() + 1 );
       
   197 	}
       
   198 
       
   199 	// if there was an error then return now
       
   200 	if( rv.iResult != ERR_NONE ) {
       
   201 		return rv;
       
   202 	}
       
   203 
       
   204 	// save the status, exitreason, etc
       
   205 	perr = process.GetExitReason( &preason );
       
   206 	assert( perr == CAE_NONE );
       
   207 	rv.iProcessExitReason = (int)preason;
       
   208 	perr = process.GetExitCode( &errcode );
       
   209 	assert( perr == CAE_NONE );
       
   210 	rv.iProcessExitDetail = errcode;
       
   211 	return rv;
       
   212 }