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

📄 interactionbroadcastlist.cc

📁 分布式仿真 开放源码
💻 CC
字号:
// ----------------------------------------------------------------------------// 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: InteractionBroadcastList.cc,v 3.8 2003/06/27 17:26:28 breholee Exp $// ----------------------------------------------------------------------------#include <config.h>#include "InteractionBroadcastList.hh"#include "PrettyDebug.hh"using std::list ;namespace certi {static pdCDebug D("INTBROADCASTLIST", "(broadcas) - ");// ----------------------------------------------------------------------------/*! Add a federate to the list. If it was not present in the list, a new line  is added and its state is set as bsNotSub. Then if the Federate has not  been sent a message for this interaction, the line's state is set to  bsWaiting.*/voidInteractionBroadcastList::addFederate(FederateHandle federate){    // 1. Is there already a line in the list for this Federate?    InteractionBroadcastLine * line = getLineWithFederate(federate);    // If NO, add a new one, in the bsWaiting State.    if (line == 0) {        line = new InteractionBroadcastLine(federate,                                            InteractionBroadcastLine::waiting);        lines.push_front(line);        D.Out(pdRegister, "Adding new line in list for Federate %d.", federate);    }    else        D.Out(pdTrace, "Message already sent to federate %d.", federate);}// ----------------------------------------------------------------------------/*! theMsg must have been allocated, and will be destroyed by the destructor.  theMsg->NumeroFedere is added to the list, and its state is set as "Sent".*/InteractionBroadcastList::InteractionBroadcastList(NetworkMessage *theMsg){    if (theMsg == 0)        throw RTIinternalError("Null Broadcast Message.");    message = theMsg ;    // Add reference of the sender(so it does not receive its own message).    if (message->federate != 0) {        InteractionBroadcastLine *firstLine ;        firstLine =            new InteractionBroadcastLine(message->federate,                                         InteractionBroadcastLine::sent);        lines.push_front(firstLine);    }}// ----------------------------------------------------------------------------//! Free all structures, including Message.InteractionBroadcastList::~InteractionBroadcastList(){    clear();}// ----------------------------------------------------------------------------//! Empty the list so it can reused(like the destructor).voidInteractionBroadcastList::clear(){    delete message ;    message = 0 ;    while (!lines.empty()) {        delete lines.front();        lines.pop_front();    }    D.Out(pdTerm, "List is now empty.");}// ----------------------------------------------------------------------------//! Return the line of the list describing federate 'federate', or 0.InteractionBroadcastLine*InteractionBroadcastList::getLineWithFederate(FederateHandle federate){    list<InteractionBroadcastLine *>::iterator i ;    for (i = lines.begin(); i != lines.end(); i++) {        if ((*i)->federate == federate)            return (*i);    }    return 0 ;}// ----------------------------------------------------------------------------/*! IMPORTANT: Before calling this method, be sure to set the  Message->NumeroFederation handle.  Broadcast the message to all the Federate in the bsWaiting state, and then  set their state to bsSent.*/voidInteractionBroadcastList::sendPendingMessage(SecurityServer *server){    list<InteractionBroadcastLine *>::iterator i ;    for (i = lines.begin(); i != lines.end(); i++) {        // If federate is waiting for a message.        if ((*i)->state == InteractionBroadcastLine::waiting) {            // 1. Send message to federate.            D.Out(pdProtocol, "Broadcasting message to Federate %d.",                  (*i)->federate);            Socket *socket = 0 ;            try {#ifdef HLA_USES_UDP                socket = server->getSocketLink((*i)->federate, BEST_EFFORT);#else                socket = server->getSocketLink((*i)->federate);#endif                message->write(socket);            }            catch (RTIinternalError &e) {                D.Out(pdExcept,                      "Reference to a killed Federate while broadcasting.");            }            catch (NetworkError &e) {                D.Out(pdExcept, "Network error while broadcasting, ignoring.");            }            // 2. Mark federate as having received the message.            (*i)->state = InteractionBroadcastLine::sent ;        }        else            D.Out(pdProtocol, "No message sent to Federate %d.",                  (*i)->federate);    }}} // namespace certi// $Id: InteractionBroadcastList.cc,v 3.8 2003/06/27 17:26:28 breholee Exp $

⌨️ 快捷键说明

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