# RTIG.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.cc,v 3.55 2009/04/02 19:58:10 erk Exp $
    00022 // ----------------------------------------------------------------------------
    00023
    00024 #include <config.h>
    00025 #include "RTIG.hh"
    00026
    00027 #include "PrettyDebug.hh"
    00028 #include "NM_Classes.hh"
    00029
    00030 #ifdef _WIN32
    00031 #include <signal.h>
    00032 #else
    00033 #include <unistd.h>
    00034 #include <iostream>
    00035 #endif
    00036 #include <cerrno>
    00037 #include <csignal>
    00038 #include <memory>
    00039
    00040 using std::cout ;
    00041 using std::endl ;
    00042 using std::cerr ;
    00043
    00044 namespace certi {
    00045 namespace rtig {
    00046
    00047 static PrettyDebug D("RTIG", __FILE__);
    00048 static PrettyDebug G("GENDOC",__FILE__);
    00049
    00050 bool RTIG::terminate = false;
    00051
    00052 // ----------------------------------------------------------------------------
    00053 // Constructor
    00054 // Note (JYR) : udpPort modified AFTER used in socketServer(.) call, strange...
    00055 RTIG::RTIG()
    00056     :  federationHandles(1),
    00057       socketServer(&tcpSocketServer, &udpSocketServer, udpPort),
    00058       auditServer(RTIG_AUDIT_FILENAME),
    00059       federations(socketServer, auditServer)
    00060 {
    00061     // Start RTIG services
    00062     const char *tcp_port_s = getenv("CERTI_TCP_PORT");
    00063     const char *udp_port_s = getenv("CERTI_UDP_PORT");
    00064     if (tcp_port_s==NULL) tcp_port_s = PORT_TCP_RTIG ;
    00065     if (udp_port_s==NULL) udp_port_s = PORT_UDP_RTIG ;
    00066     tcpPort = atoi(tcp_port_s);
    00067     udpPort = atoi(udp_port_s);
    00068
    00069     federations.setVerboseLevel(verboseLevel);
    00070 }
    00071
    00072 // ----------------------------------------------------------------------------
    00073 // Destructor
    00074
    00075 RTIG::~RTIG()
    00076 {
    00077     tcpSocketServer.close();
    00078     udpSocketServer.close();
    00079
    00080     cout << endl << "Stopping RTIG" << endl ;
    00081 }
    00082
    00083 // ----------------------------------------------------------------------------
    00085
    00088 Socket*
    00089 RTIG::chooseProcessingMethod(Socket *link, NetworkMessage *msg)
    00090 {
    00091     G.Out(pdGendoc,"enter RTIG::chooseProcessingMethod type (%s)",msg->getName().c_str());
    00092     // This may throw a security error.
    00093     if ( msg->getType() != NetworkMessage::DESTROY_FEDERATION_EXECUTION)
    00094        socketServer.checkMessage(link->returnSocket(), msg);
    00095
    00096     switch(msg->getType()) {
    00097       case NetworkMessage::MESSAGE_NULL:
    00098         D.Out(pdDebug, "Message Null.");
    00099         auditServer.setLevel(0);
    00100         processMessageNull(msg);
    00101         break ;
    00102
    00103       case NetworkMessage::UPDATE_ATTRIBUTE_VALUES:
    00104         D.Out(pdDebug, "UpdateAttributeValue.");
    00105         auditServer.setLevel(1);
    00106         processUpdateAttributeValues(link, msg);
    00107         break ;
    00108
    00109       case NetworkMessage::SEND_INTERACTION:
    00110         D.Out(pdTrace, "send interaction.");
    00111         auditServer.setLevel(2);
    00112         processSendInteraction(link, msg);
    00113         break ;
    00114
    00115       case NetworkMessage::CLOSE_CONNEXION:
    00116         D.Out(pdTrace, "Close connection %ld.", link->returnSocket());
    00117         auditServer.setLevel(9);
    00118         auditServer << "Socket " << link->returnSocket();
    00119         closeConnection(link, false);
    00120         link = NULL ;
    00121         break ;
    00122
    00123       case NetworkMessage::CREATE_FEDERATION_EXECUTION:
    00124         D.Out(pdTrace, "Create federation \"%s\".", msg->federationName.c_str());
    00125         auditServer.setLevel(9);
    00126         processCreateFederation(link, msg);
    00127         break ;
    00128
    00129       case NetworkMessage::DESTROY_FEDERATION_EXECUTION:
    00130         D.Out(pdTrace, "Destroy federation \"%s\".", msg->federationName.c_str());
    00131         auditServer.setLevel(9);
    00132         processDestroyFederation(link, msg);
    00133         break ;
    00134
    00135       case NetworkMessage::JOIN_FEDERATION_EXECUTION:
    00136         D.Out(pdTrace, "federate \"%s\" joins federation \"%s\".",
    00137               msg->federateName.c_str(), msg->federationName.c_str());
    00138         auditServer.setLevel(9);
    00139         processJoinFederation(link, msg);
    00140         break ;
    00141
    00142       case NetworkMessage::RESIGN_FEDERATION_EXECUTION:
    00143         D.Out(pdTrace, "Federate no %u leaves federation no %u .",
    00144               msg->federate, msg->federation);
    00145         auditServer.setLevel(9);
    00146         processResignFederation(link,msg->federation, msg->federate);
    00147         break ;
    00148
    00149       case NetworkMessage::REGISTER_FEDERATION_SYNCHRONIZATION_POINT:
    00150         D.Out(pdTrace,
    00151               "Federation %u: registerFedSyncPoint from federate %u.",
    00152               msg->federation, msg->federate);
    00153         auditServer.setLevel(8);
    00154         processRegisterSynchronization(link, static_cast<NM_Register_Federation_Synchronization_Point*>(msg));
    00155         break ;
    00156
    00157       case NetworkMessage::SYNCHRONIZATION_POINT_ACHIEVED:
    00158         D.Out(pdTrace,
    00159               "Federation %u: synchronizationPointAchieved from federate %u.",
    00160               msg->federation, msg->federate);
    00161         auditServer.setLevel(8);
    00162         processSynchronizationAchieved(link, msg);
    00163         break ;
    00164
    00165       case NetworkMessage::REQUEST_FEDERATION_SAVE:
    00166         D.Out(pdTrace, "Request federation save from federate %u.",
    00167               msg->federate);
    00168         auditServer.setLevel(8);
    00169         processRequestFederationSave(link, msg);
    00170         break ;
    00171
    00172       case NetworkMessage::FEDERATE_SAVE_BEGUN:
    00173         D.Out(pdTrace, "Federate %u begun save.", msg->federate);
    00174         auditServer.setLevel(8);
    00175         processFederateSaveBegun(link, msg);
    00176         break ;
    00177
    00178       case NetworkMessage::FEDERATE_SAVE_COMPLETE:
    00179       case NetworkMessage::FEDERATE_SAVE_NOT_COMPLETE:
    00180         D.Out(pdTrace, "Federate %u save complete/not complete.",
    00181               msg->federate);
    00182         auditServer.setLevel(8);
    00183         processFederateSaveStatus(link, msg);
    00184         break ;
    00185
    00186       case NetworkMessage::REQUEST_FEDERATION_RESTORE:
    00187         D.Out(pdTrace, "Federate %u request a restoration.", msg->federate);
    00188         auditServer.setLevel(8);
    00189         processRequestFederationRestore(link, msg);
    00190         break ;
    00191
    00192       case NetworkMessage::FEDERATE_RESTORE_COMPLETE:
    00193       case NetworkMessage::FEDERATE_RESTORE_NOT_COMPLETE:
    00194         D.Out(pdTrace, "Federate %u restore complete/not complete.",
    00195               msg->federate);
    00196         auditServer.setLevel(8);
    00197         processFederateRestoreStatus(link, msg);
    00198         break ;
    00199
    00200       case NetworkMessage::REQUEST_OBJECT_ATTRIBUTE_VALUE_UPDATE:
    00201     D[pdTrace] << "requestAttributeValueUpdate" << endl ;
    00202         auditServer.setLevel(6);
    00203         processRequestObjectAttributeValueUpdate(link, msg);
    00204         break ;
    00205
    00206       case NetworkMessage::SET_TIME_REGULATING:
    00207         D.Out(pdTrace, "SetTimeRegulating du federe %u(date=%f).",
    00208               msg->federate, msg->getDate().getTime());
    00209         auditServer.setLevel(8);
    00210         processSetTimeRegulating(link, static_cast<NM_Set_Time_Regulating*>(msg));
    00211         break ;
    00212
    00213       case NetworkMessage::SET_TIME_CONSTRAINED:
    00214         D.Out(pdTrace, "SetTimeConstrained du federe %u.", msg->federate);
    00215         auditServer.setLevel(8);
    00216
    00217         processSetTimeConstrained(link, static_cast<NM_Set_Time_Constrained*>(msg));
    00218         break ;
    00219
    00220       case NetworkMessage::PUBLISH_OBJECT_CLASS:
    00221       case NetworkMessage::UNPUBLISH_OBJECT_CLASS:
    00222         D.Out(pdTrace, "un/publishObjectClass.");
    00223         auditServer.setLevel(7);
    00224         processPublishObjectClass(link, msg);
    00225         break ;
    00226
    00227       case NetworkMessage::PUBLISH_INTERACTION_CLASS:
    00228       case NetworkMessage::UNPUBLISH_INTERACTION_CLASS:
    00229         D.Out(pdTrace, "un/publishInteractionClass.");
    00230         auditServer.setLevel(7);
    00231         processPublishInteractionClass(link, msg);
    00232         break ;
    00233
    00234       case NetworkMessage::SUBSCRIBE_OBJECT_CLASS:
    00235       case NetworkMessage::UNSUBSCRIBE_OBJECT_CLASS:
    00236         D.Out(pdTrace, "un/subscribeObjectClass.");
    00237         auditServer.setLevel(7);
    00238         processSubscribeObjectClass(link, msg);
    00239         break ;
    00240
    00241       case NetworkMessage::SUBSCRIBE_INTERACTION_CLASS:
    00242       case NetworkMessage::UNSUBSCRIBE_INTERACTION_CLASS:
    00243         D.Out(pdTrace, "un/subscribeInteractionClass.");
    00244         auditServer.setLevel(7);
    00245         processSubscribeInteractionClass(link, msg);
    00246         break ;
    00247
    00248       case NetworkMessage::SET_CLASS_RELEVANCE_ADVISORY_SWITCH:
    00249     D.Out(pdTrace, "setClassRelevanceAdvisorySwitch.");
    00250         auditServer.setLevel(6);
    00251         processSetClassRelevanceAdvisorySwitch(link,
    00252             static_cast<NM_Set_Class_Relevance_Advisory_Switch*>(msg));
    00253     break;
    00254
    00255       case NetworkMessage::SET_INTERACTION_RELEVANCE_ADVISORY_SWITCH:
    00256     D.Out(pdTrace, "setInteractionRelevanceAdvisorySwitch.");
    00257         auditServer.setLevel(6);
    00258         processSetInteractionRelevanceAdvisorySwitch(link,
    00259             static_cast<NM_Set_Interaction_Relevance_Advisory_Switch*>(msg));
    00260     break;
    00261
    00262       case NetworkMessage::SET_ATTRIBUTE_RELEVANCE_ADVISORY_SWITCH:
    00263     D.Out(pdTrace, "setAttributeRelevanceAdvisorySwitch.");
    00264         auditServer.setLevel(6);
    00265         processSetAttributeRelevanceAdvisorySwitch(link,
    00266             static_cast<NM_Set_Attribute_Relevance_Advisory_Switch*>(msg));
    00267     break;
    00268
    00269       case NetworkMessage::SET_ATTRIBUTE_SCOPE_ADVISORY_SWITCH:
    00270     D.Out(pdTrace, "setAttributeScopeAdvisorySwitch.");
    00271         auditServer.setLevel(6);
    00272         processSetAttributeScopeAdvisorySwitch(link,
    00273             static_cast<NM_Set_Attribute_Scope_Advisory_Switch*>(msg));
    00274     break;
    00275
    00276       case NetworkMessage::REGISTER_OBJECT:
    00277         D.Out(pdTrace, "registerObject.");
    00278         auditServer.setLevel(6);
    00279         processRegisterObject(link, msg);
    00280         break ;
    00281
    00282       case NetworkMessage::DELETE_OBJECT:
    00283         D.Out(pdTrace, "DeleteObject..");
    00284         auditServer.setLevel(6);
    00285         processDeleteObject(link, msg);
    00286         break ;
    00287
    00288       case NetworkMessage::IS_ATTRIBUTE_OWNED_BY_FEDERATE:
    00289         D.Out(pdTrace, "isAttributeOwnedByFederate..");
    00290         auditServer.setLevel(2);
    00291         processAttributeOwnedByFederate(link, msg);
    00292         break ;
    00293
    00294       case NetworkMessage::QUERY_ATTRIBUTE_OWNERSHIP:
    00295         D.Out(pdTrace, "queryAttributeOwnership..");
    00296         auditServer.setLevel(2);
    00297         processQueryAttributeOwnership(link, msg);
    00298         break ;
    00299
    00300       case NetworkMessage::NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
    00301         D.Out(pdTrace, "negotiatedAttributeOwnershipDivestiture..");
    00302         auditServer.setLevel(6);
    00303         processNegotiatedOwnershipDivestiture(link, msg);
    00304         break ;
    00305
    00306       case NetworkMessage::ATTRIBUTE_OWNERSHIP_ACQUISITION_IF_AVAILABLE:
    00307         D.Out(pdTrace, "attributeOwnershipAcquisitionIfAvailable..");
    00308         auditServer.setLevel(6);
    00309         processAcquisitionIfAvailable(link, msg);
    00310         break ;
    00311
    00312       case NetworkMessage::UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
    00313         D.Out(pdTrace, "unconditionalAttributeOwnershipDivestiture..");
    00314         auditServer.setLevel(6);
    00315         processUnconditionalDivestiture(link, msg);
    00316         break ;
    00317
    00318       case NetworkMessage::ATTRIBUTE_OWNERSHIP_ACQUISITION:
    00319         D.Out(pdTrace, "attributeOwnershipAcquisition..");
    00320         auditServer.setLevel(6);
    00321         processOwnershipAcquisition(link, msg);
    00322         break ;
    00323
    00324       case NetworkMessage::CANCEL_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE:
    00325         D.Out(pdTrace, "cancelNegociatedAttributeOwnershipDivestiture..");
    00326         auditServer.setLevel(6);
    00327         processCancelNegotiatedDivestiture(link, msg);
    00328         break ;
    00329
    00330       case NetworkMessage::ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE:
    00331         D.Out(pdTrace, "attributeOwnershipReleaseResponse..");
    00332         auditServer.setLevel(6);
    00333         processReleaseResponse(link, msg);
    00334         break ;
    00335
    00336       case NetworkMessage::CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION:
    00337         D.Out(pdTrace, "cancelAttributeOwnershipAcquisition..");
    00338         auditServer.setLevel(6);
    00339         processCancelAcquisition(link, msg);
    00340         break ;
    00341
    00342       case NetworkMessage::DDM_CREATE_REGION:
    00343         D[pdTrace] << "createRegion" << endl ;
    00344         auditServer.setLevel(6);
    00345         processCreateRegion(link, msg);
    00346         break ;
    00347
    00348       case NetworkMessage::DDM_MODIFY_REGION:
    00349         D[pdTrace] << "modifyRegion" << endl ;
    00350         auditServer.setLevel(6);
    00351         processModifyRegion(link, msg);
    00352         break ;
    00353
    00354       case NetworkMessage::DDM_DELETE_REGION:
    00355         D[pdTrace] << "deleteRegion" << endl ;
    00356         auditServer.setLevel(6);
    00357         processDeleteRegion(link, msg);
    00358         break ;
    00359
    00360       case NetworkMessage::DDM_REGISTER_OBJECT:
    00361         D[pdTrace] << "registerObjectWithRegion" << endl ;
    00362         auditServer.setLevel(6);
    00363         processRegisterObjectWithRegion(link, msg);
    00364         break ;
    00365
    00366       case NetworkMessage::DDM_ASSOCIATE_REGION:
    00367     D[pdTrace] << "associateRegionForUpdates" << endl ;
    00368         auditServer.setLevel(6);
    00369         processAssociateRegion(link, msg);
    00370         break ;
    00371
    00372       case NetworkMessage::DDM_UNASSOCIATE_REGION:
    00373     D[pdTrace] << "unassociateRegionForUpdates" << endl ;
    00374         auditServer.setLevel(6);
    00375         processUnassociateRegion(link, msg);
    00376         break ;
    00377
    00378       case NetworkMessage::DDM_SUBSCRIBE_ATTRIBUTES:
    00379     D[pdTrace] << "subscribeObjectClassAttributes (DDM)" << endl ;
    00380         auditServer.setLevel(6);
    00381         processSubscribeAttributesWR(link, msg);
    00382         break ;
    00383
    00384       case NetworkMessage::DDM_UNSUBSCRIBE_ATTRIBUTES:
    00385     D[pdTrace] << "unsubscribeObjectClassAttributes (DDM)" << endl ;
    00386         auditServer.setLevel(6);
    00387         processUnsubscribeAttributesWR(link, msg);
    00388         break ;
    00389
    00390       case NetworkMessage::DDM_SUBSCRIBE_INTERACTION:
    00391     D[pdTrace] << "subscribeInteraction (DDM)" << endl ;
    00392         auditServer.setLevel(6);
    00393         processSubscribeInteractionWR(link, msg);
    00394         break ;
    00395
    00396       case NetworkMessage::DDM_UNSUBSCRIBE_INTERACTION:
    00397     D[pdTrace] << "unsubscribeInteraction (DDM)" << endl ;
    00398         auditServer.setLevel(6);
    00399         processUnsubscribeInteractionWR(link, msg);
    00400         break ;
    00401
    00402       default:
    00403         // FIXME: Should treat other cases CHANGE_*_ORDER/TRANSPORT_TYPE
    00404         D.Out(pdError, "processMessageRecu: unknown type %u.", msg->getType());
    00405         throw RTIinternalError("Unknown Message Type");
    00406     }
    00407     G.Out(pdGendoc,"exit  RTIG::chooseProcessingMethod");
    00408     return link ; // It may have been set to NULL by closeConnection.
    00409 }
    00410
    00411 // ----------------------------------------------------------------------------
    00413
    00416 void
    00417 RTIG::closeConnection(Socket *link, bool emergency)
    00418 {
    00419     Handle federation ;
    00420     FederateHandle federate ;
    00421
    00422     G.Out(pdGendoc,"enter RTIG::closeConnection");
    00423     try {
    00424         socketServer.close(link->returnSocket(), federation, federate);
    00425     }
    00426     catch (RTIinternalError &e) {
    00427         D.Out(pdError, "Connection not found while trying to close it.");
    00428     }
    00429
    00430     if (emergency) {
    00431         D.Out(pdExcept, "Killing Federate(%u, %u)...", federation, federate);
    00432         federations.killFederate(federation, federate);
    00433         D.Out(pdExcept, "Federate(%u, %u)Killed... ", federation, federate);
    00434     }
    00435
    00436     G.Out(pdGendoc,"exit  RTIG::closeConnection");
    00437 }
    00438
    00439 // ----------------------------------------------------------------------------
    00440 // execute
    00441 // Called only by RTIG main
    00442 void
    00443 RTIG::execute()
    00444 {
    00445 int result ;
    00446 fd_set fd ;
    00447 Socket *link ;
    00448
    00449 // create TCP and UDP connections for the RTIG server
    00450 udpSocketServer.createUDPServer(udpPort);
    00451 tcpSocketServer.createTCPServer(tcpPort);
    00452 // udpSocketServer.createUDPServer(PORT_UDP_RTIG);
    00453
    00454 if (verboseLevel>0) {
    00455     cout << "CERTI RTIG up and running ..." << endl ;
    00456     }
    00457 terminate = false ;
    00458
    00459 while (!terminate) {
    00460     // Initialize fd_set structure with all opened sockets.
    00461     #if _WIN32
    00462
    00463     result = 0; // Wait for an incoming message.
    00464     while (!result)
    00465         {
    00466         int test;
    00467
    00468         FD_ZERO(&fd);
    00469         FD_SET(tcpSocketServer.returnSocket(), &fd);
    00470
    00471         int highest_fd = socketServer.addToFDSet(&fd);
    00472         int server_socket = tcpSocketServer.returnSocket();
    00473
    00474         //typedef struct timeval {  long tv_sec;  long tv_usec; }
    00475         timeval     watchDog;
    00476         watchDog.tv_sec= 0;
    00477         watchDog.tv_usec= 50000L;
    00478
    00479         highest_fd = server_socket>highest_fd ? server_socket : highest_fd;
    00480
    00481         result = select(highest_fd+1, &fd, NULL, NULL, &watchDog);
    00482         if (result < 0) test= WSAGetLastError();
    00483         if (terminate) break;
    00484         }
    00485     if (terminate) break;
    00486
    00487     if((result == -1)&&(WSAGetLastError() == WSAEINTR)) break;
    00488     #else
    00489         FD_ZERO(&fd);
    00490         FD_SET(tcpSocketServer.returnSocket(), &fd);
    00491
    00492         int fd_max = socketServer.addToFDSet(&fd);
    00493         fd_max = std::max(tcpSocketServer.returnSocket(), fd_max);
    00494
    00495         result = 0 ;    // Wait for an incoming message.
    00496         result = select(fd_max + 1, &fd, NULL, NULL, NULL);
    00497
    00498         if((result == -1)&&(errno == EINTR)) break;
    00499     #endif
    00500
    00501     // Is it a message from an already opened connection?
    00502     link = socketServer.getActiveSocket(&fd);
    00503     if (link != NULL) {
    00504         D.Out(pdCom, "Incoming message on socket %ld.",
    00505         link->returnSocket());
    00506         try {
    00507             do {
    00508                 link = processIncomingMessage(link);
    00509                 if (link == NULL)break ;
    00510                 } while (link->isDataReady());
    00511             }
    00512         catch (NetworkError &e) {
    00513             if (!e._reason.empty())
    00514             D.Out(pdExcept, "Catching Network Error, reason : %s", e._reason.c_str());
    00515             else
    00516             D.Out(pdExcept, "Catching Network Error, no reason string.");
    00517             cout << "RTIG dropping client connection " << link->returnSocket()
    00518             << '.' << endl ;
    00519             closeConnection(link, true);
    00520             link = NULL ;
    00521             }
    00522         }
    00523
    00524     // Or on the server socket ?
    00525     if (FD_ISSET(tcpSocketServer.returnSocket(), &fd)) {
    00526         D.Out(pdCom, "Demande de connexion.");
    00527         openConnection();
    00528         }
    00529     }
    00530 }
    00531
    00532 // ----------------------------------------------------------------------------
    00533 // openConnection
    00534
    00535 void
    00536 RTIG::openConnection()
    00537 {
    00538     try {
    00539         socketServer.open();
    00540     }
    00541     catch (RTIinternalError &e) {
    00542         D.Out(pdExcept, "Error while accepting new connection : %s.", e._reason.c_str());
    00543     }
    00544
    00545     D.Out(pdInit, "Accepting new connection.");
    00546 }
    00547
    00548 // ----------------------------------------------------------------------------
    00550
    00558 Socket*
    00559 RTIG::processIncomingMessage(Socket *link) throw (NetworkError)
    00560 {
    00561     NetworkMessage* msg ;
    00562
    00563     char buffer[BUFFER_EXCEPTION_REASON_SIZE] ; // To store the exception reason
    00564     G.Out(pdGendoc,"enter RTIG::processIncomingMessage");
    00565     if (link == NULL) {
    00566         D.Out(pdError, "NULL socket in processMessageRecu.");
    00567         return NULL ;
    00568     }
    00569
    00570     /* virtual constructor call */
    00571     msg = NM_Factory::receive(link);
    00572
    00573     // Server Answer(only if an exception is raised)
    00574     std::auto_ptr<NetworkMessage> rep(NM_Factory::create(msg->getType()));
    00575     rep->federate = msg->federate ;
    00576
    00577     auditServer.startLine(msg->federation, msg->federate, msg->getType());
    00578
    00579     // This macro is used to copy any non null exception reason
    00580     // string into our buffer(used for Audit purpose).
    00581
    00582 #define CPY_NOT_NULL(A) { if (!A._reason.empty())strcpy(buffer, A._reason.c_str()); }
    00583
    00584     buffer[0] = 0 ;
    00585
    00586     try {
    00587         link = chooseProcessingMethod(link, msg);
    00588     }
    00589     catch (ArrayIndexOutOfBounds &e) {
    00590         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00591         CPY_NOT_NULL(e);
    00592         rep->exception = e_ArrayIndexOutOfBounds ;
    00593     }
    00594     catch (AttributeAlreadyOwned &e) {
    00595         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00596         CPY_NOT_NULL(e);
    00597         rep->exception = e_AttributeAlreadyOwned ;
    00598     }
    00599     catch (AttributeAlreadyBeingAcquired &e) {
    00600         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00601         CPY_NOT_NULL(e);
    00602         rep->exception = e_AttributeAlreadyBeingAcquired ;
    00603     }
    00604     catch (AttributeAlreadyBeingDivested &e) {
    00605         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00606         CPY_NOT_NULL(e);
    00607         rep->exception = e_AttributeAlreadyBeingDivested ;
    00608     }
    00609     catch (AttributeDivestitureWasNotRequested &e) {
    00610         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00611         CPY_NOT_NULL(e);
    00612         rep->exception = e_AttributeDivestitureWasNotRequested ;
    00613     }
    00614     catch (AttributeAcquisitionWasNotRequested &e) {
    00615         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00616         CPY_NOT_NULL(e);
    00617         rep->exception = e_AttributeAcquisitionWasNotRequested ;
    00618     }
    00619     catch (AttributeNotDefined &e) {
    00620         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00621         CPY_NOT_NULL(e);
    00622         rep->exception = e_AttributeNotDefined ;
    00623     }
    00624     catch (AttributeNotKnown &e) {
    00625         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00626         CPY_NOT_NULL(e);
    00627         rep->exception = e_AttributeNotKnown ;
    00628     }
    00629     catch (AttributeNotOwned &e) {
    00630         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00631         CPY_NOT_NULL(e);
    00632         rep->exception = e_AttributeNotOwned ;
    00633     }
    00634     catch (AttributeNotPublished &e) {
    00635         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00636         CPY_NOT_NULL(e);
    00637         rep->exception = e_AttributeNotPublished ;
    00638     }
    00639     catch (AttributeNotSubscribed &e) {
    00640         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00641         CPY_NOT_NULL(e);
    00642         rep->exception = e_AttributeNotSubscribed ;
    00643     }
    00644     catch (ConcurrentAccessAttempted &e) {
    00645         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00646         CPY_NOT_NULL(e);
    00647         rep->exception = e_ConcurrentAccessAttempted ;
    00648     }
    00649     catch (CouldNotDiscover &e) {
    00650         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00651         CPY_NOT_NULL(e);
    00652         rep->exception = e_CouldNotDiscover ;
    00653     }
    00654     catch (CouldNotOpenRID &e) {
    00655         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00656         CPY_NOT_NULL(e);
    00657         rep->exception = e_CouldNotOpenRID ;
    00658     }
    00659     catch (CouldNotOpenFED &e) {
    00660         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00661         CPY_NOT_NULL(e);
    00662         rep->exception = e_CouldNotOpenFED ;
    00663     }
    00664     catch (CouldNotRestore &e) {
    00665         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00666         CPY_NOT_NULL(e);
    00667         rep->exception = e_CouldNotRestore ;
    00668     }
    00669     catch (DeletePrivilegeNotHeld &e) {
    00670         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00671         CPY_NOT_NULL(e);
    00672         rep->exception = e_DeletePrivilegeNotHeld ;
    00673     }
    00674     catch (ErrorReadingRID &e) {
    00675         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00676         CPY_NOT_NULL(e);
    00677         rep->exception = e_ErrorReadingRID ;
    00678     }
    00679     catch (EventNotKnown &e) {
    00680         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00681         CPY_NOT_NULL(e);
    00682         rep->exception = e_EventNotKnown ;
    00683     }
    00684     catch (FederateAlreadyPaused &e) {
    00685         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00686         CPY_NOT_NULL(e);
    00687         rep->exception = e_FederateAlreadyPaused ;
    00688     }
    00689     catch (FederateAlreadyExecutionMember &e) {
    00690         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00691         CPY_NOT_NULL(e);
    00692         rep->exception = e_FederateAlreadyExecutionMember ;
    00693     }
    00694     catch (FederateDoesNotExist &e) {
    00695         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00696         CPY_NOT_NULL(e);
    00697         rep->exception = e_FederateDoesNotExist ;
    00698     }
    00699     catch (FederateInternalError &e) {
    00700         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00701         CPY_NOT_NULL(e);
    00702         rep->exception = e_FederateInternalError ;
    00703     }
    00704     catch (FederateNameAlreadyInUse &e) {
    00705         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00706         CPY_NOT_NULL(e);
    00707         rep->exception = e_FederateNameAlreadyInUse ;
    00708     }
    00709     catch (FederateNotExecutionMember &e) {
    00710         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00711         CPY_NOT_NULL(e);
    00712         rep->exception = e_FederateNotExecutionMember ;
    00713     }
    00714     catch (FederateNotPaused &e) {
    00715         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00716         CPY_NOT_NULL(e);
    00717         rep->exception = e_FederateNotPaused ;
    00718     }
    00719     catch (FederateNotPublishing &e) {
    00720         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00721         CPY_NOT_NULL(e);
    00722         rep->exception = e_FederateNotPublishing ;
    00723     }
    00724     catch (FederateNotSubscribing &e) {
    00725         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00726         CPY_NOT_NULL(e);
    00727         rep->exception = e_FederateNotSubscribing ;
    00728     }
    00729     catch (FederateOwnsAttributes &e) {
    00730         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00731         CPY_NOT_NULL(e);
    00732         rep->exception = e_FederateOwnsAttributes ;
    00733     }
    00734     catch (FederatesCurrentlyJoined &e) {
    00735         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00736         CPY_NOT_NULL(e);
    00737         rep->exception = e_FederatesCurrentlyJoined ;
    00738     }
    00739     catch (FederateWasNotAskedToReleaseAttribute &e) {
    00740         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00741         CPY_NOT_NULL(e);
    00742         rep->exception = e_FederateWasNotAskedToReleaseAttribute ;
    00743     }
    00744     catch (FederationAlreadyPaused &e) {
    00745         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00746         CPY_NOT_NULL(e);
    00747         rep->exception = e_FederationAlreadyPaused ;
    00748     }
    00749     catch (FederationExecutionAlreadyExists &e) {
    00750         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00751         CPY_NOT_NULL(e);
    00752         rep->exception = e_FederationExecutionAlreadyExists ;
    00753     }
    00754     catch (FederationExecutionDoesNotExist &e) {
    00755         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00756         CPY_NOT_NULL(e);
    00757         rep->exception = e_FederationExecutionDoesNotExist ;
    00758     }
    00759     catch (FederationNotPaused &e) {
    00760         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00761         CPY_NOT_NULL(e);
    00762         rep->exception = e_FederationNotPaused ;
    00763     }
    00764     catch (FederationTimeAlreadyPassed &e) {
    00765         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00766         CPY_NOT_NULL(e);
    00767         rep->exception = e_FederationTimeAlreadyPassed ;
    00768     }
    00769     catch (IDsupplyExhausted &e) {
    00770         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00771         CPY_NOT_NULL(e);
    00772         rep->exception = e_IDsupplyExhausted ;
    00773     }
    00774     catch (InteractionClassNotDefined &e) {
    00775         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00776         CPY_NOT_NULL(e);
    00777         rep->exception = e_InteractionClassNotDefined ;
    00778     }
    00779     catch (InteractionClassNotKnown &e) {
    00780         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00781         CPY_NOT_NULL(e);
    00782         rep->exception = e_InteractionClassNotKnown ;
    00783     }
    00784     catch (InteractionClassNotPublished &e) {
    00785         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00786         CPY_NOT_NULL(e);
    00787         rep->exception = e_InteractionClassNotPublished ;
    00788     }
    00789     catch (InteractionParameterNotDefined &e) {
    00790         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00791         CPY_NOT_NULL(e);
    00792         rep->exception = e_InteractionParameterNotDefined ;
    00793     }
    00794     catch (InteractionParameterNotKnown &e) {
    00795         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00796         CPY_NOT_NULL(e);
    00797         rep->exception = e_InteractionParameterNotKnown ;
    00798     }
    00799     catch (InvalidDivestitureCondition &e) {
    00800         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00801         CPY_NOT_NULL(e);
    00802         rep->exception = e_InvalidDivestitureCondition ;
    00803     }
    00804     catch (InvalidExtents &e) {
    00805         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00806         CPY_NOT_NULL(e);
    00807         rep->exception = e_InvalidExtents ;
    00808     }
    00809     catch (InvalidFederationTime &e) {
    00810         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00811         CPY_NOT_NULL(e);
    00812         rep->exception = e_InvalidFederationTime ;
    00813     }
    00814     catch (InvalidFederationTimeDelta &e) {
    00815         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00816         CPY_NOT_NULL(e);
    00817         rep->exception = e_InvalidFederationTimeDelta ;
    00818     }
    00819     catch (InvalidObjectHandle &e) {
    00820         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00821         CPY_NOT_NULL(e);
    00822         rep->exception = e_InvalidObjectHandle ;
    00823     }
    00824     catch (InvalidOrderingHandle &e) {
    00825         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00826         CPY_NOT_NULL(e);
    00827         rep->exception = e_InvalidOrderingHandle ;
    00828     }
    00829     catch (InvalidResignAction &e) {
    00830         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00831         CPY_NOT_NULL(e);
    00832         rep->exception = e_InvalidResignAction ;
    00833     }
    00834     catch (InvalidRetractionHandle &e) {
    00835         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00836         CPY_NOT_NULL(e);
    00837         rep->exception = e_InvalidRetractionHandle ;
    00838     }
    00839     catch (InvalidRoutingSpace &e) {
    00840         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00841         CPY_NOT_NULL(e);
    00842         rep->exception = e_InvalidRoutingSpace ;
    00843     }
    00844     catch (InvalidTransportationHandle &e) {
    00845         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00846         CPY_NOT_NULL(e);
    00847         rep->exception = e_InvalidTransportationHandle ;
    00848     }
    00849     catch (MemoryExhausted &e) {
    00850         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00851         CPY_NOT_NULL(e);
    00852         rep->exception = e_MemoryExhausted ;
    00853     }
    00854     catch (NameNotFound &e) {
    00855         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00856         CPY_NOT_NULL(e);
    00857         rep->exception = e_NameNotFound ;
    00858     }
    00859     catch (NoPauseRequested &e) {
    00860         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00861         CPY_NOT_NULL(e);
    00862         rep->exception = e_NoPauseRequested ;
    00863     }
    00864     catch (NoResumeRequested &e) {
    00865         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00866         CPY_NOT_NULL(e);
    00867         rep->exception = e_NoResumeRequested ;
    00868     }
    00869     catch (ObjectClassNotDefined &e) {
    00870         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00871         CPY_NOT_NULL(e);
    00872         rep->exception = e_ObjectClassNotDefined ;
    00873     }
    00874     catch (ObjectClassNotKnown &e) {
    00875         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00876         CPY_NOT_NULL(e);
    00877         rep->exception = e_ObjectClassNotKnown ;
    00878     }
    00879     catch (ObjectClassNotPublished &e) {
    00880         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00881         CPY_NOT_NULL(e);
    00882         rep->exception = e_ObjectClassNotPublished ;
    00883     }
    00884     catch (ObjectClassNotSubscribed &e) {
    00885         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00886         CPY_NOT_NULL(e);
    00887         rep->exception = e_ObjectClassNotSubscribed ;
    00888     }
    00889     catch (ObjectNotKnown &e) {
    00890         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00891         CPY_NOT_NULL(e);
    00892         rep->exception = e_ObjectNotKnown ;
    00893     }
    00894     catch (ObjectAlreadyRegistered &e) {
    00895         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00896         CPY_NOT_NULL(e);
    00897         rep->exception = e_ObjectAlreadyRegistered ;
    00898     }
    00899     catch (RegionNotKnown &e) {
    00900         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00901         CPY_NOT_NULL(e);
    00902         rep->exception = e_RegionNotKnown ;
    00903     }
    00904     catch (RestoreInProgress &e) {
    00905         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00906         CPY_NOT_NULL(e);
    00907         rep->exception = e_RestoreInProgress ;
    00908     }
    00909     catch (RestoreNotRequested &e) {
    00910         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00911         CPY_NOT_NULL(e);
    00912         rep->exception = e_RestoreNotRequested ;
    00913     }
    00914     catch (RTIinternalError &e) {
    00915         if (e._reason.empty())
    00916             D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00917         else
    00918             D.Out(pdExcept, "Catching \"%s\" exception: %s.", e._name, e._reason.c_str());
    00919         CPY_NOT_NULL(e);
    00920         rep->exception = e_RTIinternalError ;
    00921     }
    00922     catch (SaveInProgress &e) {
    00923         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00924         CPY_NOT_NULL(e);
    00925         rep->exception = e_SaveInProgress ;
    00926     }
    00927     catch (SaveNotInitiated &e) {
    00928         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00929         CPY_NOT_NULL(e);
    00930         rep->exception = e_SaveNotInitiated ;
    00931     }
    00932     catch (SecurityError &e) {
    00933         cout << endl << "Security Error : " << e._reason << endl ;
    00934         CPY_NOT_NULL(e);
    00935         rep->exception = e_SecurityError ;
    00936     }
    00937     catch (SpaceNotDefined &e) {
    00938         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00939         CPY_NOT_NULL(e);
    00940         rep->exception = e_SpaceNotDefined ;
    00941     }
    00942     catch (SpecifiedSaveLabelDoesNotExist &e) {
    00943         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00944         CPY_NOT_NULL(e);
    00945         rep->exception = e_SpecifiedSaveLabelDoesNotExist ;
    00946     }
    00947     catch (TimeAdvanceAlreadyInProgress &e) {
    00948         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00949         CPY_NOT_NULL(e);
    00950         rep->exception = e_TimeAdvanceAlreadyInProgress ;
    00951     }
    00952     catch (TimeAdvanceWasNotInProgress &e) {
    00953         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00954         CPY_NOT_NULL(e);
    00955         rep->exception = e_TimeAdvanceWasNotInProgress ;
    00956     }
    00957     catch (TooManyIDsRequested &e) {
    00958         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00959         CPY_NOT_NULL(e);
    00960         rep->exception = e_TooManyIDsRequested ;
    00961     }
    00962     catch (UnableToPerformSave &e) {
    00963         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00964         CPY_NOT_NULL(e);
    00965         rep->exception = e_UnableToPerformSave ;
    00966     }
    00967     catch (UnimplementedService &e) {
    00968         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00969         CPY_NOT_NULL(e);
    00970         rep->exception = e_UnimplementedService ;
    00971     }
    00972     catch (UnknownLabel &e) {
    00973         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00974         CPY_NOT_NULL(e);
    00975         rep->exception = e_UnknownLabel ;
    00976     }
    00977     catch (ValueCountExceeded &e) {
    00978         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00979         CPY_NOT_NULL(e);
    00980         rep->exception = e_ValueCountExceeded ;
    00981     }
    00982     catch (ValueLengthExceeded &e) {
    00983         D.Out(pdExcept, "Catching \"%s\" exception.", e._name);
    00984         CPY_NOT_NULL(e);
    00985         rep->exception = e_ValueLengthExceeded ;
    00986     }
    00987
    00988     // Non RTI specific exception, Client connection problem(internal)
    00989     catch (NetworkError &e) {
    00990         strcpy(buffer, " - NetworkError");
    00991         auditServer.endLine(rep->exception, buffer);
    00992         delete msg;
    00993         throw e ;
    00994     }
    00995     // Default Handler
    00996     catch (Exception &e) {
    00997         D.Out(pdExcept, "Unknown Exception : %s.", e._name);
    00998         CPY_NOT_NULL(e);
    00999         rep->exception = e_RTIinternalError ;
    01000     }
    01001
    01002     // buffer may contain an exception reason. If not, set it to OK
    01003     // or Exception
    01004     if (strlen(buffer)== 0) {
    01005         if (rep->exception == e_NO_EXCEPTION)
    01006             strcpy(buffer, " - OK");
    01007         else
    01008             strcpy(buffer, " - Exception");
    01009     }
    01010
    01011     auditServer.endLine(rep->exception, buffer);
    01012     delete msg;
    01013     if (link == NULL) return link ;
    01014
    01015     /* FIXME ***/
    01016     if (rep->exception != e_NO_EXCEPTION) {
    01017         G.Out(pdGendoc,"            processIncomingMessage ===> write on exception to RTIA");
    01018         rep->send(link,NM_msgBufSend);
    01019         D.Out(pdExcept,
    01020               "RTIG catched exception %d and sent it back to federate %d.",
    01021               rep->exception, rep->federate);
    01022     }
    01023     G.Out(pdGendoc,"exit  RTIG::processIncomingMessage");
    01024     return link ;
    01025 }
    01026
    01027 // ----------------------------------------------------------------------------
    01029  void
    01030 RTIG::signalHandler(int sig)
    01031 {
    01032 D.Out(pdError, "Received Signal %d.", sig);
    01033
    01034 if (sig == SIGINT) terminate = true ;
    01035 #ifndef _WIN32
    01036     if (sig == SIGPIPE) cout << "Ignoring 'Broken pipe' signal." << endl ;
    01037 #endif
    01038 }
    01039
    01040 }} // namespace certi/rtig
    01041
    01042 // $Id: RTIG.cc,v 3.55 2009/04/02 19:58:10 erk Exp $