objectclassset.cc
来自「certi-SHM-3.0.tar 不错的开源的分布式方针软件 大家多多支持 他」· CC 代码 · 共 752 行 · 第 1/2 页
CC
752 行
// -*- mode:C++ ; tab-width:4 ; c-basic-offset:4 ; indent-tabs-mode:nil -*-// ----------------------------------------------------------------------------// CERTI - HLA RunTime Infrastructure// Copyright (C) 2002, 2003 ONERA//// This file is part of CERTI-libCERTI//// CERTI-libCERTI is free software ; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public License// as published by the Free Software Foundation ; either version 2 of// the License, or (at your option) any later version.//// CERTI-libCERTI is distributed in the hope that it will be useful, but// WITHOUT ANY WARRANTY ; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this program ; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307// USA//// $Id: ObjectClassSet.cc,v 3.11 2003/03/04 09:47:04 breholee Exp $// ----------------------------------------------------------------------------#include "ObjectClassSet.hh"namespace certi {static pdCDebug D("OBJECTCLASSSET", "(ObjClSet) - ");// ----------------------------------------------------------------------------//! The class is not allocated, only the pointer is memorized.voidObjectClassSet::addClass(ObjectClass *newClass){ D.Out(pdInit, "Adding new object class %d.", newClass->getHandle()); newClass->server = server ; push_front(newClass);}// ----------------------------------------------------------------------------/*! Build a Parent-Child relation between two object class, by setting the Child's Parent handle, and registering the child in the Parent's sonSet. Also copy all parent's Attributes in the child Class.*/voidObjectClassSet::buildParentRelation(ObjectClass *child, ObjectClass *parent){ // Register Parent to Son child->Father = parent->getHandle(); // Transfer Security Level child->setLevelId(parent->getLevelId()); // Register Son to Parent parent->sonSet.push_front(child->getHandle()); // Copy Parent Attribute into Child class. parent->addAttributesToChild(child);}// ----------------------------------------------------------------------------//! Constructor.ObjectClassSet::ObjectClassSet(SecurityServer *theSecurityServer) : list<ObjectClass *>(){ // It can be NULL on the RTIA. server = theSecurityServer ;}// ----------------------------------------------------------------------------//! Destructor.ObjectClassSet::~ObjectClassSet(void){ while (!empty()) { delete front(); pop_front(); }}// ----------------------------------------------------------------------------//! deleteObject.voidObjectClassSet::deleteObject(FederateHandle theFederateHandle, ObjectHandle theObjectHandle, const char *theTag) throw (DeletePrivilegeNotHeld, ObjectNotKnown, RTIinternalError){ // It may throw ObjectNotKnown ObjectClass *theClass = getInstanceClass(theObjectHandle); D.Out(pdRegister, "Federate %d attempts to delete instance %d in class %d.", theFederateHandle, theObjectHandle, theClass->getHandle()); // It may throw a bunch of exceptions. ObjectClassBroadcastList *ocbList = NULL ; ocbList = theClass->deleteInstance(theFederateHandle, theObjectHandle, theTag); // Broadcast RemoveObject message recursively ObjectClassHandle currentClass = 0 ; if (ocbList != 0) { currentClass = theClass->Father ; while (currentClass != 0) { D.Out(pdRegister, "Broadcasting Remove msg to parent class %d for instance %d.", currentClass, theObjectHandle); // It may throw ObjectClassNotDefined theClass = getWithHandle(currentClass); theClass->broadcastClassMessage(ocbList); currentClass = theClass->Father ; } delete ocbList ; } D.Out(pdRegister, "Instance %d has been deleted.", theObjectHandle);}// ----------------------------------------------------------------------------//! Print the ObjectClasses tree to the standard output.voidObjectClassSet::display(void) const{ cout << " ObjectClasses :" << endl ; list<ObjectClass *>::const_iterator i ; for (i = begin(); i != end(); i++) { (*i)->display(); }}// ----------------------------------------------------------------------------//! getAttributeHandle.AttributeHandleObjectClassSet::getAttributeHandle(const char *the_name, ObjectClassHandle the_class) const throw (AttributeNotDefined, ObjectClassNotDefined, RTIinternalError){ ObjectClass *objectClass = NULL ; if (the_name == NULL) throw RTIinternalError(); D.Out(pdRequest, "Looking for attribute \"%s\" of class %u...", the_name, the_class); // It may throw ObjectClassNotDefined. objectClass = getWithHandle(the_class); return objectClass->getAttributeHandle(the_name);}// ----------------------------------------------------------------------------//! getAttributeName.const char *ObjectClassSet::getAttributeName(AttributeHandle the_handle, ObjectClassHandle the_class) const throw (AttributeNotDefined, ObjectClassNotDefined, RTIinternalError){ ObjectClass *objectClass = NULL ; D.Out(pdRequest, "Looking for attribute %u of class %u...", the_handle, the_class); // It may throw ObjectClassNotDefined. objectClass = getWithHandle(the_class); return objectClass->getAttributeName(the_handle);}// ----------------------------------------------------------------------------//! getInstanceClass.ObjectClass *ObjectClassSet::getInstanceClass(ObjectHandle theObjectHandle) const throw (ObjectNotKnown){ // Try to find Instance's Class list<ObjectClass *>::const_iterator i ; for (i = begin(); i != end(); i++) { if ((*i)->isInstanceInClass(theObjectHandle) == true) return (*i); } D.Out(pdExcept, "Object instance %d not found in any object class.", theObjectHandle); throw ObjectNotKnown();}// ----------------------------------------------------------------------------//! getObjectClassHandle.ObjectClassHandleObjectClassSet::getObjectClassHandle(const char *the_name) const throw (ObjectClassNotDefined, RTIinternalError){ if (the_name == NULL) throw RTIinternalError(); D.Out(pdRequest, "Looking for class \"%s\"...", the_name); list<ObjectClass *>::const_iterator i ; for (i = begin(); i != end(); i++) { if (strcmp((*i)->getName(), the_name) == 0) return (*i)->getHandle(); } throw ObjectClassNotDefined();}// ----------------------------------------------------------------------------//! getObjectClassName.const char *ObjectClassSet::getObjectClassName(ObjectClassHandle the_handle) const throw (ObjectClassNotDefined, RTIinternalError){ D.Out(pdRequest, "Looking for class %u...", the_handle); return getWithHandle(the_handle)->getName();}// ----------------------------------------------------------------------------//! getWithHandle (private method).ObjectClass *ObjectClassSet::getWithHandle(ObjectClassHandle theHandle) const throw (ObjectClassNotDefined){ list<ObjectClass *>::const_iterator i ; for (i = begin(); i != end(); i++) { if ((*i)->getHandle() == theHandle) return (*i); } D.Out(pdExcept, "Unknown Object Class Handle %d .", theHandle); throw ObjectClassNotDefined("Unknow class handle.");}// ----------------------------------------------------------------------------//! killFederate.void ObjectClassSet::killFederate(FederateHandle theFederate) throw (){ ObjectClassBroadcastList *ocbList = NULL ; ObjectClassHandle currentClass = 0 ; list<ObjectClass *>::iterator i ; for (i = begin(); i != end(); i++) { // Call KillFederate on that class until it returns NULL. do { D.Out(pdExcept, "Kill Federate Handle %d .", theFederate); ocbList = (*i)->killFederate(theFederate); D.Out(pdExcept, "Federate Handle %d Killed.", theFederate); // Broadcast RemoveObject message recursively if (ocbList != 0) { currentClass = (*i)->Father ; D.Out(pdExcept, "List not NULL"); while (currentClass != 0) { D.Out(pdRegister, "Broadcasting Remove msg to parent class %d(Killed).", currentClass); // It may throw ObjectClassNotDefined (*i) = getWithHandle(currentClass); (*i)->broadcastClassMessage(ocbList); currentClass = (*i)->Father ; } delete ocbList ; } } while (ocbList != NULL); } D.Out(pdExcept, "End of the KillFederate Procedure.");}// ----------------------------------------------------------------------------//! publishvoidObjectClassSet::publish(FederateHandle theFederateHandle, ObjectClassHandle theClassHandle, AttributeHandle *theAttributeList, UShort theListSize, bool PubOrUnpub) throw (ObjectClassNotDefined, AttributeNotDefined, RTIinternalError, SecurityError){ // It may throw ObjectClassNotDefined ObjectClass *theClass = getWithHandle(theClassHandle); if (PubOrUnpub == RTI_TRUE) D.Out(pdInit, "Federate %d attempts to publish Object Class %d.", theFederateHandle, theClassHandle); else D.Out(pdTerm, "Federate %d attempts to unpublish Object Class %d.", theFederateHandle, theClassHandle); // It may throw AttributeNotDefined theClass->publish(theFederateHandle, theAttributeList, theListSize, PubOrUnpub);}// ----------------------------------------------------------------------------//! recursiveDiscovering.voidObjectClassSet::recursiveDiscovering(ObjectClassHandle theClassHandle, FederateHandle theFederate, ObjectClassHandle theOriginalClass){ // It may throw ObjectClassNotDefined ObjectClass *theClass = getWithHandle(theClassHandle); D.Out(pdInit, "Recursive Discovering on class %d for Federate %d.", theClassHandle, theFederate); Boolean result ; result = theClass->sendDiscoverMessages(theFederate, theOriginalClass); if (result == RTI_TRUE) { list<ObjectClassHandle>::const_iterator i = theClass->sonSet.begin(); for (; i != theClass->sonSet.end(); i++) { recursiveDiscovering((*i), theFederate, theOriginalClass); } }}// ----------------------------------------------------------------------------//! registerInstance.voidObjectClassSet::registerInstance(FederateHandle theFederateHandle, ObjectClassHandle theClassHandle, ObjectHandle theObjectHandle, const char *the_object_name) throw (InvalidObjectHandle, ObjectClassNotDefined, ObjectClassNotPublished, ObjectAlreadyRegistered, RTIinternalError){ ObjectClassHandle currentClass = theClassHandle ; D.Out(pdRegister, "Federate %d attempts to register instance %d in class %d.", theFederateHandle, theObjectHandle, theClassHandle); // It may throw ObjectClassNotDefined ObjectClass *theClass = getWithHandle(theClassHandle); // It may throw a bunch of exceptions. ObjectClassBroadcastList *ocbList = NULL ; ocbList = theClass->registerInstance(theFederateHandle, theObjectHandle, the_object_name);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?