示例#1
0
/*
 *******************************************************************
 * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Paramters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int CGBLLAEGetLA::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
	CKBehavior* beh = behaviorContext.Behavior;
  	CKContext* ctx = behaviorContext.Context;


	IGBLSMProfileAccess* pin = NULL;
    CGBLSMStorageManager *storageManager = (CGBLSMStorageManager *)ctx->GetManagerByGuid(GBLSMStorageManagerGUID);
	IGBLSMLAAccess *laInterface = storageManager->GetLAInterface();

	char *arrayName = "laList";
	CKDataArray* array;

	array = (CKDataArray *)ctx->GetObjectByNameAndClass(arrayName,CKCID_DATAARRAY,NULL);

	if ( !array )
	{
		array = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,arrayName, CK_OBJECTCREATION_DYNAMIC);
		behaviorContext.CurrentLevel->AddObject( array );
	
		array->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAID" );
	}
	else
	{
		array->Clear();
	}

	CGBLCOError res = laInterface->RetrieveLAList(array);
	if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
	{
		beh->ActivateInput(0, FALSE);
		beh->SetOutputParameterObject(0, array);
		beh->ActivateOutput(0);
	}
	else
	{
		beh->ActivateInput(0, FALSE);
		CKParameterOut *parameterOutError = beh->GetOutputParameter(1);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_GETLISTOFLAIDS,GBLLAE_ERROR_GETLISTOFLAIDS_DESC);
		beh->ActivateOutput(1);
	}

    return CKBR_OK;
}
示例#2
0
/*
 *******************************************************************
 * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Paramters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int CGBLLAEGetLAE::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
	CKBehavior* beh = behaviorContext.Behavior;
  	CKContext* ctx = behaviorContext.Context;


	IGBLSMProfileAccess* pin = NULL;
    CGBLSMStorageManager *storageManager = (CGBLSMStorageManager *)ctx->GetManagerByGuid(GBLSMStorageManagerGUID);
	IGBLSMLAAccess *laInterface = storageManager->GetLAInterface();
	IGBLSMLAEAccess *laeInterface = storageManager->GetLAEInterface();

	char *laListArrayName = "laList";
	CKDataArray* laListArray;
	laListArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laListArrayName, CK_OBJECTCREATION_DYNAMIC);
	behaviorContext.CurrentLevel->AddObject( laListArray );
	laListArray->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAID" );

	char *laeArrayName = "laeidList";
	CKDataArray* laeArray;
	laeArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laeArrayName, CK_OBJECTCREATION_DYNAMIC);
	behaviorContext.CurrentLevel->AddObject( laeArray );
	laeArray->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAEID" );


	char *laelaArrayName = "laelaIDList";
	CKDataArray* laelaArray;
	laelaArray = (CKDataArray *)ctx->GetObjectByNameAndClass(laelaArrayName,CKCID_DATAARRAY,NULL);

	if ( !laelaArray )
	{
		laelaArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laelaArrayName, CK_OBJECTCREATION_DYNAMIC);
		behaviorContext.CurrentLevel->AddObject( laelaArray );
	
		laelaArray->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAEID" );
		laelaArray->InsertColumn( -1, CKARRAYTYPE_STRING,	 "LAID" );
	}
	else
	{
		laelaArray->Clear();
	}

	CGBLCOError res = laInterface->RetrieveLAList(laListArray);

	if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
	{
		int count = laListArray->GetRowCount();
		for (int i=0; i < count; i++)
		{
			//get list of laes for given la and add it to results list

			XString xLAID;

			CKSTRING valueField = NULL;
			int labelLength =  laListArray->GetElementStringValue(i, 0, NULL);
			valueField = new CKCHAR[labelLength];
			labelLength =  laListArray->GetElementStringValue(i, 0, valueField);
			xLAID = valueField;
			delete valueField;


			CGBLLAID laid; 
			laid.FromString(xLAID);

			CGBLCOError res = laeInterface->RetrieveLAEList(laeArray,laid);
			if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
			{
				int count = laeArray->GetRowCount();
				for (int j=0; j < count; j++)
				{
					CKSTRING valueField = NULL;
					int labelLength =  laeArray->GetElementStringValue(j, 0, NULL);
					valueField = new CKCHAR[labelLength];

					labelLength =  laeArray->GetElementStringValue(j, 0, valueField);

					laelaArray->AddRow();
					laelaArray->SetElementStringValue(laelaArray->GetRowCount()-1, 0, valueField);
					laelaArray->SetElementStringValue(laelaArray->GetRowCount()-1, 1, xLAID.Str());

					delete valueField;
				}
			}
		}
		beh->ActivateInput(0, FALSE);
		beh->SetOutputParameterObject(0, laelaArray);
		beh->ActivateOutput(0);
	}
	else
	{
		
		beh->ActivateInput(0, FALSE);
		CKParameterOut *parameterOutError = beh->GetOutputParameter(1);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_GETLISTOFLAIDS,GBLLAE_ERROR_GETLISTOFLAIDS_DESC);
		beh->ActivateOutput(1);
	}

	behaviorContext.CurrentLevel->RemoveObject(laListArray);
	ctx->DestroyObject(laListArray);
	behaviorContext.CurrentLevel->RemoveObject(laeArray);
	ctx->DestroyObject(laeArray);
    return CKBR_OK;
}