# RTIA_network.cc

Go to the documentation of this file.

    00001 // ----------------------------------------------------------------------------
    00002 // CERTI - HLA RunTime Infrastructure
    00003 // Copyright (C) 2002, 2003  ONERA
    00004 //
    00005 // This file is part of CERTI
    00006 //
    00007 // CERTI is free software ; you can redistribute it and/or modify
    00008 // it under the terms of the GNU General Public License as published by
    00009 // the Free Software Foundation ; either version 2 of the License, or
    00010 // (at your option) any later version.
    00011 //
    00012 // CERTI is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY ; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    00015 // GNU General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU General Public License
    00018 // along with this program ; if not, write to the Free Software
    00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    00020 //
    00021 // $Id: RTIA_network.cc,v 3.32 2009/04/08 10:47:18 approx Exp $
    00022 // ----------------------------------------------------------------------------
    00023
    00024 #include <config.h>
    00025 #include "NM_Classes.hh"
    00026 #include "RTIA.hh"
    00027 #include "ObjectClassAttribute.hh"
    00028 #include "Interaction.hh"
    00029 #include "InteractionSet.hh"
    00030 #include "ObjectClass.hh"
    00031 #include "ObjectClassSet.hh"
    00032 #include <assert.h>
    00033
    00034 namespace certi {
    00035 namespace rtia {
    00036
    00037 static pdCDebug D("RTIA", "(RTIA net) ");
    00038 static PrettyDebug G("GENDOC",__FILE__);
    00039
    00040 // ----------------------------------------------------------------------------
    00042 void
    00043 RTIA::processNetworkMessage(NetworkMessage *msg)
    00044 {
    00045 NetworkMessage::Type msgType = msg->getType();
    00046
    00047     G.Out(pdGendoc,"enter RTIA::processNetworkMessage");
    00048
    00049     switch(msgType) {
    00050
    00051       case NetworkMessage::MESSAGE_NULL:
    00052       {
    00053           D.Out(pdTrace,
    00054                 "Receving Message from RTIG, type NetworkMessage::MESSAGE_NULL(%f).",
    00055                 msg->getDate().getTime());
    00056
    00057           tm->update(msg->federate, msg->getDate());
    00058           delete msg ;
    00059           break ;
    00060       }
    00061
    00062       case NetworkMessage::SET_TIME_REGULATING:
    00063       {
    00064           // Another federate is becoming regulating.
    00065           D.Out(pdTrace,
    00066                 "Receving Message from RTIG, type NetworkMessage::SET_TIME_REGULATING.");
    00067
    00068           if (static_cast<NM_Set_Time_Regulating*>(msg)->isRegulator())
    00069               tm->insert(msg->federate, msg->getDate());
    00070           else
    00071               tm->remove(msg->federate);
    00072           delete msg ;
    00073           break ;
    00074       }
    00075
    00076       case NetworkMessage::SYNCHRONIZATION_POINT_REGISTRATION_SUCCEEDED:
    00077         D.Out(pdTrace, "Receiving Message from RTIG, type NetworkMessage::SYNCHRONIZATION_"
    00078               "POINT_REGISTRATION_SUCCEEDED.");
    00079
    00080         queues->insertLastCommand(msg);
    00081         break ;
    00082       case NetworkMessage::ANNOUNCE_SYNCHRONIZATION_POINT:
    00083         D.Out(pdTrace, "Receiving Message from RTIG, type NetworkMessage::ANNOUCE_"
    00084               "SYNCHRONIZATION_POINT.");
    00085
    00086         queues->insertLastCommand(msg);
    00087         break ;
    00088       case NetworkMessage::FEDERATION_SYNCHRONIZED:
    00089         D.Out(pdTrace,
    00090               "Receiving Message from RTIG, type NetworkMessage::FEDERATION_SYNCHRONIZED.");
    00091         queues->insertLastCommand(msg);
    00092         break ;
    00093
    00094       case NetworkMessage::DISCOVER_OBJECT:
    00095       {
    00096           D.Out(pdTrace, "Receving Message from RTIG, "
    00097                 "type NetworkMessage::DISCOVER_OBJECT.");
    00098           queues->insertFifoMessage(msg);
    00099       }
    00100       break;
    00101
    00102       case NetworkMessage::REFLECT_ATTRIBUTE_VALUES:
    00103       {
    00104           OrderType updateOrder  ;
    00105
    00106           D.Out(pdTrace,
    00107                 "Receving Message from RTIG, "
    00108                 "type NetworkMessage::REFLECT_ATTRIBUTE_VALUES.");
    00109
    00110          // It is important to note that several attributes may be updated at
    00111          // the same time. Each attribute has its own order type, region, etc.
    00112          // So attributes which are meeting similar criteria should be sent
    00113          // together. It means that case REFLECT_ATTRIBUTE_VALUES can generate
    00114          // several messages in queues.
    00115          //
    00116          // At this point of development, we cannot assume this facility and
    00117          // decided to store message as TSO only if all attributes meets TSO
    00118          // criteria. Otherwise, a single message will be enqueue in FIFO.
    00119
    00120          // Here we have to consider RAV without time
    00121          if ( !msg->isDated())
    00122              {
    00123              // without time
    00124              updateOrder = RECEIVE ;
    00125              }
    00126          else
    00127              {
    00128              // Retrieve order type
    00129              updateOrder = TIMESTAMP;
    00130
    00131              for (UShort i=0; i< msg->handleArraySize; ++i)
    00132                {
    00133                 if (rootObject->ObjectClasses->getObjectFromHandle( msg->objectClass)
    00134                     ->getAttribute(msg->handleArray[i])->order != TIMESTAMP)
    00135                 {
    00136                    updateOrder = RECEIVE;
    00137                    break;
    00138                 }
    00139                }
    00140              }
    00141
    00142          // Decide which queue will be used
    00143          if(updateOrder == TIMESTAMP && tm->requestContraintState())
    00144          {
    00145             // Update is TSO
    00146             queues->insertTsoMessage(msg);
    00147          }
    00148          else
    00149          {
    00150             // Update is RO
    00151             queues->insertFifoMessage(msg);
    00152          }
    00153
    00154          break ;
    00155       }
    00156
    00157       case NetworkMessage::RECEIVE_INTERACTION:
    00158       {
    00159          OrderType interactionOrder ;
    00160
    00161          D.Out(pdTrace,
    00162             "Receving Message from RTIG, type NetworkMessage::RECEIVE_INTERACTION.");
    00163
    00164          // Here we have to consider RAV without time
    00165          if ( !msg->isDated())
    00166              {
    00167              // without time
    00168              interactionOrder = RECEIVE ;
    00169              }
    00170          else
    00171              {
    00172              // Retrieve order type
    00173              interactionOrder = rootObject->Interactions->
    00174                 getObjectFromHandle(msg->interactionClass)->order;
    00175              }
    00176
    00177          // Decide which queue will be used
    00178          if (interactionOrder == TIMESTAMP && tm->requestContraintState())
    00179          {
    00180             // Interaction is TSO
    00181             queues->insertTsoMessage(msg);
    00182          }
    00183          else
    00184          {
    00185             // Interaction is RO
    00186             queues->insertFifoMessage(msg);
    00187          }
    00188
    00189          break ;
    00190       }
    00191
    00192       case NetworkMessage::REMOVE_OBJECT:
    00193       {
    00194           D.Out(pdTrace, "Receving Message from RTIG, \
    00195               type NetworkMessage::REMOVE_OBJECT.");
    00196
    00197           if (tm->requestContraintState() && msg->isDated()) {
    00198               // Verify that received TSO timestamp is >= current
    00199               // time + lookahead
    00200               queues->insertTsoMessage(msg);
    00201           }
    00202           else {
    00203               queues->insertFifoMessage(msg);
    00204       }
    00205
    00206           break ;
    00207       }
    00208
    00209       case NetworkMessage::INFORM_ATTRIBUTE_OWNERSHIP:
    00210       {
    00211           D.Out(pdTrace,
    00212                 "Receving Message from RTIG, "
    00213                 "type NetworkMessage::INFORM_ATTRIBUTE_OWNERSHIP.");
    00214           queues->insertFifoMessage(msg);
    00215           break ;
    00216       }
    00217
    00218       case NetworkMessage::ATTRIBUTE_IS_NOT_OWNED:
    00219       {
    00220           D.Out(pdTrace,
    00221                 "Receving Message from RTIG, type NetworkMessage::ATTRIBUTE_IS_NOT_OWNED.");
    00222           queues->insertFifoMessage(msg);
    00223           break ;
    00224       }
    00225
    00226
    00227       case NetworkMessage::REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION:
    00228       {
    00229           D.Out(pdTrace, "Receving Message from RTIG, "
    00230                 "type NetworkMessage::REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION.");
    00231           queues->insertFifoMessage(msg);
    00232           break ;
    00233       }
    00234
    00235       case NetworkMessage::ATTRIBUTE_OWNERSHIP_UNAVAILABLE:
    00236       {
    00237           D.Out(pdTrace, "Receving Message from RTIG, "
    00238                 "type NetworkMessage::ATTRIBUTE_OWNERSHIP_UNAVAILABLE.");
    00239           queues->insertFifoMessage(msg);
    00240           break ;
    00241       }
    00242
    00243       case NetworkMessage::ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION:
    00244       {
    00245           D.Out(pdTrace, "Receving Message from RTIG, "
    00246                 "type NetworkMessage::ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION.");
    00247           queues->insertFifoMessage(msg);
    00248           break ;
    00249       }
    00250
    00251       case NetworkMessage::ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION:
    00252       {
    00253           D.Out(pdTrace, "Receving Message from RTIG, "
    00254                 "type NetworkMessage::ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION.");
    00255           queues->insertFifoMessage(msg);
    00256           break ;
    00257       }
    00258
    00259       case NetworkMessage::REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE:
    00260       {
    00261           D.Out(pdTrace, "Receving Message from RTIG, "
    00262                 "type NetworkMessage::REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE.");
    00263           queues->insertFifoMessage(msg);
    00264           break ;
    00265       }
    00266
    00267
    00268       case NetworkMessage::CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION:
    00269       {
    00270           D.Out(pdTrace, "Receving Message from RTIG, "
    00271                 "type NetworkMessage::CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION.");
    00272           queues->insertFifoMessage(msg);
    00273           break ;
    00274       }
    00275
    00276       case NetworkMessage::INITIATE_FEDERATE_SAVE:
    00277         D.Out(pdTrace, "Receiving Message from RTIG, "
    00278               " type InitiateFederateSave.");
    00279         queues->insertBeginCommand(msg);
    00280         break ;
    00281
    00282       case NetworkMessage::FEDERATION_SAVED:
    00283       case NetworkMessage::FEDERATION_NOT_SAVED:
    00284         D.Out(pdTrace, "Receiving Message from RTIG, "
    00285               " type Federation(Not)Saved.");
    00286         queues->insertBeginCommand(msg);
    00287         break ;
    00288
    00289       case NetworkMessage::REQUEST_FEDERATION_RESTORE_SUCCEEDED:
    00290         D.Out(pdTrace, "Receiving Message from RTIG, "
    00291               " type RequestFederationRestoreSucceeded.");
    00292         G.Out(pdGendoc,"processNetworkMessage for REQUEST_FEDERATION_RESTORE_SUCCEEDED");
    00293         queues->insertLastCommand(msg);
    00294         break ;
    00295
    00296       case NetworkMessage::REQUEST_FEDERATION_RESTORE_FAILED:
    00297         D.Out(pdTrace, "Receiving Message from RTIG, "
    00298               " type RequestFederationRestoreFailed.");
    00299         G.Out(pdGendoc,"processNetworkMessage for REQUEST_FEDERATION_RESTORE_FAILED");
    00300         queues->insertLastCommand(msg);
    00301         break ;
    00302
    00303       case NetworkMessage::FEDERATION_RESTORE_BEGUN:
    00304         D.Out(pdTrace, "Receiving Message from RTIG, "
    00305               " type FederationRestoreBegun.");
    00306         queues->insertLastCommand(msg);
    00307         break ;
    00308
    00309       case NetworkMessage::INITIATE_FEDERATE_RESTORE:
    00310         D.Out(pdTrace, "Receiving Message from RTIG, "
    00311               " type InitiateFederateRestore.");
    00312         G.Out(pdGendoc,"processNetworkMessage for INITIATE_FEDERATE_RESTORE");
    00313         queues->insertLastCommand(msg);
    00314         break ;
    00315
    00316       case NetworkMessage::FEDERATION_RESTORED:
    00317       case NetworkMessage::FEDERATION_NOT_RESTORED:
    00318         D.Out(pdTrace, "Receiving Message from RTIG, "
    00319               " type Federation(Not)Restored.");
    00320         queues->insertLastCommand(msg);
    00321         break ;
    00322
    00323       case NetworkMessage::PROVIDE_ATTRIBUTE_VALUE_UPDATE:
    00324         D.Out(pdTrace, "Receiving Message from RTIG, "
    00325               " type ProvideAttributeValueUpdate.");
    00326         queues->insertFifoMessage(msg);
    00327         break ;
    00328
    00329       case NetworkMessage::TIME_REGULATION_ENABLED:
    00330           D.Out(pdTrace, "Receiving Message from RTIG, "
    00331                   " type TimeRegulationEnabled.");
    00332           queues->insertLastCommand(msg);
    00333           break ;
    00334       case NetworkMessage::TIME_CONSTRAINED_ENABLED:
    00335           D.Out(pdTrace, "Receiving Message from RTIG, "
    00336                   " type TimeConstrainedEnabled.");
    00337           queues->insertLastCommand(msg);
    00338           break;
    00339       case NetworkMessage::SET_CLASS_RELEVANCE_ADVISORY_SWITCH:
    00340           D.Out(pdTrace, "Receiving Message from RTIG, "
    00341                   " type setCRAS.");
    00342       break;
    00343       case NetworkMessage::SET_INTERACTION_RELEVANCE_ADVISORY_SWITCH:
    00344           D.Out(pdTrace, "Receiving Message from RTIG, "
    00345                   " type setIRAS.");
    00346       break;
    00347       case NetworkMessage::SET_ATTRIBUTE_RELEVANCE_ADVISORY_SWITCH:
    00348           D.Out(pdTrace, "Receiving Message from RTIG, "
    00349                   " type setARAS.");
    00350       break;
    00351       case NetworkMessage::SET_ATTRIBUTE_SCOPE_ADVISORY_SWITCH:
    00352           D.Out(pdTrace, "Receiving Message from RTIG, "
    00353                   " type setASAS.");
    00354       break;
    00355       case NetworkMessage::START_REGISTRATION_FOR_OBJECT_CLASS:
    00356           D.Out(pdTrace, "Receiving Message from RTIG, "
    00357                   " type StartRegForObjClass.");
    00358           queues->insertLastCommand(msg);
    00359       break;
    00360
    00361       default:
    00362       {
    00363           D.Out(pdTrace,
    00364                 "Receving Message from RTIG, unknown type %d.", msgType);
    00365           delete msg ;
    00366           throw RTIinternalError("Unknown Message type received from RTIG.");
    00367       }
    00368     }
    00369
    00370     stat.rtiService(msgType);
    00371     G.Out(pdGendoc,"exit  RTIA::processNetworkMessage");
    00372 }
    00373
    00374 }} // namespace certi/rtia
    00375
    00376 // $Id: RTIA_network.cc,v 3.32 2009/04/08 10:47:18 approx Exp $