⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 federation.cc

📁 分布式仿真 开放源码
💻 CC
📖 第 1 页 / 共 4 页
字号:
// ----------------------------------------------------------------------------// divest (unconditionalAttributeOwnershipDivestiture)voidFederation::divest(FederateHandle federate,                   ObjectHandle id,                   AttributeHandle *attrs,                   UShort list_size)    throw (ObjectNotKnown,           AttributeNotDefined,           AttributeNotOwned,           FederateNotExecutionMember,           SaveInProgress,           RestoreInProgress,           RTIinternalError){    // It may throw FederateNotExecutionMember.    this->check(federate);    // It may throw *NotDefined    root->ObjectClasses->unconditionalAttributeOwnershipDivestiture(federate,                                                                    id,                                                                    attrs,                                                                    list_size);}// ----------------------------------------------------------------------------// attributeOwnershipAcquisitionvoidFederation::acquire(FederateHandle federate,                    ObjectHandle id,                    AttributeHandle *attributes,                    UShort list_size,                    const char *tag)    throw (ObjectNotKnown,           ObjectClassNotPublished,           AttributeNotDefined,           AttributeNotPublished,           FederateOwnsAttributes,           FederateNotExecutionMember,           SaveInProgress,           RestoreInProgress,           RTIinternalError){    // It may throw FederateNotExecutionMember.    this->check(federate);    // It may throw *NotDefined    root->ObjectClasses->attributeOwnershipAcquisition(federate,                                                       id,                                                       attributes,                                                       list_size,                                                       tag);    D.Out(pdDebug, "Acquisition on Object %u ", id);}// ----------------------------------------------------------------------------// cancelDivestiture (cancelNegotiatedAttributeOwnershipDivestiture)voidFederation::cancelDivestiture(FederateHandle federate,                              ObjectHandle id,                              AttributeHandle *attributes,                              UShort list_size)    throw (ObjectNotKnown,           AttributeNotDefined,           AttributeNotOwned,           AttributeDivestitureWasNotRequested,           FederateNotExecutionMember,           SaveInProgress,           RestoreInProgress,           RTIinternalError){    // It may throw FederateNotExecutionMember.    this->check(federate);    // It may throw *NotDefined    root->objects->cancelNegotiatedAttributeOwnershipDivestiture(federate,                                                                 id,                                                                 attributes,                                                                 list_size);    D.Out(pdDebug, "CancelDivestiture sur Objet %u ", id);}// ----------------------------------------------------------------------------// respondRelease (attributeOwnershipRealeaseResponse)AttributeHandleSet*Federation::respondRelease(FederateHandle federate,                           ObjectHandle id,                           AttributeHandle *attributes,                           UShort list_size)    throw (ObjectNotKnown,           AttributeNotDefined,           AttributeNotOwned,           FederateWasNotAskedToReleaseAttribute,           FederateNotExecutionMember,           SaveInProgress,           RestoreInProgress,           RTIinternalError){    // It may throw FederateNotExecutionMember.    this->check(federate);    D.Out(pdDebug, "RespondRelease on Object %u.", id);    // It may throw *NotDefined    return(root->ObjectClasses->attributeOwnershipReleaseResponse(federate,                                                                  id,                                                                  attributes,                                                                  list_size));}// ----------------------------------------------------------------------------// cancelAttributeOwnershipAcquisitionvoidFederation::cancelAcquisition(FederateHandle federate,                              ObjectHandle id,                              AttributeHandle *attributes,                              UShort list_size)    throw (ObjectNotKnown,           AttributeNotDefined,           AttributeAlreadyOwned,           AttributeAcquisitionWasNotRequested,           FederateNotExecutionMember,           SaveInProgress,           RestoreInProgress,           RTIinternalError){    // It may throw FederateNotExecutionMember.    this->check(federate);    D.Out(pdDebug, "CancelAcquisition sur Objet %u ", id);    // It may throw *NotDefined    root->ObjectClasses->cancelAttributeOwnershipAcquisition(federate,                                                             id,                                                             attributes,                                                             list_size);}// ----------------------------------------------------------------------------longFederation::createRegion(FederateHandle federate,                         SpaceHandle space,                         long nb_extents)    throw (SpaceNotDefined, InvalidExtents, SaveInProgress, RestoreInProgress,           RTIinternalError){    this->check(federate);    return root->createRegion(space, nb_extents);}// ----------------------------------------------------------------------------// modifyRegionvoidFederation::modifyRegion(FederateHandle federate, RegionHandle region,			 const vector<Extent> &extents)    throw (RegionNotKnown, InvalidExtents, SaveInProgress, RestoreInProgress,	   RTIinternalError){    check(federate);    root->modifyRegion(region, extents);}// ----------------------------------------------------------------------------//! deleteRegionvoidFederation::deleteRegion(FederateHandle federate,                         long region)    throw (RegionNotKnown, RegionInUse, SaveInProgress, RestoreInProgress,           RTIinternalError){    this->check(federate);    if (saveInProgress) {        throw SaveInProgress();    }    if (restoreInProgress) {        throw RestoreInProgress();    }    // TODO: check RegionInUse    root->deleteRegion(region);}// ----------------------------------------------------------------------------//! associateRegionvoidFederation::associateRegion(FederateHandle federate,			    ObjectHandle object,			    RegionHandle the_handle,			    unsigned short nb,			    AttributeHandle *attributes)    throw (RegionNotKnown, SaveInProgress, RestoreInProgress, RTIinternalError){    check(federate);    RegionImp *region = root->getRegion(the_handle);    root->getObject(object)->unassociate(region);	    for (int i = 0 ; i < nb ; ++i) {	root->getObjectAttribute(object, attributes[i])->associate(region);    }    }// ----------------------------------------------------------------------------//! unassociateRegionvoidFederation::unassociateRegion(FederateHandle federate, ObjectHandle object,			      RegionHandle the_handle)    throw (RegionNotKnown, SaveInProgress, RestoreInProgress,	   RTIinternalError){    check(federate);    RegionImp *region = root->getRegion(the_handle);    root->getObject(object)->unassociate(region);}// ----------------------------------------------------------------------------//! subscribeAttributesWRvoidFederation::subscribeAttributesWR(FederateHandle federate,				  ObjectClassHandle c,				  RegionHandle region_handle,				  unsigned short nb,				  AttributeHandle *attributes)    throw (RegionNotKnown,	       SaveInProgress,	       RestoreInProgress,	       RTIinternalError){    check(federate);    RegionImp *r = root->getRegion(region_handle);        root->getObjectClass(c)->unsubscribe(federate, r);    for (int i = 0 ; i < nb ; ++i) {	root->getObjectClassAttribute(c, attributes[i])->subscribe(federate, r);    } }// ----------------------------------------------------------------------------//! unsubscribeAttributesWRvoidFederation::unsubscribeAttributesWR(FederateHandle federate,				    ObjectClassHandle object_class,				    RegionHandle region_handle)	throw (RegionNotKnown,	       SaveInProgress,	       RestoreInProgress,	       RTIinternalError){    check(federate);    RegionImp *region = root->getRegion(region_handle);    root->getObjectClass(object_class)->unsubscribe(federate, region);}// ----------------------------------------------------------------------------voidFederation::subscribeInteractionWR(FederateHandle federate,				   InteractionClassHandle interaction,				   RegionHandle region_handle)	throw (RegionNotKnown,	       SaveInProgress,	       RestoreInProgress,	       RTIinternalError){    check(federate);    RegionImp *region = root->getRegion(region_handle);    root->getInteractionClass(interaction)->subscribe(federate, region);}// ----------------------------------------------------------------------------voidFederation::unsubscribeInteractionWR(FederateHandle federate,				     InteractionClassHandle interaction,				     RegionHandle region_handle)	throw (RegionNotKnown,	       SaveInProgress,	       RestoreInProgress,	       RTIinternalError){    check(federate);    RegionImp *region = root->getRegion(region_handle);    root->getInteractionClass(interaction)->unsubscribe(federate, region);}// ----------------------------------------------------------------------------boolFederation::restoreXmlData(){#ifndef HAVE_XML    return false ;#else    xmlNodePtr cur ;    cur = xmlDocGetRootElement(doc);    if (cur == 0) {        cerr << "XML file is empty" << endl ;        xmlFreeDoc(doc);        return false ;    }    // Is this root element an ROOT_NODE ?    if (xmlStrcmp(cur->name, ROOT_NODE)) {        cerr << "Wrong XML file: not the expected root node" << endl ;        return false ;    }    cur = cur->xmlChildrenNode ;    if (xmlStrcmp(cur->name, NODE_FEDERATION)) {        cerr << "Wrong XML file structure" << endl ;        return false ;    }    char *tmp ;    tmp = (char *)xmlGetProp(cur, (const xmlChar*)"name");    if (strcmp(name, tmp) != 0) {        cerr << "Wrong federation name" << endl ;    }    cur = cur->xmlChildrenNode ;    list<Federate *>::iterator i ;    bool status ;    while (cur != NULL) {        if ((!xmlStrcmp(cur->name, NODE_FEDERATE))) {            for (i = begin(); i != end(); i++) {                if (!strcmp(                        (*i)->getName(),                        (char *) xmlGetProp(cur, (const xmlChar*) "name"))) {                    // Set federate constrained status                    if (strcmp("true", (char *)xmlGetProp(                                   cur, (const xmlChar*)"constrained")) == 0)                        status = true ;                    else                        status = false ;                    (*i)->setConstrained(status);                    // Set federate regulating status                    status = !strcmp("true", (char *) xmlGetProp(                                         cur, (const xmlChar *) "regulator"));                    (*i)->setRegulator(status);                    (*i)->setHandle(                        strtol((char *) xmlGetProp(                                   cur, (const xmlChar *) "handle"), 0, 10));                    break ;                }            }        }        cur = cur->next ;    }    return status ;#endif // HAVE_XML}// ----------------------------------------------------------------------------boolFederation::saveXmlData(){#ifndef HAVE_XML    return false ;#else    doc = xmlNewDoc((const xmlChar *) "1.0");    doc->children = xmlNewDocNode(doc, NULL, ROOT_NODE, NULL);    xmlNodePtr federation ;    federation = xmlNewChild(doc->children, NULL, NODE_FEDERATION, NULL);    xmlSetProp(federation, (const xmlChar *) "name", (const xmlChar *) name);    char t[10] ;    sprintf(t, "%ld", handle);    xmlSetProp(federation, (const xmlChar *) "handle", (const xmlChar *) t);    xmlNodePtr federate ;    list<Federate *>::iterator i ;    for (i = begin(); i != end(); i++) {        federate = xmlNewChild(federation, NULL, NODE_FEDERATE, NULL);        xmlSetProp(federate,                   (const xmlChar *)"name",                   (const xmlChar *)(*i)->getName());        sprintf(t, "%ld", (*i)->getHandle());        xmlSetProp(federate, (const xmlChar *)"handle", (const xmlChar *)t);        xmlSetProp(federate,                   (const xmlChar *)"constrained", (const xmlChar *)                   (((*i)->isConstrained()) ? "true" : "false"));        xmlSetProp(federate, (const xmlChar *)"regulator",                   (const xmlChar *)(((*i)->isRegulator()) ? "true" : "false"));    }    xmlSetDocCompressMode(doc, 9);    string filename = string(name) + "_" + string(saveLabel) + ".xcs" ;    xmlSaveFile(filename.c_str(), doc);    // TODO: tests    return true ;#endif // HAVE_XML}}} // namespace certi/rtig// $Id: Federation.cc,v 3.37 2004/03/04 20:19:04 breholee Exp $

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -