# RTIG_processing.cc

Go to the documentation of this file.

    00001 // ----------------------------------------------------------------------------
    00002 // CERTI - HLA RunTime Infrastructure
    00003 // Copyright (C) 2002-2005  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: RTIG_processing.cc,v 3.82 2009/04/08 10:47:19 approx Exp $
    00022 // ----------------------------------------------------------------------------
    00023
    00024 #include <config.h>
    00025 #include "RTIG.hh"
    00026 #include "NM_Classes.hh"
    00027
    00028 #include <iostream>
    00029 #include <cassert>
    00030 #include <memory>
    00031
    00032 using std::endl ;
    00033 using std::cout ;
    00034
    00035 namespace certi {
    00036 namespace rtig {
    00037
    00038 static PrettyDebug D("RTIG", __FILE__);
    00039 static PrettyDebug G("GENDOC",__FILE__);
    00040
    00041 // ----------------------------------------------------------------------------
    00043 void
    00044 RTIG::processCreateFederation(Socket *link, NetworkMessage *req)
    00045 {
    00046     std::string federation = req->federationName;
    00047     std::string FEDid      = req->FEDid;
    00048     NM_Create_Federation_Execution  rep;   // rep for answer to RTIA
    00049
    00050     G.Out(pdGendoc,"enter RTIG::processCreateFederation");
    00051     G.Out(pdGendoc,"BEGIN ** CREATE FEDERATION SERVICE **");
    00052
    00053     if (federation.length() == 0)
    00054         {
    00055         G.Out(pdGendoc,"exit  RTIG::processCreateFederation on exception RTIinternalError");
    00056         throw RTIinternalError("Invalid Federation Name.");
    00057         }
    00058
    00059     auditServer << "Federation Name : " << federation.c_str() ;
    00060     Handle h = federationHandles.provide();
    00061
    00062 #ifdef FEDERATION_USES_MULTICAST
    00063     // multicast base address
    00064     unsigned long base_adr_mc = inet_addr(ADRESSE_MULTICAST);
    00065     SocketMC *com_mc = NULL ;
    00066
    00067     // creer la communication multicast
    00068     com_mc = new SocketMC();
    00069     if (com_mc == NULL) {
    00070         D.Out(pdExcept, "Unable to allocate Multicast socket.");
    00071         G.Out(pdGendoc,"exit  RTIG::processCreateFederation on exception RTIinternalError")
    00072         throw RTIinternalError("Unable to allocate Multicast socket.");
    00073     }
    00074
    00075     com_mc->CreerSocketMC(base_adr_mc + h, MC_PORT);
    00076
    00077     // inserer la nouvelle federation dans la liste des federations
    00078     federations->createFederation(federation, h, com_mc);
    00079
    00080     // inserer descripteur fichier pour le prochain appel a un select
    00081     ClientSockets.push_front(com_mc);
    00082
    00083 #else
    00084     // We catch createFederation because it is useful to send
    00085     // exception reason to RTIA
    00086     try {
    00087         federations.createFederation(federation.c_str(), h, FEDid.c_str());
    00088         }
    00089     catch (CouldNotOpenFED e)
    00090         {
    00091         rep.exception = e_CouldNotOpenFED ;
    00092         rep.exceptionReason=e._reason;
    00093         }
    00094     catch (ErrorReadingFED e)
    00095         {
    00096         rep.exception = e_ErrorReadingFED ;
    00097         rep.exceptionReason = e._reason ;
    00098         }
    00099     catch (FederationExecutionAlreadyExists e)
    00100         {
    00101         rep.exception = e_FederationExecutionAlreadyExists ;
    00102         rep.exceptionReason =e._reason ;
    00103         }
    00104 #endif
    00105     // Prepare answer for RTIA : store NetworkMessage rep
    00106     if ( rep.exception == e_NO_EXCEPTION )
    00107         {
    00108         rep.federation = h ;
    00109         rep.FEDid = FEDid;
    00110         rep.federationName = federation;
    00111         auditServer <<" created.";
    00112
    00113         }
    00114
    00115     G.Out(pdGendoc,"processCreateFederation===>write answer to RTIA");
    00116
    00117     rep.send(link,NM_msgBufSend); // Send answer to RTIA
    00118
    00119     D.Out(pdInit, "Federation \"%s\" created with Handle %d.",
    00120           federation.c_str(), rep.federation);
    00121
    00122     G.Out(pdGendoc,"END ** CREATE FEDERATION SERVICE **");
    00123     G.Out(pdGendoc,"exit RTIG::processCreateFederation");
    00124 }
    00125
    00126 // ----------------------------------------------------------------------------
    00128 void
    00129 RTIG::processJoinFederation(Socket *link, NetworkMessage *req)
    00130 {
    00131     std::string federation = req->federationName ;
    00132     std::string federate   = req->federateName ;
    00133     std::string filename ;
    00134
    00135     unsigned int peer     = req->bestEffortPeer ;
    00136     unsigned long address = req->bestEffortAddress ;
    00137
    00138     Handle num_federation ;
    00139     FederateHandle num_federe ;
    00140
    00141     int nb_regulateurs ;
    00142     int nb_federes ;
    00143     bool pause ;
    00144
    00145     G.Out(pdGendoc,"BEGIN ** JOIN FEDERATION SERVICE **");
    00146     G.Out(pdGendoc,"enter RTIG::processJoinFederation");
    00147
    00148     if ((federation.length()==0) || (federate.length() == 0))
    00149         throw RTIinternalError("Invalid Federation/Federate Name.");
    00150
    00151     auditServer << "Federate \"" << federate.c_str() << "\" joins Federation \""
    00152         << federation.c_str() << "\"" ;
    00153
    00154     federations.exists(federation.c_str(), num_federation);
    00155
    00156     try
    00157        {
    00158         num_federe = federations.addFederate(num_federation,
    00159                                           federate.c_str(),
    00160                                           static_cast<SocketTCP*>(link));
    00161         }
    00162     catch (FederateAlreadyExecutionMember &e)
    00163         {
    00164         // Federate yet has joined this federation(same or another with same name)
    00165         // RTIG has to return something to RTIA
    00166         // RTIA waits a GET_FED_FILE message
    00167         // RTIG says not OK to RTIA in a GET_FED_FILE message
    00168         NM_Get_FED_File repFED ;
    00169        repFED.exception = e_FederateAlreadyExecutionMember ;
    00170        repFED.exceptionReason="Federate with same name has yet joined the federation";
    00171        G.Out(pdGendoc,"processJoinFederation==>Answer to RTIA GFF ERROR %s",repFED.exceptionReason.c_str());
    00172        repFED.send(link,NM_msgBufSend);
    00173
    00174        G.Out(pdGendoc,"exit RTIG::processJoinFederation on Error");
    00175        G.Out(pdGendoc,"END ** JOIN FEDERATION (BAD) SERVICE **");
    00176        // FIXME strange to send 2 messages?
    00177        // Prepare answer about JoinFederationExecution
    00178        NM_Join_Federation_Execution rep ;
    00179        rep.exception = e_FederateAlreadyExecutionMember ;
    00180        rep.exceptionReason = "Federate with same name has yet joined the federation";
    00181
    00182        G.Out(pdGendoc,"processJoinFederation==>Answer to RTIA JFE ERROR %s",rep.exceptionReason.c_str());
    00183
    00184        rep.send(link,NM_msgBufSend);
    00185        return ;
    00186        }
    00187
    00188 #ifdef FEDERATION_USES_MULTICAST
    00189      SocketMC *com_mc = NULL ;
    00190
    00191      federations.info(num_federation, nb_federes, nb_regulateurs,
    00192                       pause, com_mc);
    00193      assert(com_mc != NULL);
    00194 #else
    00195      filename = federations.info(num_federation, nb_federes, nb_regulateurs, pause);
    00196 #endif
    00197
    00198     // Store Federate <->Socket reference.
    00199     socketServer.setReferences(link->returnSocket(),
    00200                                 num_federation,
    00201                                 num_federe,
    00202                                 address,
    00203                                 peer);
    00204
    00205     auditServer << "(" << num_federation << ")with handle " << num_federe
    00206         << ". Socket " << link->returnSocket();
    00207
    00208     // Prepare answer about JoinFederationExecution
    00209     // This answer wille be made AFTER FED file processing
    00210     NM_Join_Federation_Execution rep ;
    00211     rep.federationName = federation;
    00212     rep.federate = num_federe ;
    00213     rep.federation = num_federation ;
    00214     rep.numberOfRegulators = nb_regulateurs ;
    00215     rep.bestEffortPeer = peer ;
    00216     rep.bestEffortAddress = address ;
    00217
    00218     // Here begin FED file processing i.e. RTIG gives FED file contents to RTIA
    00219     TypeException e = e_NO_EXCEPTION ;
    00220     // Open FED file and says to RTIA if success
    00221     std::ifstream fedFile(filename.c_str());
    00222     if ( !fedFile.is_open()) {
    00223         // Problem : file has been opened during create federation and now we can't
    00224         // May be file has been deleted
    00225         cout << "processJoinFederation : FED file " << filename << " has vanished." << endl;
    00226         e = e_RTIinternalError ;
    00227     }
    00228
    00229     // RTIG says OK or not to RTIA
    00230     NM_Get_FED_File repFED ;
    00231     repFED.federate = num_federe ;
    00232     repFED.federation = num_federation ;
    00233     repFED.number = 0 ;
    00234     repFED.FEDid = filename ;
    00235     repFED.exception = e ;
    00236     // Send answer
    00237     D.Out(pdTrace,"send NetworkMessage of Type %d after open \"%s\"",
    00238           repFED.getType(),repFED.FEDid.c_str());
    00239     G.Out(pdGendoc,"processJoinFederation====>Begin FED file transfer");
    00240
    00241     repFED.send(link,NM_msgBufSend);
    00242
    00243     if ( e ==  e_NO_EXCEPTION )
    00244         {
    00245         // Wait for OK from RTIA
    00246         NM_Get_FED_File msg ;
    00247         D.Out(pdTrace,"wait NetworkMessage of Type %d",msg.getType());
    00248         msg.receive(link,NM_msgBufReceive);
    00249         assert ( msg.number == 0 );
    00250         // RTIA has opened working file then RTIG has to transfer file contents
    00251         // line by line
    00252         std::string fileLine;
    00253         int num_line = 0 ;
    00254         while (!fedFile.eof())
    00255             {
    00256             num_line++;
    00257             // Read a line
    00258             std::getline(fedFile,fileLine);
    00259             fileLine = fileLine+"\n";
    00260             // RTIG sends line to RTIA and number gives line number
    00261             repFED.exception = e_NO_EXCEPTION ;
    00262             repFED.federate = num_federe ;
    00263             repFED.federation = num_federation ;
    00264             repFED.number = num_line ;
    00265             repFED.FEDid = filename;
    00266             // line transfered
    00267             repFED.setFEDLine(fileLine);
    00268             // Send answer
    00269             repFED.send(link,NM_msgBufSend);
    00270
    00271             // Wait for OK from RTIA
    00272             msg.receive(link,NM_msgBufReceive);
    00273             assert ( msg.number == num_line );
    00274             }
    00275
    00276         // close
    00277         fedFile.close();
    00278         repFED.exception = e_NO_EXCEPTION ;
    00279         repFED.federate = num_federe ;
    00280         repFED.federation = num_federation ;
    00281         repFED.number = 0 ;
    00282         repFED.FEDid = filename;
    00283         // Send answer
    00284
    00285         G.Out(pdGendoc,"processJoinFederation====>End  FED file transfer");
    00286
    00287         repFED.send(link,NM_msgBufSend);
    00288         }
    00289     // END of FED file processing
    00290
    00291     // Now we have to answer about JoinFederationExecution
    00292
    00293 #ifdef FEDERATION_USES_MULTICAST
    00294     rep.AdresseMulticast = com_mc->returnAdress();
    00295 #endif
    00296
    00297     D.Out(pdInit, "Federate \"%s\" has joined Federation %u under handle %u.",
    00298           federate.c_str(), num_federation, num_federe);
    00299
    00300     // Send answer
    00301
    00302     rep.send(link,NM_msgBufSend);
    00303
    00304     G.Out(pdGendoc,"exit RTIG::processJoinFederation");
    00305     G.Out(pdGendoc,"END ** JOIN FEDERATION SERVICE **");
    00306
    00307 }
    00308
    00309 // ----------------------------------------------------------------------------
    00311 void
    00312 RTIG::processResignFederation(Socket *link,Handle federation,
    00313                               FederateHandle federe)
    00314 {
    00315     NM_Resign_Federation_Execution reponse ;
    00316
    00317     G.Out(pdGendoc,"BEGIN ** RESIGN FEDERATION SERVICE **");
    00318     G.Out(pdGendoc,"enter RTIG::processResignFederation");
    00319
    00320     federations.remove(federation, federe);
    00321     D.Out(pdInit, "Federate %u is resigning from federation %u.",
    00322           federe, federation);
    00323
    00324     auditServer << "Federate " << federe << " resign federation("<<federation<<")" ;
    00325
    00326     // Send answer to RTIA
    00327     reponse.federate = federe ;
    00328     reponse.federation = federation ;
    00329     reponse.send(link,NM_msgBufSend);
    00330
    00331     G.Out(pdGendoc,"exit RTIG::processResignFederation");
    00332     G.Out(pdGendoc,"END ** RESIGN FEDERATION SERVICE **");
    00333
    00334 }
    00335
    00336 // ----------------------------------------------------------------------------
    00338 void
    00339 RTIG::processDestroyFederation(Socket *link, NetworkMessage *req)
    00340 {
    00341     NM_Destroy_Federation_Execution rep ;
    00342     Handle num_federation ;
    00343
    00344     std::string federation = req->federationName ;
    00345
    00346     G.Out(pdGendoc,"enter RTIG::processDestroyFederation");
    00347     G.Out(pdGendoc,"BEGIN ** DESTROY FEDERATION SERVICE **");
    00348
    00349     if (federation.length() == 0) throw RTIinternalError("Invalid Federation Name.");
    00350
    00351     federations.exists(federation.c_str(), num_federation);
    00352     // May throw RTIinternalError
    00353     //           FederatesCurrentlyJoined
    00354     //           FederationExecutionDoesNotExist
    00355     try {
    00356       federations.destroyFederation(num_federation);
    00357       // Here delete federation (num_federation) has been done
    00358       federationHandles.free(num_federation);
    00359       D.Out(pdInit, "Federation \"%s\" has been destroyed.", federation.c_str());
    00360     }
    00361     catch (Exception &e)
    00362       { printf("ERROR : %s  reason : %s\n",e._name,e._reason.c_str());
    00363         if (strcmp(e._name,"RTIinternalError")==0 )
    00364           {
    00365           rep.exception = e_RTIinternalError;
    00366           rep.exceptionReason = e._reason;
    00367           }
    00368         else if (strcmp(e._name,"FederationExecutionDoesNotExist")==0 )
    00369           {
    00370           rep.exception = e_FederationExecutionDoesNotExist;
    00371           rep.exceptionReason =e._reason;
    00372           }
    00373         else if (strcmp(e._name,"FederatesCurrentlyJoined")==0 )
    00374           {
    00375           rep.exception = e_FederatesCurrentlyJoined;
    00376           rep.exceptionReason = "at least one federate joined";
    00377           }
    00378       }
    00379
    00380     rep.federate = req->federate ;
    00381     rep.federationName = req->federationName;
    00382     if ( rep.exception == e_NO_EXCEPTION )
    00383        {
    00384        auditServer << "Federation Name \"" << federation.c_str() << "\"("<<num_federation<<") destroyed." ;
    00385        }
    00386     G.Out(pdGendoc,"processDestroyFederation===>write DFE to RTIA");
    00387
    00388     rep.send(link,NM_msgBufSend);
    00389
    00390     G.Out(pdGendoc,"END ** DESTROY FEDERATION SERVICE **");
    00391     G.Out(pdGendoc,"exit RTIG::processDestroyFederation");
    00392 }
    00393
    00394 // ----------------------------------------------------------------------------
    00396 void
    00397 RTIG::processSetClassRelevanceAdvisorySwitch(Socket *link,
    00398                  NM_Set_Class_Relevance_Advisory_Switch *msg)
    00399 {
    00400   NM_Set_Class_Relevance_Advisory_Switch rep;
    00401
    00402   G.Out(pdGendoc,"enter RTIG::processSetClassRelevanceAdvisorySwitch");
    00403   G.Out(pdGendoc,"BEGIN ** SET CLASS RELEVANCE ADVISORY SWITCH **");
    00404
    00405   if (msg->getClassRelevanceAdvisorySwitch()) {
    00406         auditServer << "ON";
    00407     federations.setClassRelevanceAdvisorySwitch(msg->federation, msg->federate);
    00408         D.Out(pdTerm, "Federate %u of Federation %u sets AttributeRelevanceAdvisorySwitch.",
    00409               msg->federate, msg->federation);
    00410   }
    00411   else {
    00412         auditServer << "OFF";
    00413     federations.unsetClassRelevanceAdvisorySwitch(msg->federation, msg->federate);
    00414         D.Out(pdTerm, "Federate %u of Federation %u clears AttributeRelevanceAdvisorySwitch.",
    00415               msg->federate, msg->federation);
    00416   }
    00417
    00418   rep.send(link,NM_msgBufSend);
    00419
    00420   G.Out(pdGendoc,"END ** SET CLASS RELEVANCE ADVISORY SWITCH **");
    00421   G.Out(pdGendoc,"exit RTIG::processSetClassRelevanceAdvisorySwitch");
    00422 }
    00423
    00424 // ----------------------------------------------------------------------------
    00426 void
    00427 RTIG::processSetInteractionRelevanceAdvisorySwitch(Socket *link,
    00428                  NM_Set_Interaction_Relevance_Advisory_Switch *msg)
    00429 {
    00430   NM_Set_Interaction_Relevance_Advisory_Switch rep;
    00431
    00432   G.Out(pdGendoc,"enter RTIG::processSetInteractionRelevanceAdvisorySwitch");
    00433   G.Out(pdGendoc,"BEGIN ** SET INTERACTION RELEVANCE ADVISORY SWITCH **");
    00434
    00435   if (msg->getInteractionRelevanceAdvisorySwitch()) {
    00436         auditServer << "ON";
    00437     federations.setInteractionRelevanceAdvisorySwitch(msg->federation, msg->federate);
    00438         D.Out(pdTerm, "Federate %u of Federation %u sets InteractionRelevanceAdvisorySwitch.",
    00439               msg->federate, msg->federation);
    00440   }
    00441   else {
    00442         auditServer << "OFF";
    00443     federations.unsetInteractionRelevanceAdvisorySwitch(msg->federation, msg->federate);
    00444         D.Out(pdTerm, "Federate %u of Federation %u clears InteractionRelevanceAdvisorySwitch.",
    00445               msg->federate, msg->federation);
    00446   }
    00447
    00448   rep.send(link,NM_msgBufSend);
    00449
    00450   G.Out(pdGendoc,"END ** SET INTERACTION RELEVANCE ADVISORY SWITCH **");
    00451   G.Out(pdGendoc,"exit RTIG::processSetInteractionRelevanceAdvisorySwitch");
    00452 }
    00453
    00454 // ----------------------------------------------------------------------------
    00456 void
    00457 RTIG::processSetAttributeRelevanceAdvisorySwitch(Socket *link,
    00458                  NM_Set_Attribute_Relevance_Advisory_Switch *msg)
    00459 {
    00460   NM_Set_Attribute_Relevance_Advisory_Switch rep;
    00461
    00462   G.Out(pdGendoc,"enter RTIG::processSetAttributeRelevanceAdvisorySwitch");
    00463   G.Out(pdGendoc,"BEGIN ** SET ATTRIBUTE RELEVANCE ADVISORY SWITCH **");
    00464
    00465   if (msg->getAttributeRelevanceAdvisorySwitch()) {
    00466         auditServer << "ON";
    00467     federations.setAttributeRelevanceAdvisorySwitch(msg->federation, msg->federate);
    00468         D.Out(pdTerm, "Federate %u of Federation %u sets AttributeRelevanceAdvisorySwitch.",
    00469               msg->federate, msg->federation);
    00470   }
    00471   else {
    00472         auditServer << "OFF";
    00473     federations.unsetAttributeRelevanceAdvisorySwitch(msg->federation, msg->federate);
    00474         D.Out(pdTerm, "Federate %u of Federation %u clears AttributeRelevanceAdvisorySwitch.",
    00475               msg->federate, msg->federation);
    00476   }
    00477
    00478   rep.send(link,NM_msgBufSend);
    00479
    00480   G.Out(pdGendoc,"END ** SET ATTRIBUTE RELEVANCE ADVISORY SWITCH **");
    00481   G.Out(pdGendoc,"exit RTIG::processSetAttributeRelevanceAdvisorySwitch");
    00482 }
    00483
    00484 // ----------------------------------------------------------------------------
    00486 void
    00487 RTIG::processSetAttributeScopeAdvisorySwitch(Socket *link,
    00488                  NM_Set_Attribute_Scope_Advisory_Switch *msg)
    00489 {
    00490   NM_Set_Attribute_Scope_Advisory_Switch rep;
    00491
    00492   G.Out(pdGendoc,"enter RTIG::processSetAttributeScopeAdvisorySwitch");
    00493   G.Out(pdGendoc,"BEGIN ** SET ATTRIBUTE SCOPE ADVISORY SWITCH **");
    00494
    00495   if (msg->getAttributeScopeAdvisorySwitch()) {
    00496         auditServer << "ON";
    00497     federations.setAttributeScopeAdvisorySwitch(msg->federation, msg->federate);
    00498         D.Out(pdTerm, "Federate %u of Federation %u sets AttributeScopeAdvisorySwitch.",
    00499               msg->federate, msg->federation);
    00500   }
    00501   else {
    00502         auditServer << "OFF";
    00503     federations.unsetAttributeScopeAdvisorySwitch(msg->federation, msg->federate);
    00504         D.Out(pdTerm, "Federate %u of Federation %u clears AttributeScopeAdvisorySwitch.",
    00505               msg->federate, msg->federation);
    00506   }
    00507
    00508   rep.send(link,NM_msgBufSend);
    00509
    00510   G.Out(pdGendoc,"END ** SET ATTRIBUTE SCOPE ADVISORY SWITCH **");
    00511   G.Out(pdGendoc,"exit RTIG::processSetAttributeScopeAdvisorySwitch");
    00512 }
    00513
    00514 // ----------------------------------------------------------------------------
    00516 void
    00517 RTIG::processSetTimeRegulating(Socket *link, NM_Set_Time_Regulating *msg)
    00518 {
    00519   G.Out(pdGendoc,"enter RTIG::processSetTimeRegulating");
    00520   G.Out(pdGendoc,"BEGIN ** SET TIME REGULATING **");
    00521
    00522   if (msg->isRegulator()) {
    00523         auditServer << "ON at time " << msg->getDate().getTime();
    00524
    00525         federations.createRegulator(msg->federation,
    00526                                      msg->federate,
    00527                                      msg->getDate());
    00528
    00529         // send timeRegulationEnabled() to federate.
    00530         NM_Time_Regulation_Enabled rep ;
    00531         rep.federate = msg->federate ;
    00532         rep.federation = msg->federation ;
    00533     rep.setDate(msg->getDate());
    00534
    00535         G.Out(pdGendoc,"      processSetTimeRegulating====> write TRE to RTIA");
    00536
    00537         rep.send(link,NM_msgBufSend);
    00538
    00539         D.Out(pdTerm, "Federate %u of Federation %u sets TimeRegulation ON.",
    00540               msg->federate, msg->federation);
    00541     }
    00542     else {
    00543         auditServer << "OFF" ;
    00544
    00545         federations.removeRegulator(msg->federation,
    00546                     msg->federate);
    00547         D.Out(pdTerm, "Federate %u of Federation %u sets TimeRegulation OFF.",
    00548               msg->federate, msg->federation);
    00549     }
    00550
    00551     G.Out(pdGendoc,"END ** SET TIME REGULATING **");
    00552     G.Out(pdGendoc,"exit RTIG::processSetTimeRegulating");
    00553 }
    00554
    00555 // ----------------------------------------------------------------------------
    00557 void
    00558 RTIG::processSetTimeConstrained(Socket *link, NM_Set_Time_Constrained *msg)
    00559 {
    00560   G.Out(pdGendoc,"enter RTIG::processSetTimeConstrained");
    00561   G.Out(pdGendoc,"BEGIN ** SET TIME CONSTRAINED **");
    00562
    00563   if (msg->isConstrained()) {
    00564         auditServer << "ON at time " << msg->getDate().getTime();
    00565
    00566         federations.addConstrained(msg->federation,
    00567                                     msg->federate);
    00568
    00569         // send timeConstrainedEnabled() to federate.
    00570         NM_Time_Constrained_Enabled rep ;
    00571         rep.federate = msg->federate ;
    00572         rep.federation = msg->federation ;
    00573     rep.setDate(msg->getDate());
    00574
    00575         G.Out(pdGendoc,"      processSetTimeConstrained====> write TCE to RTIA");
    00576
    00577         rep.send(link,NM_msgBufSend);
    00578
    00579         D.Out(pdTerm, "Federate %u of Federation %u is now constrained.",
    00580               msg->federate, msg->federation);
    00581     }
    00582     else {
    00583         auditServer << "OFF" ;
    00584
    00585         federations.removeConstrained(msg->federation,
    00586                                        msg->federate);
    00587         D.Out(pdTerm, "Federate %u of Federation %u is no more constrained.",
    00588               msg->federate, msg->federation);
    00589     }
    00590
    00591     G.Out(pdGendoc,"END ** SET TIME CONSTRAINED **");
    00592     G.Out(pdGendoc,"exit RTIG::processSetTimeConstrained");
    00593 }
    00594
    00595 // ----------------------------------------------------------------------------
    00597 void
    00598 RTIG::processMessageNull(NetworkMessage *msg)
    00599 {
    00600     auditServer << "Date " << msg->getDate().getTime();
    00601
    00602     // Catch all exceptions because RTIA does not expect an answer anyway.
    00603     try {
    00604         federations.updateRegulator(msg->federation,
    00605                                      msg->federate,
    00606                                      msg->getDate());
    00607     } catch (Exception &e) {}
    00608 }
    00609
    00610 // ----------------------------------------------------------------------------
    00612 void
    00613 RTIG::processRegisterSynchronization(Socket *link, NM_Register_Federation_Synchronization_Point *req)
    00614 {
    00615
    00616     G.Out(pdGendoc,"BEGIN ** REGISTER FEDERATION SYNCHRONIZATION POINT Service **");
    00617     G.Out(pdGendoc,"enter RTIG::processRegisterSynchronization");
    00618
    00619     auditServer << "Label \"" << req->getLabel().c_str() << "\" registered. Tag is \""
    00620         << req->getTag().c_str() << "\"" ;
    00621
    00622     // boolean true means a federates set exists
    00623     if ( req->doesSetExist() )
    00624         federations.manageSynchronization(req->federation,
    00625                                           req->federate,
    00626                                           true,
    00627                                           req->getLabel().c_str(),
    00628                                           req->getTag().c_str(),
    00629                                           req->handleArraySize,
    00630                                           req->handleArray);
    00631     else
    00632         federations.manageSynchronization(req->federation,
    00633                                           req->federate,
    00634                                           true,
    00635                                           req->getLabel().c_str(),
    00636                                           req->getTag().c_str());
    00637     D.Out(pdTerm, "Federation %u is now synchronizing.", req->federation);
    00638
    00639     // send synchronizationPointRegistrationSucceeded() to federate.
    00640     NM_Synchronization_Point_Registration_Succeeded rep ;
    00641     rep.federate = req->federate ;
    00642     rep.federation = req->federation ;
    00643     rep.setLabel(req->getLabel().c_str());
    00644
    00645     G.Out(pdGendoc,"      processRegisterSynchronization====> write SPRS to RTIA");
    00646
    00647     rep.send(link,NM_msgBufSend);
    00648
    00649     // boolean true means a federates set exists
    00650     if ( req->doesSetExist() )
    00651         federations.broadcastSynchronization(req->federation,
    00652                                           req->federate,
    00653                                           req->getLabel().c_str(),
    00654                                           req->getTag().c_str(),
    00655                                           req->handleArraySize,
    00656                                           req->handleArray);
    00657     else
    00658         federations.broadcastSynchronization(req->federation,
    00659                                           req->federate,
    00660                                           req->getLabel().c_str(),
    00661                                           req->getTag().c_str());
    00662
    00663     G.Out(pdGendoc,"exit  RTIG::processRegisterSynchronization");
    00664     G.Out(pdGendoc,"END   ** REGISTER FEDERATION SYNCHRONIZATION POINT Service **");
    00665
    00666 }
    00667
    00668 // ----------------------------------------------------------------------------
    00670 void
    00671 RTIG::processSynchronizationAchieved(Socket *, NetworkMessage *req)
    00672 {
    00673     auditServer << "Label \"" << req->getLabel().c_str() << "\" ended." ;
    00674
    00675     federations.manageSynchronization(req->federation,
    00676                                        req->federate,
    00677                                        false,
    00678                                        req->getLabel().c_str(),
    00679                                        "");
    00680     D.Out(pdTerm, "Federate %u has synchronized.", req->federate);
    00681 }
    00682
    00683 // ----------------------------------------------------------------------------
    00684 void
    00685 RTIG::processRequestFederationSave(Socket *, NetworkMessage *req)
    00686 {
    00687     G.Out(pdGendoc,"BEGIN ** REQUEST FEDERATION SAVE SERVICE **");
    00688     G.Out(pdGendoc,"enter RTIG::processRequestFederationSave");
    00689
    00690     auditServer << "Federation save request." ;
    00691
    00692     if ( req->isDated() )
    00693         // With time
    00694         federations.requestFederationSave(req->federation, req->federate,
    00695                                           req->getLabel().c_str(), req->getDate());
    00696     else
    00697         // Without time
    00698         federations.requestFederationSave(req->federation, req->federate,
    00699                                           req->getLabel().c_str());
    00700
    00701     G.Out(pdGendoc,"exit  RTIG::processRequestFederationSave");
    00702     G.Out(pdGendoc,"END   ** REQUEST FEDERATION SAVE SERVICE **");
    00703 }
    00704 // ----------------------------------------------------------------------------
    00705 void
    00706 RTIG::processFederateSaveBegun(Socket *, NetworkMessage *req)
    00707 {
    00708     G.Out(pdGendoc,"enter RTIG::processFederateSaveBegun");
    00709     G.Out(pdGendoc,"BEGIN ** FEDERATE SAVE BEGUN SERVICE **");
    00710     G.Out(pdGendoc,"processFederateSaveBegun federation = %d",req->federation);
    00711
    00712     auditServer << "Federate " << req->federate << " save begun." ;
    00713
    00714     federations.federateSaveBegun(req->federation, req->federate);
    00715
    00716     G.Out(pdGendoc,"END   ** FEDERATE SAVE BEGUN SERVICE **");
    00717     G.Out(pdGendoc,"exit  RTIG::processFederateSaveBegun");
    00718 }
    00719
    00720 // ----------------------------------------------------------------------------
    00721 void
    00722 RTIG::processFederateSaveStatus(Socket *, NetworkMessage *req)
    00723 {
    00724     G.Out(pdGendoc,"enter RTIG::processFederateSaveStatus");
    00725     if (req->getType() == NetworkMessage::FEDERATE_SAVE_COMPLETE)
    00726         G.Out(pdGendoc,"BEGIN ** FEDERATE SAVE COMPLETE SERVICE **");
    00727     else
    00728         G.Out(pdGendoc,"BEGIN ** FEDERATE SAVE NOT COMPLETE SERVICE **");
    00729
    00730     auditServer << "Federate " << req->federate << " save ended." ;
    00731
    00732     bool status = req->getType() == NetworkMessage::FEDERATE_SAVE_COMPLETE ;
    00733     federations.federateSaveStatus(req->federation, req->federate, status);
    00734
    00735     G.Out(pdGendoc,"exit  END   ** FEDERATE SAVE (NOT) COMPLETE SERVICE **");
    00736     G.Out(pdGendoc,"exit  RTIG::processFederateSaveStatus");
    00737 }
    00738
    00739 // ----------------------------------------------------------------------------
    00740 void
    00741 RTIG::processRequestFederationRestore(Socket *, NetworkMessage *req)
    00742 {
    00743     G.Out(pdGendoc,"BEGIN ** REQUEST FEDERATION RESTORE SERVICE **");
    00744     G.Out(pdGendoc,"enter RTIG::processRequestFederationRestore");
    00745     auditServer << "Federate " << req->federate << " request restore." ;
    00746
    00747     federations.requestFederationRestore(req->federation, req->federate,
    00748                                           req->getLabel().c_str());
    00749     G.Out(pdGendoc,"exit  RTIG::processRequestFederationRestore");
    00750     G.Out(pdGendoc,"END   ** REQUEST FEDERATION RESTORE SERVICE **");
    00751 }
    00752
    00753 // ----------------------------------------------------------------------------
    00754 void
    00755 RTIG::processFederateRestoreStatus(Socket *, NetworkMessage *req)
    00756 {
    00757     G.Out(pdGendoc,"BEGIN ** FEDERATE RESTORE (NOT)COMPLETE **");
    00758     G.Out(pdGendoc,"enter RTIG::processRequestFederateRestoreStatus");
    00759     auditServer << "Federate " << req->federate << " restore ended." ;
    00760
    00761     bool status = req->getType() == NetworkMessage::FEDERATE_RESTORE_COMPLETE ;
    00762
    00763     federations.federateRestoreStatus(req->federation, req->federate, status);
    00764
    00765     G.Out(pdGendoc,"exit  RTIG::processRequestFederateRestoreStatus");
    00766     G.Out(pdGendoc,"END   ** FEDERATE RESTORE (NOT)COMPLETE **");
    00767 }
    00768
    00769 // ----------------------------------------------------------------------------
    00770 // processPublishObjectClass
    00771 void
    00772 RTIG::processPublishObjectClass(Socket *link, NetworkMessage *req)
    00773 {
    00774     bool pub = (req->getType() == NetworkMessage::PUBLISH_OBJECT_CLASS);
    00775
    00776     auditServer << "Publish Object Class = " << req->objectClass << ", # of att. = "
    00777         << req->handleArraySize ;
    00778
    00779     federations.publishObject(req->federation,
    00780                               req->federate,
    00781                               req->objectClass,
    00782                               req->handleArray,
    00783                               req->handleArraySize,
    00784                               pub);
    00785
    00786     D.Out(pdRegister, "Federate %u of Federation %u published object class %d.",
    00787           req->federate, req->federation, req->objectClass);
    00788
    00789     std::auto_ptr<NetworkMessage> rep(NM_Factory::create(req->getType()));
    00790     rep->federate    = req->federate ;
    00791     rep->objectClass = req->objectClass ;
    00792
    00793     rep->send(link,NM_msgBufSend); // send answer to RTIA
    00794 }
    00795
    00796 // ----------------------------------------------------------------------------
    00797 // processSubscribeObjectClass
    00798 void
    00799 RTIG::processSubscribeObjectClass(Socket *link, NetworkMessage *req)
    00800 {
    00801     G.Out(pdGendoc,"enter RTIG::processSubscribeObjectClass");
    00802     G.Out(pdGendoc,"BEGIN **  SUBSCRIBE OBJECT CLASS SERVICE **");
    00803
    00804     std::vector <AttributeHandle> arrayVide ;
    00805     arrayVide.empty() ;
    00806     bool sub = (req->getType() == NetworkMessage::SUBSCRIBE_OBJECT_CLASS);
    00807
    00808     auditServer << "Subscribe Object Class = " << req->objectClass
    00809         << ", # of att. = " << req->handleArraySize ;
    00810
    00811     federations.subscribeObject(req->federation,
    00812                 req->federate,
    00813                 req->objectClass,
    00814                 sub ? req->handleArray : arrayVide,
    00815                 sub ? req->handleArraySize : 0);
    00816
    00817     D.Out(pdRegister,
    00818           "Federate %u of Federation %u subscribed to object class %d.",
    00819           req->federate, req->federation, req->objectClass);
    00820
    00821     std::auto_ptr<NetworkMessage> rep(NM_Factory::create(req->getType()));
    00822     rep->federate = req->federate ;
    00823     rep->objectClass = req->objectClass ;
    00824     rep->handleArraySize = 0 ;
    00825
    00826     rep->send(link,NM_msgBufSend); // send answer to RTIA
    00827
    00828     G.Out(pdGendoc,"END   **  SUBSCRIBE OBJECT CLASS SERVICE **");
    00829     G.Out(pdGendoc,"exit  RTIG::processSubscribeObjectClass");
    00830 }
    00831
    00832 // ----------------------------------------------------------------------------
    00833 // processPublishInteractionClass
    00834 void
    00835 RTIG::processPublishInteractionClass(Socket *link, NetworkMessage *req)
    00836 {
    00837     assert(link != NULL && req != NULL);
    00838
    00839     bool pub = (req->getType() == NetworkMessage::PUBLISH_INTERACTION_CLASS);
    00840
    00841     auditServer << "Publish Interaction Class = " << req->interactionClass ;
    00842     federations.publishInteraction(req->federation,
    00843                                     req->federate,
    00844                                     req->interactionClass,
    00845                                     pub);
    00846     D.Out(pdRequest, "Federate %u of Federation %u publishes Interaction %d.",
    00847           req->federate,
    00848           req->federation,
    00849           req->interactionClass);
    00850
    00851     std::auto_ptr<NetworkMessage> rep(NM_Factory::create(req->getType())); ;
    00852     rep->federate = req->federate ;
    00853     rep->interactionClass = req->interactionClass ;
    00854
    00855     rep->send(link,NM_msgBufSend); // send answer to RTIA
    00856 }
    00857
    00858 // ----------------------------------------------------------------------------
    00859 // processSubscribeInteractionClass
    00860 void
    00861 RTIG::processSubscribeInteractionClass(Socket *link, NetworkMessage *req)
    00862 {
    00863     bool sub = (req->getType() == NetworkMessage::SUBSCRIBE_INTERACTION_CLASS);
    00864
    00865     auditServer << "Subscribe Interaction Class = " << req->interactionClass ;
    00866     federations.subscribeInteraction(req->federation,
    00867                                       req->federate,
    00868                                       req->interactionClass,
    00869                                       sub);
    00870     D.Out(pdRequest,
    00871           "Federate %u of Federation %u subscribed to Interaction %d.",
    00872           req->federate,
    00873           req->federation,
    00874           req->interactionClass);
    00875
    00876     std::auto_ptr<NetworkMessage> rep(NM_Factory::create(req->getType()));;
    00877     rep->federate = req->federate ;
    00878     rep->interactionClass = req->interactionClass ;
    00879
    00880     rep->send(link,NM_msgBufSend); // send answer to RTIA
    00881 }
    00882
    00883 // ----------------------------------------------------------------------------
    00884 // processRegisterObject
    00885 void
    00886 RTIG::processRegisterObject(Socket *link, NetworkMessage *req)
    00887 {
    00888   std::auto_ptr<NetworkMessage> rep(NM_Factory::create(req->getType()));;
    00889
    00890     auditServer << "Register Object Class = " << req->objectClass ;
    00891     rep->object = federations.registerObject(req->federation,
    00892                                              req->federate,
    00893                                              req->objectClass,
    00894                                              const_cast<char*>(req->getLabel().c_str()));
    00895     auditServer << ", Handle = " << rep->object ;
    00896
    00897     D.Out(pdRegister,
    00898           "Object \"%s\" of Federate %u has been registered under ID %u.",
    00899           req->getLabel().c_str(), req->federate, rep->object);
    00900
    00901     rep->federate    = req->federate ;
    00902     rep->federation  = req->federation;
    00903     rep->objectClass = req->objectClass;
    00904     // rep.object is set by the call of registerObject
    00905     rep->setLabel(req->getLabel());
    00906
    00907     rep->send(link,NM_msgBufSend); // Send answer to RTIA
    00908 }
    00909
    00910 // ----------------------------------------------------------------------------
    00911 // processUpdateAttributeValues
    00912 void
    00913 RTIG::processUpdateAttributeValues(Socket *link, NetworkMessage *req)
    00914 {
    00915     G.Out(pdGendoc,"enter RTIG::processUpdateAttributeValues");
    00916     std::vector <AttributeValue_t> ValueArray ;
    00917
    00918     auditServer << "ObjID = " << req->object
    00919         << ", Date = " << req->getDate().getTime();
    00920
    00921     // Get Value Array
    00922     ValueArray = req->getAttribValueArray();
    00923
    00924     // Forward the call
    00925     if ( req->isDated() )
    00926         {
    00927         // UAV with time
    00928         federations.updateAttribute(req->federation,
    00929                                  req->federate,
    00930                                  req->object,
    00931                                  req->handleArray,
    00932                                  ValueArray,
    00933                                  req->handleArraySize,
    00934                                  req->getDate(),
    00935                                  req->getLabel().c_str());
    00936         }
    00937     else
    00938         {
    00939         // UAV without time
    00940         federations.updateAttribute(req->federation,
    00941                                  req->federate,
    00942                                  req->object,
    00943                                  req->handleArray,
    00944                                  ValueArray,
    00945                                  req->handleArraySize,
    00946                                  req->getLabel().c_str());
    00947         }
    00948     ValueArray.empty();
    00949
    00950     // Building answer (Network Message re)
    00951     NM_Update_Attribute_Values rep ;
    00952     rep.federate = req->federate ;
    00953     rep.object   = req->object ;
    00954     rep.setDate(req->getDate());
    00955     rep.handleArraySize = 0 ;
    00956     // Don't forget label and tag
    00957     rep.setLabel(req->getLabel());
    00958     rep.setTag(req->getTag());
    00959
    00960     rep.send(link,NM_msgBufSend); // send answer to RTIA
    00961     G.Out(pdGendoc,"exit  RTIG::processUpdateAttributeValues");
    00962 }
    00963
    00964 // ----------------------------------------------------------------------------
    00965 // processSendInteraction
    00966 void
    00967 RTIG::processSendInteraction(Socket *link, NetworkMessage *req)
    00968 {
    00969     std::vector <ParameterValue_t> values ;
    00970
    00971     G.Out(pdGendoc,"BEGIN ** SEND INTERACTION SERVICE **");
    00972     G.Out(pdGendoc,"enter RTIG::processSendInteraction");
    00973
    00974     // Building Value Array
    00975     auditServer << "IntID = " << req->interactionClass
    00976         << ", date = " << req->getDate().getTime();
    00977     values = req->getParamValueArray();
    00978
    00979     if ( req->isDated() )
    00980         {
    00981         federations.updateParameter(req->federation,
    00982                 req->federate,
    00983                 req->interactionClass,
    00984                 req->handleArray,
    00985                 values,
    00986                 req->handleArraySize,
    00987                 req->getDate(),
    00988                 req->region,
    00989                 req->getLabel().c_str());
    00990         }
    00991     else
    00992         {
    00993         federations.updateParameter(req->federation,
    00994                 req->federate,
    00995                 req->interactionClass,
    00996                 req->handleArray,
    00997                 values,
    00998                 req->handleArraySize,
    00999                 req->region,
    01000                 req->getLabel().c_str());
    01001         }
    01002     values.empty();
    01003
    01004     D.Out(pdDebug, "Interaction %d parameters update completed",
    01005           req->interactionClass);
    01006
    01007     NM_Send_Interaction rep ;
    01008     rep.federate = req->federate ;
    01009     rep.interactionClass = req->interactionClass ;
    01010     rep.handleArraySize = 0 ;
    01011     // Don't forget label and tag
    01012     rep.setLabel(req->getLabel());
    01013     rep.setTag(req->getTag());
    01014     G.Out(pdGendoc,"processSendInteraction===>write");
    01015     rep.send(link,NM_msgBufSend); // send answer to RTIA
    01016
    01017     G.Out(pdGendoc,"exit RTIG::processSendInteraction");
    01018     G.Out(pdGendoc,"END ** SEND INTERACTION SERVICE **");
    01019
    01020 }
    01021
    01022 // ----------------------------------------------------------------------------
    01023 // processDeleteObject
    01024 void
    01025 RTIG::processDeleteObject(Socket *link, NetworkMessage *req)
    01026 {
    01027     G.Out(pdGendoc,"BEGIN ** DELETE OBJECT INSTANCE service **");
    01028     G.Out(pdGendoc,"enter RTIG::processDeleteObject");
    01029     auditServer << "Delete ObjID = " << req->object ;
    01030
    01031     if ( req->isDated() ) {
    01032         federations.destroyObject(req->federation,
    01033                               req->federate,
    01034                                   req->object,
    01035                   req->getDate(),
    01036                                   const_cast<char*>(req->getLabel().c_str()));
    01037     }
    01038     else {
    01039         federations.destroyObject(req->federation,
    01040                               req->federate,
    01041                                   req->object,
    01042                                   const_cast<char*>(req->getLabel().c_str()));
    01043     }
    01044
    01045     D.Out(pdRegister, "Object # %u of Federation %u has been deleted.",
    01046           req->object, req->federation);
    01047
    01048     NM_Delete_Object rep ;
    01049     rep.federate = req->federate ;
    01050     rep.object   = req->object ;
    01051
    01052     rep.send(link,NM_msgBufSend); // send answer to RTIA
    01053
    01054     G.Out(pdGendoc,"exit RTIG::processDeleteObject");
    01055     G.Out(pdGendoc,"END ** DELETE OBJECT INSTANCE **");
    01056 }
    01057
    01058 // ----------------------------------------------------------------------------
    01059 // processqueryAttributeOwnership
    01060 void
    01061 RTIG::processQueryAttributeOwnership(Socket *link, NetworkMessage *req)
    01062 {
    01063     D.Out(pdDebug, "Owner of Attribute %u of Object %u .",
    01064           req->handleArray[0], req->object);
    01065
    01066     auditServer << "AttributeHandle = " << req->handleArray[0] ;
    01067
    01068     federations.searchOwner(req->federation,
    01069                              req->federate,
    01070                              req->object,
    01071                              req->handleArray[0]);
    01072
    01073     D.Out(pdDebug, "Owner of Attribute %u of Object %u .",
    01074           req->handleArray[0], req->object);
    01075
    01076     NM_Query_Attribute_Ownership rep ;
    01077     rep.federate = req->federate ;
    01078     rep.object = req->object ;
    01079
    01080     rep.send(link,NM_msgBufSend); // send answer to RTIA
    01081 }
    01082
    01083 // ----------------------------------------------------------------------------
    01084 // processAttributeOwnedByFederate
    01085 void
    01086 RTIG::processAttributeOwnedByFederate(Socket *link, NetworkMessage *req)
    01087 {
    01088     NM_Is_Attribute_Owned_By_Federate rep ;
    01089
    01090     D.Out(pdDebug, "Owner of Attribute %u of Object %u .",
    01091           req->handleArray[0], req->object);
    01092
    01093     auditServer << "AttributeHandle = " << req->handleArray[0] ;
    01094
    01095     if (federations.isOwner(req->federation,
    01096                              req->federate,
    01097                              req->object,
    01098                              req->handleArray[0]))
    01099         rep.setLabel("RTI_TRUE");
    01100     else
    01101         rep.setLabel("RTI_FALSE");
    01102
    01103     D.Out(pdDebug, "Owner of Attribute %u of Object %u .",
    01104           req->handleArray[0], req->object);
    01105
    01106     rep.federate = req->federate ;
    01107     rep.object = req->object ;
    01108
    01109     rep.send(link,NM_msgBufSend); // send answer to RTIA
    01110 }
    01111
    01112 // ----------------------------------------------------------------------------
    01113 // processNegotiatedOwnershipDivestiture
    01114 void
    01115 RTIG::processNegotiatedOwnershipDivestiture(Socket *link, NetworkMessage *req)
    01116 {
    01117     auditServer << "Object = " <<  req->object
    01118         << ", # of att. = " << req->handleArraySize ;
    01119     federations.negotiateDivestiture(req->federation,
    01120                                       req->federate,
    01121                                       req->object,
    01122                                       req->handleArray,
    01123                                       req->handleArraySize,
    01124                                       req->getLabel().c_str());
    01125
    01126     D.Out(pdDebug, "Federate %u of Federation %u negotiate "
    01127           "divestiture of object %u.",
    01128           req->federate, req->federation, req->object);
    01129
    01130     NM_Negotiated_Attribute_Ownership_Divestiture rep ;
    01131     rep.federate = req->federate ;
    01132     rep.object = req->object ;
    01133     rep.handleArraySize = 0 ;
    01134
    01135     rep.send(link,NM_msgBufSend); // send answer to RTIA
    01136 }
    01137
    01138 // ----------------------------------------------------------------------------
    01139 // processAcquisitionIfAvailable
    01140 void
    01141 RTIG::processAcquisitionIfAvailable(Socket *link, NetworkMessage *req)
    01142 {
    01143     auditServer << "Object = " << req->object
    01144         << ", # of att. = " << req->handleArraySize ;
    01145
    01146     federations.acquireIfAvailable(req->federation,
    01147                                     req->federate,
    01148                                     req->object,
    01149                                     req->handleArray,
    01150                                     req->handleArraySize);
    01151
    01152     D.Out(pdDebug,
    01153           "Federate %u of Federation %u acquisitionIfAvailable "
    01154           "of object %u.",
    01155           req->federate, req->federation, req->object);
    01156
    01157     NM_Attribute_Ownership_Acquisition_If_Available rep ;
    01158     rep.federate = req->federate ;
    01159     rep.object = req->object ;
    01160     rep.handleArraySize = 0 ;
    01161
    01162     rep.send(link,NM_msgBufSend); // send answer to RTIA
    01163 }
    01164
    01165 // ----------------------------------------------------------------------------
    01166 // processUnconditionalDivestiture
    01167 void
    01168 RTIG::processUnconditionalDivestiture(Socket *link, NetworkMessage *req)
    01169 {
    01170     auditServer << "Object = " << req->object
    01171         << ", # of att. = " << req->handleArraySize ;
    01172
    01173     federations.divest(req->federation,
    01174                         req->federate,
    01175                         req->object,
    01176                         req->handleArray,
    01177                         req->handleArraySize);
    01178
    01179     D.Out(pdDebug,
    01180           "Federate %u of Federation %u UnconditionalDivestiture "
    01181           "of object %u.",
    01182           req->federate, req->federation, req->object);
    01183
    01184     NM_Unconditional_Attribute_Ownership_Divestiture rep ;
    01185     rep.federate = req->federate ;
    01186     rep.object = req->object ;
    01187     rep.handleArraySize = 0 ;
    01188
    01189     rep.send(link,NM_msgBufSend); // send answer to RTIA
    01190 }
    01191
    01192 // ----------------------------------------------------------------------------
    01193 // processOwnershipAcquisition
    01194 void
    01195 RTIG::processOwnershipAcquisition(Socket *link, NetworkMessage *req)
    01196 {
    01197     auditServer << "Object = " << req->object
    01198         << ", # of att. = " << req->handleArraySize ;
    01199
    01200     federations.acquire(req->federation,
    01201                          req->federate,
    01202                          req->object,
    01203                          req->handleArray,
    01204                          req->handleArraySize,
    01205                          req->getLabel().c_str());
    01206
    01207     D.Out(pdDebug,
    01208           "Federate %u of Federation %u ownership acquisition of object %u.",
    01209           req->federate, req->federation, req->object);
    01210
    01211     NM_Attribute_Ownership_Acquisition rep ;
    01212     rep.federate = req->federate ;
    01213     rep.object = req->object ;
    01214     rep.handleArraySize = 0 ;
    01215
    01216     rep.send(link,NM_msgBufSend); // send answer to RTIA
    01217 }
    01218
    01219 // ----------------------------------------------------------------------------
    01220 // processCancelNegotiatedDivestiture
    01221 void
    01222 RTIG::processCancelNegotiatedDivestiture(Socket *link, NetworkMessage *req)
    01223 {
    01224     auditServer << "Object = " << req->object
    01225         << ", # of att. = " << req->handleArraySize ;
    01226
    01227     federations.cancelDivestiture(req->federation,
    01228                                    req->federate,
    01229                                    req->object,
    01230                                    req->handleArray,
    01231                                    req->handleArraySize);
    01232
    01233     D.Out(pdDebug, "Federate %u of Federation %u cancel negotiate "
    01234           "divestiture of object %u.",
    01235           req->federate, req->federation, req->object);
    01236
    01237     NM_Cancel_Negotiated_Attribute_Ownership_Divestiture rep ;
    01238     rep.federate = req->federate ;
    01239     rep.object = req->object ;
    01240     rep.handleArraySize = 0 ;
    01241
    01242     rep.send(link,NM_msgBufSend); // send answer to RTIA
    01243 }
    01244
    01245 // ----------------------------------------------------------------------------
    01246 // processReleaseResponse
    01247 void
    01248 RTIG::processReleaseResponse(Socket *link, NetworkMessage *req)
    01249 {
    01250     auditServer << "Object = " << req->object
    01251         << ", # of att. = " << req->handleArraySize ;
    01252
    01253     AttributeHandleSet *attributes =
    01254         federations.respondRelease(req->federation,
    01255                                     req->federate,
    01256                                     req->object,
    01257                                     req->handleArray,
    01258                                     req->handleArraySize);
    01259
    01260     D.Out(pdDebug, "Federate %u of Federation %u release response "
    01261           "of object %u.",
    01262           req->federate, req->federation, req->object);
    01263
    01264     NM_Attribute_Ownership_Release_Response rep ;
    01265     rep.handleArraySize = attributes->size();
    01266     rep.handleArray.resize(rep.handleArraySize) ;
    01267
    01268     for (unsigned int i = 0 ; i < attributes->size(); i++) {
    01269         rep.handleArray[i] = attributes->getHandle(i);
    01270     }
    01271
    01272     rep.federate = req->federate ;
    01273     rep.object = req->object ;
    01274
    01275     rep.send(link,NM_msgBufSend); // Send answer to RTIA
    01276 }
    01277
    01278 // ----------------------------------------------------------------------------
    01279 // processCancelAcquisition
    01280 void
    01281 RTIG::processCancelAcquisition(Socket *link, NetworkMessage *req)
    01282 {
    01283     auditServer << "Object = " << req->object
    01284         << ", # of att. = " << req->handleArraySize ;
    01285
    01286     federations.cancelAcquisition(req->federation,
    01287                                    req->federate,
    01288                                    req->object,
    01289                                    req->handleArray,
    01290                                    req->handleArraySize);
    01291
    01292     D.Out(pdDebug,
    01293           "Federate %u of Federation %u release response of object %u.",
    01294           req->federate, req->federation, req->object);
    01295
    01296     NM_Cancel_Attribute_Ownership_Acquisition rep ;
    01297     rep.federate = req->federate ;
    01298     rep.object = req->object ;
    01299     rep.handleArraySize = 0 ;
    01300
    01301     rep.send(link,NM_msgBufSend); // send answer to RTIA
    01302 }
    01303
    01304 // ----------------------------------------------------------------------------
    01305 // processCreateRegion
    01306 void
    01307 RTIG::processCreateRegion(Socket *link, NetworkMessage *req)
    01308 {
    01309     // TODO: audit...
    01310
    01311     NM_DDM_Create_Region rep ;
    01312
    01313     rep.region = federations.createRegion(req->federation,
    01314                                            req->federate,
    01315                                            req->space,
    01316                                            req->nbExtents);
    01317
    01318     D[pdDebug] << "Federate " << req->federate << " of Federation "
    01319                << req->federation << " creates region " << rep.region
    01320                << endl ;
    01321
    01322     rep.federate = req->federate ;
    01323     rep.send(link,NM_msgBufSend);
    01324 }
    01325
    01326 // ----------------------------------------------------------------------------
    01327 // processModifyRegion
    01328 void
    01329 RTIG::processModifyRegion(Socket *link, NetworkMessage *req)
    01330 {
    01331     federations.modifyRegion(req->federation, req->federate,
    01332                   req->region, req->getExtents());
    01333
    01334     D[pdDebug] << "Federate " << req->federate << " of Federation "
    01335                << req->federation << " modifies region " << req->region
    01336                << endl ;
    01337
    01338     NM_DDM_Modify_Region rep ;
    01339     rep.federate = req->federate ;
    01340     rep.send(link,NM_msgBufSend);
    01341 }
    01342
    01343 // ----------------------------------------------------------------------------
    01344 // processDeleteRegion
    01345 void
    01346 RTIG::processDeleteRegion(Socket *link, NetworkMessage *req)
    01347 {
    01348     // TODO: audit...
    01349
    01350     federations.deleteRegion(req->federation, req->federate, req->region);
    01351
    01352     D[pdDebug] << "Federate " << req->federate << " of Federation "
    01353                << req->federation << " deletes region " << req->region
    01354                << endl ;
    01355
    01356     NM_DDM_Delete_Region rep ;
    01357     rep.federate = req->federate ;
    01358     rep.region = req->region ;
    01359     rep.send(link,NM_msgBufSend);
    01360 }
    01361
    01362 // ----------------------------------------------------------------------------
    01363 // processAssociateRegion
    01364 void
    01365 RTIG::processAssociateRegion(Socket *link, NetworkMessage *req)
    01366 {
    01367     // TODO: audit...
    01368
    01369     D[pdDebug] << "Federate " << req->federate << " of Federation "
    01370                << req->federation << " associates region " << req->region
    01371                << " to some attributes of object " << req->object << endl ;
    01372
    01373     federations.associateRegion(req->federation, req->federate, req->object,
    01374                  req->region, req->handleArraySize,
    01375                  req->handleArray);
    01376
    01377     NM_DDM_Associate_Region rep ;
    01378     rep.federate = req->federate ;
    01379     rep.send(link,NM_msgBufSend);
    01380 }
    01381
    01382 // ----------------------------------------------------------------------------
    01383 // processUnassociateRegion
    01384 void
    01385 RTIG::processUnassociateRegion(Socket *link, NetworkMessage *req)
    01386 {
    01387     // TODO: audit...
    01388
    01389     federations.unassociateRegion(req->federation, req->federate,
    01390                    req->object, req->region);
    01391
    01392     D[pdDebug] << "Federate " << req->federate << " of Federation "
    01393                << req->federation << " associates region " << req->region
    01394                << " from object " << req->object << endl ;
    01395
    01396     NM_DDM_Unassociate_Region rep ;
    01397     rep.federate = req->federate ;
    01398     rep.send(link,NM_msgBufSend);
    01399 }
    01400
    01401 // ----------------------------------------------------------------------------
    01402 // processSubscribeAttributes
    01403 void
    01404 RTIG::processSubscribeAttributesWR(Socket *link, NetworkMessage *req)
    01405 {
    01406     // TODO: audit...
    01407     D[pdDebug] << "Federate " << req->federate << " of Federation "
    01408                << req->federation << " subscribes with region " << req->region
    01409                << " to some attributes of class " << req->objectClass << endl ;
    01410
    01411     federations.subscribeAttributesWR(req->federation, req->federate,
    01412                        req->objectClass, req->region,
    01413                        req->handleArraySize, req->handleArray);
    01414
    01415     NM_DDM_Subscribe_Attributes rep ;
    01416     rep.federate = req->federate ;
    01417     rep.objectClass = req->objectClass ;
    01418     rep.handleArraySize = 0 ;
    01419     rep.send(link,NM_msgBufSend);
    01420 }
    01421
    01422 // ----------------------------------------------------------------------------
    01423 // processUnsubscribeAttributes
    01424 void
    01425 RTIG::processUnsubscribeAttributesWR(Socket *link, NetworkMessage *req)
    01426 {
    01427     // TODO: audit...
    01428     D[pdDebug] << "Federate " << req->federate << " of Federation "
    01429                << req->federation << " unsubscribes with region " << req->region
    01430                << " from object class " << req->objectClass << endl ;
    01431
    01432     federations.unsubscribeAttributesWR(req->federation, req->federate,
    01433                      req->objectClass, req->region);
    01434
    01435     NM_DDM_Unsubscribe_Attributes rep ;
    01436     rep.federate = req->federate ;
    01437     rep.send(link,NM_msgBufSend);
    01438 }
    01439
    01440 // ----------------------------------------------------------------------------
    01441 // processSubscribeInteractions
    01442 void
    01443 RTIG::processSubscribeInteractionWR(Socket *link, NetworkMessage *req)
    01444 {
    01445     // TODO: audit...
    01446
    01447     federations.subscribeInteractionWR(req->federation, req->federate,
    01448                     req->interactionClass, req->region);
    01449
    01450     D[pdDebug] << "Federate " << req->federate << " of Federation "
    01451                << req->federation << " subscribes with region " << req->region
    01452                << " to interaction class " << req->interactionClass << endl ;
    01453
    01454     NM_DDM_Subscribe_Interaction rep ;
    01455     rep.federate = req->federate ;
    01456     rep.send(link,NM_msgBufSend);
    01457 }
    01458
    01459 // ----------------------------------------------------------------------------
    01460 // processUnsubscribeInteractions
    01461 void
    01462 RTIG::processUnsubscribeInteractionWR(Socket *link, NetworkMessage *req)
    01463 {
    01464     // TODO: audit...
    01465
    01466     federations.unsubscribeInteractionWR(req->federation, req->federate,
    01467                    req->interactionClass, req->region);
    01468
    01469     D[pdDebug] << "Federate " << req->federate << " of Federation "
    01470                << req->federation << " unsubscribes with region " << req->region
    01471                << " from interaction class " << req->interactionClass << endl ;
    01472
    01473     NM_DDM_Unsubscribe_Interaction rep ;
    01474     rep.federate = req->federate ;
    01475     rep.send(link,NM_msgBufSend);
    01476 }
    01477
    01478 // ----------------------------------------------------------------------------
    01479 // processRegisterObjectWithRegion
    01480 void
    01481 RTIG::processRegisterObjectWithRegion(Socket *link, NetworkMessage *req)
    01482 {
    01483     std::auto_ptr<NetworkMessage> rep(NM_Factory::create(req->getType()));
    01484     // FIXME bug #9869
    01485     // When we were passed a set of region
    01486     // we should register object for each region
    01487     // the trouble comes from the fact that
    01488     // there is both
    01489     //     - req->region  (coming from NetworkMessage::region)
    01490     //     - req->regions (coming from BasicMessage::regions)
    01491     // would be nice to sort those thing out.
    01492     rep->object = federations.registerObjectWithRegion(req->federation,
    01493                               req->federate,
    01494                               req->objectClass,
    01495                               const_cast<char*>(req->getLabel().c_str()),
    01496                               req->region,
    01497                               req->handleArraySize,
    01498                               req->handleArray);
    01499
    01500     D.Out(pdRegister,
    01501           "Object \"%s\" of Federate %u has been registered under ID %u.",
    01502           req->getLabel().c_str(), req->federate, rep->object);
    01503
    01504     rep->federate = req->federate ;
    01505     rep->send(link,NM_msgBufSend); // Send answer to RTIA
    01506 }
    01507
    01508 // ----------------------------------------------------------------------------
    01509 // processRequestObjectAttributeValueUpdate
    01510 void
    01511 RTIG::processRequestObjectAttributeValueUpdate(Socket *link, NetworkMessage *request)
    01512 {
    01513     NM_Request_Object_Attribute_Value_Update answer ;
    01514     Handle federateOwner ;  // federate owner of the object
    01515     G.Out(pdGendoc,"enter RTIG::processRequestObjectAttributeValueUpdate");
    01516     G.Out(pdGendoc,"BEGIN ** REQUEST OBJECT ATTRIBUTE VALUE UPDATE **");
    01517
    01518     auditServer << "ObjID = " << request->object ;
    01519
    01520     // We have to do verifications about this object and we need owner
    01521     answer.exception = e_NO_EXCEPTION ;
    01522     try
    01523       {
    01524       federateOwner = federations.requestObjectOwner(request->federation,
    01525                                  request->federate,
    01526                                  request->object,
    01527                                  request->handleArray,
    01528                                  request->handleArraySize);
    01529       }
    01530      catch (ObjectNotKnown e)
    01531         {
    01532         answer.exception = e_ObjectNotKnown ;
    01533         answer.exceptionReason = e._reason ;
    01534         }
    01535      catch (FederationExecutionDoesNotExist e)
    01536         {
    01537         answer.exception = e_FederationExecutionDoesNotExist ;
    01538         answer.exceptionReason = e._reason ;
    01539         }
    01540      catch (RTIinternalError e)
    01541         {
    01542         answer.exception = e_RTIinternalError ;
    01543         answer.exceptionReason = e._reason ;
    01544         }
    01545
    01546     answer.federate = request->federate ;
    01547     answer.object = request->object ;
    01548
    01549     answer.send(link,NM_msgBufSend); // Send answer to RTIA
    01550     G.Out(pdGendoc,"exit  RTIG::processRequestObjectAttributeValueUpdate");
    01551     G.Out(pdGendoc,"END   ** REQUEST OBJECT ATTRIBUTE VALUE UPDATE **");
    01552 }
    01553
    01554 }} // namespace certi/rtig
    01555
    01556 // $Id: RTIG_processing.cc,v 3.82 2009/04/08 10:47:19 approx Exp $