testexecmgmt/ucc/Source/Uccs.v2/ServiceStubs/HomeAgent/CCHacontroller.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 "CCHacontroller.h"
       
    33 
       
    34 
       
    35 /****************************************************************************************
       
    36  * 
       
    37  * Implementation
       
    38  * 
       
    39  ***************************************************************************************/
       
    40 CCHacontroller::CCHacontroller()
       
    41 {
       
    42 	cl = NULL;
       
    43 	iLastRPCError.re_status = RPC_SUCCESS;
       
    44 }
       
    45 
       
    46 CCHacontroller::~CCHacontroller()
       
    47 {
       
    48 	assert( cl == NULL );
       
    49 }
       
    50 
       
    51 char *CCHacontroller::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 CCHacontroller::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(), HACONTROLLER, HACONTROLLER_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 CCHacontroller::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 CCHacontroller::ss_startuprpcservice( TStartupInfo 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_8( &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 CCHacontroller::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_8( &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 CCHacontroller::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_8( &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_createagent
       
   208  * 
       
   209  ***************************************************************************************/
       
   210 int CCHacontroller::cstr_createagent( TResult *rv )
       
   211 {
       
   212 	struct rpc_err rerr;
       
   213 	int aArgs = 0;
       
   214 
       
   215 	// check the rv pointer
       
   216 	if( rv == NULL ) {
       
   217 		return ERR_INVALID_RV_POINTER;
       
   218 	}
       
   219 
       
   220 	// check that we have a connection
       
   221 	if( cl == NULL ) {
       
   222 		return ERR_STUB_NOT_CONNECTED;
       
   223 	}
       
   224 
       
   225 	// do the call
       
   226 	*rv = *cstr_createagent_8( &aArgs, cl );
       
   227 
       
   228 	// check for rpc errors and return the result
       
   229 	clnt_geterr( cl, &rerr );
       
   230 	if( rerr.re_status != RPC_SUCCESS ) {
       
   231 		iLastRPCError = rerr;
       
   232 		return ERR_RPC_ERROR;
       
   233 	}
       
   234 	return ERR_NONE;
       
   235 }
       
   236 
       
   237 
       
   238 /****************************************************************************************
       
   239  * 
       
   240  * PUBLIC FUNCTION: dstr_removeagent
       
   241  * 
       
   242  ***************************************************************************************/
       
   243 int CCHacontroller::dstr_removeagent( int aArgs, TResult *rv )
       
   244 {
       
   245 	struct rpc_err rerr;
       
   246 
       
   247 	// check the rv pointer
       
   248 	if( rv == NULL ) {
       
   249 		return ERR_INVALID_RV_POINTER;
       
   250 	}
       
   251 
       
   252 	// check that we have a connection
       
   253 	if( cl == NULL ) {
       
   254 		return ERR_STUB_NOT_CONNECTED;
       
   255 	}
       
   256 
       
   257 	// do the call
       
   258 	*rv = *dstr_removeagent_8( &aArgs, cl );
       
   259 
       
   260 	// check for rpc errors and return the result
       
   261 	clnt_geterr( cl, &rerr );
       
   262 	if( rerr.re_status != RPC_SUCCESS ) {
       
   263 		iLastRPCError = rerr;
       
   264 		return ERR_RPC_ERROR;
       
   265 	}
       
   266 	return ERR_NONE;
       
   267 }
       
   268 
       
   269 
       
   270 /****************************************************************************************
       
   271  * 
       
   272  * PUBLIC FUNCTION: startmobileagent
       
   273  * 
       
   274  ***************************************************************************************/
       
   275 int CCHacontroller::startmobileagent( int aArgs, TResult *rv )
       
   276 {
       
   277 	struct rpc_err rerr;
       
   278 
       
   279 	// check the rv pointer
       
   280 	if( rv == NULL ) {
       
   281 		return ERR_INVALID_RV_POINTER;
       
   282 	}
       
   283 
       
   284 	// check that we have a connection
       
   285 	if( cl == NULL ) {
       
   286 		return ERR_STUB_NOT_CONNECTED;
       
   287 	}
       
   288 
       
   289 	// do the call
       
   290 	*rv = *startmobileagent_8( &aArgs, cl );
       
   291 
       
   292 	// check for rpc errors and return the result
       
   293 	clnt_geterr( cl, &rerr );
       
   294 	if( rerr.re_status != RPC_SUCCESS ) {
       
   295 		iLastRPCError = rerr;
       
   296 		return ERR_RPC_ERROR;
       
   297 	}
       
   298 	return ERR_NONE;
       
   299 }
       
   300 
       
   301 
       
   302 /****************************************************************************************
       
   303  * 
       
   304  * PUBLIC FUNCTION: stopmobileagent
       
   305  * 
       
   306  ***************************************************************************************/
       
   307 int CCHacontroller::stopmobileagent( int aArgs, TResult *rv )
       
   308 {
       
   309 	struct rpc_err rerr;
       
   310 
       
   311 	// check the rv pointer
       
   312 	if( rv == NULL ) {
       
   313 		return ERR_INVALID_RV_POINTER;
       
   314 	}
       
   315 
       
   316 	// check that we have a connection
       
   317 	if( cl == NULL ) {
       
   318 		return ERR_STUB_NOT_CONNECTED;
       
   319 	}
       
   320 
       
   321 	// do the call
       
   322 	*rv = *stopmobileagent_8( &aArgs, cl );
       
   323 
       
   324 	// check for rpc errors and return the result
       
   325 	clnt_geterr( cl, &rerr );
       
   326 	if( rerr.re_status != RPC_SUCCESS ) {
       
   327 		iLastRPCError = rerr;
       
   328 		return ERR_RPC_ERROR;
       
   329 	}
       
   330 	return ERR_NONE;
       
   331 }
       
   332 
       
   333 
       
   334 /****************************************************************************************
       
   335  * 
       
   336  * PUBLIC FUNCTION: getmobileagentstatus
       
   337  * 
       
   338  ***************************************************************************************/
       
   339 int CCHacontroller::getmobileagentstatus( int aArgs, TResult *rv )
       
   340 {
       
   341 	struct rpc_err rerr;
       
   342 
       
   343 	// check the rv pointer
       
   344 	if( rv == NULL ) {
       
   345 		return ERR_INVALID_RV_POINTER;
       
   346 	}
       
   347 
       
   348 	// check that we have a connection
       
   349 	if( cl == NULL ) {
       
   350 		return ERR_STUB_NOT_CONNECTED;
       
   351 	}
       
   352 
       
   353 	// do the call
       
   354 	*rv = *getmobileagentstatus_8( &aArgs, cl );
       
   355 
       
   356 	// check for rpc errors and return the result
       
   357 	clnt_geterr( cl, &rerr );
       
   358 	if( rerr.re_status != RPC_SUCCESS ) {
       
   359 		iLastRPCError = rerr;
       
   360 		return ERR_RPC_ERROR;
       
   361 	}
       
   362 	return ERR_NONE;
       
   363 }
       
   364 
       
   365 
       
   366 /****************************************************************************************
       
   367  * 
       
   368  * PUBLIC FUNCTION: setsingleoption
       
   369  * 
       
   370  ***************************************************************************************/
       
   371 int CCHacontroller::setsingleoption( TOptionDesc aArgs, TResult *rv )
       
   372 {
       
   373 	struct rpc_err rerr;
       
   374 
       
   375 	// check the rv pointer
       
   376 	if( rv == NULL ) {
       
   377 		return ERR_INVALID_RV_POINTER;
       
   378 	}
       
   379 
       
   380 	// check that we have a connection
       
   381 	if( cl == NULL ) {
       
   382 		return ERR_STUB_NOT_CONNECTED;
       
   383 	}
       
   384 
       
   385 	// do the call
       
   386 	*rv = *setsingleoption_8( &aArgs, cl );
       
   387 
       
   388 	// check for rpc errors and return the result
       
   389 	clnt_geterr( cl, &rerr );
       
   390 	if( rerr.re_status != RPC_SUCCESS ) {
       
   391 		iLastRPCError = rerr;
       
   392 		return ERR_RPC_ERROR;
       
   393 	}
       
   394 	return ERR_NONE;
       
   395 }
       
   396 
       
   397 
       
   398 /****************************************************************************************
       
   399  * 
       
   400  * PUBLIC FUNCTION: removesingleoption
       
   401  * 
       
   402  ***************************************************************************************/
       
   403 int CCHacontroller::removesingleoption( TOptionDesc aArgs, TResult *rv )
       
   404 {
       
   405 	struct rpc_err rerr;
       
   406 
       
   407 	// check the rv pointer
       
   408 	if( rv == NULL ) {
       
   409 		return ERR_INVALID_RV_POINTER;
       
   410 	}
       
   411 
       
   412 	// check that we have a connection
       
   413 	if( cl == NULL ) {
       
   414 		return ERR_STUB_NOT_CONNECTED;
       
   415 	}
       
   416 
       
   417 	// do the call
       
   418 	*rv = *removesingleoption_8( &aArgs, cl );
       
   419 
       
   420 	// check for rpc errors and return the result
       
   421 	clnt_geterr( cl, &rerr );
       
   422 	if( rerr.re_status != RPC_SUCCESS ) {
       
   423 		iLastRPCError = rerr;
       
   424 		return ERR_RPC_ERROR;
       
   425 	}
       
   426 	return ERR_NONE;
       
   427 }
       
   428 
       
   429 
       
   430 /****************************************************************************************
       
   431  * 
       
   432  * PUBLIC FUNCTION: addlistoption
       
   433  * 
       
   434  ***************************************************************************************/
       
   435 int CCHacontroller::addlistoption( TOptionDesc aArgs, TResult *rv )
       
   436 {
       
   437 	struct rpc_err rerr;
       
   438 
       
   439 	// check the rv pointer
       
   440 	if( rv == NULL ) {
       
   441 		return ERR_INVALID_RV_POINTER;
       
   442 	}
       
   443 
       
   444 	// check that we have a connection
       
   445 	if( cl == NULL ) {
       
   446 		return ERR_STUB_NOT_CONNECTED;
       
   447 	}
       
   448 
       
   449 	// do the call
       
   450 	*rv = *addlistoption_8( &aArgs, cl );
       
   451 
       
   452 	// check for rpc errors and return the result
       
   453 	clnt_geterr( cl, &rerr );
       
   454 	if( rerr.re_status != RPC_SUCCESS ) {
       
   455 		iLastRPCError = rerr;
       
   456 		return ERR_RPC_ERROR;
       
   457 	}
       
   458 	return ERR_NONE;
       
   459 }
       
   460 
       
   461 
       
   462 /****************************************************************************************
       
   463  * 
       
   464  * PUBLIC FUNCTION: removelistoption
       
   465  * 
       
   466  ***************************************************************************************/
       
   467 int CCHacontroller::removelistoption( TOptionDesc aArgs, TResult *rv )
       
   468 {
       
   469 	struct rpc_err rerr;
       
   470 
       
   471 	// check the rv pointer
       
   472 	if( rv == NULL ) {
       
   473 		return ERR_INVALID_RV_POINTER;
       
   474 	}
       
   475 
       
   476 	// check that we have a connection
       
   477 	if( cl == NULL ) {
       
   478 		return ERR_STUB_NOT_CONNECTED;
       
   479 	}
       
   480 
       
   481 	// do the call
       
   482 	*rv = *removelistoption_8( &aArgs, cl );
       
   483 
       
   484 	// check for rpc errors and return the result
       
   485 	clnt_geterr( cl, &rerr );
       
   486 	if( rerr.re_status != RPC_SUCCESS ) {
       
   487 		iLastRPCError = rerr;
       
   488 		return ERR_RPC_ERROR;
       
   489 	}
       
   490 	return ERR_NONE;
       
   491 }
       
   492 
       
   493 
       
   494 /****************************************************************************************
       
   495  * 
       
   496  * PUBLIC FUNCTION: getstatus
       
   497  * 
       
   498  ***************************************************************************************/
       
   499 int CCHacontroller::getstatus( int aArgs, THaStatus *rv )
       
   500 {
       
   501 	struct rpc_err rerr;
       
   502 
       
   503 	// check the rv pointer
       
   504 	if( rv == NULL ) {
       
   505 		return ERR_INVALID_RV_POINTER;
       
   506 	}
       
   507 
       
   508 	// check that we have a connection
       
   509 	if( cl == NULL ) {
       
   510 		return ERR_STUB_NOT_CONNECTED;
       
   511 	}
       
   512 
       
   513 	// do the call
       
   514 	*rv = *getstatus_8( &aArgs, cl );
       
   515 
       
   516 	// check for rpc errors and return the result
       
   517 	clnt_geterr( cl, &rerr );
       
   518 	if( rerr.re_status != RPC_SUCCESS ) {
       
   519 		iLastRPCError = rerr;
       
   520 		return ERR_RPC_ERROR;
       
   521 	}
       
   522 	return ERR_NONE;
       
   523 }
       
   524 
       
   525 
       
   526 /****************************************************************************************
       
   527  * 
       
   528  * PUBLIC FUNCTION: destroytunnelid
       
   529  * 
       
   530  ***************************************************************************************/
       
   531 int CCHacontroller::destroytunnelid( THaTunnelID aArgs, TResult *rv )
       
   532 {
       
   533 	struct rpc_err rerr;
       
   534 
       
   535 	// check the rv pointer
       
   536 	if( rv == NULL ) {
       
   537 		return ERR_INVALID_RV_POINTER;
       
   538 	}
       
   539 
       
   540 	// check that we have a connection
       
   541 	if( cl == NULL ) {
       
   542 		return ERR_STUB_NOT_CONNECTED;
       
   543 	}
       
   544 
       
   545 	// do the call
       
   546 	*rv = *destroytunnelid_8( &aArgs, cl );
       
   547 
       
   548 	// check for rpc errors and return the result
       
   549 	clnt_geterr( cl, &rerr );
       
   550 	if( rerr.re_status != RPC_SUCCESS ) {
       
   551 		iLastRPCError = rerr;
       
   552 		return ERR_RPC_ERROR;
       
   553 	}
       
   554 	return ERR_NONE;
       
   555 }
       
   556 
       
   557 
       
   558 /****************************************************************************************
       
   559  * 
       
   560  * PUBLIC FUNCTION: listtunnels
       
   561  * 
       
   562  ***************************************************************************************/
       
   563 int CCHacontroller::listtunnels( int aArgs, THaTunnelList *rv )
       
   564 {
       
   565 	struct rpc_err rerr;
       
   566 
       
   567 	// check the rv pointer
       
   568 	if( rv == NULL ) {
       
   569 		return ERR_INVALID_RV_POINTER;
       
   570 	}
       
   571 
       
   572 	// check that we have a connection
       
   573 	if( cl == NULL ) {
       
   574 		return ERR_STUB_NOT_CONNECTED;
       
   575 	}
       
   576 
       
   577 	// do the call
       
   578 	*rv = *listtunnels_8( &aArgs, cl );
       
   579 
       
   580 	// check for rpc errors and return the result
       
   581 	clnt_geterr( cl, &rerr );
       
   582 	if( rerr.re_status != RPC_SUCCESS ) {
       
   583 		iLastRPCError = rerr;
       
   584 		return ERR_RPC_ERROR;
       
   585 	}
       
   586 	return ERR_NONE;
       
   587 }
       
   588 
       
   589 
       
   590 /****************************************************************************************
       
   591  * 
       
   592  * PUBLIC FUNCTION: gettunnelinfo
       
   593  * 
       
   594  ***************************************************************************************/
       
   595 int CCHacontroller::gettunnelinfo( TGetTunnelRequest aArgs, THaTunnelInfo *rv )
       
   596 {
       
   597 	struct rpc_err rerr;
       
   598 
       
   599 	// check the rv pointer
       
   600 	if( rv == NULL ) {
       
   601 		return ERR_INVALID_RV_POINTER;
       
   602 	}
       
   603 
       
   604 	// check that we have a connection
       
   605 	if( cl == NULL ) {
       
   606 		return ERR_STUB_NOT_CONNECTED;
       
   607 	}
       
   608 
       
   609 	// do the call
       
   610 	*rv = *gettunnelinfo_8( &aArgs, cl );
       
   611 
       
   612 	// check for rpc errors and return the result
       
   613 	clnt_geterr( cl, &rerr );
       
   614 	if( rerr.re_status != RPC_SUCCESS ) {
       
   615 		iLastRPCError = rerr;
       
   616 		return ERR_RPC_ERROR;
       
   617 	}
       
   618 	return ERR_NONE;
       
   619 }
       
   620 
       
   621 
       
   622 /****************************************************************************************
       
   623  * 
       
   624  * PUBLIC FUNCTION: settimeout
       
   625  * 
       
   626  ***************************************************************************************/
       
   627 int CCHacontroller::settimeout( TTimeoutRequest aArgs )
       
   628 {
       
   629 	struct rpc_err rerr;
       
   630 
       
   631 	// check that we have a connection
       
   632 	if( cl == NULL ) {
       
   633 		return ERR_STUB_NOT_CONNECTED;
       
   634 	}
       
   635 
       
   636 	// do the call
       
   637 	settimeout_8( &aArgs, cl );
       
   638 
       
   639 	// check for rpc errors and return the result
       
   640 	clnt_geterr( cl, &rerr );
       
   641 	if( rerr.re_status != RPC_SUCCESS ) {
       
   642 		iLastRPCError = rerr;
       
   643 		return ERR_RPC_ERROR;
       
   644 	}
       
   645 	return ERR_NONE;
       
   646 }