testexecmgmt/ucc/Source/Uccs.v2/ServiceStubs/Mobster.v2/CCMobster.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 <stdio.h>
       
    23 #include <assert.h>
       
    24 #include <rpc/types.h>
       
    25 
       
    26 
       
    27 /****************************************************************************************
       
    28  * 
       
    29  * Local Includes
       
    30  * 
       
    31  ***************************************************************************************/
       
    32 #include "CCMobster.h"
       
    33 
       
    34 
       
    35 /****************************************************************************************
       
    36  * 
       
    37  * Implementation
       
    38  * 
       
    39  ***************************************************************************************/
       
    40 CCMobster::CCMobster()
       
    41 {
       
    42 	cl = NULL;
       
    43 	iLastRPCError.re_status = RPC_SUCCESS;
       
    44 }
       
    45 
       
    46 CCMobster::~CCMobster()
       
    47 {
       
    48 	assert( cl == NULL );
       
    49 }
       
    50 
       
    51 char *CCMobster::GetLastRPCError( int *aIntErr )
       
    52 {
       
    53 	struct rpc_err rpcerr;
       
    54 
       
    55 	// check that the handle is valid
       
    56 	if( cl == NULL ) {
       
    57 		return NULL;
       
    58 	}
       
    59 
       
    60 	// pass the aIntErr
       
    61 	if( aIntErr != NULL ) {
       
    62 		clnt_geterr( cl, &rpcerr );
       
    63 		*aIntErr = rpcerr.re_status;
       
    64 	}
       
    65 
       
    66 	// return the errorstring
       
    67 	return clnt_sperror( cl, NULL );
       
    68 }
       
    69 
       
    70 int CCMobster::Connect( string aRemoteHost )
       
    71 {
       
    72 	// check that we are not already connected
       
    73 	if( cl != NULL ) {
       
    74 		return ERR_STUB_ALREADY_CONNECTED;
       
    75 	}
       
    76 
       
    77 	// start the rpc library
       
    78 	rpc_nt_init();
       
    79 
       
    80 	// connect to the service
       
    81 	cl = clnt_create( aRemoteHost.c_str(), MOBSTER, MOBSTER_VERSION, "tcp" );
       
    82 	if( cl == NULL ) {
       
    83 		rpc_nt_exit();
       
    84 		return ERR_FAILED_TO_CONNECT;
       
    85 	}
       
    86 
       
    87 	// done
       
    88 	return ERR_NONE;
       
    89 }
       
    90 
       
    91 int CCMobster::Disconnect( )
       
    92 {
       
    93 	// check that we are connected
       
    94 	if( cl == NULL ) {
       
    95 		return ERR_STUB_NOT_CONNECTED;
       
    96 	}
       
    97 
       
    98 	// cleanup the client handle
       
    99 	clnt_destroy( cl );
       
   100 	cl = NULL;
       
   101 	rpc_nt_exit();
       
   102 
       
   103 	// done
       
   104 	return ERR_NONE;
       
   105 }
       
   106 
       
   107 
       
   108 /****************************************************************************************
       
   109  * 
       
   110  * PUBLIC FUNCTION: ss_startuprpcservice
       
   111  * 
       
   112  ***************************************************************************************/
       
   113 int CCMobster::ss_startuprpcservice( struct TChannelAddress aArgs, int *rv )
       
   114 {
       
   115 	struct rpc_err rerr;
       
   116 
       
   117 	// check the rv pointer
       
   118 	if( rv == NULL ) {
       
   119 		return ERR_INVALID_RV_POINTER;
       
   120 	}
       
   121 
       
   122 	// check that we have a connection
       
   123 	if( cl == NULL ) {
       
   124 		return ERR_STUB_NOT_CONNECTED;
       
   125 	}
       
   126 
       
   127 	// do the call
       
   128 	*rv = *ss_startuprpcservice_1( &aArgs, cl );
       
   129 
       
   130 	// check for rpc errors and return the result
       
   131 	clnt_geterr( cl, &rerr );
       
   132 	if( rerr.re_status != RPC_SUCCESS ) {
       
   133 		iLastRPCError = rerr;
       
   134 		return ERR_RPC_ERROR;
       
   135 	}
       
   136 	return ERR_NONE;
       
   137 }
       
   138 
       
   139 
       
   140 /****************************************************************************************
       
   141  * 
       
   142  * PUBLIC FUNCTION: sc_shutdownrpcservice
       
   143  * 
       
   144  ***************************************************************************************/
       
   145 int CCMobster::sc_shutdownrpcservice( int aArgs, int *rv )
       
   146 {
       
   147 	struct rpc_err rerr;
       
   148 
       
   149 	// check the rv pointer
       
   150 	if( rv == NULL ) {
       
   151 		return ERR_INVALID_RV_POINTER;
       
   152 	}
       
   153 
       
   154 	// check that we have a connection
       
   155 	if( cl == NULL ) {
       
   156 		return ERR_STUB_NOT_CONNECTED;
       
   157 	}
       
   158 
       
   159 	// do the call
       
   160 	*rv = *sc_shutdownrpcservice_1( &aArgs, cl );
       
   161 
       
   162 	// check for rpc errors and return the result
       
   163 	clnt_geterr( cl, &rerr );
       
   164 	if( rerr.re_status != RPC_SUCCESS ) {
       
   165 		iLastRPCError = rerr;
       
   166 		return ERR_RPC_ERROR;
       
   167 	}
       
   168 	return ERR_NONE;
       
   169 }
       
   170 
       
   171 
       
   172 /****************************************************************************************
       
   173  * 
       
   174  * PUBLIC FUNCTION: list_devices
       
   175  * 
       
   176  ***************************************************************************************/
       
   177 int CCMobster::list_devices( TComponentList *rv )
       
   178 {
       
   179 	struct rpc_err rerr;
       
   180 	int aArgs = 0;
       
   181 
       
   182 	// check the rv pointer
       
   183 	if( rv == NULL ) {
       
   184 		return ERR_INVALID_RV_POINTER;
       
   185 	}
       
   186 
       
   187 	// check that we have a connection
       
   188 	if( cl == NULL ) {
       
   189 		return ERR_STUB_NOT_CONNECTED;
       
   190 	}
       
   191 
       
   192 	// do the call
       
   193 	*rv = *list_devices_1( &aArgs, cl );
       
   194 
       
   195 	// check for rpc errors and return the result
       
   196 	clnt_geterr( cl, &rerr );
       
   197 	if( rerr.re_status != RPC_SUCCESS ) {
       
   198 		iLastRPCError = rerr;
       
   199 		return ERR_RPC_ERROR;
       
   200 	}
       
   201 	return ERR_NONE;
       
   202 }
       
   203 
       
   204 
       
   205 /****************************************************************************************
       
   206  * 
       
   207  * PUBLIC FUNCTION: cstr_startdevice
       
   208  * 
       
   209  ***************************************************************************************/
       
   210 int CCMobster::cstr_startdevice( TDeviceDesc aArgs, int *rv )
       
   211 {
       
   212 	struct rpc_err rerr;
       
   213 
       
   214 	// check the rv pointer
       
   215 	if( rv == NULL ) {
       
   216 		return ERR_INVALID_RV_POINTER;
       
   217 	}
       
   218 
       
   219 	// check that we have a connection
       
   220 	if( cl == NULL ) {
       
   221 		return ERR_STUB_NOT_CONNECTED;
       
   222 	}
       
   223 
       
   224 	// do the call
       
   225 	*rv = *cstr_startdevice_1( &aArgs, cl );
       
   226 
       
   227 	// check for rpc errors and return the result
       
   228 	clnt_geterr( cl, &rerr );
       
   229 	if( rerr.re_status != RPC_SUCCESS ) {
       
   230 		iLastRPCError = rerr;
       
   231 		return ERR_RPC_ERROR;
       
   232 	}
       
   233 	return ERR_NONE;
       
   234 }
       
   235 
       
   236 
       
   237 /****************************************************************************************
       
   238  * 
       
   239  * PUBLIC FUNCTION: dstr_removedevice
       
   240  * 
       
   241  ***************************************************************************************/
       
   242 int CCMobster::dstr_removedevice( int aArgs, int *rv )
       
   243 {
       
   244 	struct rpc_err rerr;
       
   245 
       
   246 	// check the rv pointer
       
   247 	if( rv == NULL ) {
       
   248 		return ERR_INVALID_RV_POINTER;
       
   249 	}
       
   250 
       
   251 	// check that we have a connection
       
   252 	if( cl == NULL ) {
       
   253 		return ERR_STUB_NOT_CONNECTED;
       
   254 	}
       
   255 
       
   256 	// do the call
       
   257 	*rv = *dstr_removedevice_1( &aArgs, cl );
       
   258 
       
   259 	// check for rpc errors and return the result
       
   260 	clnt_geterr( cl, &rerr );
       
   261 	if( rerr.re_status != RPC_SUCCESS ) {
       
   262 		iLastRPCError = rerr;
       
   263 		return ERR_RPC_ERROR;
       
   264 	}
       
   265 	return ERR_NONE;
       
   266 }
       
   267 
       
   268 
       
   269 /****************************************************************************************
       
   270  * 
       
   271  * PUBLIC FUNCTION: getdeviceinfo
       
   272  * 
       
   273  ***************************************************************************************/
       
   274 int CCMobster::getdeviceinfo( int aArgs, TDeviceDesc *rv )
       
   275 {
       
   276 	struct rpc_err rerr;
       
   277 
       
   278 	// check the rv pointer
       
   279 	if( rv == NULL ) {
       
   280 		return ERR_INVALID_RV_POINTER;
       
   281 	}
       
   282 
       
   283 	// check that we have a connection
       
   284 	if( cl == NULL ) {
       
   285 		return ERR_STUB_NOT_CONNECTED;
       
   286 	}
       
   287 
       
   288 	// do the call
       
   289 	*rv = *getdeviceinfo_1( &aArgs, cl );
       
   290 
       
   291 	// check for rpc errors and return the result
       
   292 	clnt_geterr( cl, &rerr );
       
   293 	if( rerr.re_status != RPC_SUCCESS ) {
       
   294 		iLastRPCError = rerr;
       
   295 		return ERR_RPC_ERROR;
       
   296 	}
       
   297 	return ERR_NONE;
       
   298 }
       
   299 
       
   300 
       
   301 /****************************************************************************************
       
   302  * 
       
   303  * PUBLIC FUNCTION: getdevicelog
       
   304  * 
       
   305  ***************************************************************************************/
       
   306 int CCMobster::getdevicelog( int aArgs, TVarData *rv )
       
   307 {
       
   308 	struct rpc_err rerr;
       
   309 
       
   310 	// check the rv pointer
       
   311 	if( rv == NULL ) {
       
   312 		return ERR_INVALID_RV_POINTER;
       
   313 	}
       
   314 
       
   315 	// check that we have a connection
       
   316 	if( cl == NULL ) {
       
   317 		return ERR_STUB_NOT_CONNECTED;
       
   318 	}
       
   319 
       
   320 	// do the call
       
   321 	*rv = *getdevicelog_1( &aArgs, cl );
       
   322 
       
   323 	// check for rpc errors and return the result
       
   324 	clnt_geterr( cl, &rerr );
       
   325 	if( rerr.re_status != RPC_SUCCESS ) {
       
   326 		iLastRPCError = rerr;
       
   327 		return ERR_RPC_ERROR;
       
   328 	}
       
   329 	return ERR_NONE;
       
   330 }
       
   331 
       
   332 
       
   333 /****************************************************************************************
       
   334  * 
       
   335  * PUBLIC FUNCTION: stopdevice
       
   336  * 
       
   337  ***************************************************************************************/
       
   338 int CCMobster::stopdevice( int aArgs, int *rv )
       
   339 {
       
   340 	struct rpc_err rerr;
       
   341 
       
   342 	// check the rv pointer
       
   343 	if( rv == NULL ) {
       
   344 		return ERR_INVALID_RV_POINTER;
       
   345 	}
       
   346 
       
   347 	// check that we have a connection
       
   348 	if( cl == NULL ) {
       
   349 		return ERR_STUB_NOT_CONNECTED;
       
   350 	}
       
   351 
       
   352 	// do the call
       
   353 	*rv = *stopdevice_1( &aArgs, cl );
       
   354 
       
   355 	// check for rpc errors and return the result
       
   356 	clnt_geterr( cl, &rerr );
       
   357 	if( rerr.re_status != RPC_SUCCESS ) {
       
   358 		iLastRPCError = rerr;
       
   359 		return ERR_RPC_ERROR;
       
   360 	}
       
   361 	return ERR_NONE;
       
   362 }
       
   363 
       
   364 
       
   365 /****************************************************************************************
       
   366  * 
       
   367  * PUBLIC FUNCTION: setremoteuuaddress
       
   368  * 
       
   369  ***************************************************************************************/
       
   370 int CCMobster::setremoteuuaddress( struct TUUAddress aArgs, int *rv )
       
   371 {
       
   372 	struct rpc_err rerr;
       
   373 
       
   374 	// check the rv pointer
       
   375 	if( rv == NULL ) {
       
   376 		return ERR_INVALID_RV_POINTER;
       
   377 	}
       
   378 
       
   379 	// check that we have a connection
       
   380 	if( cl == NULL ) {
       
   381 		return ERR_STUB_NOT_CONNECTED;
       
   382 	}
       
   383 
       
   384 	// do the call
       
   385 	*rv = *setremoteuuaddress_1( &aArgs, cl );
       
   386 
       
   387 	// check for rpc errors and return the result
       
   388 	clnt_geterr( cl, &rerr );
       
   389 	if( rerr.re_status != RPC_SUCCESS ) {
       
   390 		iLastRPCError = rerr;
       
   391 		return ERR_RPC_ERROR;
       
   392 	}
       
   393 	return ERR_NONE;
       
   394 }