testexecmgmt/ucc/Source/HostExecuteSimple/hostexecute_svc_stub_impl.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 IS AUTOGENERATED. Do not modify the contents of this file directly
       
    16 * as changes will be lost
       
    17 * Tue Oct 28 11:38:50 2003
       
    18 * System Includes
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #include <assert.h>
       
    26 
       
    27 
       
    28 /****************************************************************************************
       
    29  * 
       
    30  * Local Includes
       
    31  * 
       
    32  ***************************************************************************************/
       
    33 #include "CSvcHostexecute.h"
       
    34 #include "CSHostexecute.h"
       
    35 #include "CComponentManager.h"
       
    36 
       
    37 
       
    38 /****************************************************************************************
       
    39  * 
       
    40  * Static Variables
       
    41  * 
       
    42  ***************************************************************************************/
       
    43 static CComponentManager<CSHostexecute> *iComponentManager;
       
    44 
       
    45 
       
    46 /****************************************************************************************
       
    47  * 
       
    48  * PUBLIC FUNCTION: ss_startuprpcservice
       
    49  * 
       
    50  ***************************************************************************************/
       
    51 int *ss_startuprpcservice_3( TStartupInfo *aArgs, CLIENT *aDutout )
       
    52 {
       
    53 	static int rv;
       
    54 
       
    55 	// if the service is already started then return an error
       
    56 	if( iComponentManager != NULL ) {
       
    57 		rv = ERR_SERVICE_ALREADY_STARTED;
       
    58 		return &rv;
       
    59 	}
       
    60 
       
    61 	// create the component manager
       
    62 	iComponentManager = new CComponentManager<CSHostexecute>( INFO_MAXIMUM_OBJECTS );
       
    63 	if( iComponentManager == NULL ) {
       
    64 		rv = ERR_FAILED_TO_CREATE_COMPONENT_MANAGER;
       
    65 		return &rv;
       
    66 	}
       
    67 
       
    68 	// call the custom service manager
       
    69 	rv = CSvcHostexecute::StartRPCService( iComponentManager, aArgs );
       
    70 	if( rv != ERR_NONE ) {
       
    71 		delete iComponentManager;
       
    72 		iComponentManager = NULL;
       
    73 		return &rv;
       
    74 	}
       
    75 
       
    76 	// success
       
    77 	rv = ERR_NONE;
       
    78 	return &rv;
       
    79 }
       
    80 
       
    81 
       
    82 /****************************************************************************************
       
    83  * 
       
    84  * PUBLIC FUNCTION: sc_shutdownrpcservice
       
    85  * 
       
    86  ***************************************************************************************/
       
    87 int *sc_shutdownrpcservice_3( int *aArgs, CLIENT *aDutout )
       
    88 {
       
    89 	static int rv;
       
    90 	int instance_count;
       
    91 	int err;
       
    92 
       
    93 	// check that the service is started
       
    94 	if( iComponentManager == NULL ) {
       
    95 		rv = ERR_SERVICE_NOT_RUNNING;
       
    96 		return &rv;
       
    97 	}
       
    98 
       
    99 	// if there are active sessions and the force flag isn't set then return an error
       
   100 	instance_count = iComponentManager->GetInstanceCount();
       
   101 	if( (instance_count > 0) && (*aArgs == 0) ) {
       
   102 		rv = ERR_ACTIVE_USER_SESSIONS;
       
   103 		return &rv;
       
   104 	};
       
   105 
       
   106 	// if the force flag IS set then reset all active connections
       
   107 	instance_count = iComponentManager->GetInstanceCount();
       
   108 	if( instance_count > 0 ) {
       
   109 		err = iComponentManager->DeleteAllInstances();
       
   110 		if( err != 0 ) {
       
   111 			rv = ERR_FAILED_TO_REMOVE_ACTIVE_SESSIONS;
       
   112 			return &rv;
       
   113 		}
       
   114 	}
       
   115 
       
   116 	// call the custom service manager
       
   117 	rv = CSvcHostexecute::StopRPCService();
       
   118 	if( rv != ERR_NONE ) {
       
   119 		return &rv;
       
   120 	}
       
   121 
       
   122 	// delete the component manager
       
   123 	delete iComponentManager;
       
   124 	iComponentManager = NULL;
       
   125 
       
   126 	// success
       
   127 	rv = ERR_NONE;
       
   128 	return &rv;
       
   129 }
       
   130 
       
   131 
       
   132 /****************************************************************************************
       
   133  * 
       
   134  * PUBLIC FUNCTION: list_devices
       
   135  * 
       
   136  ***************************************************************************************/
       
   137 TComponentList *list_devices_3( void *aArgs, CLIENT *aDutout )
       
   138 {
       
   139 	static TComponentList rv;
       
   140 	int i, valid_count, component_instance_count;
       
   141 
       
   142 	//free any allocated memory
       
   143 	if( rv.TComponentList_val != NULL ) {
       
   144 		free( rv.TComponentList_val );
       
   145 		rv.TComponentList_val = NULL;
       
   146 		rv.TComponentList_len = 0;
       
   147 	}
       
   148 
       
   149 	// check that the service is started
       
   150 	if( iComponentManager == NULL ) {
       
   151 		CSvcHostexecute::SetError( LIST_DEVICES, (void*)&rv, ERR_SERVICE_NOT_RUNNING );
       
   152 		return &rv;
       
   153 	}
       
   154 
       
   155 	// set the return value to generic error
       
   156 	CSvcHostexecute::SetError( LIST_DEVICES, (void*)&rv, ERR_FAILED_TO_RETRIEVE_KEY );
       
   157 
       
   158 	// get the number of active component instances
       
   159 	component_instance_count = iComponentManager->GetInstanceCount();
       
   160 
       
   161 	// if there are one or more instances then allocate the memory
       
   162 	if( component_instance_count > 0 ) {
       
   163 		rv.TComponentList_val = (int*)malloc( sizeof(int) * component_instance_count );
       
   164 		assert( rv.TComponentList_val != NULL );
       
   165 		rv.TComponentList_len = component_instance_count;
       
   166 	}
       
   167 
       
   168 	// store all the currently active IDs in the list
       
   169 	for( i = 0, valid_count = 0; i < INFO_MAXIMUM_OBJECTS; i++ ) {
       
   170 		if( iComponentManager->IsValidKey(i) != 0 ) {
       
   171 			assert( valid_count < component_instance_count );
       
   172 			(rv.TComponentList_val)[valid_count++] = i;
       
   173 		}
       
   174 	}
       
   175 
       
   176 	// ok return everything
       
   177 	return &rv;
       
   178 }
       
   179 
       
   180 
       
   181 /****************************************************************************************
       
   182  * 
       
   183  * PUBLIC FUNCTION: st_executecommand
       
   184  * 
       
   185  ***************************************************************************************/
       
   186 TExecuteResult *st_executecommand_3( TExecuteRequest *aArgs, CLIENT *aDutout )
       
   187 {
       
   188 	static TExecuteResult rv;
       
   189 
       
   190 	// check that the service is started
       
   191 	if( iComponentManager == NULL ) {
       
   192 		CSvcHostexecute::SetError( ST_EXECUTECOMMAND, (void*)&rv, ERR_SERVICE_NOT_RUNNING );
       
   193 		return &rv;
       
   194 	}
       
   195 
       
   196 	// call the corresponding method on the instance
       
   197 	rv = CSvcHostexecute::st_executecommand( *aArgs );
       
   198 	return &rv;
       
   199 }