00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "InteractionBroadcastList.hh"
00028 #include "PrettyDebug.hh"
00029
00030 using std::list ;
00031
00032 namespace certi {
00033
00034 static pdCDebug D("INTBROADCASTLIST", "(broadcas) - ");
00035 static PrettyDebug G("GENDOC",__FILE__) ;
00036
00037
00043 void
00044 InteractionBroadcastList::addFederate(FederateHandle federate)
00045 {
00046
00047 InteractionBroadcastLine * line = getLineWithFederate(federate);
00048
00049
00050 if (line == 0) {
00051 line = new InteractionBroadcastLine(federate,
00052 InteractionBroadcastLine::waiting);
00053 lines.push_front(line);
00054 D.Out(pdRegister, "Adding new line in list for Federate %d.", federate);
00055 }
00056 else
00057 D.Out(pdTrace, "Message already sent to federate %d.", federate);
00058 }
00059
00060
00064 InteractionBroadcastList::InteractionBroadcastList(NetworkMessage *theMsg)
00065 {
00066
00067 G.Out(pdGendoc,"enter InteractionBroadcastList::InteractionBroadcastList");
00068
00069 if (theMsg == 0)
00070 throw RTIinternalError("Null Broadcast Message.");
00071
00072 message = theMsg ;
00073
00074
00075 if (message->federate != 0) {
00076 InteractionBroadcastLine *firstLine ;
00077 firstLine =
00078 new InteractionBroadcastLine(message->federate,
00079 InteractionBroadcastLine::sent);
00080 lines.push_front(firstLine);
00081 }
00082
00083 G.Out(pdGendoc,"exit InteractionBroadcastList::InteractionBroadcastList");
00084
00085 }
00086
00087
00089 InteractionBroadcastList::~InteractionBroadcastList()
00090 {
00091 clear();
00092 }
00093
00094
00096 void
00097 InteractionBroadcastList::clear()
00098 {
00099 delete message ;
00100 message = NULL ;
00101
00102 while (!lines.empty()) {
00103 delete lines.front();
00104 lines.pop_front();
00105 }
00106
00107 D.Out(pdTerm, "List is now empty.");
00108 }
00109
00110
00112 InteractionBroadcastLine*
00113 InteractionBroadcastList::getLineWithFederate(FederateHandle federate)
00114 {
00115 list<InteractionBroadcastLine *>::iterator i ;
00116 for (i = lines.begin(); i != lines.end(); i++) {
00117 if ((*i)->federate == federate)
00118 return (*i);
00119 }
00120
00121 return 0 ;
00122 }
00123
00124
00131 void
00132 InteractionBroadcastList::sendPendingMessage(SecurityServer *server)
00133 {
00134
00135 G.Out(pdGendoc,"enter InteractionBroadcastList::sendPendingMessage");
00136
00137 list<InteractionBroadcastLine *>::iterator i ;
00138 for (i = lines.begin(); i != lines.end(); i++) {
00139
00140 if ((*i)->state == InteractionBroadcastLine::waiting) {
00141
00142
00143 D.Out(pdProtocol, "Broadcasting message to Federate %d.",
00144 (*i)->federate);
00145
00146 Socket *socket = 0 ;
00147 try {
00148 #ifdef HLA_USES_UDP
00149 socket = server->getSocketLink((*i)->federate, BEST_EFFORT);
00150 #else
00151 socket = server->getSocketLink((*i)->federate);
00152 #endif
00153
00154 G.Out(pdGendoc,"sendPendingMessage===>write");
00155
00156 message->send(socket,NM_msgBufSend);
00157 }
00158 catch (RTIinternalError &e) {
00159 D.Out(pdExcept,
00160 "Reference to a killed Federate while broadcasting.");
00161 }
00162 catch (NetworkError &e) {
00163 D.Out(pdExcept, "Network error while broadcasting, ignoring.");
00164 }
00165
00166
00167 (*i)->state = InteractionBroadcastLine::sent ;
00168 }
00169 else
00170 D.Out(pdProtocol, "No message sent to Federate %d.",
00171 (*i)->federate);
00172 }
00173
00174 G.Out(pdGendoc,"exit InteractionBroadcastList::sendPendingMessage");
00175
00176 }
00177
00178 }
00179
00180