📄 federateambassador.cpp
字号:
//FederateAmbassador.cpp: the implementation of the CFederateAmbassador class
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Global.h"
#include "FederateAmbassador.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern RTI::Boolean TimeAdvGrant;
extern RTIfedTime GrantTime;
extern CFederate Fed;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CFederateAmbassador::CFederateAmbassador()
{
}
CFederateAmbassador::~CFederateAmbassador()
{
}
void CFederateAmbassador::synchronizationPointRegistrationSucceeded(const char *Label)
throw (RTI::FederateInternalError)
{
int i=0;
BOOL issuc = false;
for(i=0;i<Fed.m_SynPoints.GetSize();i++)
{
if((strcmp(Label,Fed.m_SynPoints[i].getlabel()) == 0)&&
Fed.m_SynPoints[i].isRegister())
{issuc = true;break;}
}
if(issuc)
{
//cout<<"Synchronization Point Registration Succeeded: "
// <<label << endl;
Fed.m_SynPoints.RemoveAt(i);
}
// else
// {
//cout<<"RTI::FederateInternalError:"Unexpected exception"<<endl;
// }
}
void CFederateAmbassador::synchronizationPointRegistrationFailed(const char *Label)
throw (RTI::FederateInternalError)
{
int i=0;
BOOL issuc = false;
for(i=0;i<Fed.m_SynPoints.GetSize();i++)
{
if((strcmp(Label,Fed.m_SynPoints[i].getlabel()) == 0)&&
Fed.m_SynPoints[i].isRegister())
{issuc = true;break;}
}
if(issuc)
// {
//cout<<"Synchronization Point Registration failed: "
// <<label << endl;
Fed.m_SynPoints.RemoveAt(i);
// }
// else
// {
//cout<<"RTI::FederateInternalError:"Unexpected exception"<<endl;
// }
}
void CFederateAmbassador::announceSynchronizationPoint(const char *Label, const char *tag)
throw (RTI::FederateInternalError)
{
CSyncPiont syncpoint(Label,tag);
Fed.m_SynPoints.Add(syncpoint);
}
void CFederateAmbassador::federationSynchronized(const char *Label)
throw (RTI::FederateInternalError)
{
int i=0;
for(i=0;i<Fed.m_SynPoints.GetSize();i++)
{
if((strcmp(Label,Fed.m_SynPoints[i].getlabel()) == 0)&&
(!Fed.m_SynPoints[i].isRegister()))
{
Fed.m_SynPoints[i].setSync();
break;
}
}
}
void CFederateAmbassador::initiateFederateSave(const char *Label)
throw (RTI::UnableToPerformSave,
RTI::FederateInternalError)
{
// "your code";
}
void CFederateAmbassador::federationSaved()
throw ( RTI::FederateInternalError)
{
// "your code";
}
void CFederateAmbassador::federationNotSaved()
throw ( RTI::FederateInternalError)
{
// "your code";
}
void CFederateAmbassador::requestFederationRestoreSucceeded(
const char *Label)
throw ( RTI::FederateInternalError)
{
// "your code";
}
void CFederateAmbassador::requestFederationRestoreFailed(
const char *Label)
throw ( RTI::FederateInternalError)
{
// "your code";
}
void CFederateAmbassador::requestFederationRestoreFailed(
const char *Label,
const char *reason)
throw ( RTI::FederateInternalError)
{
// "your code";
}
void CFederateAmbassador::federationRestoreBegun()
throw ( RTI::FederateInternalError)
{
// "your code";
}
void CFederateAmbassador::initiateFederateRestore(
const char *Label,
RTI::FederateHandle Federhandle)
throw ( RTI::SpecifiedSaveLabelDoesNotExist,
RTI::CouldNotRestore,
RTI::FederateInternalError)
{
// "your code";
}
void CFederateAmbassador::federationRestored()
throw ( RTI::FederateInternalError)
{
// "your code";
}
void CFederateAmbassador::federationNotRestored()
throw ( RTI::FederateInternalError)
{
// "your code";
}
void CFederateAmbassador::startRegistrationForObjectClass(
RTI::ObjectClassHandle theClass)
throw ( RTI::ObjectClassNotPublished,
RTI::FederateInternalError)
{
if ( theClass == CPub_Person::GetClassId()) {
CPub_Person::SetRegistration(RTI::RTI_TRUE);
return;
}
AfxMessageBox("FED:startRegistrationForObjectClass unknown class: " + theClass);
}
void CFederateAmbassador::stopRegistrationForObjectClass(
RTI::ObjectClassHandle theClass)
throw ( RTI::ObjectClassNotPublished,
RTI::FederateInternalError)
{
if ( theClass == CPub_Person::GetClassId()) {
CPub_Person::SetRegistration(RTI::RTI_FALSE);
return;
}
AfxMessageBox("FED:stopRegistrationForObjectClass unknown class: " + theClass);
}
void CFederateAmbassador::turnInteractionsOn(
RTI::InteractionClassHandle theInteractionHandle)
throw ( RTI::InteractionClassNotPublished,
RTI::FederateInternalError)
{
if(theInteractionHandle == Communication_inter::GetClassId()) {
Communication_inter::SetInteractionControl(RTI::RTI_TRUE);
return;
}
}
void CFederateAmbassador::turnInteractionsOff(
RTI::InteractionClassHandle theInteractionHandle)
throw ( RTI::InteractionClassNotPublished,
RTI::FederateInternalError)
{
if(theInteractionHandle == Communication_inter::GetClassId()) {
Communication_inter::SetInteractionControl(RTI::RTI_FALSE);
return;
}
}
void CFederateAmbassador::discoverObjectInstance(
RTI::ObjectHandle theObject,
RTI::ObjectClassHandle theClass,
const char * theObjectName)
throw ( RTI::CouldNotDiscover,
RTI::ObjectClassNotKnown,
RTI::FederateInternalError)
{
if ( theClass == CSub_Person::GetClassId()) {
Fed.m_Sub_Persons.AddObjInst(theObject,theObjectName);
return;
}
}
void CFederateAmbassador::reflectAttributeValues(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleValuePairSet& theAttributes,
const RTI::FedTime& theFederateTime,
const char *tag,
RTI::EventRetractionHandle theHandle)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::FederateOwnsAttributes,
RTI::InvalidFederationTime,
RTI::FederateInternalError)
{
CSub_Person* Sub_Person = NULL;
Sub_Person = Fed.m_Sub_Persons.FindObjInst(theObject);
if ( Sub_Person != NULL) {
Sub_Person->ReflectAttributeValues(theAttributes, theFederateTime);
return;
}
}
void CFederateAmbassador::reflectAttributeValues(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleValuePairSet& theAttributes,
const char *tag)
throw ( RTI::ObjectNotKnown,
RTI::FederateOwnsAttributes,
RTI::InvalidFederationTime,
RTI::FederateInternalError)
{
CSub_Person* Sub_Person = NULL;
Sub_Person = Fed.m_Sub_Persons.FindObjInst(theObject);
if ( Sub_Person != NULL) {
Sub_Person->ReflectAttributeValues(theAttributes);
return;
}
}
void CFederateAmbassador::receiveInteraction(
RTI::InteractionClassHandle theInteractionHandle,
const RTI::ParameterHandleValuePairSet& theParameters,
const RTI::FedTime& theFederateTime,
const char *tag,
RTI::EventRetractionHandle theHandle)
throw ( RTI::InteractionClassNotKnown,
RTI::InteractionParameterNotKnown,
RTI::InvalidFederationTime,
RTI::FederateInternalError)
{
int i = 0;
for(i = 0; i < Fed.m_Pub_Persons.GetSize(); i++) {
Fed.m_Pub_Persons.GetAt(i)->ProcessReceiveInter(theInteractionHandle,
theParameters, theFederateTime, tag);
}
Fed.ProcessReceiveInter(theInteractionHandle,theParameters, theFederateTime, tag);
}
void CFederateAmbassador::receiveInteraction(
RTI::InteractionClassHandle theInteractionHandle,
const RTI::ParameterHandleValuePairSet& theParameters,
const char *tag)
throw ( RTI::InteractionClassNotKnown,
RTI::InteractionParameterNotKnown,
RTI::FederateInternalError)
{
int i = 0;
for(i = 0; i < Fed.m_Pub_Persons.GetSize(); i++) {
Fed.m_Pub_Persons.GetAt(i)->ProcessReceiveInter(theInteractionHandle,
theParameters, tag);
}
Fed.ProcessReceiveInter(theInteractionHandle,theParameters, tag);
}
void CFederateAmbassador::removeObjectInstance(
RTI::ObjectHandle theObject,
const RTI::FedTime& theFederateTime,
const char *tag,
RTI::EventRetractionHandle theHandle)
throw ( RTI::ObjectNotKnown,
RTI::InvalidFederationTime,
RTI::FederateInternalError)
{
this->removeObjectInstance(theObject,tag);
}
void CFederateAmbassador::removeObjectInstance(
RTI::ObjectHandle theObject,
const char *tag)
throw ( RTI::ObjectNotKnown,
RTI::InvalidFederationTime,
RTI::FederateInternalError)
{
CSub_Person* Sub_Person = NULL;
Sub_Person = Fed.m_Sub_Persons.FindObjInst(theObject);
if ( Sub_Person != NULL) {
Fed.m_Sub_Persons.RemoveObjInst(theObject);
return;
}
}
void CFederateAmbassador::attributesInScope(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet& theAttributes)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::attributesOutOfScope(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet& theAttributes)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::provideAttributeValueUpdate(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet& theAttributes)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::AttributeNotOwned,
RTI::FederateInternalError)
{
CPub_Person* Pub_Person = NULL;
Pub_Person = Fed.m_Pub_Persons.FindObjInst(theObject);
if ( Pub_Person != NULL) {
Pub_Person->ProvideUpdate(theAttributes);
return;
}
}
void CFederateAmbassador::turnUpdatesOnForObjectInstance(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet& theAttributes)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotOwned,
RTI::FederateInternalError)
{
CPub_Person* Pub_Person = NULL;
Pub_Person = Fed.m_Pub_Persons.FindObjInst(theObject);
if ( Pub_Person != NULL) {
Pub_Person->SetUpdateControl(RTI::RTI_TRUE, theAttributes);
return;
}
}
void CFederateAmbassador::turnUpdatesOffForObjectInstance(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet& theAttributes)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotOwned,
RTI::FederateInternalError)
{
CPub_Person* Pub_Person = NULL;
Pub_Person = Fed.m_Pub_Persons.FindObjInst(theObject);
if ( Pub_Person != NULL) {
Pub_Person->SetUpdateControl(RTI::RTI_FALSE, theAttributes);
return;
}
}
void CFederateAmbassador::requestAttributeOwnershipAssumption(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet& offeredAttributes,
const char *tag)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::AttributeAlreadyOwned,
RTI::AttributeNotPublished,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::attributeOwnershipDivestitureNotification(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet& releasedAttributes)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::AttributeAlreadyOwned,
RTI::AttributeDivestitureWasNotRequested,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::attributeOwnershipAcquisitionNotification(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet& securedAttributes)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::AttributeAcquisitionWasNotRequested,
RTI::AttributeAlreadyOwned,
RTI::AttributeNotPublished,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::attributeOwnershipUnavailable(
RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet &theAttributes)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::AttributeAcquisitionWasNotRequested,
RTI::AttributeAlreadyOwned,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::requestAttributeOwnershipRelease(RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet &candidateAttributes,
const char *tag)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::AttributeNotOwned,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::confirmAttributeOwnershipAcquisitionCancellation(RTI::ObjectHandle theObject,
const RTI::AttributeHandleSet &theAttributes)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::AttributeAlreadyOwned,
RTI::AttributeAcquisitionWasNotCanceled,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::informAttributeOwnership(RTI::ObjectHandle theObject,
RTI::AttributeHandle theAttribute,
RTI::FederateHandle Federhandle)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::attributeIsNotOwned(RTI::ObjectHandle theObject, RTI::AttributeHandle theAttribute)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::attributeOwnedByRTI(RTI::ObjectHandle theObject, RTI::AttributeHandle theAttribute)
throw ( RTI::ObjectNotKnown,
RTI::AttributeNotKnown,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
void CFederateAmbassador::timeRegulationEnabled(const RTI::FedTime &theFederateTime)
throw ( RTI::InvalidFederationTime,
RTI::EnableTimeRegulationWasNotPending,
RTI::FederateInternalError)
{
GrantTime = theFederateTime;
TimeAdvGrant = RTI::RTI_TRUE;
Fed.SetRegulationFlag(RTI::RTI_TRUE);
}
void CFederateAmbassador::timeConstrainedEnabled(const RTI::FedTime &theFederateTime)
throw ( RTI::InvalidFederationTime,
RTI::EnableTimeConstrainedWasNotPending,
RTI::FederateInternalError)
{
GrantTime = theFederateTime;
TimeAdvGrant = RTI::RTI_TRUE;
Fed.SetConstrainedFlag(RTI::RTI_TRUE);
}
void CFederateAmbassador::timeAdvanceGrant(const RTI::FedTime &theTime)
throw ( RTI::InvalidFederationTime,
RTI::TimeAdvanceWasNotInProgress,
RTI::FederateInternalError)
{
GrantTime = theTime;
TimeAdvGrant = RTI::RTI_TRUE;
}
void CFederateAmbassador::requestRetraction(RTI::EventRetractionHandle theHandle)
throw ( RTI::EventNotKnown,
RTI::FederateInternalError)
{
// "FED: federationNotSaved not supported in FED";
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -