objectclass.cc~
来自「certi-SHM-3.0.tar 不错的开源的分布式方针软件 大家多多支持 他」· CC~ 代码 · 共 1,185 行 · 第 1/3 页
CC~
1,185 行
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]); attribute->subscribe(theFederate, SubOrUnsub); } // 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 theFederateHandle, ObjectHandle theObjectHandle, AttributeHandle *theAttributeArray, AttributeValue *theValueArray, UShort theArraySize, FederationTime theTime, const char *theUserTag) throw (ObjectNotKnown, AttributeNotDefined, AttributeNotOwned, RTIinternalError, InvalidObjectHandle){ // Pre-conditions checking Object *object = getInstanceWithID(theObjectHandle); // Ownership management: Test ownership on each attribute before updating. ObjectAttribute * oa ; for (int i = 0 ; i < theArraySize ; i++) { oa = object->getAttribute(theAttributeArray[i]); if (oa->getOwner() != theFederateHandle) throw AttributeNotOwned(); } // Federate must be Owner of all attributes(not Owner of the instance). // if (object->Owner != theFederateHandle) // throw AttributeNotOwned(); // Prepare and Broadcast message for this class ObjectClassBroadcastList *ocbList = NULL ; if (server != NULL) { NetworkMessage *answer = new NetworkMessage ; answer->type = m_REFLECT_ATTRIBUTE_VALUES ; answer->federation = server->federation(); answer->federate = theFederateHandle ; answer->exception = e_NO_EXCEPTION ; answer->object = theObjectHandle ; answer->date = theTime ; strcpy(answer->label, theUserTag); answer->handleArraySize = theArraySize ; for (int i = 0 ; i < theArraySize ; i++) { answer->handleArray[i] = theAttributeArray[i] ; answer->setValue(i, theValueArray[i]); } ocbList = new ObjectClassBroadcastList(answer, attributeSet.size()); D.Out(pdProtocol, "Object %u updated in class %u, now broadcasting...", theObjectHandle, 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 ;}// ----------------------------------------------------------------------------//! isAttributeOwnedByFederate.BooleanObjectClass::isAttributeOwnedByFederate(ObjectHandle theObject, AttributeHandle theAttribute, FederateHandle theFederateHandle) throw (ObjectNotKnown, AttributeNotDefined, RTIinternalError){ // Pre-conditions checking // may throw ObjectNotKnown Object* object = getInstanceWithID(theObject); // It may throw AttributeNotDefined getAttributeWithHandle(theAttribute); D.Out(pdDebug, "isAttributeOwnedByFederate sur l'attribut %u de l'objet %u", theAttribute, theObject); ObjectAttribute * oa ; if (server != NULL) { oa = object->getAttribute(theAttribute); return (oa->getOwner() == theFederateHandle) ? RTI_TRUE : RTI_FALSE ; } else { D.Out(pdDebug, "Only called on RTIG"); } return RTI_FALSE ;}// ----------------------------------------------------------------------------//! queryAttributeOwnership.voidObjectClass::queryAttributeOwnership(ObjectHandle theObject, AttributeHandle theAttribute, FederateHandle theFederateHandle) throw (ObjectNotKnown, AttributeNotDefined, RTIinternalError){ // Pre-conditions checking // may throw ObjectNotKnown Object* object = getInstanceWithID(theObject); // It may throw AttributeNotDefined getAttributeWithHandle(theAttribute); D.Out(pdDebug, "queryAttributeOwnership sur l'attribut %u de l'objet %u", theAttribute, theObject); if (server != NULL) { ObjectAttribute * oa ; oa = object->getAttribute(theAttribute); NetworkMessage *answer = new NetworkMessage ; answer->federation = server->federation(); answer->exception = e_NO_EXCEPTION ; answer->object = theObject ; answer->handleArray[0] = theAttribute ; answer->federate = oa->getOwner(); if (answer->federate != 0) answer->type = m_INFORM_ATTRIBUTE_OWNERSHIP ; else answer->type = m_ATTRIBUTE_IS_NOT_OWNED ; sendToFederate(answer, theFederateHandle); } else { D.Out(pdDebug, "Only called on RTIG"); }}// ----------------------------------------------------------------------------//! 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") == 0) object->Owner = 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, m_ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION); } delete diffusionAcquisition ; if (compteur_divestiture !=0) { AnswerDivestiture->type = m_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 = m_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 theFederateHandle, ObjectHandle theObjectHandle, AttributeHandle *theAttributeList, UShort theListSize) throw (ObjectNotKnown, ObjectClassNotPublished, AttributeNotDefined, AttributeNotPublished, FederateOwnsAttributes, AttributeAlreadyBeingAcquired, RTIinternalError){ // Pre-conditions checking //It 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]); if (server != NULL) { // Federate must publish the class. if (!isFederatePublisher(theFederateHandle)) { 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(theAttributeList[i]); oa = object->getAttribute(theAttributeList[i]); // The federate has to publish attributes he desire to // acquire. if (!oca->isPublishing(theFederateHandle) && (strcmp(oca->getName(), "privilegeToDelete") != 0)) throw AttributeNotPublished(); // Does federate already owns some attributes. if (oa->getOwner() == theFederateHandle) throw FederateOwnsAttributes(); // Does federate is on the way to acquire something. if (oa->isCandidate(theFederateHandle) != 0) throw AttributeAlreadyBeingAcquired(); } NetworkMessage *Answer_notification = new NetworkMessage ; Answer_notification->type = m_ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION ; Answer_notification->federation = server->federation(); Answer_notification->federate = theFederateHandle ; Answer_notification->exception = e_NO_EXCEPTION ; Answer_notification->object = theObjectHandle ; NetworkMessage *Answer_unavailable = new NetworkMessage ; Answer_unavailable->type = m_ATTRIBUTE_OWNERSHIP_UNAVAILABLE ; Answer_unavailable->federation = server->federation(); Answer_unavailable->federate = theFederateHandle ; Answer_unavailable->exception = e_NO_EXCEPTION ; Answer_unavailable->object = theObjectHandle ; CDiffusion *diffusionDivestiture = new CDiffusion(); // //Ce service ne doit pas ajouter le f閐閞
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?