testexecmgmt/ucc/Source/Uccs.v2/Core/UCCS_CExecuteCommand.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 * Switches
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /****************************************************************************************
       
    21  *
       
    22  * System Includes
       
    23  *
       
    24  ***************************************************************************************/
       
    25 #include <stdio.h>
       
    26 #include <stdlib.h>
       
    27 #include <assert.h>
       
    28 #include <string.h>
       
    29 #include <windows.h>
       
    30 
       
    31 /****************************************************************************************
       
    32  *
       
    33  * Local Includes
       
    34  *
       
    35  ***************************************************************************************/
       
    36 #include "UCCS_CExecuteCommand.h"
       
    37 
       
    38 
       
    39 /****************************************************************************************
       
    40  *
       
    41  * Definitions
       
    42  *
       
    43  ***************************************************************************************/
       
    44 #define REPEATCOMMANDWAITPERIOD		2000
       
    45 
       
    46 
       
    47 /********************************************************************************
       
    48  *
       
    49  * Macro Functions
       
    50  *
       
    51  ********************************************************************************/
       
    52 #define NOT_IS_WHITESPACE(c)		((c != '\t')&&(c != '\n')&&(c != 0)&&(c != ' '))
       
    53  
       
    54 /****************************************************************************************
       
    55  *
       
    56  * File-scope variables
       
    57  *
       
    58  ***************************************************************************************/
       
    59 static const char *iCommandStrings[] = {	"<invalid>", 
       
    60 											"quit", 
       
    61 											"runcmd", 
       
    62 											"assign",
       
    63 											"waitfor", 
       
    64 											"waitforsignal", 
       
    65 											"rendezvous", 
       
    66 											"require", 
       
    67 											"requirenot", 
       
    68 											"check", 
       
    69 											"checknot", 
       
    70 											"showenvironment", 
       
    71 											"waitfornot", 
       
    72 											"signal", 
       
    73 											NULL };
       
    74 
       
    75 /****************************************************************************************
       
    76  *
       
    77  * PUBLIC FUNCTION: GetScriptCommandString
       
    78  *
       
    79  ***************************************************************************************/
       
    80 const char *GetScriptCommandString( int aCommandID )
       
    81 {
       
    82 	// make sure the command ID is valid
       
    83 	if( (aCommandID < UC_QUIT) || (aCommandID > UC_SIGNAL) ) {
       
    84 		return NULL;
       
    85 	}
       
    86 	
       
    87 	// return the string
       
    88 	return iCommandStrings[aCommandID];
       
    89 }
       
    90 
       
    91 
       
    92 /****************************************************************************************
       
    93  *
       
    94  * Construction
       
    95  *
       
    96  ***************************************************************************************/
       
    97 CExecuteCommand::CExecuteCommand( CSynchronisation *aSync, IOutput *aOutput )
       
    98 {
       
    99 	// check params
       
   100 	assert( aOutput != NULL );
       
   101 	assert( aSync != NULL );
       
   102 
       
   103 	// init vars
       
   104 	iSync = aSync;
       
   105 	iOutput = aOutput;
       
   106 	iLastResult = NULL;
       
   107 	iCommandContextSize = 0;
       
   108 
       
   109 	// create objs
       
   110 	iEnvironment = new CDataRecord();
       
   111 	assert( iEnvironment != NULL );
       
   112 	iServiceManager = new CServiceManager( aOutput );
       
   113 	assert( iServiceManager != NULL );
       
   114 	iCommandDecoder = new CCommandDecoder( iEnvironment );
       
   115 	assert( iCommandDecoder != NULL );
       
   116 }
       
   117 
       
   118 
       
   119 CExecuteCommand::~CExecuteCommand()
       
   120 {
       
   121 	ClearCommandContext();
       
   122 	if( iLastResult != NULL ) {
       
   123 		delete iLastResult;
       
   124 	}
       
   125 	delete iCommandDecoder;
       
   126 	delete iServiceManager;
       
   127 	delete iEnvironment;
       
   128 }
       
   129 
       
   130 
       
   131 /****************************************************************************************
       
   132  *
       
   133  * Public Methoid: Execute Command -- parse into (command, argument)
       
   134  *
       
   135  ***************************************************************************************/
       
   136 int CExecuteCommand::ExecuteCommand( char *aCommandLine )
       
   137 {
       
   138 	char *command, *arguments;
       
   139 
       
   140 	// check the params
       
   141 	assert( aCommandLine != NULL );
       
   142 
       
   143 	// parse the line into (commandPtr, argumentPtr)
       
   144 	for( command = aCommandLine, arguments = aCommandLine; NOT_IS_WHITESPACE(*arguments) && (*arguments != 0); arguments++ )
       
   145 			;
       
   146 
       
   147 	// check for no arguments (fine for quit) -- otherwise null the command and set the arg ptr
       
   148 	if( *arguments == 0 ) {
       
   149 		arguments = NULL;
       
   150 	} else {
       
   151 		*arguments = 0;
       
   152 		arguments++;
       
   153 	}
       
   154 
       
   155 
       
   156 	// call the handler
       
   157 	return ExecuteCommand( command, arguments );
       
   158 }
       
   159 
       
   160 
       
   161 /****************************************************************************************
       
   162  *
       
   163  * Public Method: Execute Command -- deals with contexts and waitfors
       
   164  *
       
   165  ***************************************************************************************/
       
   166 int CExecuteCommand::ExecuteCommand( char *aCommand, char *aArgs )
       
   167 {
       
   168 	int i;
       
   169 	int err;
       
   170 	int match;
       
   171 	TUccsCommand command;
       
   172 	CDataRecord *command_arguments;
       
   173 
       
   174 	// resolve the command
       
   175 	for( i = 0; iCommandStrings[i] != NULL; i++ ) {
       
   176 		match = strcmp( aCommand, iCommandStrings[i] );
       
   177 		if( match == 0 ) {
       
   178 			break;
       
   179 		}
       
   180 	}
       
   181 
       
   182 	// if no match is found then error
       
   183 	if( iCommandStrings[i] == 0 ) {
       
   184 		return UCCS_UNKNOWNCOMMAND;
       
   185 	}
       
   186 	command = (TUccsCommand)i;
       
   187 
       
   188 	// create a new request record
       
   189 	command_arguments = new CDataRecord();
       
   190 
       
   191 	// create a data object from the argument string
       
   192 	err = iCommandDecoder->ParseCommandToRecord(aArgs, command_arguments);
       
   193 	if( err != UCCS_OK ) {
       
   194 		return err;
       
   195 	}
       
   196 
       
   197 	// if the command is a run command then we clear the context
       
   198 	if( command == UC_RUNCMD ) {
       
   199 		ClearCommandContext();
       
   200 	}
       
   201 
       
   202 	// add the command to the context
       
   203 	AddToCommandContext( command, command_arguments );
       
   204 
       
   205 	// now execute the command for the first time
       
   206 	err = InternalExecuteCommand( command, command_arguments );
       
   207 
       
   208 	// if the result was NOT UCCS_REPLAYCOMMAND then just return
       
   209 	if( err != UCCS_REPLAYCOMMAND ) {
       
   210 		return err;
       
   211 	}
       
   212 
       
   213 
       
   214 	// NOTE: if we get here then we are asked to replay
       
   215 
       
   216 	// Run each command in the context again in order. If an error occurs then exit. If someone
       
   217 	// asks to wait again then start agani
       
   218 	for( i = 0; i < iCommandContextSize; i++ ) {
       
   219 		err = InternalExecuteCommand( iCommandContextCommands[i], iCommandContextArgs[i] );
       
   220 		if( err == UCCS_REPLAYCOMMAND ) {
       
   221 			i = -1;
       
   222 			continue;
       
   223 		} else if( err != UCCS_OK ) {
       
   224 			return err;
       
   225 		}
       
   226 	}
       
   227 
       
   228 	// done
       
   229 	return UCCS_OK;
       
   230 }
       
   231 
       
   232 /****************************************************************************************
       
   233  *
       
   234  * Public Method: Execute Command -- dispatch commands to appropriate 
       
   235  * handlers
       
   236  *
       
   237  ***************************************************************************************/
       
   238 int CExecuteCommand::InternalExecuteCommand( TUccsCommand aCmd, CDataRecord *aArgs )
       
   239 {
       
   240 	int err;
       
   241 
       
   242 	// let the output know that we are executing a command
       
   243 	if( aCmd != UC_RUNCMD )
       
   244 	{
       
   245 		iOutput->ExecuteCommand( aCmd, aArgs );
       
   246 	}
       
   247 
       
   248 	// pass the command to the appropriate handler
       
   249 	switch( aCmd ) {
       
   250 
       
   251 	case UC_QUIT:
       
   252 		err = UCCS_QUIT;
       
   253 		break;
       
   254 
       
   255 	case UC_RUNCMD:
       
   256 		err = HandleRunCmd( aArgs );
       
   257 		break;
       
   258 
       
   259 	case UC_ASSIGN:
       
   260 		err = HandleAssignment( aArgs );
       
   261 		break;
       
   262 
       
   263 	case UC_WAITFOR:
       
   264 		err = HandleWaitFor( aArgs );
       
   265 		break;
       
   266 
       
   267 	case UC_REQUIRE:
       
   268 		err = HandleRequire( aArgs );
       
   269 		break;
       
   270 
       
   271 	case UC_REQUIRENOT:
       
   272 		err = HandleRequireNot( aArgs );
       
   273 		break;
       
   274 
       
   275 	case UC_CHECK:
       
   276 		err = HandleCheck( aArgs );
       
   277 		break;
       
   278 
       
   279 	case UC_CHECKNOT:
       
   280 		err = HandleCheckNot( aArgs );
       
   281 		break;
       
   282 
       
   283 	case UC_WAITFORSIGNAL:
       
   284 		err = HandleWaitForSignal( aArgs );
       
   285 		break;
       
   286 
       
   287 	case UC_RENDEZVOUS:
       
   288 		err = HandleRendezvous( aArgs );
       
   289 		break;
       
   290 
       
   291 	case UC_PRINTENVIRONMENT:
       
   292 		iOutput->DisplayEnvironment( iEnvironment );
       
   293 		err = UCCS_OK;
       
   294 		break;
       
   295 
       
   296 	case UC_WAITFORNOT:
       
   297 		err = HandleWaitForNot( aArgs );
       
   298 		break;
       
   299 
       
   300 	case UC_SIGNAL:
       
   301 		err = HandleSignal( aArgs );
       
   302 		break;
       
   303 	}
       
   304 
       
   305 	// output the result
       
   306 	iOutput->ExecuteCommandResult( err );
       
   307 	
       
   308 	// should always get here
       
   309 	return err;
       
   310 }
       
   311 
       
   312 
       
   313 /****************************************************************************************
       
   314  *
       
   315  * Private Method: HandleRunCmd
       
   316  *
       
   317  ***************************************************************************************/
       
   318 int CExecuteCommand::HandleRunCmd( CDataRecord *aArgs )
       
   319 {
       
   320 	int err;
       
   321 	CDataRecord *result = NULL;
       
   322 
       
   323 	// run the command
       
   324 	err = iServiceManager->IssueCommand( aArgs, &result );
       
   325 	
       
   326 	// if the command fails then return the error
       
   327 	if( err != UCCS_OK && err != UCCS_ERROR_NONE ) {
       
   328 			return err;
       
   329 	}
       
   330 	assert( result != NULL );
       
   331 
       
   332 	// otherwise this is success -- let the output know
       
   333 	iOutput->ExecuteCommandReply( result );
       
   334 
       
   335 	// otherwise we clear the previous saved command and result
       
   336 	if( iLastResult != NULL ) {
       
   337 		delete iLastResult;
       
   338 	}
       
   339 
       
   340 	// now save this command and result
       
   341 	iLastResult = result;
       
   342 	iCommandDecoder->SetLastReply( iLastResult );
       
   343 
       
   344 	// done
       
   345 	return err;
       
   346 }
       
   347 
       
   348 
       
   349 /****************************************************************************************
       
   350  *
       
   351  * Private Method: HandlePrintLastCommand
       
   352  *
       
   353  ***************************************************************************************/
       
   354 int CExecuteCommand::HandlePrintLastCommand( CDataRecord *aArgs )
       
   355 {
       
   356 	iOutput->DisplayLastCommand( iCommandContextArgs[0] );
       
   357 	return UCCS_OK;
       
   358 }
       
   359 
       
   360 
       
   361 /****************************************************************************************
       
   362  *
       
   363  * Private Method: HandlePrintLastResult
       
   364  *
       
   365  ***************************************************************************************/
       
   366 int CExecuteCommand::HandlePrintLastResult( CDataRecord *aArgs )
       
   367 {
       
   368 	iOutput->DisplayLastReply( iLastResult );
       
   369 	return UCCS_OK;
       
   370 }
       
   371 
       
   372 
       
   373 /****************************************************************************************
       
   374  *
       
   375  * Private Method: HandleAssignment -- allows elements of the reply to be assigned. For
       
   376  * each field (name1, value1) in the passed record we:
       
   377  *
       
   378  *	field_value = reply->GetField( name1 );
       
   379  *	environment->NewField( value1, field_value );
       
   380  *
       
   381  ***************************************************************************************/
       
   382 int CExecuteCommand::HandleAssignment( CDataRecord *aArgs )
       
   383 {
       
   384 	int err;
       
   385 //	char *source_field_name;
       
   386 	char *dest_field_name;
       
   387 	char *dest_field_value;
       
   388 	CDataField *element = NULL;
       
   389 
       
   390 	// now do the assignment -- first try and update, then a new
       
   391 	element = aArgs->GetFirstField();
       
   392 	while( element != NULL ) {
       
   393 		dest_field_name = element->GetName();
       
   394 		dest_field_value = element->GetStrValue();
       
   395 		err = iEnvironment->ChangeFieldData( dest_field_name, dest_field_value );
       
   396 		if( err == UCCS_FIELDNOTFOUND ) {
       
   397 			err = iEnvironment->NewField( dest_field_name, dest_field_value );
       
   398 			if( err != UCCS_OK ) {
       
   399 				return err;
       
   400 			}
       
   401 		} else if( err != UCCS_OK ) {
       
   402 			return err;
       
   403 		}
       
   404 		element = aArgs->GetNextField();
       
   405 	}
       
   406 
       
   407 
       
   408 	// done
       
   409 	return UCCS_OK;
       
   410 }
       
   411 
       
   412 
       
   413 
       
   414 /****************************************************************************************
       
   415  *
       
   416  * Private Method: HandleWaitFor. For each field in the args (namei, valuei)
       
   417  *
       
   418  * rv = reply->GetField(namei);
       
   419  * if( rv != valuei ) 
       
   420  *		repeat the last command with X second wait
       
   421  *
       
   422  *
       
   423  ***************************************************************************************/
       
   424 int CExecuteCommand::HandleWaitFor( CDataRecord *aArgs )
       
   425 {
       
   426 	char *field_name;
       
   427 	char *reference_value;
       
   428 	char *actual_value;
       
   429 	int err, match;
       
   430 	CDataField *element = NULL;
       
   431 
       
   432 	// make sure there is a previous reply and request
       
   433 	if( iLastResult == NULL ) {
       
   434 		return UCCS_NORESULT;
       
   435 	}
       
   436 
       
   437 	// now do the waitfor
       
   438 	element = aArgs->GetFirstField();
       
   439 	while( element != NULL ) {
       
   440 
       
   441 		field_name = element->GetName();
       
   442 		reference_value = element->GetStrValue();
       
   443 		err = iLastResult->GetFieldAsString( field_name, &actual_value );
       
   444 		if( err != UCCS_OK ) {
       
   445 			return err;
       
   446 		}
       
   447 		match = strcmp( reference_value, actual_value );
       
   448 		if( match != 0 ) {
       
   449 			Sleep( REPEATCOMMANDWAITPERIOD );
       
   450 			return UCCS_REPLAYCOMMAND;
       
   451 		}
       
   452 
       
   453 		element = aArgs->GetNextField();
       
   454 	}
       
   455 
       
   456 	// done
       
   457 	return UCCS_OK;
       
   458 }
       
   459 
       
   460 
       
   461 /****************************************************************************************
       
   462  *
       
   463  * Private Method: HandleWaitForNot. For each field in the args (namei, valuei)
       
   464  *
       
   465  * rv = reply->GetField(namei);
       
   466  * if( rv != valuei ) 
       
   467  *		repeat the last command with X second wait
       
   468  *
       
   469  *
       
   470  ***************************************************************************************/
       
   471 int CExecuteCommand::HandleWaitForNot( CDataRecord *aArgs )
       
   472 {
       
   473 	char *field_name;
       
   474 	char *reference_value;
       
   475 	char *actual_value;
       
   476 	int err, match;
       
   477 	CDataField *element = NULL;
       
   478 
       
   479 	// make sure there is a previous reply and request
       
   480 	if( iLastResult == NULL ) {
       
   481 		return UCCS_NORESULT;
       
   482 	}
       
   483 
       
   484 	// now do the waitfornot
       
   485 	element = aArgs->GetFirstField();
       
   486 	while( element != NULL ) {
       
   487 
       
   488 		field_name = element->GetName();
       
   489 		reference_value = element->GetStrValue();
       
   490 		err = iLastResult->GetFieldAsString( field_name, &actual_value );
       
   491 		if( err != UCCS_OK ) {
       
   492 			return err;
       
   493 		}
       
   494 		match = strcmp( reference_value, actual_value );
       
   495 		if( match == 0 ) {
       
   496 			Sleep( REPEATCOMMANDWAITPERIOD );
       
   497 			return UCCS_REPLAYCOMMAND;
       
   498 		}
       
   499 
       
   500 		element = aArgs->GetNextField();
       
   501 	}
       
   502 
       
   503 	// done
       
   504 	return UCCS_OK;
       
   505 }
       
   506 
       
   507 
       
   508 /****************************************************************************************
       
   509  *
       
   510  * Private Method: HandleRequire.  
       
   511  *
       
   512  ***************************************************************************************/
       
   513 int CExecuteCommand::HandleRequire( CDataRecord *aArgs )
       
   514 {
       
   515 	int err, match;
       
   516 	char *field_name, *field_value, *actual_value;
       
   517 	CDataField *element;
       
   518 
       
   519 	// make sure there is a previous reply
       
   520 	if( iLastResult == NULL ) {
       
   521 		return UCCS_NORESULT;
       
   522 	}
       
   523 
       
   524 	// now do the require
       
   525 	element = aArgs->GetFirstField();
       
   526 	while( element != NULL ) {
       
   527 
       
   528 		field_name = element->GetName();
       
   529 		field_value = element->GetStrValue();
       
   530 		err = iLastResult->GetFieldAsString( field_name, &actual_value );
       
   531 		if( err != UCCS_OK ) {
       
   532 			return UCCS_REQUIREDVALUEERROR;
       
   533 		}
       
   534 		match = strcmp( actual_value, field_value );
       
   535 		if( match != 0 ) {
       
   536 			return UCCS_REQUIREDVALUEINCORRECT;
       
   537 		}
       
   538 
       
   539 		element = aArgs->GetNextField();
       
   540 	}
       
   541 	return UCCS_OK;
       
   542 }
       
   543 
       
   544 
       
   545 /****************************************************************************************
       
   546  *
       
   547  * Private Method: HandleRequireNot.  
       
   548  *
       
   549  ***************************************************************************************/
       
   550 int CExecuteCommand::HandleRequireNot( CDataRecord *aArgs )
       
   551 {
       
   552 	int err, match;
       
   553 	char *field_name, *field_value, *actual_value;
       
   554 	CDataField *element;
       
   555 
       
   556 	// make sure there is a previous reply
       
   557 	if( iLastResult == NULL ) {
       
   558 		return UCCS_NORESULT;
       
   559 	}
       
   560 
       
   561 	// now do the requirenot
       
   562 	element = aArgs->GetFirstField();
       
   563 	while( element != NULL ) {
       
   564 
       
   565 		field_name = element->GetName();
       
   566 		field_value = element->GetStrValue();
       
   567 		err = iLastResult->GetFieldAsString( field_name, &actual_value );
       
   568 		if( err != UCCS_OK ) {
       
   569 			return UCCS_REQUIREDNOTVALUEERROR;
       
   570 		}
       
   571 		match = strcmp( actual_value, field_value );
       
   572 		if( match == 0 ) {
       
   573 			return UCCS_REQUIREDNOTVALUEMATCH;
       
   574 		}
       
   575 
       
   576 		element = aArgs->GetNextField();
       
   577 	}
       
   578 	return UCCS_OK;
       
   579 }
       
   580 
       
   581 
       
   582 /****************************************************************************************
       
   583  *
       
   584  * Private Method: HandleCheck.  
       
   585  *
       
   586  ***************************************************************************************/
       
   587 int CExecuteCommand::HandleCheck( CDataRecord *aArgs )
       
   588 {
       
   589 	int err, match;
       
   590 	char *field_name, *field_value, *actual_value;
       
   591 	CDataField *element;
       
   592 
       
   593 	// make sure there is a previous reply
       
   594 	if( iLastResult == NULL ) {
       
   595 		return UCCS_NORESULT;
       
   596 	}
       
   597 
       
   598 	// now do the check
       
   599 	element = aArgs->GetFirstField();
       
   600 	while( element != NULL ) {
       
   601 
       
   602 		field_name = element->GetName();
       
   603 		field_value = element->GetStrValue();
       
   604 		err = iLastResult->GetFieldAsString( field_name, &actual_value );
       
   605 		if( err != UCCS_OK ) {
       
   606 			return UCCS_CHECKVALUEERROR;
       
   607 		}
       
   608 		match = strcmp( actual_value, field_value );
       
   609 		if( match != 0 ) {
       
   610 			return UCCS_CHECKVALUEINCORRECT;
       
   611 		}
       
   612 
       
   613 		element = aArgs->GetNextField();
       
   614 	}
       
   615 	return UCCS_OK;
       
   616 }
       
   617 
       
   618 
       
   619 /****************************************************************************************
       
   620  *
       
   621  * Private Method: HandleCheckNot.  
       
   622  *
       
   623  ***************************************************************************************/
       
   624 int CExecuteCommand::HandleCheckNot( CDataRecord *aArgs )
       
   625 {
       
   626 	int err, match;
       
   627 	char *field_name, *field_value, *actual_value;
       
   628 	CDataField *element;
       
   629 
       
   630 	// make sure there is a previous reply
       
   631 	if( iLastResult == NULL ) {
       
   632 		return UCCS_NORESULT;
       
   633 	}
       
   634 
       
   635 	// now do the checknot
       
   636 	element = aArgs->GetFirstField();
       
   637 	while( element != NULL ) {
       
   638 
       
   639 		field_name = element->GetName();
       
   640 		field_value = element->GetStrValue();
       
   641 		err = iLastResult->GetFieldAsString( field_name, &actual_value );
       
   642 		if( err != UCCS_OK ) {
       
   643 			return UCCS_CHECKNOTVALUEERROR;
       
   644 		}
       
   645 		match = strcmp( actual_value, field_value );
       
   646 		if( match == 0 ) {
       
   647 			return UCCS_CHECKNOTVALUEMATCH;
       
   648 		}
       
   649 
       
   650 		element = aArgs->GetNextField();
       
   651 	}
       
   652 	return UCCS_OK;
       
   653 }
       
   654 
       
   655 
       
   656 /****************************************************************************************
       
   657  *
       
   658  * Private Method: HandleWaitForSignal.  
       
   659  *
       
   660  ***************************************************************************************/
       
   661 int CExecuteCommand::HandleWaitForSignal( CDataRecord *aArgs )
       
   662 {
       
   663 	return iSync->WaitFromScript();
       
   664 }
       
   665 
       
   666 
       
   667 /****************************************************************************************
       
   668  *
       
   669  * Private Method: HandleSignal.  
       
   670  *
       
   671  ***************************************************************************************/
       
   672 int CExecuteCommand::HandleSignal( CDataRecord *aArgs )
       
   673 {
       
   674 	return iSync->SignalFromScript();
       
   675 }
       
   676 
       
   677 
       
   678 /****************************************************************************************
       
   679  *
       
   680  * Private Method: HandleRendezvous.  
       
   681  *
       
   682  ***************************************************************************************/
       
   683 int CExecuteCommand::HandleRendezvous( CDataRecord *aArgs )
       
   684 {
       
   685 	return iSync->RendezvousFromScript();
       
   686 }
       
   687 
       
   688 
       
   689 /****************************************************************************************
       
   690  *
       
   691  * PRIVATE METHODS: Manage the command contexts
       
   692  *
       
   693  ***************************************************************************************/
       
   694 void CExecuteCommand::ClearCommandContext()
       
   695 {
       
   696 	int i;
       
   697 	for( i = 0; i <iCommandContextSize; i++ ) {
       
   698 		assert( iCommandContextArgs[i] != NULL );
       
   699 		delete iCommandContextArgs[i];
       
   700 		iCommandContextArgs[i] = NULL;
       
   701 	}
       
   702 	iCommandContextSize = 0;
       
   703 }
       
   704 
       
   705 
       
   706 void CExecuteCommand::AddToCommandContext( TUccsCommand aCommand, CDataRecord *aRec )
       
   707 {
       
   708 	assert( aRec != NULL );
       
   709 	assert( iCommandContextSize < MAXRECENTCOMMANDS );
       
   710 	iCommandContextCommands[iCommandContextSize] = aCommand;
       
   711 	iCommandContextArgs[iCommandContextSize++] = aRec;
       
   712 }
       
   713 
       
   714 
       
   715 /****************************************************************************************
       
   716  *
       
   717  * PUBLIC METHODS: To get the value of an varible in the environment
       
   718  *
       
   719  ***************************************************************************************/
       
   720 int CExecuteCommand::GetEnvironmentVariable ( char *aVariableName, char *aOutputBuffer, int aOutputBufferSize )
       
   721 {
       
   722 	int ret, len;
       
   723 	char* fieldValue;
       
   724 
       
   725 	// Check params
       
   726 	assert ( aVariableName != NULL );
       
   727 	assert ( aOutputBuffer != NULL );
       
   728 	assert ( aOutputBufferSize > 0 );
       
   729 
       
   730 	// If there is nothing in the environment then return that env var not found Error
       
   731 	if ( iEnvironment == NULL )
       
   732 		return UCCS_NOENVIRONMENT;
       
   733 
       
   734 	// Query the environment for this variable name
       
   735 	ret = iEnvironment->GetFieldAsString( aVariableName, &fieldValue );
       
   736 	assert ( (ret == UCCS_OK) || (ret == UCCS_FIELDNOTFOUND) ); 
       
   737 	if( ret == UCCS_FIELDNOTFOUND ) 
       
   738 		return UCCS_VARIABLEDOESNOTEXIST;
       
   739 
       
   740 	// Now copy the fieldValue returned into the return output buffer
       
   741 	// First check we have sufficient memory to hold the value in the return buffer
       
   742 	len = strlen (fieldValue) + 1;
       
   743 
       
   744 	if ( len > aOutputBufferSize )
       
   745 		return UCCS_VARIABLEVALTOOLONG;
       
   746 
       
   747 	// Else we copy the data
       
   748 	memcpy( aOutputBuffer, fieldValue, len );
       
   749 
       
   750 	return UCCS_OK;
       
   751 }
       
   752 
       
   753 
       
   754