#include #include "ExampleFedAmb.h" #include "fedtime.hh" using namespace std; ExampleFedAmb::ExampleFedAmb() { // initialize all the variable values this->federateTime = 0.0; this->federateLookahead = 1.0; this->isRegulating = false; this->isConstrained = false; this->isAdvancing = false; this->isAnnounced = false; this->isReadyToRun = false; } ExampleFedAmb::~ExampleFedAmb() throw( RTI::FederateInternalError ) { } double ExampleFedAmb::convertTime( const RTI::FedTime& theTime ) { RTIfedTime castedTime = (RTIfedTime)theTime; return castedTime.getTime(); } /////////////////////////////////////////////////////////////////////////////// /////////////////////// Synchronization Point Callbacks /////////////////////// /////////////////////////////////////////////////////////////////////////////// void ExampleFedAmb::synchronizationPointRegistrationSucceeded( const char* label ) throw(RTI::FederateInternalError) { cout << "Successfully registered sync point: " << label << endl; } void ExampleFedAmb::synchronizationPointRegistrationFailed( const char *label ) throw(RTI::FederateInternalError) { cout << "Failed to register sync point: " << label << endl; } void ExampleFedAmb::announceSynchronizationPoint( const char *label, const char *tag ) throw(RTI::FederateInternalError) { cout << "Synchronization point announced: " << label << endl; if( strcmp(label,"ReadyToRun") == 0 ) this->isAnnounced = true; } void ExampleFedAmb::federationSynchronized( const char *label ) throw(RTI::FederateInternalError) { cout << "Federation Synchronized: " << label << endl; if( strcmp(label,"ReadyToRun") == 0 ) this->isReadyToRun = true; } /////////////////////////////////////////////////////////////////////////////// //////////////////////////////// Time Callbacks /////////////////////////////// /////////////////////////////////////////////////////////////////////////////// void ExampleFedAmb::timeRegulationEnabled( const RTI::FedTime& theFederateTime ) throw( RTI::InvalidFederationTime, RTI::EnableTimeRegulationWasNotPending, RTI::FederateInternalError ) { this->isRegulating = true; this->federateTime = convertTime( theFederateTime ); } void ExampleFedAmb::timeConstrainedEnabled( const RTI::FedTime& theFederateTime ) throw( RTI::InvalidFederationTime, RTI::EnableTimeConstrainedWasNotPending, RTI::FederateInternalError) { this->isConstrained = true; this->federateTime = convertTime( theFederateTime ); } void ExampleFedAmb::timeAdvanceGrant( const RTI::FedTime& theTime ) throw( RTI::InvalidFederationTime, RTI::TimeAdvanceWasNotInProgress, RTI::FederateInternalError) { this->isAdvancing = false; this->federateTime = convertTime( theTime ); } /////////////////////////////////////////////////////////////////////////////// ///////////////////////// Object Management Callbacks ///////////////////////// /////////////////////////////////////////////////////////////////////////////// // // // Discover Object Methods // // // void ExampleFedAmb::discoverObjectInstance( RTI::ObjectHandle theObject, RTI::ObjectClassHandle theObjectClass, const char* theObjectName ) throw( RTI::CouldNotDiscover, RTI::ObjectClassNotKnown, RTI::FederateInternalError ) { cout << "Discoverd Object: handle=" << theObject << ", classHandle=" << theObjectClass << ", name=" << theObjectName << endl; } // // // Reflect Attribute Value Methods // // // void ExampleFedAmb::reflectAttributeValues( RTI::ObjectHandle theObject, const RTI::AttributeHandleValuePairSet& theAttributes, const char *theTag ) throw( RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::FederateOwnsAttributes, RTI::FederateInternalError ) { cout << "Reflection Received:"; // print the handle cout << " object=" << theObject; // print the tag cout << ", tag=" << theTag; // print the attribute information cout << ", attributeCount=" << theAttributes.size() << endl; for( RTI::ULong i = 0; i < theAttributes.size(); i++ ) { // print the attribute handle cout << "\tattrHandle=" << theAttributes.getHandle(i); // print the attribute value RTI::ULong length = theAttributes.getValueLength(i); char *value = theAttributes.getValuePointer(i,length); cout << ", attrValue=" << value << endl; } } void ExampleFedAmb::reflectAttributeValues( RTI::ObjectHandle theObject, const RTI::AttributeHandleValuePairSet& theAttributes, const RTI::FedTime& theTime, const char *theTag, RTI::EventRetractionHandle theHandle ) throw( RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::FederateOwnsAttributes, RTI::InvalidFederationTime, RTI::FederateInternalError ) { cout << "Reflection Received:"; // print the handle cout << " object=" << theObject; // print the tag cout << ", tag=" << theTag; // print the time cout << ", time=" << convertTime( theTime ); // print the attribute information cout << ", attributeCount=" << theAttributes.size() << endl; for( RTI::ULong i = 0; i < theAttributes.size(); i++ ) { // print the attribute handle cout << "\tattrHandle=" << theAttributes.getHandle(i); // print the attribute value RTI::ULong length = theAttributes.getValueLength(i); char *value = theAttributes.getValuePointer(i,length); cout << ", attrValue=" << value << endl; } } // // // Receive Interaction Methods // // // void ExampleFedAmb::receiveInteraction( RTI::InteractionClassHandle theInteraction, const RTI::ParameterHandleValuePairSet& theParameters, const char *theTag ) throw( RTI::InteractionClassNotKnown, RTI::InteractionParameterNotKnown, RTI::FederateInternalError ) { cout << "Interaction Received:"; // print the handle cout << " handle=" << theInteraction; // print the tag cout << ", tag=" << theTag; // print the attribute information cout << ", parameterCount=" << theParameters.size() << endl; for( RTI::ULong i = 0; i < theParameters.size(); i++ ) { // print the parameter handle cout << "\tparamHandle=" << theParameters.getHandle(i); // print the parameter value RTI::ULong length = theParameters.getValueLength(i); char *value = theParameters.getValuePointer(i,length); cout << ", paramValue=" << value << endl; } } void ExampleFedAmb::receiveInteraction( RTI::InteractionClassHandle theInteraction, const RTI::ParameterHandleValuePairSet& theParameters, const RTI::FedTime& theTime, const char *theTag, RTI::EventRetractionHandle theHandle ) throw( RTI::InteractionClassNotKnown, RTI::InteractionParameterNotKnown, RTI::InvalidFederationTime, RTI::FederateInternalError ) { cout << "Interaction Received:"; // print the handle cout << " handle=" << theInteraction; // print the tag cout << ", tag=" << theTag; // print the time cout << ", time=" << convertTime( theTime ); // print the attribute information cout << ", parameterCount=" << theParameters.size() << endl; for( RTI::ULong i = 0; i < theParameters.size(); i++ ) { // print the parameter handle cout << "\tparamHandle=" << theParameters.getHandle(i); // print the parameter value RTI::ULong length = theParameters.getValueLength(i); char *value = theParameters.getValuePointer(i,length); cout << ", paramValue=" << value << endl; } } // // // Remove Object Methods // // // void ExampleFedAmb::removeObjectInstance( RTI::ObjectHandle theObject, const char *theTag ) throw( RTI::ObjectNotKnown, RTI::FederateInternalError ) { cout << "Object Removed: handle=" << theObject << endl; } void ExampleFedAmb::removeObjectInstance( RTI::ObjectHandle theObject, const RTI::FedTime& theTime, const char *theTag, RTI::EventRetractionHandle theHandle) throw( RTI::ObjectNotKnown, RTI::InvalidFederationTime, RTI::FederateInternalError ) { cout << "Object Removed: handle=" << theObject << endl; }