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

📄 interaction.cc

📁 certi-SHM-3.0.tar 不错的开源的分布式方针软件 大家多多支持 他是linux
💻 CC
📖 第 1 页 / 共 2 页
字号:
// -*- 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: Interaction.cc,v 3.10 2003/02/19 18:07:29 breholee Exp $// ----------------------------------------------------------------------------#include "Interaction.hh"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->Handle = 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.Out(pdRegister, "Interaction %u(\"%s\") has a new parameter %u.",          handle, name, the_parameter->Handle);    return the_parameter->Handle ;}// ----------------------------------------------------------------------------//! 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)->Handle, the_child->handle);        the_child->addParameter(child, RTI_TRUE);        if (child->Handle != (*p)->Handle)            throw RTIinternalError("Error while copying child's attributes.");    }}// ----------------------------------------------------------------------------//! addPublisher (private).voidInteraction::addPublisher(FederateHandle the_federate)    throw (RTIinternalError){    Publisher *publisher = new Publisher(the_federate);    if (publisher == NULL) {        D.Out(pdExcept, "Memory exhausted while publishing interaction.");        throw            RTIinternalError("Memory Exhausted while publishing interaction.");    }    publishers.push_front(publisher);}// ----------------------------------------------------------------------------// addSubscriber (private).voidInteraction::addSubscriber(FederateHandle the_federate)    throw (RTIinternalError){    Subscriber *subscriber = new Subscriber(the_federate);    if (subscriber == NULL) {        D.Out(pdExcept, "Memory exhausted while subscribing interaction.");        throw            RTIinternalError("Memory Exhausted while "                             "subscribing interaction.");    }    subscribers.push_front(subscriber);}// ----------------------------------------------------------------------------/*! 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(void)    : handle(0), parent(0), depth(0), transport(BEST_EFFORT), order(RECEIVE),      name(NULL), id(PublicLevelID){}// ----------------------------------------------------------------------------//! Destructor.Interaction::~Interaction(void){    if (name != NULL) {        free(name);        name = NULL ;    }    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(int the_rank){    list<Publisher *>::iterator p = publishers.begin();    for (int i = 1 ; p != publishers.end(); i++, p++) {        if (i == the_rank) {            delete (*p);            publishers.erase(p);            return ;        }    }}// ----------------------------------------------------------------------------//! Delete a subscriber with rank (private module).voidInteraction::deleteSubscriber(int the_rank){    list<Subscriber *>::iterator s = subscribers.begin();    for (int i = 1 ; s != subscribers.end(); i++, s++) {        if (i == the_rank) {            delete (*s);            subscribers.erase(s);            return ;        }    }}// ----------------------------------------------------------------------------//! Print the Interaction to the standard output.voidInteraction::display(void) 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*

⌨️ 快捷键说明

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