testexecmgmt/ucc/Source/MobsterRPCService/CSMobster.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 * Fri Sep 12 12:11:08 2003
       
    18 * System Includes
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #include <stdio.h>
       
    26 #include <assert.h>
       
    27 #ifdef WIN32
       
    28 #include <winsock2.h>
       
    29 #else
       
    30 #include <sys/socket.h>
       
    31 #include <netinet/in.h>
       
    32 #include <arpa/inet.h>
       
    33 #endif
       
    34 
       
    35 
       
    36 /****************************************************************************************
       
    37  * 
       
    38  * Local Includes
       
    39  * 
       
    40  ***************************************************************************************/
       
    41 #include "CSvcMobster.h"
       
    42 #include "CSMobster.h"
       
    43 
       
    44 
       
    45 /****************************************************************************************
       
    46  * 
       
    47  * Definitions
       
    48  * 
       
    49  ***************************************************************************************/
       
    50 #define MAXLOGNAME		64
       
    51 #ifndef WIN32
       
    52 #define _snprintf               snprintf
       
    53 #define ADDRESS_INTEGER         s_addr
       
    54 #endif
       
    55 
       
    56 /****************************************************************************************
       
    57  * 
       
    58  * Implementation
       
    59  * 
       
    60  ***************************************************************************************/
       
    61 CSMobster::CSMobster()
       
    62 {
       
    63 }
       
    64 
       
    65 CSMobster::~CSMobster()
       
    66 {
       
    67 	stopdevice( 0 );
       
    68 }
       
    69 
       
    70 int CSMobster::GetKey()
       
    71 {
       
    72 	return iKey;
       
    73 }
       
    74 
       
    75 void CSMobster::SetKey( int aKey )
       
    76 {
       
    77 	iKey = aKey;
       
    78 }
       
    79 
       
    80 
       
    81 /****************************************************************************************
       
    82  * 
       
    83  * PUBLIC FUNCTION: cstr_startdevice
       
    84  * 
       
    85  ***************************************************************************************/
       
    86 int CSMobster::cstr_startdevice( TDeviceDesc aDeviceDesc )
       
    87 {
       
    88 	int rv, err, errcode;
       
    89 
       
    90 	// set the state info for this object
       
    91 	memset( &iDeviceDesc, 0, sizeof(iDeviceDesc) );
       
    92 	iDeviceDesc.iDatalinkConfig = aDeviceDesc.iDatalinkConfig;
       
    93 	iDeviceDesc.iFilterConfig = aDeviceDesc.iFilterConfig;
       
    94 	iDeviceDesc.iMTID = iKey;
       
    95 	iDeviceDesc.iTEID = INVALID_DEVICE_ID;
       
    96 	iDeviceDesc.iDeviceStatus = CS_INACTIVE;
       
    97 	iDeviceDesc.iDeviceExitReason = DER_INVALID;
       
    98 
       
    99 	// start a phone in another thread, note that if it fails the call still succeeds, we
       
   100 	// treat this as the phone starting and then ending asynchronously. The main motivation
       
   101 	// for this is that it allows us to get all the debug info out.
       
   102 	err = iPhone.StartPhone( iKey, iDeviceDesc.iDatalinkConfig, iDeviceDesc.iFilterConfig, &errcode );
       
   103 	if( err != MTL_SUCCESS ) {
       
   104 		iDeviceDesc.iDeviceExitReason = DER_START_PHONE_FAILED;
       
   105 		iDeviceDesc.iDeviceExitSubReason = err;
       
   106 		iDeviceDesc.iDeviceExitDetail = errcode;
       
   107 		iDeviceDesc.iDeviceStatus = CS_CLOSED;
       
   108 	} else {
       
   109 		iDeviceDesc.iDeviceStatus = CS_ACTIVE;
       
   110 	}
       
   111 
       
   112 	// we now just wait for the other thread to get the channel connection
       
   113 	rv = ERR_NONE;
       
   114 	return rv;
       
   115 }
       
   116 
       
   117 
       
   118 /****************************************************************************************
       
   119  * 
       
   120  * PUBLIC FUNCTION: dstr_removedevice
       
   121  * 
       
   122  ***************************************************************************************/
       
   123 int CSMobster::dstr_removedevice( int aArgs, int *aDeleteInstance )
       
   124 {
       
   125 	int rv;
       
   126 	MTStatus mtstatus;
       
   127 
       
   128 	// if the phone was CS_ACTIVE last time then we have to check that it hasn't 
       
   129 	// change on its own accord.
       
   130 	if( iDeviceDesc.iDeviceStatus == CS_ACTIVE ) {
       
   131 		mtstatus = iPhone.GetStatus();
       
   132 		if( mtstatus == MTS_SHUTDOWN_ALL ) {
       
   133 			iDeviceDesc.iDeviceStatus = CS_CLOSED;
       
   134 		}
       
   135 	}
       
   136 
       
   137 	// cannot remove the device unless it is in the closed state
       
   138 	if( iDeviceDesc.iDeviceStatus != CS_CLOSED ) {
       
   139 		*aDeleteInstance = 0;
       
   140 		return ERR_INVALIDSTATE;
       
   141 	}
       
   142 
       
   143 	// otherwise let everything be cleaned up
       
   144 	*aDeleteInstance = 1;
       
   145 	rv = ERR_NONE;
       
   146 	return rv;
       
   147 }
       
   148 
       
   149 
       
   150 /****************************************************************************************
       
   151  * 
       
   152  * PUBLIC FUNCTION: getdeviceinfo
       
   153  * 
       
   154  ***************************************************************************************/
       
   155 TDeviceDesc CSMobster::getdeviceinfo( int aArgs )
       
   156 {
       
   157 	struct sockaddr_in sockaddr;
       
   158 	TDeviceDesc rv;
       
   159 	char *addr;
       
   160 	MTStatus mtstatus;
       
   161 
       
   162 	// if the phone was CS_ACTIVE last time then we have to check that it hasn't 
       
   163 	// change on its own accord.
       
   164 	if( iDeviceDesc.iDeviceStatus == CS_ACTIVE ) {
       
   165 		mtstatus = iPhone.GetStatus();
       
   166 		if( mtstatus == MTS_SHUTDOWN_ALL ) {
       
   167 			iDeviceDesc.iDeviceStatus = CS_CLOSED;
       
   168 		}
       
   169 	}
       
   170 
       
   171 	// copy the static values from the local version
       
   172 	rv = iDeviceDesc;
       
   173 
       
   174 	// update the addresses from the MT
       
   175 	iPhone.GetLocalUUAddress( &sockaddr );
       
   176 	sprintf( rv.iLocalAirInterfacePort, "%d", ntohs(sockaddr.sin_port) );
       
   177 	iPhone.GetRemoteUUAddress( &sockaddr );
       
   178 	sprintf( rv.iRemoteAirInterfacePort, "%d", ntohs(sockaddr.sin_port) );
       
   179 	addr = inet_ntoa( sockaddr.sin_addr );
       
   180 	_snprintf( rv.iRemoteAirInterfaceAddress, MAXADDRLEN, "%s", addr ); 
       
   181 
       
   182 	// done
       
   183 	return rv;
       
   184 }
       
   185 
       
   186 
       
   187 /****************************************************************************************
       
   188  * 
       
   189  * PUBLIC FUNCTION: getdevicelog
       
   190  * 
       
   191  ***************************************************************************************/
       
   192 TVarData CSMobster::getdevicelog( int aArgs )
       
   193 {
       
   194 	TVarData rv;
       
   195 	CLog *log;
       
   196 	int logsize;
       
   197 
       
   198 	// init the rv
       
   199 	rv.TVarData_len = 0;
       
   200 	rv.TVarData_val = NULL;
       
   201 
       
   202 	// get the log from the device
       
   203 	log = iPhone.GetLog();
       
   204 
       
   205 	// get the size of the log and allocate the space
       
   206 	logsize = log->CalculateLogSize();
       
   207 	if( logsize == 0 ) {
       
   208 		return rv;
       
   209 	}
       
   210 	rv.TVarData_val = (char*)malloc( logsize );
       
   211 	rv.TVarData_len = logsize;
       
   212 
       
   213 	// copy the log into the buffer
       
   214 	log->PrintLogToBuffer( logsize, rv.TVarData_val );
       
   215 
       
   216 	// close up the file and return data
       
   217 	return rv;
       
   218 }
       
   219 
       
   220 
       
   221 /****************************************************************************************
       
   222  * 
       
   223  * PUBLIC FUNCTION: stopdevice
       
   224  * 
       
   225  ***************************************************************************************/
       
   226 int CSMobster::stopdevice( int aArgs )
       
   227 {
       
   228 	int rv, err;
       
   229 
       
   230 	// no phone should be in the ps_inactive state (non-atomically)
       
   231 	assert( iDeviceDesc.iDeviceStatus != CS_INACTIVE );
       
   232 
       
   233 	// if we are in the closed state already then return invalid state
       
   234 	if( iDeviceDesc.iDeviceStatus == CS_CLOSED ) {
       
   235 		rv = ERR_INVALIDSTATE;
       
   236 		return rv;
       
   237 	}
       
   238 
       
   239 	// if we are in the active state then stop the phone -- if stop fails then we 
       
   240 	// return without changing the state -- this means that the phone should only
       
   241 	// return an error from StopPhone() if it is a transient error.
       
   242 	assert( iDeviceDesc.iDeviceStatus == CS_ACTIVE );
       
   243 	err = iPhone.StopPhone();
       
   244 	if( err != 0 ) {
       
   245 		rv = ERR_STOPFAILED;
       
   246 		return rv;
       
   247 	}
       
   248 	iDeviceDesc.iDeviceExitReason = DER_USER_REQUEST;
       
   249 	iDeviceDesc.iDeviceExitSubReason = 0;
       
   250 	iDeviceDesc.iDeviceExitDetail = 0;
       
   251 	iDeviceDesc.iDeviceStatus = CS_CLOSED;
       
   252 
       
   253 	// return success
       
   254 	rv = ERR_NONE;
       
   255 	return rv;
       
   256 }
       
   257 
       
   258 
       
   259 /****************************************************************************************
       
   260  * 
       
   261  * PUBLIC FUNCTION: setremoteuuaddress
       
   262  * 
       
   263  ***************************************************************************************/
       
   264 int CSMobster::setremoteuuaddress( TUUAddress aArgs )
       
   265 {
       
   266 	int rv, err;
       
   267 	struct sockaddr_in sockaddr;
       
   268 
       
   269 	// call the phone
       
   270 	sockaddr.sin_family = AF_INET;
       
   271 	sockaddr.sin_addr.ADDRESS_INTEGER = aArgs.iRemoteAddress;
       
   272 	sockaddr.sin_port = aArgs.iRemotePort;
       
   273 	err = iPhone.SetRemoteUUAddress( sockaddr );
       
   274 
       
   275 	// translate cphone error to mobster
       
   276 	assert( err == MTL_SUCCESS );
       
   277 	rv = ERR_NONE;
       
   278 	return rv;
       
   279 }
       
   280 
       
   281 
       
   282 /****************************************************************************************
       
   283  * 
       
   284  * PUBLIC FUNCTION: settesocket
       
   285  * 
       
   286  ***************************************************************************************/
       
   287 int CSMobster::settesocket( int aSock )
       
   288 {
       
   289 	MTError merr;
       
   290 
       
   291 	// pass the socket to the phone
       
   292 	merr = iPhone.SetTeSocket( aSock );
       
   293 
       
   294 	// 	translate the errors
       
   295 	return ((merr == MTL_SUCCESS) ? ERR_NONE : ERR_CHANNEL_SOCKET_ALREADY_SET);
       
   296 }