📄 interaction.cc
字号:
Interaction::getParameterByHandle(ParameterHandle the_handle) const throw (InteractionParameterNotDefined, RTIinternalError){ list<Parameter *>::const_iterator p ; for (p = parameterSet.begin(); p != parameterSet.end(); p++) { if ((*p)->Handle == the_handle) return (*p); } throw InteractionParameterNotDefined();}// ----------------------------------------------------------------------------//! Returns the parameter handle obtained by its name.ParameterHandleInteraction::getParameterHandle(const char *the_name) const throw (InteractionParameterNotDefined, RTIinternalError){ list<Parameter *>::const_iterator p ; for (p = parameterSet.begin(); p != parameterSet.end(); p++) { if (strcmp((*p)->getName(), the_name) == 0) return (*p)->Handle ; } throw InteractionParameterNotDefined();}// ----------------------------------------------------------------------------//! Returns the parameter name obtained by its handle.const char *Interaction::getParameterName(ParameterHandle the_handle) const throw (InteractionParameterNotDefined, RTIinternalError){ return getParameterByHandle(the_handle)->getName();}// ----------------------------------------------------------------------------//! Returns the publisher rank from its handle (private module)./*! Return the Rank of the Federate in the list, or ZERO if not found. */intInteraction::getPublisherRank(FederateHandle the_federate) const{ list<Publisher *>::const_iterator p = publishers.begin(); for (int i = 1 ; p != publishers.end(); i++, p++) { if ((*p)->getHandle() == the_federate) return i ; } return 0 ;}// ----------------------------------------------------------------------------//! Returns the subscriber rank from its handle (private module)./*! Return the Rank of the Federate in the list, or ZERO if not found. */intInteraction::getSubscriberRank(FederateHandle the_federate) const{ list<Subscriber *>::const_iterator s = subscribers.begin(); for (int i = 1 ; s != subscribers.end(); i++, s++) { if ((*s)->getHandle() == the_federate) return i ; } return 0 ;}// ----------------------------------------------------------------------------//! Return true if federate has subscribed to this attribute.boolInteraction::isSubscribed(FederateHandle the_handle) const{ return(getSubscriberRank(the_handle) != 0);}// ----------------------------------------------------------------------------//! Return true if federate is publishing the attribute.boolInteraction::isPublishing(FederateHandle the_handle) const{ return(getPublisherRank(the_handle) != 0);}// ----------------------------------------------------------------------------/*! Check a SendInteractionOrder to see if it's OK for sending, but without sending it(to be called on the RTIA only).*/voidInteraction::isReady(FederateHandle federate_handle, ParameterHandle *parameter_list, UShort list_size) const throw (FederateNotPublishing, InteractionParameterNotDefined, RTIinternalError){ // Is Federate Publishing Interaction? if (!isPublishing(federate_handle)) throw FederateNotPublishing(); // Are Parameters Defined? for (UShort i = 0 ; i < list_size ; i++) getParameterByHandle(parameter_list[i]);}// ----------------------------------------------------------------------------//! killFederate.voidInteraction::killFederate(FederateHandle the_federate) throw (){ try { // Is federate publishing something ? (not important) if (isPublishing(the_federate)) publish(RTI_FALSE, the_federate); // Does federate subscribed to something ? if (isSubscribed(the_federate)) subscribe(RTI_FALSE, the_federate); } catch (SecurityError &e) {}}// ----------------------------------------------------------------------------/*! Pour publier : PubOrUnpub = RTI_TRUE, sinon PubOrUnPub = RTI_FALSE. theHandle : le numero du federe*/voidInteraction::publish(bool publish, FederateHandle the_handle) throw (FederateNotPublishing, RTIinternalError, SecurityError){ bool alreadyPublishing = isPublishing(the_handle); checkFederateAccess(the_handle, (char *) "Publish"); if (publish) { // Federate wants to Publish if (alreadyPublishing == RTI_FALSE) { D.Out(pdInit, "Interaction %d: Added Federate %d to publishers list.", handle, the_handle); addPublisher(the_handle); } else D.Out(pdError, "Interaction %d: Inconsistent publish request from" " Federate %d.", handle, the_handle); } else { // Federate wants to Unpublish if (alreadyPublishing == RTI_TRUE) { D.Out(pdTerm, "Interaction %d: Removed Federate %d from publishers list.", handle, the_handle); deletePublisher(getPublisherRank(the_handle)); } else throw FederateNotPublishing(); }}// ----------------------------------------------------------------------------/*! Called by RTIG in order to start the broadcasting of an Interaction Message(to all federates who subscribed to this Interaction Class).*/InteractionBroadcastList *Interaction::sendInteraction(FederateHandle federate_handle, ParameterHandle *parameter_list, ParameterValue *value_list, UShort list_size, FederationTime theTime, const char *the_tag) throw (FederateNotPublishing, InteractionClassNotDefined, InteractionParameterNotDefined, RTIinternalError){ // Pre-conditions checking if (!isPublishing(federate_handle)) throw FederateNotPublishing(); // Prepare and Broadcast message for this class InteractionBroadcastList *ibList = NULL ; if (server != NULL) { NetworkMessage *answer = new NetworkMessage ; answer->type = m_RECEIVE_INTERACTION ; answer->exception = e_NO_EXCEPTION ; answer->federation = server->federation(); answer->federate = federate_handle ; answer->interactionClass = handle ; // Interaction Class Handle answer->date = theTime ; strcpy(answer->label, the_tag); answer->handleArraySize = list_size ; for (int i = 0 ; i < list_size ; i++) { answer->handleArray[i] = parameter_list[i] ; answer->setValue(i, value_list[i]); } D.Out(pdProtocol, "Preparing broadcast list."); ibList = new InteractionBroadcastList(answer); broadcastInteractionMessage(ibList); } else // SendInteraction should not be called on the RTIA. throw RTIinternalError("SendInteraction called by RTIA."); // Return the BroadcastList in case it had to be passed to the // parent class. return ibList ;}// ----------------------------------------------------------------------------/*! Name attribute access(GetName reference must be considered READ-ONLY). NewName length must be lower or equal to MAX_USER_TAG_LENGTH.*/const char *Interaction::getName(void) const{ return name ;}// ----------------------------------------------------------------------------//! Change the interaction name.voidInteraction::setName(const char *new_name) throw (ValueLengthExceeded, RTIinternalError){ // Check Length if ((new_name == NULL) || (strlen(new_name) > MAX_USER_TAG_LENGTH)) { D.Out(pdExcept, "Interaction Name %s too long.", new_name); throw ValueLengthExceeded("Interaction name too long."); } // Free previous name if (name != NULL) free(name); // Store new name name = strdup(new_name); if (name == NULL) throw RTIinternalError("Memory Exhausted.");}// ----------------------------------------------------------------------------//! Change the level ID./*! A class' LevelID can only be increased. */voidInteraction::setLevelId(SecurityLevelID new_levelID){ if (server->dominates(new_levelID, id) == RTI_FALSE) throw SecurityError("Attempt to lower interaction class level."); id = new_levelID ;}// ----------------------------------------------------------------------------/*! To subscribe, 'subscribe' = RTI_TRUE, otherwise 'subscribe' = RTI_FALSE. theHandle : the federate number.*/voidInteraction::subscribe(bool subscribe, FederateHandle the_handle) throw (FederateNotSubscribing, RTIinternalError, SecurityError){ bool alreadySubscribed = isSubscribed(the_handle); checkFederateAccess(the_handle, "Subscribe"); if (subscribe) { // Federate wants to Subscribe if (alreadySubscribed == RTI_FALSE) { addSubscriber(the_handle); D.Out(pdInit, "Parameter %d: Added Federate %d to subscribers list.", handle, the_handle); } else D.Out(pdError, "Parameter %d: Unconsistent subscribe request from " "federate %d.", handle, the_handle); } else { // Federate wants to unsubscribe if (alreadySubscribed == RTI_TRUE) { deleteSubscriber(getSubscriberRank(the_handle)); D.Out(pdTerm, "Parameter %d: Removed Federate %d from subscribers list.", handle, the_handle); } else throw FederateNotSubscribing(); }}// ----------------------------------------------------------------------------/*! To subscribe, 'subscribe' = RTI_TRUE, otherwise 'subscribe' = RTI_FALSE. Is used to subscribe or not to an interaction in a region.*/voidInteraction::subscribe(bool, Subscriber*) throw (RegionNotKnown, InvalidRoutingSpace, RTIinternalError){ // BUG: Subscribe With Region Not Implemented D.Out(pdExcept, "subscribe(with Region) not implemented in Interaction."); throw RTIinternalError("subscribe(with Region) not implemented.");}} // namespace certi// $Id: Interaction.cc,v 3.10 2003/02/19 18:07:29 breholee Exp $
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -