testexecmgmt/ucc/Source/Uccs.v2/ServiceStubs/Mobster.v2/CMobsterStub.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  * Local Includes
       
    27  *
       
    28  ******************************************************************************/
       
    29 #include "../../Core/UCCS_ServiceValues.h"
       
    30 #include "../../Core/UCCS_ErrorCodes.h"
       
    31 #include "CMobsterStub.h"
       
    32 #include "CCMobster.h"
       
    33 
       
    34 
       
    35 /*******************************************************************************
       
    36  *
       
    37  * Definitions
       
    38  *
       
    39  ******************************************************************************/
       
    40 
       
    41 /*******************************************************************************
       
    42  *
       
    43  * Macro Functions
       
    44  *
       
    45  ******************************************************************************/
       
    46 																		
       
    47 /*******************************************************************************
       
    48  *
       
    49  * Constructor / Destructor
       
    50  *
       
    51  ******************************************************************************/
       
    52 CMobsterServiceStub::CMobsterServiceStub() 
       
    53 {
       
    54 	iClientMobster = new CCMobster();
       
    55 	assert( iClientMobster != NULL );
       
    56 }
       
    57 
       
    58 
       
    59 CMobsterServiceStub::~CMobsterServiceStub()
       
    60 {
       
    61 	delete iClientMobster;
       
    62 }
       
    63 
       
    64 
       
    65 /*******************************************************************************
       
    66  *
       
    67  * Startup / Shutdown
       
    68  *
       
    69  ******************************************************************************/
       
    70 int CMobsterServiceStub::StartUccsService( char *aHostName, int *aErrorInfo, int *aUnused )
       
    71 {
       
    72 	int client_stub_error;
       
    73 	*aErrorInfo = *aUnused = 0;
       
    74 
       
    75 	// connect the stub to the remote service
       
    76 	client_stub_error = iClientMobster->Connect( aHostName );
       
    77 
       
    78 	// return the result
       
    79 	return client_stub_error;
       
    80 }
       
    81 
       
    82 
       
    83 int CMobsterServiceStub::StopUccsService( int *aErrorInfo, int *aUnused )
       
    84 {
       
    85 	int client_stub_error;
       
    86 	*aErrorInfo = *aUnused = 0;
       
    87 
       
    88 	// disconnect the stub from the remote service
       
    89 	client_stub_error = iClientMobster->Disconnect();
       
    90 
       
    91 	// return the result
       
    92 	return client_stub_error;
       
    93 }
       
    94 
       
    95 
       
    96 /*******************************************************************************
       
    97  *
       
    98  * IssueCommand
       
    99  *
       
   100  ******************************************************************************/
       
   101 CDataRecord* CMobsterServiceStub::IssueCommand( CDataRecord* aRequest )
       
   102 {
       
   103 	int i, client_result, method_id = -1;
       
   104 	CDataRecord *request_reply;
       
   105 	
       
   106 	char *sarg_string;
       
   107 	int sarg_integer, rv_integer;
       
   108 	TDeviceDesc sarg_devicedesc, rv_devicedesc;
       
   109 	TChannelAddress sarg_channel_address;
       
   110 	TUUAddress sarg_uu_address;
       
   111 	TComponentList rv_component_list;
       
   112 	TVarData rv_vardata;
       
   113 
       
   114 	// check params
       
   115 	assert( aRequest != NULL );
       
   116 
       
   117 	// create a standard reply 
       
   118 	request_reply = CreateBaseReply( aRequest );
       
   119 	assert( request_reply != NULL );
       
   120 
       
   121 	// get and check the method_id
       
   122 	request_reply->GetFieldAsInt( "METHODID", &method_id );
       
   123 	if( method_id == -1 ) {
       
   124 		UpdateCompletionCode( request_reply, ERR_INVALID_METHOD );
       
   125 		return request_reply;
       
   126 	}
       
   127 
       
   128 	// now dispatch and call the appropriate method
       
   129 	switch( method_id ) {
       
   130 
       
   131 	// ss_startuprpcservice
       
   132 	case 1:
       
   133 
       
   134 		// extract the parameters
       
   135 		GETINTEGERARGUMENT( "PORT", &(sarg_channel_address.iPort), 1, 0, aRequest, request_reply );
       
   136 
       
   137 		// make the call and update the return value
       
   138 		client_result = iClientMobster->ss_startuprpcservice( sarg_channel_address, &rv_integer );
       
   139 		UpdateCompletionCode( request_reply, client_result );
       
   140 		if( client_result != ERR_NONE ) {
       
   141 			break;
       
   142 		}
       
   143 
       
   144 		// set the return values
       
   145 		request_reply->NewField( "RESULT", rv_integer );
       
   146 		break;
       
   147 
       
   148 	// sc_shutdownrpcservice
       
   149 	case 2:
       
   150 		
       
   151 		// extract the parameters
       
   152 		GETINTEGERARGUMENT( "FORCE", &sarg_integer, 1, 1, aRequest, request_reply );
       
   153 
       
   154 		// make the call and update the return value
       
   155 		client_result = iClientMobster->sc_shutdownrpcservice( sarg_integer, &rv_integer );
       
   156 		UpdateCompletionCode( request_reply, client_result );
       
   157 		if( client_result != ERR_NONE ) {
       
   158 			break;
       
   159 		}
       
   160 
       
   161 		// set the return values
       
   162 		request_reply->NewField( "RESULT", rv_integer );
       
   163 		break;
       
   164 
       
   165 	// list_devices
       
   166 	case 9:
       
   167 
       
   168 		// make the call and update the return value
       
   169 		client_result = iClientMobster->list_devices( &rv_component_list );
       
   170 		UpdateCompletionCode( request_reply, client_result );
       
   171 		if( client_result != ERR_NONE ) {
       
   172 			break;
       
   173 		}
       
   174 
       
   175 		// set the return values
       
   176 		request_reply->NewField( "DEVICECOUNT", rv_component_list.TComponentList_len );
       
   177 		for( i = 0; i < rv_component_list.TComponentList_len; i++ ) {
       
   178 			AddIteratedIntegerFieldName( "DEVICEID", i, (rv_component_list.TComponentList_val)[i], request_reply );
       
   179 		}
       
   180 		break;
       
   181 
       
   182 
       
   183 	// cstr_startdevice
       
   184 	case 3:
       
   185 
       
   186 		// extract the parameters
       
   187 		GETINTEGERARGUMENT( "DATALINKCONFIG",	(int*)&(sarg_devicedesc.iDatalinkConfig), 1, 0, aRequest, request_reply );
       
   188 		GETINTEGERARGUMENT( "FILTERCONFIG",		&(sarg_devicedesc.iFilterConfig),	2, 0, aRequest, request_reply );
       
   189 
       
   190 		// make the call and update the return value
       
   191 		client_result = iClientMobster->cstr_startdevice( sarg_devicedesc, &rv_integer );
       
   192 		UpdateCompletionCode( request_reply, client_result );
       
   193 		if( client_result != ERR_NONE ) {
       
   194 			break;
       
   195 		}
       
   196 
       
   197 		// set the return values
       
   198 		request_reply->NewField( "RESULT", rv_integer );
       
   199 		break;
       
   200 
       
   201 
       
   202 	// dstr_removedevice
       
   203 	case 7:
       
   204 
       
   205 		// extract the parameters
       
   206 		GETINTEGERARGUMENT( "DEVICEID", &sarg_integer, 1, 0, aRequest, request_reply );
       
   207 
       
   208 		// make the call and update the return value
       
   209 		client_result = iClientMobster->dstr_removedevice( sarg_integer, &rv_integer );
       
   210 		UpdateCompletionCode( request_reply, client_result );
       
   211 		if( client_result != ERR_NONE ) {
       
   212 			break;
       
   213 		}
       
   214 
       
   215 		// set the return values
       
   216 		request_reply->NewField( "RESULT", rv_integer );
       
   217 		break;
       
   218 
       
   219 
       
   220 	// GetDeviceInfo
       
   221 	case 4:
       
   222 
       
   223 		// extract the parameters
       
   224 		GETINTEGERARGUMENT( "DEVICEID", &sarg_integer, 1, 0, aRequest, request_reply );
       
   225 
       
   226 		// make the call and update the return value
       
   227 		client_result = iClientMobster->getdeviceinfo( sarg_integer, &rv_devicedesc );
       
   228 		UpdateCompletionCode( request_reply, client_result );
       
   229 		if( client_result != ERR_NONE ) {
       
   230 			break;
       
   231 		}
       
   232 
       
   233 		// set the return values
       
   234 		request_reply->NewField( "DATALINKCONFIG",	rv_devicedesc.iDatalinkConfig );
       
   235 		request_reply->NewField( "FILTERCONFIG",	rv_devicedesc.iFilterConfig );
       
   236 		request_reply->NewField( "MTID",			rv_devicedesc.iMTID );
       
   237 		request_reply->NewField( "TEID",			rv_devicedesc.iTEID );
       
   238 		request_reply->NewField( "AIR_INPORT",		rv_devicedesc.iLocalAirInterfacePort );
       
   239 		request_reply->NewField( "AIR_OUTADDR",		rv_devicedesc.iRemoteAirInterfaceAddress );
       
   240 		request_reply->NewField( "AIR_OUTPORT",		rv_devicedesc.iRemoteAirInterfacePort );
       
   241 		request_reply->NewField( "DEVICESTATUS",	rv_devicedesc.iDeviceStatus );
       
   242 		request_reply->NewField( "DEVICEEXITREASON",	rv_devicedesc.iDeviceExitReason );
       
   243 		request_reply->NewField( "DEVICEEXITSUBREASON",	rv_devicedesc.iDeviceExitSubReason );
       
   244 		request_reply->NewField( "DEVICEEXITCODE",		rv_devicedesc.iDeviceExitDetail );
       
   245 		break;
       
   246 
       
   247 
       
   248 	// getdevicelog
       
   249 	case 5:
       
   250 
       
   251 		// extract the parameters
       
   252 		GETINTEGERARGUMENT( "DEVICEID", &sarg_integer, 1, 0, aRequest, request_reply );
       
   253 
       
   254 		// make the call and update the return value
       
   255 		client_result = iClientMobster->getdevicelog( sarg_integer, &rv_vardata );
       
   256 		UpdateCompletionCode( request_reply, client_result );
       
   257 		if( client_result != ERR_NONE ) {
       
   258 			break;
       
   259 		}
       
   260 
       
   261 		// set the result (this copies)
       
   262  		request_reply->NewField( "DEVICELOG",			rv_vardata.TVarData_val );
       
   263 		request_reply->NewField( "DEVICELOGLENGTH",		rv_vardata.TVarData_len );
       
   264 
       
   265 		// free the memory (if any was allocated)
       
   266 		if( rv_vardata.TVarData_len > 0 ) {
       
   267 			XdrFree( &(rv_vardata.TVarData_val), (int*)&(rv_vardata.TVarData_len) );
       
   268 		}
       
   269 		break;
       
   270 
       
   271 
       
   272 	// stopdevice
       
   273 	case 6:
       
   274 
       
   275 		// extract the parameters
       
   276 		GETINTEGERARGUMENT( "DEVICEID", &sarg_integer, 1, 0, aRequest, request_reply );
       
   277 
       
   278 		// make the call and update the return value
       
   279 		client_result = iClientMobster->stopdevice( sarg_integer, &rv_integer );
       
   280 		UpdateCompletionCode( request_reply, client_result );
       
   281 		if( client_result != ERR_NONE ) {
       
   282 			break;
       
   283 		}
       
   284 
       
   285 		// set the result
       
   286 		request_reply->NewField( "RESULT", rv_integer );
       
   287 		break;
       
   288 
       
   289 
       
   290 	// setremoteuuaddress
       
   291 	case 10:
       
   292 
       
   293 		// extract the parameters
       
   294 		GETINTEGERARGUMENT( "DEVICEID",			&(sarg_uu_address.iDeviceID),		1, 0, aRequest, request_reply );
       
   295 		GETSTRINGARGUMENT(	"REMOTE_ADDRESS",	&(sarg_string),						2, 0, aRequest, request_reply );
       
   296 		GETINTEGERARGUMENT( "REMOTE_PORT",		&(sarg_integer),					3, 0, aRequest, request_reply );
       
   297 		sarg_uu_address.iRemoteAddress = AddressToInt(sarg_string);
       
   298 		sarg_uu_address.iRemotePort = htons(sarg_integer);
       
   299 
       
   300 		// make the call and update the return value
       
   301 		client_result = iClientMobster->setremoteuuaddress( sarg_uu_address, &rv_integer );
       
   302 		UpdateCompletionCode( request_reply, client_result );
       
   303 		if( client_result != ERR_NONE ) {
       
   304 			break;
       
   305 		}
       
   306 
       
   307 		// set the result
       
   308 		request_reply->NewField( "RESULT", rv_integer );
       
   309 		break;
       
   310 
       
   311 
       
   312 	// Any other method id results in an invalid method id result
       
   313 	default:
       
   314 		UpdateCompletionCode( request_reply, ERR_INVALID_METHOD );
       
   315 		break;
       
   316 	}
       
   317 
       
   318 	// everything should be handled above 
       
   319 	return request_reply;
       
   320 }
       
   321 
       
   322 
       
   323 /*******************************************************************************
       
   324  *
       
   325  * GetStatus()
       
   326  *
       
   327  ******************************************************************************/
       
   328 int CMobsterServiceStub::GetStatus()
       
   329 {
       
   330 	assert( !"GetStatus() - is not implemented" );
       
   331 	return -1;
       
   332 }
       
   333 
       
   334 
       
   335 /*******************************************************************************
       
   336  *
       
   337  * GetLastRPCError()
       
   338  *
       
   339  ******************************************************************************/
       
   340 char *CMobsterServiceStub::GetLastRPCError( int *aIntError )
       
   341 {
       
   342 	return iClientMobster->GetLastRPCError( aIntError );
       
   343 }