/* ******************************************************************* * Function: CKBehavior* GetTargetCommand(const int commandId, const CKBehaviorContext& behaviorContext) * * Description : Gets target behavior object given the command ID * * Paramters : * * commandId r command id of the target object to get * behaviorContext r context * * Returns : * pointer to the behavior object, NULL if no object found * ******************************************************************* */ CKBehavior* CGBLCommandController::GetTargetCommand(const int commandId, const CKBehaviorContext& behaviorContext) { CKBehavior* targetBehavior = NULL; CKContext* context = behaviorContext.Context; int behaviorCount = context->GetObjectsCountByClassID(CKCID_BEHAVIOR); CK_ID* behaviorIds = context->GetObjectsListByClassID(CKCID_BEHAVIOR); int currentID; for (int i = 0; i < behaviorCount; ++i) { CKBehavior* behavior = (CKBehavior*)context->GetObject(behaviorIds[i]); if (behavior->GetPrototypeGuid() == GUID_GBLWAITFORCOMMAND_PROTOTYPE) { CKParameterLocal *localParam = NULL; localParam = behavior->GetLocalParameter(2); //Get command ID if (localParam != NULL) { localParam->GetValue(¤tID); //Get command ID's value localParam = NULL; } else { break; } if (currentID == commandId) { targetBehavior = behavior; break; } } } return targetBehavior; }
/* ******************************************************************* * Function: CKERROR BGWrapperCB(const CKBehaviorContext& behContext) * * Description : The Behavior Callback function is called by Virtools * when various events happen in the life of a BuildingBlock. * * Parameters : * behaviourContext Behavior context reference, which gives access to * frequently used global objects ( context, level, manager, etc... ) * * Returns : CKERROR * ******************************************************************* */ CKERROR GBLCOBGWrapper::BGWrapperCB(const CKBehaviorContext& behContext) { CKERROR result = CKBR_GENERICERROR; // Initialize common pointers. CKBehavior *behaviour = behContext.Behavior; CKContext *context = behContext.Context; CKLevel *level = behContext.CurrentLevel; CKBeObject *owner = behContext.Behavior->GetOwner(); char*name = behaviour->GetName(); if ( behaviour == NULL || context == NULL || level == NULL /*|| owner == NULL*/ ) return CKBR_OK; //Get The BG Script Object if exists CKBehavior* newBG = NULL; CKBehavior* curBG = (CKBehavior*)behaviour->GetLocalParameterObject(EGBLCOBGWRAPPERPARAM_PARAMETER_SCRIPT); // Get the BG nms file path. GetStringValue doesn't work with setting... char fileName[_MAX_PATH+1]; memset(fileName,0,_MAX_PATH+1); CKParameter* scriptPath = behaviour->GetLocalParameter(EGBLCOBGWRAPPERPARAM_PARAMETER_NAME); if ( scriptPath == NULL ) return CKBR_OK; int lenPath = scriptPath->GetDataSize(); if ( lenPath >= _MAX_PATH ) return CKBR_OK; void*ptrPath = scriptPath->GetReadDataPtr(TRUE); if ( ptrPath == NULL ) return CKBR_OK; memcpy(fileName,ptrPath,lenPath); CKDWORD message = behContext.CallbackMessage; switch (message) { case CKM_BEHAVIORLOAD : // when the behavior is loaded case CKM_BEHAVIORRESET: // when the behavior is reseted case CKM_BEHAVIORSETTINGSEDITED : // when the settings are edited { if ( curBG != NULL ) { DestroyCurrentBG(level,behaviour,curBG); curBG = NULL; } newBG = BGLoader( fileName, behContext ); if ( newBG == NULL ) return CKBR_OK; if ( message == CKM_BEHAVIORLOAD || message == CKM_BEHAVIORRESET ) { //context->OutputToConsoleExBeep("%s : LOADED %s",behaviour->GetName(), fileName); if ( CheckIO(behaviour, newBG) == TRUE ) result = CKBR_OK; else context->OutputToConsoleExBeep("%s : Too many inputs/outputs changes in %s\r\nPlease reconstruct the wrapper.",behaviour->GetName(), fileName); } else if ( message == CKM_BEHAVIORSETTINGSEDITED ) { if ( CheckIO(behaviour, newBG) == TRUE ) { result = CKBR_OK; } else if (DeleteIO(behaviour) == TRUE) { if ( CreateIO(behaviour, newBG ) == TRUE ) result = CKBR_OK; else context->OutputToConsoleExBeep("%s : Cannot Create Inputs/Outputs %s",behaviour->GetName(), fileName); } else context->OutputToConsoleExBeep("%s : Cannot Delete Inputs/Outputs %s",behaviour->GetName(), fileName); } if ( result == CKBR_OK && newBG != NULL ) SetNewBG(behaviour,newBG); } break; case CKM_BEHAVIORDEACTIVATESCRIPT: { if ( curBG != NULL ) DesactivateSubBB(curBG); result = CKBR_OK; } break; case CKM_BEHAVIORDETACH : // when the behavior is deleted { if (curBG != NULL) { DestroyCurrentBG(level,behaviour,curBG); curBG = NULL; } result = CKBR_OK; } break; default: { result = CKBR_OK; } break; } if (result != CKBR_OK) context->OutputToConsoleExBeep("%s : Problem while manipulating",behaviour->GetName()); return result; }
/* ******************************************************************* * Function: int CGBLBuildCommand::DoHandleNextNetworkArgument (const CKBehaviorContext& behaviorContext) * * Description : Checks if there are more arguments to be specified for network command * and takes corresponded actions * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * ******************************************************************* */ int CGBLBuildCommand::DoHandleNextNetworkArgument (const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; int gblBuildCommandState; CKBehavior* targetBB = NULL; CK_ID targetID; behavior->GetLocalParameterValue (targetBBLocalPos, &targetID); targetBB = (CKBehavior*)behaviorContext.Context->GetObject(targetID); if (targetBB == NULL) { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } int currentParameterPosition = 0; behavior->GetLocalParameterValue (currentParameterPositionLocalPos, ¤tParameterPosition); CKParameter* nextArgument = CGBLCommandUtil::GetCommandArgument(*targetBB, currentParameterPosition); currentParameterPosition++; behavior->SetLocalParameterValue (currentParameterPositionLocalPos, ¤tParameterPosition); if (nextArgument == NULL) { //no arguments required, build finished CKParameter *outputCommandString, *localCommandString; CKParameter *outputDests; CKParameterIn *inputDests; ClearParameterOutputs(behaviorContext); outputCommandString = (CKParameter*) behavior->GetOutputParameter (EGBLBuildCommandParamOutputs::GetCommandString); localCommandString = (CKParameter*) behavior->GetLocalParameter (commandStringLocalPos); outputCommandString->CopyValue(localCommandString); // Copy list of recipients from input to output outputDests = (CKParameter*) (behavior->GetOutputParameter (EGBLBuildCommandParamOutputs::GetDests)); inputDests = behavior->GetInputParameter (EGBLBuildCommandParamInputs::SetDests); outputDests->CopyValue(inputDests->GetDirectSource()); gblBuildCommandState = EGBLBuildCommandState::Completed; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::HandleTargetedCommand); return CKBR_OK; } else { //get next argument gblBuildCommandState = EGBLBuildCommandState::AwaitingParametersForNetwork; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState); GetNextArgument (nextArgument, targetBB, behaviorContext); return CKBR_OK; } }
/* ******************************************************************* * Function: int CGBLBuildCommand::DoHandleNextLocalArgument (const CKBehaviorContext& behaviorContext) * * Description : Checks if there are more arguments to be specified for global command * and takes corresponded actions * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * ******************************************************************* */ int CGBLBuildCommand::DoHandleNextLocalArgument (const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; int gblBuildCommandState; CKBehavior* targetBB = NULL; CK_ID targetID; behavior->GetLocalParameterValue (targetBBLocalPos, &targetID); targetBB = (CKBehavior*)behaviorContext.Context->GetObject(targetID); if (targetBB == NULL) { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } int currentParameterPosition = 0; behavior->GetLocalParameterValue (currentParameterPositionLocalPos, ¤tParameterPosition); CKParameter* nextArgument = CGBLCommandUtil::GetCommandArgument(*targetBB, currentParameterPosition); currentParameterPosition++; behavior->SetLocalParameterValue (currentParameterPositionLocalPos, ¤tParameterPosition); if (nextArgument == NULL) { //no arguments required, build finished //char commandString[512]; //behavior->GetLocalParameterValue(commandStringLocalPos,&commandString); CKSTRING commandString = (CKSTRING) behavior->GetLocalParameter(commandStringLocalPos)->GetReadDataPtr(); int res = CGBLCommandUtil::InvokeCommand (commandString, behaviorContext); ClearParameterOutputs(behaviorContext); if (res != CK_OK) { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_INVOKING_FAILED, GBLFC_ERROR_BUILDCOMMAND_INVOKING_FAILED_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } behavior->ActivateOutput (EGBLBuildCommandBehOutputs::HandleUntargetedCommand); return CKBR_OK; } else { //get next argument gblBuildCommandState = EGBLBuildCommandState::AwaitingParametersForUntargeted; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState); GetNextArgument (nextArgument, targetBB, behaviorContext); return CKBR_OK; } }
/* ******************************************************************* * Function: int CGBLBuildCommand::DoReadNextParameterValue (const CKBehaviorContext& behaviorContext) * * Description : Read next provided argument from SetParameterString p-in and add it to command string * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * ******************************************************************* */ int CGBLBuildCommand::DoReadNextParameterValue (const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; int gblBuildCommandState; behavior->GetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState); switch (gblBuildCommandState) { case EGBLBuildCommandState::Initial: { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } break; case EGBLBuildCommandState::GetTargets: { //check if the array of recipients is provided void* recipients = NULL; recipients = behavior->GetInputParameter (EGBLBuildCommandParamInputs::SetDests)->GetDirectSource()->GetValueObject(); if (recipients == NULL) { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_NO_DESTS,GBLFC_ERROR_BUILDCOMMAND_NO_DESTS_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } int targetID = 0; behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetCommandID, &targetID); XString commandString; commandString << targetID << CGBLCommandUtil::commandSeparator; behavior->SetLocalParameterValue(commandStringLocalPos, commandString.Str(), strlen(commandString.Str()) + 1 ); //check if there are more arguments return DoHandleNextNetworkArgument (behaviorContext); } break; case EGBLBuildCommandState::AwaitingParametersForNetwork: case EGBLBuildCommandState::AwaitingParametersForUntargeted: { CKSTRING commandString = (CKSTRING) behavior->GetLocalParameter(commandStringLocalPos)->GetReadDataPtr(); CKSTRING argumentString = (CKSTRING) behavior->GetInputParameter(EGBLBuildCommandParamInputs::SetParameterString)->GetReadDataPtr(); //char commandString[512]; //char argumentString[512]; //behavior->GetLocalParameterValue(commandStringLocalPos,&commandString); //behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetParameterString, &argumentString); if (strlen (argumentString) == 0) { behavior->ActivateOutput (EGBLBuildCommandBehOutputs::InvalidValue); return CKBR_OK; } CKSTRING argumentType = (CKSTRING) behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetArgumentType)->GetReadDataPtr(); if ( (strcmp (argumentType, "Integer") == 0) || (strcmp (argumentType, "Float") == 0)) { bool isArgumentNumeric = CGBLCommandUtil::IsNumeric(argumentString); if (!isArgumentNumeric) { behavior->ActivateOutput (EGBLBuildCommandBehOutputs::InvalidValue); return CKBR_OK; } } XString updatedCommandString; updatedCommandString << commandString << argumentString << CGBLCommandUtil::commandSeparator; behavior->SetLocalParameterValue(commandStringLocalPos, updatedCommandString.Str(), strlen(updatedCommandString.Str()) + 1 ); if (gblBuildCommandState == EGBLBuildCommandState::AwaitingParametersForUntargeted) { return DoHandleNextLocalArgument (behaviorContext); } return DoHandleNextNetworkArgument (behaviorContext); } break; default: break; } return CKBR_OK; }