testexecmgmt/ucc/Source/Uccs.v2/DeviceControlChannel/CApplicationControlNull.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 #include <stdio.h>
       
    22 #include <stdlib.h>
       
    23 #include <windows.h>
       
    24 #include <assert.h>
       
    25 
       
    26 
       
    27 /**********************************************************************************************
       
    28  *
       
    29  * Local Includes
       
    30  *
       
    31  *********************************************************************************************/
       
    32 #include "CApplicationControlNull.h"
       
    33 #include "../Core/UCCS_ErrorCodes.h"
       
    34 
       
    35 
       
    36 /**********************************************************************************************
       
    37  *
       
    38  * Defines
       
    39  *
       
    40  *********************************************************************************************/
       
    41 #define MAXTOKENS 64
       
    42 
       
    43 
       
    44 /**********************************************************************************************
       
    45  *
       
    46  * Constructor
       
    47  *
       
    48  *********************************************************************************************/
       
    49 CApplicationControlNull::CApplicationControlNull( MUccsControl *aCallBackService, IOutput *aOutput )
       
    50 {
       
    51 	assert( aCallBackService != NULL );
       
    52 	assert( aOutput != NULL );
       
    53 	iOutput = aOutput;
       
    54 	iCallBackService = aCallBackService;
       
    55 }
       
    56 
       
    57 /**********************************************************************************************
       
    58  *
       
    59  * Destructor
       
    60  *
       
    61  *********************************************************************************************/
       
    62 CApplicationControlNull::~CApplicationControlNull()
       
    63 {
       
    64 }
       
    65 
       
    66 
       
    67 /**********************************************************************************************
       
    68  *
       
    69  * Run() -- the main routine called to run the serial listener.
       
    70  *
       
    71  *********************************************************************************************/
       
    72 TCommandControlError CApplicationControlNull::Start( TRemoteControlTransport aTransport, char* aPortname, int *aErrorCode, int *aScriptError )
       
    73 {
       
    74 	int err, i;
       
    75 	static int execution_count = 0;
       
    76 
       
    77 	// check params
       
    78 	assert( aScriptError != NULL );
       
    79 	*aScriptError = 0;
       
    80 
       
    81 	// check the parameters are valid
       
    82 	if( aPortname == NULL ) {
       
    83 		return EAC_INVALIDPORT;
       
    84 	}
       
    85 
       
    86 	// only run once -- then exit
       
    87 	if( execution_count > 0 ) {
       
    88 		return EAC_QUIT;
       
    89 	}
       
    90 	execution_count++;
       
    91 
       
    92 	// parse the params
       
    93 	err = ParseArgumentString( aPortname );
       
    94 	if( err == -1 ) {
       
    95 		return EAC_INVALIDPORT;
       
    96 	}
       
    97 
       
    98 	// start the use-case
       
    99 	err = iCallBackService->StartUsecase( iArgs.iUsecaseID );
       
   100 	if( err != UCCS_OK ) {
       
   101 		*aErrorCode = err;
       
   102 		return EAC_STARTUSECASEFAILED;
       
   103 	}
       
   104 
       
   105 	// run rendezvous the set number of times - wait for user input before each one 
       
   106 	// if the interactive flag is set. The last rendezvous is never interactive.
       
   107 	for( i = 0; i < iArgs.iRendezvousCount; i++ ) {
       
   108 		if( (iArgs.iInteractiveFlag != 0) && (i != (iArgs.iRendezvousCount-1)) ) {
       
   109 			fprintf( stdout, "Press enter to rendezvous.\n" );
       
   110 			getchar();
       
   111 		}
       
   112 		err = iCallBackService->Rendezvous( iArgs.iUsecaseID );
       
   113 		if( err != UCCS_OK ) {
       
   114 			*aErrorCode = err;
       
   115 			return EAC_RENDEZVOUSFAILED;
       
   116 		}
       
   117 	}
       
   118 
       
   119 	// put in a wait so that the other thread has time to finish up
       
   120 	Sleep( 1000 );
       
   121 
       
   122 	// end use-case 
       
   123 	err = iCallBackService->EndUsecase( iArgs.iUsecaseID, 0, aScriptError );
       
   124 	*aErrorCode = err; 
       
   125 	if( ( err != UCCS_OK ) ){
       
   126 		return EAC_ENDUSECASEFAILED;
       
   127 	}
       
   128 
       
   129 	// done
       
   130 	return EAC_SUCCESS;
       
   131 }
       
   132 
       
   133 
       
   134 /**********************************************************************************************
       
   135  *
       
   136  * ParseArgumentString() - portname should be a string:
       
   137  * "<usecaseid>[:<rendezvous count>[:<interactive_flag>]]"
       
   138  *
       
   139  *********************************************************************************************/
       
   140 int CApplicationControlNull::ParseArgumentString( char *str )
       
   141 {
       
   142 	char *ptr, *tokens[MAXTOKENS];
       
   143 	int token_count = 0, i;
       
   144 
       
   145 	// check params
       
   146 	assert( str != NULL );
       
   147 
       
   148 	// tokenise the string based on the ':' delimiter
       
   149 	for( ptr = str, i = 0; i < MAXTOKENS; i++ ) {
       
   150 		tokens[i] = ptr;
       
   151 		ptr = strchr( ptr, ':' );
       
   152 		if( ptr == NULL ) 
       
   153 			break;
       
   154 		*ptr = 0;
       
   155 		ptr++;
       
   156 	}
       
   157 	token_count = i + 1;
       
   158 
       
   159 	// check that at least one token was found
       
   160 	if( token_count == 0 ) {
       
   161 		return -1;
       
   162 	}
       
   163 
       
   164 	// initialise the optional args to their defaults
       
   165 	iArgs.iRendezvousCount = 1;
       
   166 	iArgs.iInteractiveFlag = 0;
       
   167 
       
   168 	// now convert the tokens into meaningful things
       
   169 	iArgs.iUsecaseID = atoi(tokens[0]);
       
   170 	if( token_count > 1 ) {
       
   171 		iArgs.iRendezvousCount = atoi(tokens[1]);
       
   172 	}
       
   173 	if( token_count > 2 ) {
       
   174 		iArgs.iInteractiveFlag = atoi(tokens[2]);
       
   175 	}
       
   176 
       
   177 	// done - success
       
   178 	return 0;
       
   179 }