DeclarationManagement.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: DeclarationManagement.cc,v 3.26 2009/04/08 10:47:17 approx Exp $
00022 // ----------------------------------------------------------------------------
00023 
00024 #include <config.h>
00025 
00026 #include "InteractionSet.hh"
00027 #include "ObjectClassSet.hh"
00028 #include "DeclarationManagement.hh"
00029 #include "NM_Classes.hh"
00030 
00031 #ifdef _WIN32
00032 #include <windows.h>
00033 #else
00034 #include <sys/types.h>
00035 #include <sys/stat.h>
00036 #include <unistd.h>
00037 #include <stdlib.h>
00038 #endif
00039 
00040 #include <memory>
00041 
00042 namespace certi {
00043 namespace rtia {
00044 
00045 static pdCDebug D("RTIA_DM", "(RTIA DM) ");
00046 static PrettyDebug G("GENDOC",__FILE__) ;
00047 
00048 // ----------------------------------------------------------------------------
00050 DeclarationManagement::DeclarationManagement(Communications *GC,
00051                                              FederationManagement *GF,
00052                                              RootObject *theRootObj)
00053 {
00054     comm = GC ;
00055     fm = GF ;
00056     rootObject = theRootObj ;
00057 }
00058 
00059 // ----------------------------------------------------------------------------
00060 // ~DeclarationManagement
00061 DeclarationManagement::~DeclarationManagement()
00062 {
00063 }
00064 
00065 // ----------------------------------------------------------------------------
00066 // publishObjectClass
00067 void
00068 DeclarationManagement::publishObjectClass(ObjectClassHandle theClassHandle,
00069                                           std::vector <AttributeHandle> &attribArray,
00070                                           UShort attribArraySize,
00071                                           TypeException &e)
00072 {
00073     G.Out(pdGendoc,"enter DeclarationManagement::publishObjectClass") ;
00074     e = e_NO_EXCEPTION ;
00075 
00076     // Partie Locale
00077 
00078     try {
00079         rootObject->ObjectClasses->publish(fm->federate,
00080                                            theClassHandle,
00081                                            attribArray,
00082                                            attribArraySize,
00083                                            true);
00084     }
00085     catch (Exception *e) {
00086         G.Out(pdGendoc,"exit  DeclarationManagement::publishObjectClass on exception") ;
00087         D.Out(pdExcept, "Exception catched in PublishObjectClass.");
00088         throw e ;
00089     }
00090 
00091     // Partie RTIG
00092     NM_Publish_Object_Class req ;    
00093     req.objectClass     = theClassHandle ;
00094     req.handleArraySize = attribArraySize ;
00095     req.handleArray.resize(attribArraySize) ;
00096     req.federation      = fm->_numero_federation ;
00097     req.federate        = fm->federate ;
00098 
00099     for (int i=0 ; i<attribArraySize ; i++)
00100         req.handleArray[i] = attribArray[i] ;
00101 
00102     // Emission
00103     comm->sendMessage(&req);
00104 
00105     // Reception    
00106     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::PUBLISH_OBJECT_CLASS, req.federate));
00107 
00108     e = rep->exception ;
00109     G.Out(pdGendoc,"exit  DeclarationManagement::publishObjectClass") ;
00110 } /* end of publishObjectClass */
00111 
00112 // ----------------------------------------------------------------------------
00113 // unpublishObjectClass
00114 void
00115 DeclarationManagement::unpublishObjectClass(ObjectClassHandle theClassHandle,
00116                                             TypeException &e)
00117 {
00118     // Variables leurres
00119     //AttributeHandle *attribArray = NULL ;
00120     UShort attribArraySize = 0 ;
00121     std::vector <AttributeHandle> attribArrayVector ;
00122     attribArrayVector.empty();
00123 
00124     e = e_NO_EXCEPTION ;
00125 
00126     // Partie Locale
00127 
00128     try {
00129         rootObject->ObjectClasses->publish(fm->federate,
00130                                            theClassHandle,
00131                                            attribArrayVector,
00132                                            attribArraySize,
00133                                            false);
00134     } catch (Exception *e) {
00135         D.Out(pdExcept, "Exception catched in UnpublishObjectClass.");
00136         throw e ;
00137     }
00138 
00139     // Partie RTIG
00140     NM_Unpublish_Object_Class req ;
00141    
00142     req.federation = fm->_numero_federation ;
00143     req.federate = fm->federate ;
00144     req.objectClass = theClassHandle ;
00145 
00146     // Emission de la requete vers le RTIG
00147     comm->sendMessage(&req);
00148 
00149     // On attend une reponse
00150     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::UNPUBLISH_OBJECT_CLASS, req.federate));
00151 
00152     e = rep->exception ;
00153 } /* end of unpublishObjectClass */
00154 
00155 // ----------------------------------------------------------------------------
00156 // publishInteractionClass
00157 void
00158 DeclarationManagement::
00159 publishInteractionClass(InteractionClassHandle theInteractionHandle,
00160                         TypeException &e)
00161 {
00162     e = e_NO_EXCEPTION ;
00163 
00164     // Local publish
00165     try {
00166         rootObject->Interactions->publish(fm->federate,
00167                                           theInteractionHandle,
00168                                           true);
00169     } catch (Exception *e) {
00170         D.Out(pdExcept, "Exception catched in publishInteractionClass.");
00171         throw e ;
00172     }
00173 
00174     // RTIG (may be non-local) request
00175     NM_Publish_Interaction_Class req ;
00176     
00177     req.federation = fm->_numero_federation ;
00178     req.federate = fm->federate ;
00179     req.interactionClass = theInteractionHandle ;
00180 
00181     comm->sendMessage(&req);    
00182     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::PUBLISH_INTERACTION_CLASS, req.federate));
00183 
00184     e = rep->exception ;
00185 } /* end of publishInteractionClass */
00186 
00187 // ----------------------------------------------------------------------------
00188 // unpublishInteractionClass
00189 void
00190 DeclarationManagement::
00191 unpublishInteractionClass(InteractionClassHandle theInteractionHandle,
00192                           TypeException &e)
00193 {
00194     e = e_NO_EXCEPTION ;
00195 
00196     // Partie Locale
00197 
00198     try {
00199         rootObject->Interactions->publish(fm->federate,
00200                                           theInteractionHandle,
00201                                           false);
00202     } catch (Exception *e) {
00203         D.Out(pdExcept, "Exception catched in UnpublishInteractionClass.");
00204         throw e ;
00205     }
00206 
00207     // Partie RTIG
00208     NM_Unpublish_Interaction_Class req;   
00209     req.interactionClass = theInteractionHandle ;
00210     req.federation = fm->_numero_federation ;
00211     req.federate = fm->federate ;
00212 
00213     comm->sendMessage(&req);
00214     
00215     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::UNPUBLISH_INTERACTION_CLASS, req.federate));
00216 
00217     e = rep->exception ;
00218 } /* end of unpublishInteractionClass */
00219 
00220 // ----------------------------------------------------------------------------
00221 // subscribeObjectClassAttribute
00222 void
00223 DeclarationManagement::
00224 subscribeObjectClassAttribute(ObjectClassHandle theClassHandle,
00225                               std::vector <AttributeHandle> &attribArray,
00226                               UShort attribArraySize,
00227                               TypeException &e)
00228 {
00229     NM_Subscribe_Object_Class req;
00230 
00231     G.Out(pdGendoc,"enter DeclarationManagement::subscribeObjectClassAttribute");
00232     // Pas de partie locale pour les abonnements
00233 
00234     // Partie RTIG
00235 
00236     req.federation      = fm->_numero_federation ;
00237     req.federate        = fm->federate ;
00238     req.objectClass     = theClassHandle ;
00239     req.handleArray.resize(attribArraySize) ;
00240     req.handleArraySize = attribArraySize ;
00241 
00242     for (int i=0 ; i<attribArraySize ; i++)
00243         req.handleArray[i] = attribArray[i] ;
00244 
00245     // Emission
00246     G.Out(pdGendoc,"                              =====> send S_O_C to RTIG");
00247     comm->sendMessage(&req);
00248 
00249     // Reception
00250     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(
00251                       NetworkMessage::SUBSCRIBE_OBJECT_CLASS,
00252                       req.federate));
00253     G.Out(pdGendoc,"                              =====> received S_O_C from RTIG");
00254 
00255     e = rep->exception ;
00256     G.Out(pdGendoc,"exit  DeclarationManagement::subscribeObjectClassAttribute");
00257 } /* end of subscribeObjectClassAttribute */
00258 
00259 // ----------------------------------------------------------------------------
00260 // unsubscribeObjectClassAttribute
00261 void
00262 DeclarationManagement::
00263 unsubscribeObjectClassAttribute(ObjectClassHandle theClassHandle,
00264                                 TypeException &e)
00265 {
00266     NM_Unsubscribe_Object_Class req;
00267 
00268     e = e_NO_EXCEPTION ;
00269 
00270     // Pas de Partie Locale pour les abonnements
00271 
00272     // Partie RTIG    
00273     req.objectClass = theClassHandle ;
00274     req.federation = fm->_numero_federation ;
00275     req.federate = fm->federate ;
00276 
00277     comm->sendMessage(&req);
00278 
00279     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(
00280                       NetworkMessage::UNSUBSCRIBE_OBJECT_CLASS,
00281                       req.federate));
00282 
00283     e = rep->exception ;
00284 } /* end of unsubscribeObjectClassAttribute */
00285 
00286 // ----------------------------------------------------------------------------
00287 // subscribeInteractionClass
00288 void
00289 DeclarationManagement::
00290 subscribeInteractionClass(InteractionClassHandle theClassHandle,
00291                           TypeException &e)
00292 {
00293     NM_Subscribe_Interaction_Class req;
00294 
00295     e = e_NO_EXCEPTION ;
00296 
00297     // Partie Locale
00298 
00299     // BUG: Pourquoi il y a-t-il une partie locale pour un abonnement ?
00300     // Ca ne va pas marcher avec les niveaux de securite !!!!
00301 
00302     try {
00303         rootObject->Interactions->subscribe(fm->federate, theClassHandle, 0, true);
00304     } catch (Exception *e) {
00305         D.Out(pdExcept, "Exception catched in subscribeInteractionClass.");
00306         throw e ;
00307     }
00308 
00309     // Partie RTIG    
00310     req.interactionClass = theClassHandle ;
00311     req.federation = fm->_numero_federation ;
00312     req.federate = fm->federate ;
00313 
00314     comm->sendMessage(&req);
00315 
00316     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::SUBSCRIBE_INTERACTION_CLASS,
00317               req.federate));
00318 
00319     e = rep->exception ;
00320 } /* end of subscribeInteractionClass */
00321 
00322 // ----------------------------------------------------------------------------
00323 // unsubscribeInteractionClass
00324 void
00325 DeclarationManagement::
00326 unsubscribeInteractionClass(InteractionClassHandle theClassHandle,
00327                             TypeException &e)
00328 {
00329     NM_Unsubscribe_Interaction_Class req;
00330 
00331     e = e_NO_EXCEPTION ;
00332 
00333     // Partie Locale
00334 
00335     // BUG: Pourquoi il y a-t-il une partie locale pour un abonnement ?
00336     // Ca ne va pas marcher avec les niveaux de securite !!!!
00337 
00338     try {
00339         rootObject->Interactions->subscribe(fm->federate, theClassHandle, 0, false);
00340     } catch (Exception *e) {
00341         D.Out(pdExcept, "Exception catched in subscribeInteractionClass.");
00342         throw e ;
00343     }
00344 
00345     // Partie RTIG    
00346     req.interactionClass = theClassHandle ;
00347     req.federation = fm->_numero_federation ;
00348     req.federate = fm->federate ;
00349 
00350     comm->sendMessage(&req);
00351 
00352     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(
00353                       NetworkMessage::UNSUBSCRIBE_INTERACTION_CLASS,
00354                       req.federate));
00355 
00356     e = rep->exception ;
00357 } /* end of unsubscribeInteractionClass */
00358 
00359 void
00360 DeclarationManagement::
00361 setClassRelevanceAdvisorySwitch(bool state, TypeException &e) {
00362     G.Out(pdGendoc,"enter DeclarationManagement::setClassRelevanceAdvisorySwitch");
00363 
00364     NM_Set_Class_Relevance_Advisory_Switch msg ;
00365 
00366     e = e_NO_EXCEPTION ;
00367 
00368     msg.federation = fm->_numero_federation ;
00369     msg.federate = fm->federate ;
00370 
00371     if (state) {
00372         msg.classRelevanceAdvisorySwitchOn();
00373     }
00374     else {
00375         msg.classRelevanceAdvisorySwitchOff();
00376     }
00377 
00378     comm->sendMessage(&msg);
00379 
00380     G.Out(pdGendoc,"exit DeclarationManagement::setClassRelevanceAdvisorySwitch");
00381 }
00382 
00383 // ----------------------------------------------------------------------------
00384 // startRegistrationForObjectClass
00385 void
00386 DeclarationManagement::
00387 startRegistrationForObjectClass(ObjectClassHandle the_class,
00388                                 TypeException &e)
00389 {
00390     G.Out(pdGendoc,"enter DeclarationManagement::startRegistrationForObjectClass");
00391 
00392     Message req;
00393 
00394     req.type = Message::START_REGISTRATION_FOR_OBJECT_CLASS ;
00395     req.setObjectClass(the_class);
00396 
00397     comm->requestFederateService(&req);
00398 
00399     G.Out(pdGendoc,"exit  DeclarationManagement::startRegistrationForObjectClass");
00400 }
00401 
00402 // ----------------------------------------------------------------------------
00403 // stopRegistrationForObjectClass
00404 void
00405 DeclarationManagement::
00406 stopRegistrationForObjectClass(ObjectClassHandle the_class,
00407                                TypeException &e)
00408 {
00409     Message req, rep ;
00410 
00411     // Pas de partie Locale
00412 
00413     // Partie Federe
00414 
00415     req.type = Message::STOP_REGISTRATION_FOR_OBJECT_CLASS ;
00416     req.setObjectClass(the_class);
00417 
00418     comm->sendUN(&req);
00419 
00420     comm->receiveUN(&rep);
00421 
00422     if (rep.type != req.type) {
00423         D.Out(pdExcept, "Unknown response type when waiting for "
00424               "START_REGISTRATION_FOR_OBJECT_CLASS.");
00425         throw RTIinternalError("");
00426     }
00427 
00428     e = rep.getExceptionType();
00429 }
00430 
00431 void
00432 DeclarationManagement::
00433 setInteractionRelevanceAdvisorySwitch(bool state, TypeException &e) {
00434     G.Out(pdGendoc,"enter DeclarationManagement::setInteractionRelevanceAdvisorySwitch");
00435 
00436     NM_Set_Interaction_Relevance_Advisory_Switch msg ;
00437 
00438     e = e_NO_EXCEPTION ;
00439 
00440     msg.federation = fm->_numero_federation ;
00441     msg.federate = fm->federate ;
00442 
00443     if (state) {
00444         msg.interactionRelevanceAdvisorySwitchOn();
00445     }
00446     else {
00447         msg.interactionRelevanceAdvisorySwitchOff();
00448     }
00449 
00450     comm->sendMessage(&msg);
00451 
00452     G.Out(pdGendoc,"exit DeclarationManagement::setInteractionRelevanceAdvisorySwitch");
00453 }
00454 
00455 // ----------------------------------------------------------------------------
00456 // turnInteractionsOn
00457 void
00458 DeclarationManagement::
00459 turnInteractionsOn(InteractionClassHandle interaction,
00460                    TypeException &e)
00461 {
00462     Message req, rep ;
00463     req.type = Message::TURN_INTERACTIONS_ON ;
00464     req.setInteractionClass(interaction);
00465     comm->sendUN(&req);
00466     comm->receiveUN(&rep);
00467 
00468     if (rep.type != req.type) {
00469         D.Out(pdExcept,
00470               "Unknown response type, expecting TURN_INTERACTIONS_ON.");
00471         throw RTIinternalError("");
00472     }
00473 
00474     e = rep.getExceptionType();
00475 }
00476 
00477 // ----------------------------------------------------------------------------
00478 // turnInteractionsOff
00479 void
00480 DeclarationManagement::
00481 turnInteractionsOff(InteractionClassHandle interaction,
00482                     TypeException &e)
00483 {
00484     Message req ;
00485     req.type = Message::TURN_INTERACTIONS_OFF ;
00486     req.setInteractionClass(interaction);
00487     comm->sendUN(&req);
00488     Message rep ;
00489     comm->receiveUN(&rep);
00490 
00491     if (rep.type != req.type) {
00492         D.Out(pdExcept,
00493               "Unknown response type, expecting TURN_INTERACTIONS_OFF.");
00494         throw RTIinternalError("");
00495     }
00496 
00497     e = rep.getExceptionType();
00498 }
00499 
00500 }} // namespace certi/rtia
00501 
00502 // $Id: DeclarationManagement.cc,v 3.26 2009/04/08 10:47:17 approx Exp $

Generated on Thu Apr 30 15:53:48 2009 for CERTIDeveloperDocumentation by doxygen 1.5.5