# OwnershipManagement.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: OwnershipManagement.cc,v 3.17 2008/12/07 20:16:09 gotthardp Exp $
    00022 // ----------------------------------------------------------------------------
    00023
    00024 #include <config.h>
    00025 #include "OwnershipManagement.hh"
    00026
    00027 #include "PrettyDebug.hh"
    00028 #include "NM_Classes.hh"
    00029
    00030 #ifdef _WIN32
    00031 #include <windows.h>
    00032 #else
    00033 #include <cstdio>
    00034 #include <sys/types.h>
    00035 #include <sys/stat.h>
    00036 #include <unistd.h>
    00037 #include <cstdlib>
    00038 #endif
    00039 #include <memory>
    00040
    00041 namespace certi {
    00042 namespace rtia {
    00043
    00044 static pdCDebug D("RTIA_OWM", "(RTIA OwM) ");
    00045
    00046 // ----------------------------------------------------------------------------
    00048 OwnershipManagement::OwnershipManagement(Communications *GC,
    00049                                          FederationManagement *GF)
    00050 {
    00051     comm = GC ;
    00052     fm = GF ;
    00053 }
    00054
    00055 // ----------------------------------------------------------------------------
    00057 OwnershipManagement::~OwnershipManagement()
    00058 {
    00059 }
    00060
    00061 // ----------------------------------------------------------------------------
    00063 const char *
    00064 OwnershipManagement::attributeOwnedByFederate(ObjectHandle theObject,
    00065                                               AttributeHandle theAttribute,
    00066                                               TypeException &e)
    00067 {
    00068     NM_Is_Attribute_Owned_By_Federate req ;
    00069
    00070     D.Out(pdDebug,
    00071           "IS_ATTRIBUTE_OWNED_BY_FEDERATE, attribute %u of object %u",
    00072           theAttribute, theObject);
    00073
    00074     req.federation = fm->_numero_federation ;
    00075     req.federate = fm->federate ;
    00076     req.object = theObject ;
    00077     req.handleArray.resize(1) ;
    00078     req.handleArray[0] = theAttribute ;
    00079     req.handleArraySize = 1 ;
    00080
    00081     D.Out(pdDebug, "Federate %u ", fm->federate);
    00082
    00083     comm->sendMessage(&req);
    00084
    00085     // waitMessage is only used to verify transmission was OK.
    00086     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(
    00087                       NetworkMessage::IS_ATTRIBUTE_OWNED_BY_FEDERATE,
    00088                       req.federate));
    00089
    00090     e = rep->exception ;
    00091
    00092     if (e == e_NO_EXCEPTION)
    00093         return(rep->getLabel().c_str());
    00094     else
    00095         return("\0");
    00096 }
    00097
    00098 // ----------------------------------------------------------------------------
    00100 void
    00101 OwnershipManagement::queryAttributeOwnership(ObjectHandle theObject,
    00102                                              AttributeHandle theAttribute,
    00103                                              TypeException &e)
    00104 {
    00105     NM_Query_Attribute_Ownership req;
    00106
    00107     D.Out(pdDebug,
    00108           "QUERY_ATTRIBUTE_OWNERSHIP, attribute %u from object %u",
    00109           theAttribute, theObject);
    00110
    00111     req.federation = fm->_numero_federation ;
    00112     req.federate = fm->federate ;
    00113     req.object = theObject ;
    00114     req.handleArray.resize(1) ;
    00115     req.handleArray[0] = theAttribute ;
    00116     req.handleArraySize = 1 ;
    00117
    00118     D.Out(pdDebug, "Federate %u ", fm->federate);
    00119
    00120     comm->sendMessage(&req);
    00121
    00122     //AttendreMsg ne sert que pour verifier que la transmission a ete OK
    00123     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::QUERY_ATTRIBUTE_OWNERSHIP, req.federate));
    00124
    00125     e = rep->exception ;
    00126 }
    00127
    00128 // ----------------------------------------------------------------------------
    00130 void
    00131 OwnershipManagement::
    00132 negotiatedAttributeOwnershipDivestiture(ObjectHandle theObject,
    00133                                         std::vector <AttributeHandle> &attribArray,
    00134                                         UShort attribArraySize,
    00135                                         std::string theTag,
    00136                                         TypeException &e)
    00137
    00138 {
    00139     NM_Negotiated_Attribute_Ownership_Divestiture req;
    00140
    00141     req.federation = fm->_numero_federation ;
    00142     req.federate = fm->federate ;
    00143     req.object = theObject ;
    00144     req.handleArray.resize(attribArraySize) ;
    00145     req.handleArraySize = attribArraySize ;
    00146
    00147     for (int i = 0 ; i < attribArraySize ; i++)
    00148         req.handleArray[i] = attribArray[i] ;
    00149
    00150     req.setLabel(theTag);
    00151
    00152     D.Out(pdDebug, "NEGOTIATED_DIVESTITURE Federate %u ", fm->federate);
    00153
    00154     comm->sendMessage(&req);
    00155
    00156     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE,
    00157                       req.federate));
    00158
    00159     e = rep->exception ;
    00160 }
    00161
    00162 // ----------------------------------------------------------------------------
    00164 void
    00165 OwnershipManagement::
    00166 cancelnegotiatedAttributeOwnershipDivestiture(ObjectHandle theObject,
    00167                                               std::vector <AttributeHandle> &attribArray,
    00168                                               UShort attribArraySize,
    00169                                               TypeException &e)
    00170 {
    00171     NM_Cancel_Negotiated_Attribute_Ownership_Divestiture req;
    00172
    00173     req.federation = fm->_numero_federation ;
    00174     req.federate = fm->federate ;
    00175     req.object = theObject ;
    00176     req.handleArray.resize(attribArraySize) ;
    00177     req.handleArraySize = attribArraySize ;
    00178
    00179     for (int i = 0 ; i < attribArraySize ; i++)
    00180         req.handleArray[i] = attribArray[i] ;
    00181
    00182     D.Out(pdDebug, "CANCEL_NEGOTIATED_DIVESTITURE Federate %u ",
    00183           fm->federate);
    00184
    00185     comm->sendMessage(&req);
    00186
    00187     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(
    00188                       NetworkMessage::CANCEL_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE,
    00189                       req.federate));
    00190
    00191     e = rep->exception ;
    00192 }
    00193
    00194 // ----------------------------------------------------------------------------
    00196 void
    00197 OwnershipManagement::
    00198 attributeOwnershipAcquisitionIfAvailable(ObjectHandle theObject,
    00199                                          std::vector <AttributeHandle> &attribArray,
    00200                                          UShort attribArraySize,
    00201                                          TypeException &e)
    00202 {
    00203     NM_Attribute_Ownership_Acquisition_If_Available req;
    00204
    00205     req.federation = fm->_numero_federation ;
    00206     req.federate = fm->federate ;
    00207     req.object = theObject ;
    00208     req.handleArray.resize(attribArraySize) ;
    00209     req.handleArraySize = attribArraySize ;
    00210
    00211     for (int i = 0 ; i < attribArraySize ; i++)
    00212         req.handleArray[i] = attribArray[i] ;
    00213
    00214     D.Out(pdDebug, "AcquisitionIfAvailable Federate %u ", fm->federate);
    00215
    00216     comm->sendMessage(&req);
    00217
    00218     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::ATTRIBUTE_OWNERSHIP_ACQUISITION_IF_AVAILABLE,
    00219                       req.federate));
    00220
    00221     e = rep->exception ;
    00222 }
    00223
    00224 // ----------------------------------------------------------------------------
    00226 void
    00227 OwnershipManagement::
    00228 unconditionalAttributeOwnershipDivestiture(ObjectHandle theObject,
    00229                                            std::vector <AttributeHandle> &attribArray,
    00230                                            UShort attribArraySize,
    00231                                            TypeException &e)
    00232 {
    00233     NM_Unconditional_Attribute_Ownership_Divestiture req;
    00234
    00235     req.federation = fm->_numero_federation ;
    00236     req.federate = fm->federate ;
    00237     req.object = theObject ;
    00238     req.handleArray.resize(attribArraySize) ;
    00239     req.handleArraySize = attribArraySize ;
    00240
    00241     for (int i = 0 ; i < attribArraySize ; i++)
    00242         req.handleArray[i] = attribArray[i] ;
    00243
    00244     D.Out(pdDebug, "UNCONDITIONAL_DIVESTITURE Federate %u ",
    00245           fm->federate);
    00246
    00247     comm->sendMessage(&req);
    00248
    00249     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE,
    00250                       req.federate));
    00251
    00252     e = rep->exception ;
    00253 }
    00254
    00255 // ----------------------------------------------------------------------------
    00257 void
    00258 OwnershipManagement::
    00259 attributeOwnershipAcquisition(ObjectHandle theObject,
    00260                               std::vector <AttributeHandle> &attribArray,
    00261                               UShort attribArraySize,
    00262                               std::string theTag,
    00263                               TypeException &e)
    00264 {
    00265     NM_Attribute_Ownership_Acquisition req;
    00266
    00267     req.federation = fm->_numero_federation ;
    00268     req.federate = fm->federate ;
    00269     req.object = theObject ;
    00270     req.handleArray.resize(attribArraySize) ;
    00271     req.handleArraySize = attribArraySize ;
    00272
    00273     for (int i = 0 ; i < attribArraySize ; i++)
    00274         req.handleArray[i] = attribArray[i] ;
    00275
    00276     req.setLabel(theTag);
    00277
    00278     D.Out(pdDebug, "OWNERSHIP_ACQUISITION Federate %u ", fm->federate);
    00279
    00280     comm->sendMessage(&req);
    00281
    00282     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::ATTRIBUTE_OWNERSHIP_ACQUISITION,
    00283                       req.federate));
    00284
    00285     e = rep->exception ;
    00286 }
    00287
    00288 // ----------------------------------------------------------------------------
    00290 AttributeHandleSet*
    00291 OwnershipManagement::
    00292 attributeOwnershipRealeaseResponse(ObjectHandle theObject,
    00293                                    std::vector <AttributeHandle> &attribArray,
    00294                                    UShort attribArraySize,
    00295                                    TypeException &e)
    00296 {
    00297     NM_Attribute_Ownership_Release_Response req;
    00298
    00299     req.federation = fm->_numero_federation ;
    00300     req.federate = fm->federate ;
    00301     req.object = theObject ;
    00302     req.handleArray.resize(attribArraySize) ;
    00303     req.handleArraySize = attribArraySize ;
    00304
    00305     D.Out(pdDebug, "RELEASE_RESPONSE Object %u handleArraySize %u",
    00306           theObject, req.handleArraySize);
    00307
    00308     for (int i = 0 ; i < attribArraySize ; i++) {
    00309         req.handleArray[i] = attribArray[i] ;
    00310     }
    00311
    00312
    00313     comm->sendMessage(&req);
    00314
    00315     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE,
    00316                       req.federate));
    00317
    00318     e = rep->exception ;
    00319
    00320     if (e == e_NO_EXCEPTION) {
    00321         AttributeHandleSet *AttributeSet ;
    00322         AttributeSet = new AttributeHandleSet(rep->handleArraySize);
    00323
    00324         for (int i = 0 ; i < rep->handleArraySize ; i++) {
    00325             AttributeSet->add(rep->handleArray[i]);
    00326         }
    00327
    00328         return(AttributeSet);
    00329     }
    00330     else
    00331         return NULL ;
    00332 }
    00333
    00334 // ----------------------------------------------------------------------------
    00336 void
    00337 OwnershipManagement::
    00338 cancelattributeOwnershipAcquisition(ObjectHandle theObject,
    00339                                     std::vector <AttributeHandle> &attribArray,
    00340                                     UShort attribArraySize,
    00341                                     TypeException &e)
    00342 {
    00343     NM_Cancel_Attribute_Ownership_Acquisition req;
    00344
    00345     req.federation = fm->_numero_federation ;
    00346     req.federate = fm->federate ;
    00347     req.object = theObject ;
    00348     req.handleArray.resize(attribArraySize) ;
    00349     req.handleArraySize = attribArraySize ;
    00350
    00351     for (int i = 0 ; i < attribArraySize ; i++)
    00352         req.handleArray[i] = attribArray[i] ;
    00353
    00354     D.Out(pdDebug, "CANCEL_ACQUISITION Federate %u ", fm->federate);
    00355
    00356     comm->sendMessage(&req);
    00357
    00358     std::auto_ptr<NetworkMessage> rep(comm->waitMessage(NetworkMessage::CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION,
    00359                       req.federate));
    00360
    00361     e = rep->exception ;
    00362 }
    00363
    00364 // ----------------------------------------------------------------------------
    00366 void
    00367 OwnershipManagement::informAttributeOwnership(ObjectHandle the_object,
    00368                                               AttributeHandle the_attribute,
    00369                                               FederateHandle the_owner,
    00370                                               TypeException &)
    00371 {
    00372     Message req;
    00373
    00374     req.type = Message::INFORM_ATTRIBUTE_OWNERSHIP ;
    00375     req.setObject(the_object);
    00376     req.setAttribute(the_attribute);
    00377     req.setFederate(the_owner);
    00378
    00379     comm->requestFederateService(&req);
    00380 }
    00381
    00382 // ----------------------------------------------------------------------------
    00384 void
    00385 OwnershipManagement::attributeIsNotOwned(ObjectHandle the_object,
    00386                                          AttributeHandle the_attribute,
    00387                                          FederateHandle,
    00388                                          TypeException &)
    00389 {
    00390     Message req;
    00391
    00392     req.type = Message::ATTRIBUTE_IS_NOT_OWNED ;
    00393     req.setObject(the_object);
    00394     req.setAttribute(the_attribute);
    00395     // req.setFederate(the_owner);
    00396
    00397     comm->requestFederateService(&req);
    00398 }
    00399
    00400 // ----------------------------------------------------------------------------
    00402 void
    00403 OwnershipManagement::
    00404 attributeOwnershipUnavailable(ObjectHandle the_object,
    00405                               std::vector <AttributeHandle> &the_attributes,
    00406                               UShort the_size,
    00407                               FederateHandle,
    00408                               TypeException &)
    00409 {
    00410     Message req;
    00411
    00412     req.type = Message::ATTRIBUTE_OWNERSHIP_UNAVAILABLE ;
    00413     req.setObject(the_object);
    00414     req.setAttributes(the_attributes, the_size);
    00415
    00416     comm->requestFederateService(&req);
    00417 }
    00418
    00419 // ----------------------------------------------------------------------------
    00421 void
    00422 OwnershipManagement::
    00423 attributeOwnershipAcquisitionNotification(ObjectHandle the_object,
    00424                                           std::vector <AttributeHandle> &the_attributes,
    00425                                           UShort the_size,
    00426                                           FederateHandle,
    00427                                           TypeException &)
    00428 {
    00429     Message req;
    00430
    00431     req.type = Message::ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION ;
    00432     req.setObject(the_object);
    00433     req.setAttributes(the_attributes, the_size);
    00434
    00435     comm->requestFederateService(&req);
    00436 }
    00437
    00438 // ----------------------------------------------------------------------------
    00440 void
    00441 OwnershipManagement::
    00442 requestAttributeOwnershipAssumption(ObjectHandle the_object,
    00443                                     std::vector <AttributeHandle> &the_attributes,
    00444                                     UShort the_size,
    00445                                     FederateHandle,
    00446                                     std::string the_tag,
    00447                                     TypeException &)
    00448 {
    00449     Message req;
    00450
    00451     req.type = Message::REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION ;
    00452     req.setObject(the_object);
    00453     req.setAttributes(the_attributes, the_size);
    00454     req.setTag(the_tag);
    00455
    00456     comm->requestFederateService(&req);
    00457 }
    00458
    00459 // ----------------------------------------------------------------------------
    00461 void
    00462 OwnershipManagement::
    00463 requestAttributeOwnershipRelease(ObjectHandle the_object,
    00464                                  std::vector <AttributeHandle> &the_attributes,
    00465                                  UShort the_size,
    00466                                  std::string the_tag,
    00467                                  TypeException &)
    00468 {
    00469     Message req;
    00470
    00471     req.type = Message::REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE ;
    00472     req.setObject(the_object);
    00473     req.setAttributes(the_attributes, the_size);
    00474     req.setTag(the_tag);
    00475
    00476     comm->requestFederateService(&req);
    00477 }
    00478
    00479 // ----------------------------------------------------------------------------
    00481 void
    00482 OwnershipManagement::
    00483 attributeOwnershipDivestitureNotification(ObjectHandle the_object,
    00484                                           std::vector <AttributeHandle> &the_attributes,
    00485                                           UShort the_size,
    00486                                           TypeException &)
    00487 {
    00488     Message req;
    00489
    00490     req.type = Message::ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION ;
    00491     req.setObject(the_object);
    00492     req.setAttributes(the_attributes, the_size);
    00493
    00494     comm->requestFederateService(&req);
    00495 }
    00496
    00497 // ----------------------------------------------------------------------------
    00499 void
    00500 OwnershipManagement::
    00501 confirmAttributeOwnershipAcquisitionCancellation(ObjectHandle the_object,
    00502                                                  std::vector <AttributeHandle> &the_attributes,
    00503                                                  UShort the_size,
    00504                                                  TypeException &)
    00505 {
    00506     Message req;
    00507
    00508     req.type = Message::CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION ;
    00509     req.setObject(the_object);
    00510     req.setAttributes(the_attributes, the_size);
    00511
    00512     comm->requestFederateService(&req);
    00513 }
    00514
    00515 }} // namespace certi/rtia
    00516
    00517 // $Id: OwnershipManagement.cc,v 3.17 2008/12/07 20:16:09 gotthardp Exp $