# RTIA_federate.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 // ----------------------------------------------------------------------------
    00022
    00023 #include <config.h>
    00024 #include "RTIA.hh"
    00025
    00026 #include "fed.hh"
    00027 #include "RoutingSpace.hh"
    00028 #include "XmlParser.hh"
    00029 #include <assert.h>
    00030 #ifdef _WIN32
    00031 #include <time.h>
    00032 #include <sys/timeb.h>
    00033 #endif
    00034
    00035 using std::string ;
    00036 using std::ifstream ;
    00037
    00038 namespace certi {
    00039 namespace rtia {
    00040
    00041 static pdCDebug D("RTIA", __FILE__);
    00042 static PrettyDebug G("GENDOC",__FILE__) ;
    00043
    00044 // ----------------------------------------------------------------------------
    00045 static RTI::TickTime currentTickTime()
    00046 {
    00047     RTI::TickTime result;
    00048 #ifdef _WIN32
    00049     _timeb timev;
    00050     _ftime(&timev);
    00051     result = static_cast<RTI::TickTime>(timev.time + timev.millitm/1000);
    00052 #else
    00053     struct timeval timev;
    00054     gettimeofday(&timev, NULL);
    00055     result = timev.tv_sec + timev.tv_usec/1000000;
    00056 #endif
    00057     return result;
    00058 }
    00059
    00060 // ----------------------------------------------------------------------------
    00062 void
    00063 RTIA::saveAndRestoreStatus(Message::Type type)
    00064     throw (SaveInProgress, RestoreInProgress)
    00065 {
    00066 G.Out(pdGendoc,"enter RTIA::saveAndRestoreStatus");
    00067 //D.Mes(pdMessage, 'N', type);
    00068
    00069     switch (type) {
    00070       case Message::CLOSE_CONNEXION:
    00071       case Message::RESIGN_FEDERATION_EXECUTION:
    00072       case Message::TICK_REQUEST:
    00073       case Message::TICK_REQUEST_NEXT:
    00074       case Message::TICK_REQUEST_STOP:
    00075       case Message::GET_OBJECT_CLASS_HANDLE:
    00076       case Message::GET_OBJECT_CLASS_NAME:
    00077       case Message::GET_ATTRIBUTE_HANDLE:
    00078       case Message::GET_ATTRIBUTE_NAME:
    00079       case Message::GET_INTERACTION_CLASS_HANDLE:
    00080       case Message::GET_INTERACTION_CLASS_NAME:
    00081       case Message::GET_PARAMETER_HANDLE:
    00082       case Message::GET_PARAMETER_NAME:
    00083       case Message::GET_OBJECT_INSTANCE_HANDLE:
    00084       case Message::GET_OBJECT_INSTANCE_NAME:
    00085       case Message::GET_SPACE_HANDLE:
    00086       case Message::GET_SPACE_NAME:
    00087       case Message::GET_DIMENSION_HANDLE:
    00088       case Message::GET_DIMENSION_NAME:
    00089       case Message::GET_ATTRIBUTE_SPACE_HANDLE:
    00090       case Message::GET_OBJECT_CLASS:
    00091       case Message::GET_INTERACTION_SPACE_HANDLE:
    00092       case Message::GET_TRANSPORTATION_HANDLE:
    00093       case Message::GET_TRANSPORTATION_NAME:
    00094       case Message::GET_ORDERING_HANDLE:
    00095       case Message::GET_ORDERING_NAME:
    00096         break ;
    00097       case Message::FEDERATE_SAVE_BEGUN:
    00098       case Message::FEDERATE_SAVE_COMPLETE:
    00099       case Message::FEDERATE_SAVE_NOT_COMPLETE:
    00100         fm->checkFederationRestoring();
    00101         break ;
    00102       case Message::FEDERATE_RESTORE_COMPLETE:
    00103       case Message::FEDERATE_RESTORE_NOT_COMPLETE:
    00104         fm->checkFederationSaving();
    00105         break ;
    00106       default:
    00107         fm->checkFederationSaving();
    00108         fm->checkFederationRestoring();
    00109     }
    00110 G.Out(pdGendoc,"exit  RTIA::saveAndRestoreStatus");
    00111 }
    00112
    00113 // ----------------------------------------------------------------------------
    00115 void
    00116 RTIA::chooseFederateProcessing(Message *req, Message &rep, TypeException &e)
    00117 {
    00118     G.Out(pdGendoc,"enter RTIA::chooseFederateProcessing for type = %d",req->type);
    00119
    00120     // Verify not in saving or restoring state.
    00121     // May throw SaveInProgress or RestoreInProgress
    00122     saveAndRestoreStatus(req->type);
    00123
    00124     e = e_NO_EXCEPTION ;
    00125
    00126     switch(req->type) {
    00127
    00128       case Message::CLOSE_CONNEXION:
    00129         D.Out(pdTrace,
    00130               "Receiving Message from Federate, type CloseConnexion.");
    00131         fm->_fin_execution = true;
    00132         // the this->comm can now be used only to sent the CLOSE_CONNEXION response
    00133         break ;
    00134
    00135       case Message::CREATE_FEDERATION_EXECUTION:
    00136         D.Out(pdTrace,
    00137               "Receiving Message from Federate, type CreateFederation.");
    00138         // Store FEDid for future usage (JOIN_FEDERATION_EXECUTION) into fm
    00139         fm->_FEDid = req->getFEDid() ;
    00140         fm->createFederationExecution(req->getFederationName(), e);
    00141         if ( e == e_RTIinternalError )
    00142             {
    00143             rep.setException(e,"Federate is yet a creator or a member !");
    00144             }
    00145         D.Out(pdTrace, "Receiving Message from Federate, "
    00146               "type CreateFederation done.");
    00147         // RTIA needs FEDid into the answer (rep Message) to federate
    00148         rep.setFEDid(fm->_FEDid) ;
    00149         // RTIA needs federation name into the answer (rep Message) to federate
    00150         rep.setFederationName(req->getFederationName());
    00151         break ;
    00152
    00153       case Message::DESTROY_FEDERATION_EXECUTION:
    00154         D.Out(pdTrace,
    00155               "Receiving Message from Federate, type DestroyFederation.");
    00156
    00157         fm->destroyFederationExecution(req->getFederationName(), e);
    00158         if ( e == e_RTIinternalError )
    00159             {
    00160             rep.setException(e,"Illegal federation handle");
    00161             }
    00162         // RTIA needs federation name into the answer (rep Message) to federate
    00163         rep.setFederationName(req->getFederationName());
    00164         break ;
    00165
    00166       case Message::JOIN_FEDERATION_EXECUTION: {
    00167           D.Out(pdTrace,
    00168                 "Receiving Message from Federate, type JoinFederation.");
    00169           rep.setFederate(fm->joinFederationExecution(req->getFederateName(),
    00170                                                       req->getFederationName(),
    00171                                                       e));
    00172           if ( e == e_NO_EXCEPTION )
    00173               {
    00175               PrettyDebug::setFederateName(req->getFederateName());
    00176               // Set federation name for the answer message (rep)
    00177               rep.setFederationName(req->getFederationName());
    00178
    00179               string filename = fm->_FEDid ;
    00180               int nbcar_filename=filename.length();
    00181               bool is_a_fed = false ;
    00182               bool is_an_xml = false ;
    00183
    00184               // Hope there is a . before fed or xml
    00185               if ( filename.at(nbcar_filename-4) != '.' )
    00186                   throw CouldNotOpenFED(". missing or not in place");
    00187
    00188               string extension = filename.substr(nbcar_filename-3,3) ;
    00189               if ( !strcasecmp(extension.c_str(),"fed") )
    00190                   {
    00191                   is_a_fed = true ;
    00192                   D.Out(pdTrace, "Trying to use .fed file");
    00193                   }
    00194               else if  ( !strcasecmp(extension.c_str(),"xml") )
    00195                   {
    00196                   is_an_xml = true ;
    00197                   D.Out(pdTrace, "Trying to use .xml file");
    00198                   }
    00199               else
    00200                   throw CouldNotOpenFED("nor .fed nor .xml");
    00201
    00202               ifstream fdd(filename.c_str());
    00203               if (fdd.is_open())
    00204                   {
    00205                   if ( is_a_fed )
    00206                       {
    00207                   int result = certi::fedparser::build(filename.c_str(),
    00208                                    rootObject, false);
    00209                       if (result != 0 ) throw ErrorReadingFED("invalid .fed");
    00210                       }
    00211                   else if ( is_an_xml )
    00212                       {
    00213                       if (XmlParser::exists())
    00214                           {
    00215                           XmlParser parser(rootObject);
    00216                           parser.parse(filename);
    00217                           }
    00218                else
    00219                           throw CouldNotOpenFED("no XmlParser");
    00220                       }
    00221                   }
    00222               else
    00223                   throw CouldNotOpenFED("File not found");
    00224               break ;
    00225               }
    00226           else
    00227               {
    00228               // JOIN FAILED
    00229               throw FederateAlreadyExecutionMember("Federate yet joined or same name");
    00230               break;
    00231               }
    00232       }
    00233       case Message::RESIGN_FEDERATION_EXECUTION:
    00234         D.Out(pdTrace,
    00235               "Receiving Message from Federate, type ResignFederation.");
    00236
    00237         fm->resignFederationExecution(req->getResignAction(), e);
    00238         break ;
    00239
    00240       case Message::REGISTER_FEDERATION_SYNCHRONIZATION_POINT:
    00241         D.Out(pdTrace, "Receiving Message from Federate, type RegisterFederationSynchronizationPoint.");
    00242
    00243         // boolean true means with federates set
    00244         if ( req->getBoolean() )
    00245             fm->registerSynchronization(req->getLabel(), req->getTag(),
    00246                 (unsigned short)req->handleArraySize, req->handleArray, e);
    00247         else
    00248             fm->registerSynchronization(req->getLabel(), req->getTag(), e);
    00249         // Don't forget boolean for the answer
    00250         rep.setBoolean(req->getBoolean()) ;
    00251         break ;
    00252
    00253       case Message::SYNCHRONIZATION_POINT_ACHIEVED:
    00254         D.Out(pdTrace, "Receiving Message from Federate, type SynchronizationPointAchieved.");
    00255
    00256         fm->unregisterSynchronization(req->getLabel(), e);
    00257         break ;
    00258
    00259       case Message::REQUEST_FEDERATION_SAVE:
    00260         // boolean true means with time
    00261         if ( req->getBoolean() )
    00262             {
    00263             D.Out(pdTrace, "Receiving Message from Federate, type"
    00264                            " RequestFederationSave with time.");
    00265             fm->requestFederationSave(req->getLabel(),req->getFederationTime(),
    00266                                       e);
    00267             }
    00268         else
    00269             {
    00270             D.Out(pdTrace, "Receiving Message from Federate, type"
    00271                            " RequestFederationSave without time.");
    00272             fm->requestFederationSave(req->getLabel(),e);
    00273             }
    00274         // Don't forget boolean value (req Message) for the answer (rep Message)
    00275         rep.setBoolean(req->getBoolean()) ;
    00276         break ;
    00277
    00278       case Message::FEDERATE_SAVE_BEGUN:
    00279         D.Out(pdTrace, "Receiving Message from Federate, type"
    00280               " FederateSaveBegun.");
    00281         G.Out(pdGendoc,"chooseFederateProcessing FEDERATE_SAVE_BEGUN");
    00282         fm->federateSaveBegun(e);
    00283         break ;
    00284
    00285       case Message::FEDERATE_SAVE_COMPLETE:
    00286       case Message::FEDERATE_SAVE_NOT_COMPLETE: {
    00287           D.Out(pdTrace, "Receiving Message from Federate, type"
    00288                 " FederateSave(Not)Complete.");
    00289           bool result = req->type == Message::FEDERATE_SAVE_COMPLETE ;
    00290           if (result)
    00291               {
    00292               G.Out(pdGendoc,"chooseFederateProcessing FEDERATE_SAVE_COMPLETE");
    00293               }
    00294           else
    00295               {
    00296               G.Out(pdGendoc,"chooseFederateProcessing FEDERATE_SAVE_NOT_COMPLETE");
    00297               }
    00298           fm->federateSaveStatus(result, e);
    00299       }
    00300         break ;
    00301
    00302       case Message::REQUEST_FEDERATION_RESTORE:
    00303         D.Out(pdTrace, "Receiving Message from Federate, type"
    00304               " RequestFederationRestore.");
    00305         G.Out(pdGendoc,"chooseFederateProcessing REQUEST_FEDERATION_RESTORE");
    00306
    00307         fm->requestFederationRestore(req->getLabel(), e);
    00308         break ;
    00309
    00310       case Message::FEDERATE_RESTORE_COMPLETE:
    00311       case Message::FEDERATE_RESTORE_NOT_COMPLETE: {
    00312           D.Out(pdTrace, "Receiving Message from Federate, type"
    00313                 " FederateRestore(Not)Complete.");
    00314
    00315           bool result = req->type == Message::FEDERATE_RESTORE_COMPLETE ;
    00316           if (result)
    00317               {
    00318               G.Out(pdGendoc,"chooseFederateProcessing FEDERATE_RETORE_COMPLETE");
    00319               }
    00320           else
    00321               {
    00322               G.Out(pdGendoc,"chooseFederateProcessing FEDERATE_RESTORE_NOT_COMPLETE");
    00323               }
    00324           fm->federateRestoreStatus(result, e);
    00325       }
    00326         break ;
    00327
    00328       case Message::PUBLISH_OBJECT_CLASS:
    00329         D.Out(pdTrace,
    00330               "Receiving Message from Federate, type PublishObjectClass.");
    00331
    00332         dm->publishObjectClass(req->getObjectClass(),
    00333                                req->handleArray,
    00334                                req->handleArraySize,
    00335                                e);
    00336         break ;
    00337
    00338       case Message::UNPUBLISH_OBJECT_CLASS:
    00339         D.Out(pdTrace,
    00340               "Receiving Message from Federate, type UnpublishObjectClass.");
    00341
    00342         dm->unpublishObjectClass(req->getObjectClass(), e);
    00343         break ;
    00344
    00345       case Message::PUBLISH_INTERACTION_CLASS:
    00346         D.Out(pdTrace,
    00347               "Receiving Message from Federate, type PublishInteractionClass.");
    00348
    00349         dm->publishInteractionClass(req->getInteractionClass(), e);
    00350         break ;
    00351
    00352       case Message::UNPUBLISH_INTERACTION_CLASS:
    00353         D.Out(pdTrace,
    00354               "Receiving Message from Federate, "
    00355               "type UnpublishInteractionClass");
    00356
    00357         dm->unpublishInteractionClass(req->getInteractionClass(), e);
    00358         break ;
    00359
    00360       case Message::SUBSCRIBE_OBJECT_CLASS_ATTRIBUTES:
    00361         D.Out(pdTrace,
    00362               "Receiving Message from Federate, type SubscribeObjectClass.");
    00363         dm->subscribeObjectClassAttribute(req->getObjectClass(),
    00364                                           req->handleArray,
    00365                                           req->handleArraySize,
    00366                                           e);
    00367         break ;
    00368
    00369       case Message::UNSUBSCRIBE_OBJECT_CLASS:
    00370         D.Out(pdTrace,
    00371               "Receiving Message from Federate, type UnsubscribeObjectClass.");
    00372
    00373         // BUG: Why attributes are not transmitted ?
    00374         dm->unsubscribeObjectClassAttribute(req->getObjectClass(), e);
    00375         break ;
    00376
    00377       case Message::SUBSCRIBE_INTERACTION_CLASS:
    00378         D.Out(pdTrace,
    00379               "Receiving Message from Federate, type SubscribeInteraction.");
    00380
    00381         dm->subscribeInteractionClass(req->getInteractionClass(), e);
    00382         break ;
    00383
    00384       case Message::UNSUBSCRIBE_INTERACTION_CLASS:
    00385         D.Out(pdTrace,
    00386               "Receiving Message from Federate, type UnsubscribeInteraction.");
    00387
    00388         dm->unsubscribeInteractionClass(req->getInteractionClass(), e);
    00389         break ;
    00390
    00391       case Message::REGISTER_OBJECT_INSTANCE: {
    00392           FederationTime date = tm->requestFederateTime();
    00393           FederationTime heure = date + tm->requestLookahead();
    00394
    00395           D.Out(pdTrace,
    00396         "Receiving Message from Federate, type RegisterObject.");
    00397
    00398           rep.setObject(om->registerObject(req->getObjectClass(),
    00399                                            req->getName().c_str(),
    00400                                            date, heure, e));
    00401           break ;
    00402       }
    00403
    00404       case Message::UPDATE_ATTRIBUTE_VALUES: {
    00405           std::vector <AttributeValue_t> ValueArrayTemp ;
    00406           ValueArrayTemp = req->getValueArray();
    00407           try {
    00408               if (req->getBoolean() )
    00409                   {
    00410                   D.Out(pdTrace,"Receiving Message from Federate, type "
    00411                                 "UpdateAttribValues with TIMESTAMP.");
    00412                   rep.setEventRetraction(
    00413           om->updateAttributeValues(req->getObject(),
    00414                                             req->handleArray,
    00415                                             ValueArrayTemp,
    00416                                             req->handleArraySize,
    00417                                             req->getFederationTime(),
    00418                                             req->getTag(),
    00419                                             e));
    00420                   }
    00421               else
    00422                   {
    00423                   D.Out(pdTrace,"Receiving Message from Federate, type "
    00424                                 "UpdateAttribValues without TIMESTAMP.");
    00425           om->updateAttributeValues(req->getObject(),
    00426                                             req->handleArray,
    00427                                             ValueArrayTemp,
    00428                                             req->handleArraySize,
    00429                                             req->getTag(),
    00430                                             e);
    00431                   }
    00432               // Don't forget boolean value for the answer
    00433               rep.setBoolean(req->getBoolean()) ;
    00434               ValueArrayTemp.empty() ;
    00435           } catch (Exception *e) {
    00436               ValueArrayTemp.empty() ;
    00437               throw e ;
    00438           }
    00439       }
    00440         break ;
    00441
    00442       case Message::SEND_INTERACTION: {
    00443
    00444           std::vector <ParameterValue_t> ValueArrayTemp = req->getValueArray();
    00445           G.Out(pdGendoc,"S_I into RTIA::chooseFederateProcessing") ;
    00446           try {
    00447               if (req->getBoolean() )
    00448                   {
    00449                   D.Out(pdTrace,
    00450    "Receiving Message from Federate, type SendInteraction with TIMESTAMP.");
    00451                   rep.setEventRetraction(
    00452                       om->sendInteraction(req->getInteractionClass(),
    00453                                       req->handleArray,
    00454                                       ValueArrayTemp,
    00455                                       req->handleArraySize,
    00456                                       req->getFederationTime(),
    00457                                       req->getTag(),
    00458                       req->getRegion(),
    00459                                       e));
    00460                   }
    00461             else
    00462                   {
    00463                   D.Out(pdTrace,
    00464    "Receiving Message from Federate, type SendInteraction without TIMESTAMP.");
    00465                       om->sendInteraction(req->getInteractionClass(),
    00466                                       req->handleArray,
    00467                                       ValueArrayTemp,
    00468                                       req->handleArraySize,
    00469                                       req->getTag(),
    00470                       req->getRegion(),
    00471                                       e);
    00472                   }
    00473               ValueArrayTemp.empty();
    00474           } catch (Exception *e) {
    00475               ValueArrayTemp.empty();
    00476               throw e ;
    00477           }
    00478       }
    00479         break ;
    00480
    00481       case Message::DELETE_OBJECT_INSTANCE: {
    00482
    00483     G.Out(pdGendoc,"D_O_I into RTIA::chooseFederateProcessing") ;
    00484
    00485     try {
    00486         if ( req->getBoolean() ) {
    00487             D.Out(pdTrace,
    00488     "Receiving Message from Federate, type DeleteObjectInstance with \
    00489      TIMESTAMP.");
    00490                 rep.setEventRetraction(
    00491             om->deleteObject(
    00492                 req->getObject(),
    00493                 req->getFederationTime(),
    00494                 req->getTag(),
    00495                 e));
    00496         }
    00497         else {
    00498             D.Out(pdTrace,
    00499     "Receiving Message from Federate, type DeleteObjectInstance without \
    00500      TIMESTAMP.");
    00501         om->deleteObject(
    00502             req->getObject(),
    00503             req->getTag(),
    00504             e);
    00505         }
    00506     } catch (Exception *e) {
    00507         throw e;
    00508     }
    00509       }
    00510         break ;
    00511
    00512       case Message::CHANGE_ATTRIBUTE_TRANSPORTATION_TYPE:
    00513         D.Out(pdTrace,
    00514               "Receiving Message from Federate, type ChangeAttribTransport.");
    00515
    00516         om->changeAttributeTransportType(req->getObject(),
    00517                                          req->handleArray,
    00518                                          req->handleArraySize,
    00519                                          req->getTransportation(),
    00520                                          e);
    00521         break ;
    00522
    00523       case Message::CHANGE_ATTRIBUTE_ORDER_TYPE:
    00524         D.Out(pdTrace,
    00525               "Receiving Message from Federate, type ChangeAttribOrder.");
    00526
    00527         om->changeAttributeOrderType(req->getObject(),
    00528                                      req->handleArray,
    00529                                      req->handleArraySize,
    00530                                      req->getOrdering(),
    00531                                      e);
    00532         break ;
    00533
    00534       case Message::CHANGE_INTERACTION_TRANSPORTATION_TYPE:
    00535         D.Out(pdTrace,
    00536               "Receiving Message from Federate, type ChangeInterTransport.");
    00537
    00538         om->changeInteractionTransportType(req->getInteractionClass(),
    00539                                            req->getTransportation(),
    00540                                            e);
    00541         break ;
    00542
    00543       case Message::CHANGE_INTERACTION_ORDER_TYPE:
    00544         D.Out(pdTrace,
    00545               "Receiving Message from Federate, type ChangeInterOrder.");
    00546
    00547         om->changeInteractionOrderType(req->getInteractionClass(),
    00548                                        req->getOrdering(), e);
    00549         break ;
    00550
    00551       case Message::REQUEST_OBJECT_ATTRIBUTE_VALUE_UPDATE:
    00552             D.Out(pdTrace,"Receiving Message from Federate, type "
    00553                                 "RequestAttributeValueUpadate.");
    00554             om->requestObjectAttributeValueUpdate(req->getObject(),
    00555                                             req->handleArray,
    00556                                             req->handleArraySize,
    00557                                             e);
    00558         break ;
    00559
    00560       case Message::REQUEST_CLASS_ATTRIBUTE_VALUE_UPDATE:
    00561         std::cout<<"request class attribute value update not yet implemented in chooseFederateProcessing"
    00562         <<std::endl;
    00563         e = e_UnimplementedService ;
    00564         break ;
    00565
    00566       case Message::RETRACT:
    00567         std::cout<<"retract not yet implemented in chooseFederateProcessing"<<std::endl;
    00568         e = e_UnimplementedService ;
    00569         break ;
    00570
    00571       case Message::UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
    00572         D.Out(pdTrace, "Receiving Message from Federate, "
    00573               "type unconditionalAttributeOwnershipDivestiture.");
    00574         D.Out(pdTrace, "Object %u number of attributes %u ",
    00575               req->getObject(), req->handleArraySize);
    00576         owm->unconditionalAttributeOwnershipDivestiture(req->getObject(),
    00577                                                         req->handleArray,
    00578                                                         req->handleArraySize,
    00579                                                         e);
    00580         break ;
    00581
    00582       case Message::NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
    00583         D.Out(pdTrace, "Receiving Message from Federate, "
    00584               "type negotiatedAttributeOwnershipDivestiture.");
    00585         D.Out(pdTrace, "Object %u ; %u nb Attribute ", req->getObject(),
    00586               req->handleArraySize);
    00587         owm->negotiatedAttributeOwnershipDivestiture(req->getObject(),
    00588                                                      req->handleArray,
    00589                                                      req->handleArraySize,
    00590                                                      req->getTag(),
    00591                                                      e);
    00592         break ;
    00593
    00594       case Message::ATTRIBUTE_OWNERSHIP_ACQUISITION:
    00595         D.Out(pdTrace, "Receiving Message from Federate, "
    00596               "type attributeOwnershipAcquisition.");
    00597         D.Out(pdTrace, "Object %u ; Nb d'Attributs ", req->getObject(),
    00598               req->handleArraySize);
    00599         owm->attributeOwnershipAcquisition(req->getObject(),
    00600                                            req->handleArray,
    00601                                            req->handleArraySize,
    00602                                            req->getTag(), e);
    00603         break ;
    00604
    00605       case Message::ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE:
    00606       {
    00607           D.Out(pdTrace, "Receiving Message from Federate, "
    00608                 "type attributeOwnershipRealeaseResponse.");
    00609           D.Out(pdTrace, "Object %u nb Attribute %u ",
    00610                 req->getObject(), req->handleArraySize);
    00611
    00612           AttributeHandleSet* theAttributes =
    00613               owm->attributeOwnershipRealeaseResponse(req->getObject(),
    00614                                                       req->handleArray,
    00615                                                       req->handleArraySize,
    00616                                                       e);
    00617           if (e == e_NO_EXCEPTION) {
    00618               rep.handleArraySize = theAttributes->size();
    00619
    00620               for (unsigned int i=0 ; i<theAttributes->size(); i++) {
    00621                   rep.handleArray[i] = theAttributes->getHandle(i);
    00622               }
    00623           }
    00624       }
    00625       break ;
    00626
    00627       case Message::CANCEL_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
    00628         D.Out(pdTrace, "Receiving Message from Federate, "
    00629               "type cancelNegociatedAttributeOwnershipDivestiture.");
    00630         D.Out(pdTrace, "Object %u nb Attribute %u ",
    00631               req->getObject(), req->handleArraySize);
    00632         owm->cancelnegotiatedAttributeOwnershipDivestiture(req->getObject(),
    00633                                                            req->handleArray,
    00634                                                            req->handleArraySize,
    00635                                                            e);
    00636         break ;
    00637
    00638
    00639       case Message::CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION:
    00640         D.Out(pdTrace, "Receiving Message from Federate, "
    00641               "type cancelAttributeOwnershipAcquisition.");
    00642         D.Out(pdTrace, "Object %u nb Attribute %u ",
    00643               req->getObject(), req->handleArraySize);
    00644         owm->cancelattributeOwnershipAcquisition(req->getObject(),
    00645                                                  req->handleArray,
    00646                                                  req->handleArraySize,
    00647                                                  e);
    00648         break ;
    00649
    00650       case Message::ATTRIBUTE_OWNERSHIP_ACQUISITION_IF_AVAILABLE:
    00651         D.Out(pdTrace, "Receiving Message from Federate, "
    00652               "type attributeOwnershipAcquisitionIfAvailable.");
    00653         D.Out(pdTrace, "Object %u nb Attribute %u ",
    00654               req->getObject(), req->handleArraySize);
    00655         owm->attributeOwnershipAcquisitionIfAvailable(req->getObject(),
    00656                                                       req->handleArray,
    00657                                                       req->handleArraySize,
    00658                                                       e);
    00659         break ;
    00660
    00661       case Message::QUERY_ATTRIBUTE_OWNERSHIP:
    00662         D.Out(pdTrace, "Receiving Message from Federate, "
    00663               "type queryAttributeOwnership.");
    00664         D.Out(pdTrace, "Object %u Attribute %u ",
    00665               req->getObject(), req->getAttribute());
    00666         owm->queryAttributeOwnership(req->getObject(), req->getAttribute(), e);
    00667
    00668         break ;
    00669
    00670       case Message::IS_ATTRIBUTE_OWNED_BY_FEDERATE:
    00671         D.Out(pdTrace, "Receiving Message from Federate, "
    00672               "type isAttributeOwnedByFederate.");
    00673         D.Out(pdTrace, "Object %u Attribute %u ",
    00674               req->getObject(), req->getAttribute());
    00675         rep.setTag(owm->attributeOwnedByFederate(req->getObject(),
    00676                                                  req->getAttribute(), e));
    00677         break ;
    00678
    00679       case Message::QUERY_LBTS:
    00680         D.Out(pdTrace, "Receiving Message from Federate, type RequestLBTS.");
    00681
    00682         rep.setFederationTime(tm->requestLBTS());
    00683         break ;
    00684
    00685       case Message::ENABLE_ASYNCHRONOUS_DELIVERY:
    00686         D.Out(pdTrace, "Receiving Message from Federate, "
    00687                        "type EnableAsynchronousDelivery.");
    00688         if (! tm->_asynchronous_delivery)
    00689            tm->_asynchronous_delivery = true ;
    00690         else
    00691            e = e_AsynchronousDeliveryAlreadyEnabled;
    00692         break ;
    00693
    00694       case Message::DISABLE_ASYNCHRONOUS_DELIVERY:
    00695         D.Out(pdTrace, "Receiving Message from Federate, "
    00696                        "type DisableAsynchronousDelivery.");
    00697         if (tm->_asynchronous_delivery)
    00698            tm->_asynchronous_delivery = false ;
    00699         else
    00700           e = e_AsynchronousDeliveryAlreadyDisabled;
    00701         break ;
    00702
    00703
    00704       case Message::QUERY_FEDERATE_TIME:
    00705         D.Out(pdTrace,
    00706               "Receiving Message from Federate, type RequestFederateTime.");
    00707
    00708         rep.setFederationTime(tm->requestFederateTime());
    00709         break ;
    00710
    00711       case Message::QUERY_MIN_NEXT_EVENT_TIME:
    00712         D.Out(pdTrace,
    00713               "Receiving Message from Federate, type QueryMinNextEventTime.");
    00714
    00715         rep.setFederationTime(tm->requestMinNextEventTime());
    00716         break ;
    00717
    00718       case Message::MODIFY_LOOKAHEAD:
    00719         D.Out(pdTrace, "Receiving Message from Federate, type SetLookAhead.");
    00720
    00721         tm->setLookahead(req->getFederationTimeDelta(), e);
    00722         break ;
    00723
    00724       case Message::QUERY_LOOKAHEAD:
    00725         D.Out(pdTrace,
    00726               "Receiving Message from Federate, type RequestLookAhead.");
    00727
    00728         rep.setFederationTimeDelta(tm->requestLookahead());
    00729         break ;
    00730
    00731       case Message::TIME_ADVANCE_REQUEST:
    00732         D.Out(pdTrace,
    00733               "Receiving Message from Federate, type TimeAdvanceRequest.");
    00734
    00735         tm->timeAdvanceRequest(req->getFederationTime(), e);
    00736         break ;
    00737
    00738       case Message::TIME_ADVANCE_REQUEST_AVAILABLE:
    00739         D.Out(pdTrace,
    00740               "Receiving Message from Federate, type TimeAdvanceRequestAvailable.");
    00741
    00742         tm->timeAdvanceRequestAvailable(req->getFederationTime(), e);
    00743         break ;
    00744
    00745       case Message::NEXT_EVENT_REQUEST:
    00746         D.Out(pdTrace,
    00747               "Receiving Message from Federate, type NestEventRequest.");
    00748
    00749         tm->nextEventRequest(req->getFederationTime(), e);
    00750         break ;
    00751
    00752       case Message::NEXT_EVENT_REQUEST_AVAILABLE:
    00753         D.Out(pdTrace,
    00754               "Receiving Message from Federate, type NestEventRequestAvailable.");
    00755
    00756         tm->nextEventRequestAvailable(req->getFederationTime(), e);
    00757         break ;
    00758
    00759       case Message::FLUSH_QUEUE_REQUEST:
    00760         e = e_UnimplementedService ;
    00761         break ;
    00762
    00763       // May throw NameNotFound
    00764       // Exception catched and stored in rep Message for answer
    00765       case Message::GET_OBJECT_CLASS_HANDLE:
    00766         D.Out(pdTrace,
    00767               "Receiving Message from Federate, type GetObjectClassHandle.");
    00768         try {
    00769             rep.setObjectClass(om->getObjectClassHandle(req->getName().c_str()));
    00770             }
    00771         catch (Exception &egoch)
    00772             {
    00773             rep.setException(static_cast<TypeException>(egoch.getType()),egoch._reason);
    00774             }
    00775         break ;
    00776
    00777       case Message::GET_OBJECT_CLASS_NAME:
    00778         D.Out(pdTrace,
    00779               "Receiving Message from Federate, type GetObjectClassName.");
    00780
    00781         try {
    00782             rep.setName(om->getObjectClassName(req->getObjectClass()).c_str());
    00783         }
    00784         catch (ObjectClassNotDefined) {
    00785             rep.setException(e_ObjectClassNotDefined);
    00786         }
    00787         catch (RTIinternalError) {
    00788             rep.setException(e_RTIinternalError);
    00789         }
    00790         break ;
    00791
    00792       case Message::GET_OBJECT_INSTANCE_HANDLE:
    00793         D.Out(pdTrace,
    00794               "Receiving Message from Federate, type getObjectInstanceHandle.");
    00795         rep.setObject(om->getObjectInstanceHandle(req->getName().c_str()));
    00796         break ;
    00797
    00798       case Message::GET_OBJECT_INSTANCE_NAME:
    00799         D.Out(pdTrace,
    00800               "Receiving Message from Federate, type getObjectInstanceName.");
    00801
    00802         rep.setName(om->getObjectInstanceName(req->getObject()));
    00803         break ;
    00804
    00805       // May throw NameNotFound
    00806       // Exception catched and stored in rep Message for answer
    00807       case Message::GET_ATTRIBUTE_HANDLE:
    00808         D.Out(pdTrace,
    00809               "Receiving Message from Federate, type GetAttributeHandle.");
    00810         try {
    00811             rep.setAttribute(om->getAttributeHandle(req->getName().c_str(),
    00812                                                 req->getObjectClass()));
    00813             }
    00814         catch (Exception &egah)
    00815             {
    00816             rep.setException(static_cast<TypeException>(egah.getType()),egah._reason);
    00817             }
    00818         break ;
    00819
    00820       case Message::GET_ATTRIBUTE_NAME:
    00821         D.Out(pdTrace,
    00822               "Receiving Message from Federate, type GetAttributeName.");
    00823
    00824         rep.setName(om->getAttributeName(req->getAttribute(),
    00825                                          req->getObjectClass()));
    00826         break ;
    00827
    00828       case Message::GET_INTERACTION_CLASS_HANDLE:
    00829         D.Out(pdTrace,
    00830               "Receiving Message from Federate, type GetInteractionHandle.");
    00831
    00832         rep.setInteractionClass(om->getInteractionClassHandle(req->getName().c_str()));
    00833         break ;
    00834
    00835       case Message::GET_INTERACTION_CLASS_NAME:
    00836         D.Out(pdTrace,
    00837               "Receiving Message from Federate, type GetInteractionName.");
    00838
    00839         rep.setName(om->getInteractionClassName(req->getInteractionClass()).c_str());
    00840         break ;
    00841
    00842       case Message::GET_PARAMETER_HANDLE:
    00843         D.Out(pdTrace,
    00844               "Receiving Message from Federate, type GetParameterHandle.");
    00845
    00846         rep.setParameter(om->getParameterHandle(req->getName().c_str(),
    00847                                                 req->getInteractionClass()));
    00848         break ;
    00849
    00850       case Message::GET_PARAMETER_NAME:
    00851         D.Out(pdTrace,
    00852               "Receiving Message from Federate, type GetParameterName.");
    00853
    00854         rep.setName(om->getParameterName(req->getParameter(),
    00855                                          req->getInteractionClass()).c_str());
    00856         break ;
    00857
    00858       case Message::GET_SPACE_HANDLE:
    00859         D.Out(pdTrace, "Receiving Message from Federate, type GetSpaceHandle.");
    00860         rep.setSpace(ddm->getRoutingSpaceHandle(req->getName()));
    00861         break ;
    00862
    00863       case Message::GET_SPACE_NAME:
    00864         D.Out(pdTrace, "Receiving Message from Federate, type GetSpaceName.");
    00865         rep.setName(ddm->getRoutingSpaceName(req->getSpace()).c_str());
    00866         break ;
    00867
    00868       case Message::GET_DIMENSION_HANDLE:
    00869         D.Out(pdTrace,
    00870               "Receiving Message from Federate, type GetDimensionHandle");
    00871         rep.setDimension(ddm->getDimensionHandle(string(req->getName()),
    00872                                                  req->getSpace()));
    00873         break ;
    00874
    00875       case Message::GET_DIMENSION_NAME:
    00876         D.Out(pdTrace,
    00877               "Receiving Message from Federate, type GetDimensionName");
    00878         rep.setName(ddm->getDimensionName(req->getDimension(),
    00879                                           req->getSpace()).c_str());
    00880         break ;
    00881
    00882       case Message::GET_ATTRIBUTE_SPACE_HANDLE:
    00883         D.Out(pdTrace,
    00884               "Receiving Message from Federate, type GetAttributeSpaceHandle");
    00885         rep.setSpace(ddm->getAttributeSpace(req->getAttribute(),
    00886                                             req->getObjectClass()));
    00887         break ;
    00888
    00889       case Message::GET_INTERACTION_SPACE_HANDLE:
    00890         D.Out(pdTrace,
    00891               "Receiving Message from Federate: GetInteractionSpaceHandle");
    00892         rep.setSpace(ddm->getInteractionSpace(req->getInteractionClass()));
    00893         break ;
    00894
    00895       case Message::GET_OBJECT_CLASS:
    00896         D[pdTrace] << "Message from Federate: getObjectClass" << endl ;
    00897     rep.setObjectClass(om->getObjectClass(req->getObject()));
    00898     break ;
    00899
    00900       case Message::GET_TRANSPORTATION_HANDLE:
    00901         D[pdTrace] << "Message from Federate: getTransportationHandle" << endl ;
    00902         rep.setTransportation(om->getTransportationHandle(req->getName().c_str()));
    00903         break ;
    00904
    00905       case Message::GET_TRANSPORTATION_NAME:
    00906         D[pdTrace] << "Message from Federate: getTransportationName" << endl ;
    00907         rep.setName(om->getTransportationName(req->getTransportation()));
    00908         break ;
    00909
    00910       case Message::GET_ORDERING_HANDLE:
    00911         D[pdTrace] << "Message from Federate: getOrderingHandle" << endl ;
    00912         rep.setOrdering(om->getOrderingHandle(req->getName().c_str()));
    00913         break ;
    00914
    00915       case Message::GET_ORDERING_NAME:
    00916         D[pdTrace] << "Message from Federate: getOrderingName" << endl ;
    00917         rep.setName(om->getOrderingName(req->getOrdering()));
    00918         break ;
    00919
    00920       case Message::DDM_CREATE_REGION:
    00921         D[pdTrace] << "Receiving Message from Federate: CreateRegion" << endl ;
    00922         rep.setRegion(ddm->createRegion(req->getSpace(), req->getNumber(), e));
    00923     rep.setNumber(rootObject->getRoutingSpace(req->getSpace()).size());
    00924         break ;
    00925
    00926       case Message::DDM_MODIFY_REGION:
    00927     D[pdTrace] << "Receiving Message from Federate: Modify Region" << endl ;
    00928     ddm->modifyRegion(req->getRegion(), req->getExtents(), e);
    00929     break ;
    00930
    00931       case Message::DDM_DELETE_REGION:
    00932         D[pdTrace] << "Receiving Message from Federate: DeleteRegion" << endl ;
    00933         ddm->deleteRegion(req->getRegion(), e);
    00934         break ;
    00935
    00936       case Message::DDM_ASSOCIATE_REGION:
    00937     D[pdTrace] << "Receiving Message from Federate: Associate Region"
    00938            << endl ;
    00939     ddm->associateRegion(req->getObject(), req->getRegion(),
    00940                  req->handleArray, req->handleArraySize, e);
    00941     break ;
    00942
    00943       case Message::DDM_REGISTER_OBJECT:
    00944     D[pdTrace] << "Receiving Message from Federate: Register with Region"
    00945            << endl ;
    00946     rep.setObject(ddm->registerObject(req->getObjectClass(),
    00947                       req->getName(),
    00948                       req->handleArray,
    00949                       req->handleArraySize,
    00950                       req->getRegions(),
    00951                       e));
    00952     break ;
    00953
    00954       case Message::DDM_UNASSOCIATE_REGION:
    00955     D[pdTrace] << "Receiving Message from Federate: Unassociate Region"
    00956            << endl ;
    00957     ddm->unassociateRegion(req->getObject(), req->getRegion(), e);
    00958     break ;
    00959
    00960       case Message::DDM_SUBSCRIBE_ATTRIBUTES:
    00961     D[pdTrace] << "Receiving Message from Federate: Subscribe Attributes"
    00962            << endl ;
    00963     ddm->subscribe(req->getObjectClass(), req->getRegion(),
    00964                req->handleArray, req->handleArraySize, e);
    00965     break ;
    00966
    00967       case Message::DDM_UNSUBSCRIBE_ATTRIBUTES:
    00968     D[pdTrace] << "Receiving Message from Federate: Unsubscribe class "
    00969            << req->getObjectClass() << endl ;
    00970     ddm->unsubscribeAttributes(req->getObjectClass(), req->getRegion(), e);
    00971     break ;
    00972
    00973       case Message::DDM_SUBSCRIBE_INTERACTION:
    00974     D[pdTrace] << "Receiving Message from Federate: Subscribe Interaction"
    00975            << endl ;
    00976     ddm->subscribeInteraction(req->getInteractionClass(),
    00977                   req->getRegion(), e);
    00978     break ;
    00979
    00980       case Message::DDM_UNSUBSCRIBE_INTERACTION:
    00981     D[pdTrace] << "Receiving Message from Federate: Unsubscribe Interaction"
    00982            << endl ;
    00983     ddm->unsubscribeInteraction(req->getInteractionClass(),
    00984                     req->getRegion(), e);
    00985     break ;
    00986
    00987       case Message::ENABLE_TIME_REGULATION:
    00988       case Message::DISABLE_TIME_REGULATION:
    00989         D.Out(pdTrace,
    00990               "Receiving Message from Federate, type SetTimeRegulating.");
    00991
    00992         tm->setTimeRegulating(req->getBoolean(),req->getFederationTime(),req->getFederationTimeDelta(), e);
    00993         break ;
    00994
    00995       case Message::ENABLE_TIME_CONSTRAINED:
    00996       case Message::DISABLE_TIME_CONSTRAINED:
    00997         D.Out(pdTrace,
    00998               "Receiving Message from Federate, type SetTimeConstrained.");
    00999
    01000         tm->setTimeConstrained(req->getBoolean(), e);
    01001         break ;
    01002
    01003       case Message::TICK_REQUEST:
    01004         // called when tick() is invoked
    01005         if (tm->_tick_state != TimeManagement::NO_TICK)
    01006             throw RTIinternalError("TICK_REQUEST cannot be called recursively");
    01007
    01008         tm->_tick_multiple = req->getBoolean();
    01009         tm->_tick_result = false; // default return value
    01010
    01011         if (req->getMinTickTime() > 0.0)
    01012         {
    01013             tm->_tick_timeout = req->getMinTickTime();
    01014             tm->_tick_stop_time = currentTickTime() + req->getMaxTickTime();
    01015             tm->_tick_state = TimeManagement::TICK_BLOCKING;
    01016         }
    01017         else
    01018             tm->_tick_state = TimeManagement::TICK_CALLBACK;
    01019
    01020         processOngoingTick();
    01021         break ;
    01022
    01023       case Message::TICK_REQUEST_NEXT:
    01024         // called when tick() queries result, or next callback
    01025         if (tm->_tick_state != TimeManagement::TICK_CALLBACK &&
    01026             tm->_tick_state != TimeManagement::TICK_RETURN)
    01027             throw RTIinternalError("unexpected TICK_REQUEST_NEXT");
    01028
    01029         processOngoingTick();
    01030         break ;
    01031
    01032       case Message::TICK_REQUEST_STOP:
    01033         // called to terminate tick() when error occured
    01034         // do not invoke any callbacks, reset _tick_state and return
    01035         tm->_tick_state = TimeManagement::TICK_RETURN;
    01036
    01037         processOngoingTick();
    01038         break ;
    01039
    01040       case Message::ENABLE_CLASS_RELEVANCE_ADVISORY_SWITCH:
    01041         D.Out(pdTrace,
    01042               "Receiving Message from Federate, type EnableClassRelevanceAdvisorySwitch.");
    01043     dm->setClassRelevanceAdvisorySwitch(true, e);
    01044     break;
    01045
    01046       case Message::DISABLE_CLASS_RELEVANCE_ADVISORY_SWITCH:
    01047         D.Out(pdTrace,
    01048               "Receiving Message from Federate, type DisableClassRelevanceAdvisorySwitch.");
    01049     dm->setClassRelevanceAdvisorySwitch(false, e);
    01050     break;
    01051
    01052       case Message::ENABLE_INTERACTION_RELEVANCE_ADVISORY_SWITCH:
    01053         D.Out(pdTrace,
    01054               "Receiving Message from Federate, type SetInteractionRelevanceAdvisorySwitch.");
    01055     dm->setInteractionRelevanceAdvisorySwitch(true, e);
    01056     break;
    01057
    01058       case Message::DISABLE_INTERACTION_RELEVANCE_ADVISORY_SWITCH:
    01059         D.Out(pdTrace,
    01060               "Receiving Message from Federate, type SetInteractionRelevanceAdvisorySwitch.");
    01061     dm->setInteractionRelevanceAdvisorySwitch(false, e);
    01062     break;
    01063
    01064       case Message::ENABLE_ATTRIBUTE_RELEVANCE_ADVISORY_SWITCH:
    01065         D.Out(pdTrace,
    01066               "Receiving Message from Federate, type SetAttributeRelevanceAdvisorySwitch.");
    01067     om->setAttributeRelevanceAdvisorySwitch(true, e);
    01068     break;
    01069
    01070       case Message::DISABLE_ATTRIBUTE_RELEVANCE_ADVISORY_SWITCH:
    01071         D.Out(pdTrace,
    01072               "Receiving Message from Federate, type SetAttributeRelevanceAdvisorySwitch.");
    01073     om->setAttributeRelevanceAdvisorySwitch(false, e);
    01074     break;
    01075
    01076       case Message::ENABLE_ATTRIBUTE_SCOPE_ADVISORY_SWITCH:
    01077         D.Out(pdTrace,
    01078               "Receiving Message from Federate, type SetAttributeScopeAdvisorySwitch.");
    01079     om->setAttributeScopeAdvisorySwitch(true, e);
    01080     break;
    01081
    01082       case Message::DISABLE_ATTRIBUTE_SCOPE_ADVISORY_SWITCH:
    01083         D.Out(pdTrace,
    01084               "Receiving Message from Federate, type SetAttributeScopeAdvisorySwitch.");
    01085     om->setAttributeScopeAdvisorySwitch(false, e);
    01086     break;
    01087
    01088       default:
    01089         D.Out(pdExcept,
    01090               "Receiving Message from Federate, Unknown Type %d.", req->type);
    01091         throw RTIinternalError("");
    01092     }
    01093     stat.federateService(req->type);
    01094     G.Out(pdGendoc,"exit  chooseFederateProcessing");
    01095 }
    01096
    01097 // ----------------------------------------------------------------------------
    01099 void
    01100 RTIA::processOngoingTick()
    01101 {
    01102     Message msg_ack;
    01103     TypeException exc = e_NO_EXCEPTION;
    01104
    01105     while (1) {
    01106         switch (tm->_tick_state) {
    01107           case TimeManagement::TICK_BLOCKING:
    01108             /* blocking tick() waits for an event to come:
    01109              *   try to evoke a single callback
    01110              */
    01111             tm->_tick_result = tm->tick(exc);
    01112             // if a callback has not been evoked
    01113             if (tm->_tick_state != TimeManagement::TICK_NEXT)
    01114                 return; // keep waiting
    01115             // else goto TICK_NEXT
    01116
    01117           case TimeManagement::TICK_NEXT:
    01118             /* a callback was evoked
    01119              *   decide how to continue
    01120              */
    01121             if (tm->_tick_result &&
    01122                 tm->_tick_multiple && currentTickTime() < tm->_tick_stop_time)
    01123                 tm->_tick_state = TimeManagement::TICK_CALLBACK;
    01124             else
    01125                 tm->_tick_state = TimeManagement::TICK_RETURN;
    01126
    01127             return;
    01128
    01129           case TimeManagement::TICK_CALLBACK:
    01130             /* tick() waits until a federate callback finishes
    01131              *   try to evoke a single callback
    01132              */
    01133             tm->_tick_result = tm->tick(exc);
    01134             // if a callback has been evoked
    01135             if (tm->_tick_state == TimeManagement::TICK_NEXT)
    01136                 break; // goto TICK_NEXT
    01137             // else goto TICK_RETURN
    01138
    01139           case TimeManagement::TICK_RETURN:
    01140             /* send TICK_REQUEST response
    01141              */
    01142             if ( exc != e_RTIinternalError )
    01143                 msg_ack.setException(exc);
    01144             // terminate __tick() call in the federate
    01145             msg_ack.type = Message::TICK_REQUEST;
    01146             msg_ack.setBoolean(tm->_tick_result);
    01147             msg_ack.setMinTickTime(0); // unused
    01148             msg_ack.setMaxTickTime(0); // unused
    01149             comm->requestFederateService(&msg_ack);
    01150
    01151             tm->_tick_state = TimeManagement::NO_TICK;
    01152             return;
    01153
    01154           default:
    01155             std::cerr << "Unknown state: " << tm->_tick_state << std::endl;
    01156             assert(false);
    01157         }
    01158     }
    01159 }
    01160
    01161 // ----------------------------------------------------------------------------
    01163 void
    01164 RTIA::processFederateRequest(Message *req)
    01165 {
    01166     Message rep ;
    01167
    01168     G.Out(pdGendoc,"enter RTIA::processFederateRequest");
    01169
    01170     rep.type = req->type ;
    01171
    01172     try {
    01173         TypeException exc ;
    01174         chooseFederateProcessing(req, rep, exc);
    01175         if ( exc != e_RTIinternalError && exc != e_NO_EXCEPTION)
    01176            rep.setException(exc);
    01177     }
    01178     catch (ArrayIndexOutOfBounds &e) {
    01179         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01180         rep.setException(e_ArrayIndexOutOfBounds);
    01181     }
    01182     catch (AttributeAlreadyOwned &e) {
    01183         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01184         rep.setException(e_AttributeAlreadyOwned);
    01185     }
    01186     catch (AttributeAlreadyBeingDivested &e) {
    01187         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01188         rep.setException(e_AttributeAlreadyBeingDivested);
    01189     }
    01190     catch (AttributeAlreadyBeingAcquired &e) {
    01191         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01192         rep.setException(e_AttributeAlreadyBeingAcquired);
    01193     }
    01194     catch (AttributeAcquisitionWasNotRequested &e) {
    01195         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01196         rep.setException(e_AttributeAcquisitionWasNotRequested);
    01197     }
    01198     catch (AttributeDivestitureWasNotRequested &e) {
    01199         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01200         rep.setException(e_AttributeDivestitureWasNotRequested);
    01201     }
    01202     catch (AttributeNotDefined &e) {
    01203         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01204         rep.setException(e_AttributeNotDefined);
    01205     }
    01206     catch (AttributeNotKnown &e) {
    01207         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01208         rep.setException(e_AttributeNotKnown);
    01209     }
    01210     catch (AttributeNotOwned &e) {
    01211         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01212         rep.setException(e_AttributeNotOwned);
    01213     }
    01214     catch (AttributeNotPublished &e) {
    01215         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01216         rep.setException(e_AttributeNotPublished);
    01217     }
    01218     catch (AttributeNotSubscribed &e) {
    01219         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01220         rep.setException(e_AttributeNotSubscribed);
    01221     }
    01222     catch (ConcurrentAccessAttempted &e) {
    01223         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01224         rep.setException(e_ConcurrentAccessAttempted);
    01225     }
    01226     catch (CouldNotDiscover &e) {
    01227         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01228         rep.setException(e_CouldNotDiscover);
    01229     }
    01230     catch (CouldNotOpenRID &e) {
    01231         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01232         rep.setException(e_CouldNotOpenRID);
    01233     }
    01234     catch (CouldNotOpenFED &e) {
    01235         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01236         rep.setException(e_CouldNotOpenFED,e._reason);
    01237     }
    01238     catch (CouldNotRestore &e) {
    01239         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01240         rep.setException(e_CouldNotRestore);
    01241     }
    01242     catch (DeletePrivilegeNotHeld &e) {
    01243         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01244         rep.setException(e_DeletePrivilegeNotHeld);
    01245     }
    01246     catch (ErrorReadingRID &e) {
    01247         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01248         rep.setException(e_ErrorReadingRID,e._reason);
    01249     }
    01250     catch (ErrorReadingFED &e) {
    01251         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01252         rep.setException(e_ErrorReadingFED,e._reason);
    01253     }
    01254     catch (EventNotKnown &e) {
    01255         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01256         rep.setException(e_EventNotKnown);
    01257     }
    01258     catch (FederateAlreadyPaused &e) {
    01259         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01260         rep.setException(e_FederateAlreadyPaused);
    01261     }
    01262     catch (FederateAlreadyExecutionMember &e) {
    01263         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01264         rep.setException(e_FederateAlreadyExecutionMember,e._reason);
    01265     }
    01266     catch (FederateDoesNotExist &e) {
    01267         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01268         rep.setException(e_FederateDoesNotExist);
    01269     }
    01270     catch (FederateInternalError &e) {
    01271         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01272         rep.setException(e_FederateInternalError);
    01273     }
    01274     catch (FederateNameAlreadyInUse &e) {
    01275         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01276         rep.setException(e_FederateNameAlreadyInUse);
    01277     }
    01278     catch (FederateNotExecutionMember &e) {
    01279         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01280         rep.setException(e_FederateNotExecutionMember);
    01281     }
    01282     catch (FederateNotPaused &e) {
    01283         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01284         rep.setException(e_FederateNotPaused);
    01285     }
    01286     catch (FederateNotPublishing &e) {
    01287         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01288         rep.setException(e_FederateNotPublishing);
    01289     }
    01290     catch (FederateNotSubscribing &e) {
    01291         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01292         rep.setException(e_FederateNotSubscribing);
    01293     }
    01294     catch (FederateOwnsAttributes &e) {
    01295         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01296         rep.setException(e_FederateOwnsAttributes);
    01297     }
    01298     catch (FederatesCurrentlyJoined &e) {
    01299         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01300         rep.setException(e_FederatesCurrentlyJoined);
    01301     }
    01302     catch (FederateWasNotAskedToReleaseAttribute &e) {
    01303         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01304         rep.setException(e_FederateWasNotAskedToReleaseAttribute);
    01305     }
    01306     catch (FederationAlreadyPaused &e) {
    01307         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01308         rep.setException(e_FederationAlreadyPaused);
    01309     }
    01310     catch (FederationExecutionAlreadyExists &e) {
    01311         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01312         rep.setException(e_FederationExecutionAlreadyExists,e._reason);
    01313     }
    01314     catch (FederationExecutionDoesNotExist &e) {
    01315         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01316         rep.setException(e_FederationExecutionDoesNotExist);
    01317     }
    01318     catch (FederationNotPaused &e) {
    01319         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01320         rep.setException(e_FederationNotPaused);
    01321     }
    01322     catch (FederationTimeAlreadyPassed &e) {
    01323         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01324         rep.setException(e_FederationTimeAlreadyPassed);
    01325     }
    01326     catch (IDsupplyExhausted &e) {
    01327         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01328         rep.setException(e_IDsupplyExhausted);
    01329     }
    01330     catch (InteractionClassNotDefined &e) {
    01331         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01332         rep.setException(e_InteractionClassNotDefined);
    01333     }
    01334     catch (InteractionClassNotKnown &e) {
    01335         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01336         rep.setException(e_InteractionClassNotKnown);
    01337     }
    01338     catch (InteractionClassNotPublished &e) {
    01339         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01340         rep.setException(e_InteractionClassNotPublished);
    01341     }
    01342     catch (InteractionParameterNotDefined &e) {
    01343         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01344         rep.setException(e_InteractionParameterNotDefined);
    01345     }
    01346     catch (InteractionParameterNotKnown &e) {
    01347         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01348         rep.setException(e_InteractionParameterNotKnown);
    01349     }
    01350     catch (InvalidDivestitureCondition &e) {
    01351         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01352         rep.setException(e_InvalidDivestitureCondition);
    01353     }
    01354     catch (InvalidExtents &e) {
    01355         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01356         rep.setException(e_InvalidExtents);
    01357     }
    01358     catch (InvalidFederationTime &e) {
    01359         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01360         rep.setException(e_InvalidFederationTime);
    01361     }
    01362     catch (InvalidFederationTimeDelta &e) {
    01363         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01364         rep.setException(e_InvalidFederationTimeDelta);
    01365     }
    01366     catch (InvalidObjectHandle &e) {
    01367         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01368         rep.setException(e_InvalidObjectHandle);
    01369     }
    01370     catch (InvalidOrderingHandle &e) {
    01371         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01372         rep.setException(e_InvalidOrderingHandle);
    01373     }
    01374     catch (InvalidResignAction &e) {
    01375         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01376         rep.setException(e_InvalidResignAction);
    01377     }
    01378     catch (InvalidRetractionHandle &e) {
    01379         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01380         rep.setException(e_InvalidRetractionHandle);
    01381     }
    01382     catch (InvalidRoutingSpace &e) {
    01383         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01384         rep.setException(e_InvalidRoutingSpace);
    01385     }
    01386     catch (InvalidTransportationHandle &e) {
    01387         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01388         rep.setException(e_InvalidTransportationHandle);
    01389     }
    01390     catch (MemoryExhausted &e) {
    01391         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01392         rep.setException(e_MemoryExhausted);
    01393     }
    01394     catch (NameNotFound &e) {
    01395         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01396         rep.setException(e_NameNotFound);
    01397     }
    01398     catch (NoPauseRequested &e) {
    01399         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01400         rep.setException(e_NoPauseRequested);
    01401     }
    01402     catch (NoResumeRequested &e) {
    01403         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01404         rep.setException(e_NoResumeRequested);
    01405     }
    01406     catch (ObjectClassNotDefined &e) {
    01407         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01408         rep.setException(e_ObjectClassNotDefined);
    01409     }
    01410     catch (ObjectClassNotKnown &e) {
    01411         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01412         rep.setException(e_ObjectClassNotKnown);
    01413     }
    01414     catch (ObjectClassNotPublished &e) {
    01415         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01416         rep.setException(e_ObjectClassNotPublished);
    01417     }
    01418     catch (ObjectClassNotSubscribed &e) {
    01419         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01420         rep.setException(e_ObjectClassNotSubscribed);
    01421     }
    01422     catch (ObjectNotKnown &e) {
    01423         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01424         rep.setException(e_ObjectNotKnown);
    01425     }
    01426     catch (ObjectAlreadyRegistered &e) {
    01427         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01428         rep.setException(e_ObjectAlreadyRegistered);
    01429     }
    01430     catch (RegionNotKnown &e) {
    01431         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01432         rep.setException(e_RegionNotKnown);
    01433     }
    01434     catch (RestoreInProgress &e) {
    01435         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01436         rep.setException(e_RestoreInProgress);
    01437     }
    01438     catch (RestoreNotRequested &e) {
    01439         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01440         rep.setException(e_RestoreNotRequested);
    01441     }
    01442     catch (RTIinternalError &e) {
    01443         cout << "RTIA sends InternalError to Fed., " ;
    01444         if (!e._reason.empty())
    01445             cout << "reason : " << e._reason << endl ;
    01446         else
    01447             cout << "no reason given." << endl ;
    01448         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01449         rep.setException(e_RTIinternalError);
    01450     }
    01451     catch (SpaceNotDefined &e) {
    01452         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01453         rep.setException(e_SpaceNotDefined);
    01454     }
    01455     catch (SaveInProgress &e) {
    01456         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01457         rep.setException(e_SaveInProgress);
    01458     }
    01459     catch (SaveNotInitiated &e) {
    01460         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01461         rep.setException(e_SaveNotInitiated);
    01462     }
    01463     catch (SpecifiedSaveLabelDoesNotExist &e) {
    01464         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01465         rep.setException(e_SpecifiedSaveLabelDoesNotExist);
    01466     }
    01467     catch (TimeAdvanceAlreadyInProgress &e) {
    01468         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01469         rep.setException(e_TimeAdvanceAlreadyInProgress);
    01470     }
    01471     catch (TimeAdvanceWasNotInProgress &e) {
    01472         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01473         rep.setException(e_TimeAdvanceWasNotInProgress);
    01474     }
    01475     catch (TooManyIDsRequested &e) {
    01476         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01477         rep.setException(e_TooManyIDsRequested);
    01478     }
    01479     catch (UnableToPerformSave &e) {
    01480         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01481         rep.setException(e_UnableToPerformSave);
    01482     }
    01483     catch (UnimplementedService &e) {
    01484         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01485         rep.setException(e_UnimplementedService);
    01486     }
    01487     catch (UnknownLabel &e) {
    01488         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01489         rep.setException(e_UnknownLabel);
    01490     }
    01491     catch (ValueCountExceeded &e) {
    01492         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01493         rep.setException(e_ValueCountExceeded);
    01494     }
    01495     catch (ValueLengthExceeded &e) {
    01496         D.Out(pdExcept, "Catched %s Exception.", e._name);
    01497         rep.setException(e_ValueLengthExceeded);
    01498     }
    01499
    01500     // Default Handler
    01501     catch (Exception &e) {
    01502         D.Out(pdExcept, "Unknown Exception : %s.", e._name);
    01503         rep.setException(e_RTIinternalError);
    01504     }
    01505
    01506     delete req;
    01507
    01508     if (rep.type != Message::TICK_REQUEST &&
    01509         rep.type != Message::TICK_REQUEST_NEXT &&
    01510         rep.type != Message::TICK_REQUEST_STOP) {
    01511        // generic federate service acknowledgment
    01512        // the TICK_REQUEST confirmation is generated in processOngoingTick()
    01513        comm->sendUN(&rep);
    01514        D.Out(pdDebug, "Reply send to Unix socket.");
    01515     }
    01516     G.Out(pdGendoc,"exit  RTIA::processFederateRequest");
    01517 }
    01518
    01519 }} // namespace certi/rtia
    01520