📄 objectclass.cc
字号:
{ if (server->dominates(new_levelID, LevelID) == RTI_FALSE) throw SecurityError("Attempt to lower object class level."); LevelID = new_levelID ;}// ----------------------------------------------------------------------------/*! Return RTI_TRUE if theFederate had never subscribed to this class before. In that case, ObjectClassSet will call SendDiscoverMessages on this class and on all child classes to allow them to send Discover Messages for already registered instances.*/BooleanObjectClass::subscribe(FederateHandle theFederate, AttributeHandle *theAttributeList, UShort theListSize, bool SubOrUnsub) throw (AttributeNotDefined, RTIinternalError, SecurityError){ // Check Security Levels checkFederateAccess(theFederate, "Subscribe"); // Do all attribute handles exist ? It may throw AttributeNotDefined. for (UShort index = 0 ; index < theListSize ; index++) getAttributeWithHandle(theAttributeList[index]); // Save the Federate number. if (theFederate > MaxSubscriberHandle) MaxSubscriberHandle = theFederate ; // A new subscribtion invalidates all previous subscription to the same // object class, so we first remove all previous subscription information. D.Out(pdInit, "ObjectClass %d: Resetting previous Sub info of Federate %d.", handle, theFederate); Boolean wasPreviousSubscriber = RTI_FALSE ; list<ObjectClassAttribute *>::iterator a ; for (a = attributeSet.begin(); a != attributeSet.end(); a++) { if ((*a)->hasSubscribed(theFederate)) { (*a)->unsubscribe(theFederate); wasPreviousSubscriber = RTI_TRUE ; } } // Subscribe to attributes one by one. ObjectClassAttribute *attribute ; for (UShort index = 0 ; index < theListSize ; index++) { D.Out(pdInit, "ObjectClass %d: Federate %d subscribes to attribute %d.", handle, theFederate, theAttributeList[index]); attribute = getAttributeWithHandle(theAttributeList[index]); if (SubOrUnsub) attribute->subscribe(theFederate); else attribute->unsubscribe(theFederate); } // If the Federate was not a subscriber before, and has now subscribed // to at least one attribute, it must discover class' current instances. // BUG: If the Federate unsubscribe, he should receive RemoveObject msgs? if ((wasPreviousSubscriber == RTI_FALSE) && // Not sub. before (SubOrUnsub == RTI_TRUE) && // subscribe(and not Unsub.) (theListSize > 0)) // at least to 1 attribute. return RTI_TRUE ; else return RTI_FALSE ;}// ----------------------------------------------------------------------------//! update Attribute Values (with time).ObjectClassBroadcastList *ObjectClass::updateAttributeValues(FederateHandle the_federate, ObjectHandle the_object, AttributeHandle *the_attributes, AttributeValue *the_values, UShort the_size, FederationTime the_time, const char *the_tag) throw (ObjectNotKnown, AttributeNotDefined, AttributeNotOwned, RTIinternalError, InvalidObjectHandle){ // Pre-conditions checking Object *object = getInstanceWithID(the_object); // Ownership management: Test ownership on each attribute before updating. ObjectAttribute * oa ; for (int i = 0 ; i < the_size ; i++) { oa = object->getAttribute(the_attributes[i]); if (oa->getOwner() != the_federate) throw AttributeNotOwned(); } // Federate must be Owner of all attributes(not Owner of the instance). // if (object->getOwner() != the_federate) // throw AttributeNotOwned(); // Prepare and Broadcast message for this class ObjectClassBroadcastList *ocbList = NULL ; if (server != NULL) { NetworkMessage *answer = new NetworkMessage ; answer->type = NetworkMessage::REFLECT_ATTRIBUTE_VALUES ; answer->federation = server->federation(); answer->federate = the_federate ; answer->exception = e_NO_EXCEPTION ; answer->object = the_object ; answer->date = the_time ; strcpy(answer->label, the_tag); answer->handleArraySize = the_size ; for (int i = 0 ; i < the_size ; i++) { answer->handleArray[i] = the_attributes[i] ; answer->setValue(i, the_values[i]); } ocbList = new ObjectClassBroadcastList(answer, attributeSet.size()); D.Out(pdProtocol, "Object %u updated in class %u, now broadcasting...", the_object, handle); broadcastClassMessage(ocbList); } else { D.Out(pdExcept, "UpdateAttributeValues should not be called on the RTIA."); throw RTIinternalError("UpdateAttributeValues called on the RTIA."); } // Return the BroadcastList in case it had to be passed to the parent // class. return ocbList ;}// ----------------------------------------------------------------------------//! negotiatedAttributeOwnershipDivestiture.ObjectClassBroadcastList * ObjectClass::negotiatedAttributeOwnershipDivestiture(FederateHandle theFederateHandle, ObjectHandle theObjectHandle, AttributeHandle *theAttributeList, UShort theListSize, const char *theTag) throw (ObjectNotKnown, AttributeNotDefined, AttributeNotOwned, AttributeAlreadyBeingDivested, RTIinternalError){ // Pre-conditions checking // may throw ObjectNotKnown Object *object = getInstanceWithID(theObjectHandle); // Do all attribute handles exist ? It may throw AttributeNotDefined. for (int index = 0 ; index < theListSize ; index++) getAttributeWithHandle(theAttributeList[index]); // Does federate owns every attributes. // Does federate has called NegotiatedAttributeOwnershipDivestiture. D.Out(pdDebug, "NegotiatedDivestiture Demandeur : %u", theFederateHandle); ObjectAttribute * oa ; ObjectClassAttribute * oca ; for (int i = 0 ; i < theListSize ; i++) { oca = getAttributeWithHandle(theAttributeList[i]); oa = object->getAttribute(theAttributeList[i]); D.Out(pdDebug, "Attribute Name : %s", oca->getName()); D.Out(pdDebug, "Attribute Handle : %u", oa->getHandle()); D.Out(pdDebug, "Attribute Owner : %u", oa->getOwner()); if (oa->getOwner() != theFederateHandle) throw AttributeNotOwned(); if (oa->beingDivested()) throw AttributeAlreadyBeingDivested(); } int compteur_acquisition = 0 ; int compteur_assumption = 0 ; int compteur_divestiture = 0 ; ObjectClassBroadcastList *List = NULL ; FederateHandle NewOwner ; if (server != NULL) { NetworkMessage *AnswerAssumption = NULL ; NetworkMessage *AnswerDivestiture = NULL ; AnswerDivestiture = new NetworkMessage ; AnswerAssumption = new NetworkMessage ; AnswerAssumption->handleArraySize = theListSize ; CDiffusion *diffusionAcquisition = new CDiffusion(); ObjectAttribute * oa ; ObjectClassAttribute * oca ; for (int i = 0 ; i < theListSize ; i++) { oa = object->getAttribute(theAttributeList[i]); if (oa->hasCandidates()) { // An attributeOwnershipAcquisition is on the way // with this attribute. // Le demandeur le plus r閏ent devient propri閠aire NewOwner = oa->getCandidate(1); oa->setOwner(NewOwner); // On le supprime de la liste des demandeurs oa->removeCandidate(NewOwner); // On r閕nitialise divesting oa->setDivesting(RTI_FALSE); diffusionAcquisition->DiffArray[compteur_acquisition] .federate = NewOwner ; diffusionAcquisition->DiffArray[compteur_acquisition] .attribute = oa->getHandle(); compteur_acquisition++ ; AnswerDivestiture->handleArray[compteur_divestiture] = theAttributeList[i] ; compteur_divestiture++ ; if (!strcmp(oca->getName(), "privilegeToDelete")) { object->setOwner(NewOwner); } } else { AnswerAssumption->handleArray[compteur_assumption] = theAttributeList[i] ; oa->setDivesting(RTI_TRUE); compteur_assumption++ ; } } if (compteur_acquisition != 0) { diffusionAcquisition->size = compteur_acquisition ; sendToOwners(diffusionAcquisition, theObjectHandle, theFederateHandle, theTag, NetworkMessage::ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION); } delete diffusionAcquisition ; if (compteur_divestiture !=0) { AnswerDivestiture->type = NetworkMessage::ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION ; AnswerDivestiture->federation = server->federation(); AnswerDivestiture->federate = theFederateHandle ; AnswerDivestiture->exception = e_NO_EXCEPTION ; AnswerDivestiture->object = theObjectHandle ; strcpy(AnswerDivestiture->label, "\0"); AnswerDivestiture->handleArraySize = compteur_divestiture ; sendToFederate(AnswerDivestiture, theFederateHandle); } else delete AnswerDivestiture ; if (compteur_assumption !=0) { AnswerAssumption->type = NetworkMessage::REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION ; AnswerAssumption->federation = server->federation(); AnswerAssumption->federate = theFederateHandle ; AnswerAssumption->exception = e_NO_EXCEPTION ; AnswerAssumption->object = theObjectHandle ; strcpy(AnswerAssumption->label, theTag); AnswerAssumption->handleArraySize = compteur_assumption ; List = new ObjectClassBroadcastList(AnswerAssumption, attributeSet.size()); D.Out(pdProtocol, "Object %u divestiture in class %u, now broadcasting...", theObjectHandle, handle); broadcastClassMessage(List); } else delete AnswerAssumption ; } else { D.Out(pdExcept, "NegotiatedAttributeOwnershipDivestiture should not " "be called on the RTIA."); throw RTIinternalError("NegotiatedAttributeOwnershipDivestiture " "called on the RTIA."); } // Return the BroadcastList in case it had to be passed to the parent // class. return List ;}// ----------------------------------------------------------------------------//! attributeOwnershipAcquisitionIfAvailable.void ObjectClass::attributeOwnershipAcquisitionIfAvailable(FederateHandle the_federate, ObjectHandle the_object, AttributeHandle *the_attributes, UShort theListSize) throw (ObjectNotKnown, ObjectClassNotPublished, AttributeNotDefined, AttributeNotPublished, FederateOwnsAttributes, AttributeAlreadyBeingAcquired, RTIinternalError){ // Pre-conditions checking //It may throw ObjectNotKnown. Object *object = getInstanceWithID(the_object); // Do all attribute handles exist ? It may throw AttributeNotDefined. for (int index = 0 ; index < theListSize ; index++) { getAttributeWithHandle(the_attributes[index]); } if (server) { // Federate must publish the class. if (!isFederatePublisher(the_federate)) { D.Out(pdExcept, "exception : ObjectClassNotPublished."); throw ObjectClassNotPublished(); } //rem attributeSet.size()=attributeState.size() ObjectAttribute * oa ; ObjectClassAttribute * oca ; for (int i = 0 ; i < theListSize ; i++) { oca = getAttributeWithHandle(the_attributes[i]); oa = object->getAttribute(the_attributes[i]); // The federate has to publish attributes he desire to // acquire. if (!oca->isPublishing(the_federate) && (strcmp(oca->getName(), "privilegeToDelete"))) throw AttributeNotPublished(); // Does federate already owns some attributes. if (oa->getOwner() == the_federate) throw FederateOwnsAttributes(); // Does federate is on the way to acquire something. if (oa->isCandidate(the_federate)) throw AttributeAlreadyBeingAcquired(); } NetworkMessage *Answer_notification = new NetworkMessage ; Answer_notification->type = NetworkMessage::ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION ; Answer_notification->federation = server->federation(); Answer_notification->federate = the_federate ; Answer_notification->exception = e_NO_EXCEPTION ; Answer_notification->object = the_object ; NetworkMessage *Answer_unavailable = new NetworkMessage ; Answer_unavailable->type = NetworkMessage::ATTRIBUTE_OWNERSHIP_UNAVAILABLE ; Answer_unavailable->federation = server->federation(); Answer_unavailable->federate = the_federate ; Answer_unavailable->exception = e_NO_EXCEPTION ; Answer_unavailable->object = the_object ; CDiffusion *diffusionDivestiture = new CDiffusion(); // //Ce service ne doit pas ajouter le f閐閞
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -