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

📄 interaction.cc

📁 分布式仿真 开放源码
💻 CC
📖 第 1 页 / 共 2 页
字号:
// ----------------------------------------------------------------------------// CERTI - HLA RunTime Infrastructure// Copyright (C) 2002, 2003, 2004  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: Interaction.cc,v 3.19 2004/03/04 20:19:05 breholee Exp $// ----------------------------------------------------------------------------#include <config.h>#include "Interaction.hh"#include "PrettyDebug.hh"#include <iostream>#include <assert.h>using std::cout ;using std::endl ;using std::list ;namespace certi {static pdCDebug D("INTERACTION", "(Interact) - ");// ----------------------------------------------------------------------------//! Used only by CRead, return the new parameter's handle.ParameterHandleInteraction::addParameter(Parameter *the_parameter, bool is_inherited){    the_parameter->setHandle(parameterSet.size() + 1);    // An inherited parameter keeps its security level, any other get the    // default security level of the class.    if (!is_inherited)        the_parameter->LevelID = id ;    parameterSet.push_front(the_parameter);    D[pdRegister] << "Interaction " << handle << "(\"" << name.c_str()		  << "\") has a new parameter " << the_parameter->getHandle();    return the_parameter->getHandle();}// ----------------------------------------------------------------------------//! Add the class' attributes to the 'Child' Class.voidInteraction::addParametersToChild(Interaction *the_child){    // The Parameter List is read backward to respect the same attribute order    // for the child (Parameters are inserted at the beginning of the list)    Parameter *child = NULL ;    list<Parameter *>::reverse_iterator p ;    for (p = parameterSet.rbegin(); p != parameterSet.rend(); p++) {        assert((*p) != NULL);        child = new Parameter(*p);        assert(child != NULL);        D.Out(pdProtocol,              "ObjectClass %u adding new attribute %d to child class %u.",              handle, (*p)->getHandle(), the_child->handle);        the_child->addParameter(child, RTI_TRUE);        if (child->getHandle() != (*p)->getHandle())            throw RTIinternalError("Error while copying child's attributes.");    }}// ----------------------------------------------------------------------------/*! Called by the InteractionSet on Parent Classes whose Childrens  initiated a SendInteraction, to allow them to broadcast the  Interaction Message of their child to their own subscribers.  See InteractionSet::SendInteraction.*/voidInteraction::broadcastInteractionMessage(InteractionBroadcastList *ibList){    // 1. Set InteractionHandle to local class Handle.    ibList->message->interactionClass = handle ;    // 2. Update message Parameters list by removing child's Parameters.    for (int i = 0 ; i < ibList->message->handleArraySize ;) {        // If the Parameter is not in that class, remove it from the message.        try {            getParameterByHandle(ibList->message->handleArray[i]);            i++ ;        }        catch (InteractionParameterNotDefined) {            ibList->message->removeParameter(i);        }    }    // 3. Add Interaction subscribers to the list.    list<Subscriber *>::iterator s ;    for (s = subscribers.begin(); s != subscribers.end(); s++) {        D.Out(pdDebug, "Adding federate %d to BroadcastList.",              (*s)->getHandle());        ibList->addFederate((*s)->getHandle());    }    // 4. Send pending messages.    D.Out(pdDebug, "Calling SendPendingMessage...");    ibList->sendPendingMessage(server);}// ----------------------------------------------------------------------------//! changeTransportationType.voidInteraction::changeTransportationType(TransportType new_type,                                      FederateHandle the_handle)    throw (FederateNotPublishing,           InvalidTransportType,           RTIinternalError){    if (!isPublishing(the_handle))        throw FederateNotPublishing("Change Interaction Transport Type.");    if ((new_type != RELIABLE) && (new_type != BEST_EFFORT))        throw InvalidTransportType();    transport = new_type ;    D.Out(pdInit,          "Interaction %d: New Transport type is %d.", handle, transport);}// ----------------------------------------------------------------------------//! changeOrderType.voidInteraction::changeOrderType(OrderType new_order, FederateHandle the_handle)    throw (FederateNotPublishing,           InvalidOrderType,           RTIinternalError){    if (!isPublishing(the_handle))        throw FederateNotPublishing("Change Interaction Order Type.");    if ((new_order != RECEIVE) && (new_order != TIMESTAMP))        throw InvalidOrderType();    D.Out(pdInit, "Interaction %d: New Order type is %d.", handle, order);}// ----------------------------------------------------------------------------/*! Throw SecurityError is the Federate is not allowed to access the  Interaction Class, and print an Audit message containing Reason.*/voidInteraction::checkFederateAccess(FederateHandle the_federate,                                 const char *reason) const    throw (SecurityError){    // BUG: Should at least but a line in Audit    if (server == NULL)        return ;    bool result = server->canFederateAccessData(the_federate, id);    // BUG: Should use Audit.    if (!result) {        cout << "Interaction " << handle << " : SecurityError for federate "             << the_federate << '(' << reason << ")." << endl ;        throw SecurityError("Federate should not access Interaction.");    }}// ----------------------------------------------------------------------------//! Interaction.Interaction::Interaction()    : parent(0), depth(0), transport(BEST_EFFORT), order(RECEIVE), handle(0),      id(PublicLevelID){}// ----------------------------------------------------------------------------//! Destructor.Interaction::~Interaction(){    while (!parameterSet.empty()) {        delete parameterSet.front();        parameterSet.pop_front();    }    // Deleting Publishers    if (!publishers.empty())        D.Out(pdError,              "Interaction %d: publishers list not empty at termination.",              handle);    while (!publishers.empty()) {        delete publishers.front();        publishers.pop_front();    }    // Deleting Subscribers    if (!subscribers.empty())        D.Out(pdError,              "Interaction %d: Subscribers list not empty at termination.",              handle);    while (!subscribers.empty()) {        delete subscribers.front();        subscribers.pop_front();    }    // Deleting Sons    while (!children.empty()) {        children.pop_front();    }}// ----------------------------------------------------------------------------//! Delete a publisher with rank (private module).voidInteraction::deletePublisher(FederateHandle fed){    list<Publisher *>::iterator p ;    for (p = publishers.begin(); p != publishers.end(); ++p) {        if ((*p)->getHandle() == fed) {            delete (*p);            publishers.erase(p);            return ;        }    }}// ----------------------------------------------------------------------------//! Delete a subscriber with rank (private module).voidInteraction::deleteSubscriber(FederateHandle fed, RegionImp *region){    list<Subscriber *>::iterator s ;    for (s = subscribers.begin(); s != subscribers.end(); ++s) {        if ((*s)->match(fed, region)) {            delete *s ;            subscribers.erase(s);            return ;        }    }}// ----------------------------------------------------------------------------//! Print the Interaction to the standard output.voidInteraction::display() const{    cout << " Interaction " << handle << " \"" << name << "\" :" << endl ;    // Display inheritance    cout << " Parent Class Handle: " << parent << endl ;    cout << " Security Level: " << id << endl ;    cout << " " << children.size() << " Child(s):" << endl ;    list<InteractionClassHandle>::const_iterator c = children.begin();    for (int i = 1 ; c != children.end(); i++, c++) {        cout << " child " << i << " Handle: " << (*c) << endl ;    }    // Display parameters    cout << " " << parameterSet.size() << " Parameters:" << endl ;    list<Parameter *>::const_iterator p = parameterSet.begin();    for (; p != parameterSet.end(); p++) {        (*p)->display();    }}// ----------------------------------------------------------------------------//! Returns the parameter by its handle (private module).Parameter*Interaction::getParameterByHandle(ParameterHandle the_handle) const    throw (InteractionParameterNotDefined, RTIinternalError){    list<Parameter *>::const_iterator p ;    for (p = parameterSet.begin(); p != parameterSet.end(); p++) {        if ((*p)->getHandle() == the_handle)            return (*p);    }    throw InteractionParameterNotDefined();

⌨️ 快捷键说明

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