00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "Object.hh"
00027 #include "ObjectClass.hh"
00028 #include "ObjectClassSet.hh"
00029 #include "ObjectClassBroadcastList.hh"
00030 #include "SecurityServer.hh"
00031 #include "PrettyDebug.hh"
00032 #include "Named.hh"
00033
00034
00035 #include <iostream>
00036 #include <sstream>
00037 #include <assert.h>
00038
00039 using std::list ;
00040 using std::cout ;
00041 using std::endl ;
00042 using std::string ;
00043
00044 namespace certi {
00045
00046 static PrettyDebug D("OBJECTCLASSSET", __FILE__);
00047 static PrettyDebug G("GENDOC",__FILE__) ;
00048
00049 ObjectClassSet::ObjectClassSet(SecurityServer *theSecurityServer, bool isRootClassSet)
00050 : TreeNamedAndHandledSet<ObjectClass>("Object Classes",isRootClassSet)
00051 {
00052
00053 server = theSecurityServer ;
00054 }
00055
00056
00058 ObjectClassSet::~ObjectClassSet()
00059 {
00060
00061 }
00062
00063 void
00064 ObjectClassSet::addClass(ObjectClass *newClass,ObjectClass *parentClass) throw (RTIinternalError)
00065 {
00066 D.Out(pdInit, "Adding new object class %d.", newClass->getHandle());
00067
00068 newClass->server = server ;
00069 add(newClass,parentClass);
00070
00071 }
00072
00073
00075 void
00076 ObjectClassSet::deleteObject(FederateHandle federate,
00077 ObjectHandle object,
00078 FederationTime theTime,
00079 std::string tag)
00080 throw (DeletePrivilegeNotHeld, ObjectNotKnown, RTIinternalError)
00081 {
00082
00083 ObjectClass *oclass = getInstanceClass(object);
00084
00085 D.Out(pdRegister,
00086 "Federate %d attempts to delete instance %d in class %d.",
00087 federate, object, oclass->getHandle());
00088
00089
00090 ObjectClassBroadcastList *ocbList = oclass->deleteInstance(federate,
00091 object,
00092 theTime,
00093 tag);
00094
00095
00096 ObjectClassHandle current_class = 0 ;
00097 if (ocbList != 0) {
00098
00099 current_class = oclass->getSuperclass();
00100
00101 while (current_class) {
00102 D.Out(pdRegister,
00103 "Broadcasting Remove msg to parent class %d for instance %d.",
00104 current_class, object);
00105
00106
00107 oclass = getObjectFromHandle(current_class);
00108 oclass->broadcastClassMessage(ocbList);
00109
00110 current_class = oclass->getSuperclass();
00111 }
00112
00113 delete ocbList ;
00114 }
00115 }
00116
00118 void
00119 ObjectClassSet::deleteObject(FederateHandle federate,
00120 ObjectHandle object,
00121 std::string tag)
00122 throw (DeletePrivilegeNotHeld, ObjectNotKnown, RTIinternalError)
00123 {
00124
00125 ObjectClass *oclass = getInstanceClass(object);
00126
00127 D.Out(pdRegister,
00128 "Federate %d attempts to delete instance %d in class %d.",
00129 federate, object, oclass->getHandle());
00130
00131
00132 ObjectClassBroadcastList *ocbList = oclass->deleteInstance(federate,
00133 object,
00134 tag);
00135
00136
00137 ObjectClassHandle current_class = 0 ;
00138 if (ocbList != 0) {
00139
00140 current_class = oclass->getSuperclass();
00141
00142 while (current_class) {
00143 D.Out(pdRegister,
00144 "Broadcasting Remove msg to parent class %d for instance %d.",
00145 current_class, object);
00146
00147
00148 oclass = getObjectFromHandle(current_class);
00149 oclass->broadcastClassMessage(ocbList);
00150
00151 current_class = oclass->getSuperclass();
00152 }
00153
00154 delete ocbList ;
00155 }
00156
00157 D.Out(pdRegister, "Instance %d has been deleted.", object);
00158 }
00159
00160
00162 AttributeHandle
00163 ObjectClassSet::getAttributeHandle(const char *the_name,
00164 ObjectClassHandle the_class) const
00165 throw (NameNotFound, ObjectClassNotDefined, RTIinternalError)
00166 {
00167 G.Out(pdGendoc,"enter ObjectClassSet::getAttributeHandle");
00168
00169 ObjectClass *objectClass = 0 ;
00170 AttributeHandle handle ;
00171
00172 if (the_name == 0)
00173 throw RTIinternalError("name is null");
00174
00175 D.Out(pdRequest, "Looking for attribute \"%s\" of class %u...",
00176 the_name, the_class);
00177
00178
00179 objectClass = getObjectFromHandle(the_class);
00180
00181
00182 try
00183 {
00184 handle = objectClass->getAttributeHandle(the_name);
00185 G.Out(pdGendoc,"exit ObjectClassSet::getAttributeHandle");
00186 return handle ;
00187 }
00188 catch ( NameNotFound )
00189 {
00190 G.Out(pdGendoc,"exit ObjectClassset::getAttributeHandle on NameNotFound");
00191 throw NameNotFound (the_name) ;
00192 }
00193 }
00194
00195
00197 const char *
00198 ObjectClassSet::getAttributeName(AttributeHandle the_handle,
00199 ObjectClassHandle the_class) const
00200 throw (AttributeNotDefined,
00201 ObjectClassNotDefined,
00202 RTIinternalError)
00203 {
00204 ObjectClass *objectClass = NULL ;
00205
00206 D.Out(pdRequest, "Looking for attribute %u of class %u...",
00207 the_handle, the_class);
00208
00209
00210 objectClass = getObjectFromHandle(the_class);
00211
00212 return objectClass->getAttributeName(the_handle);
00213 }
00214
00215
00217 ObjectClass *
00218 ObjectClassSet::getInstanceClass(ObjectHandle theObjectHandle) const
00219 throw (ObjectNotKnown)
00220 {
00221 std::stringstream msg;
00222
00223 handled_const_iterator i ;
00224 for (i = fromHandle.begin(); i != fromHandle.end(); ++i) {
00225 if (i->second->isInstanceInClass(theObjectHandle) == true)
00226 return (i->second);
00227 }
00228
00229 msg << "ObjectHandle <" << theObjectHandle <<"> not found in any object class.";
00230 D.Out(pdExcept, msg.str().c_str());
00231 throw ObjectNotKnown(msg.str().c_str());
00232 }
00233
00234
00237 Object *
00238 ObjectClassSet::getObject(ObjectHandle h) const
00239 throw (ObjectNotKnown)
00240 {
00241
00242 handled_const_iterator i ;
00243
00244 for (i = fromHandle.begin(); i != fromHandle.end(); ++i) {
00245 try {
00246 Object *object = i->second->getInstanceWithID(h);
00247 return object ;
00248 }
00249 catch (ObjectNotKnown &e) {
00250 }
00251 }
00252 throw ObjectNotKnown("");
00253 }
00254
00255
00257 ObjectClassHandle
00258 ObjectClassSet::getObjectClassHandle(std::string class_name) const
00259 throw (NameNotFound){
00260 return getHandleFromName(class_name);
00261 }
00262
00263
00265 string
00266 ObjectClassSet::getObjectClassName(ObjectClassHandle the_handle) const
00267 throw (ObjectClassNotDefined)
00268 {
00269 D.Out(pdRequest, "Looking for class %u...", the_handle);
00270 return getNameFromHandle(the_handle);
00271 }
00272
00273
00275 void ObjectClassSet::killFederate(FederateHandle theFederate)
00276 throw ()
00277 {
00278 ObjectClassBroadcastList *ocbList = NULL ;
00279 ObjectClassHandle currentClass = 0 ;
00280
00281 handled_iterator i;
00282
00283 for (i = fromHandle.begin(); i != fromHandle.end(); ++i) {
00284
00285 do {
00286 D.Out(pdExcept, "Kill Federate Handle %d .", theFederate);
00287 ocbList = i->second->killFederate(theFederate);
00288
00289 D.Out(pdExcept, "Federate Handle %d Killed.", theFederate);
00290
00291
00292 if (ocbList != 0) {
00293 currentClass = i->second->getSuperclass();
00294 D.Out(pdExcept, "List not NULL");
00295 while (currentClass != 0) {
00296 D.Out(pdRegister,
00297 "Broadcasting Remove msg to parent class %d(Killed).",
00298 currentClass);
00299
00300
00301 i->second = getObjectFromHandle(currentClass);
00302
00303 i->second->broadcastClassMessage(ocbList);
00304
00305 currentClass = i->second->getSuperclass();
00306 }
00307
00308 delete ocbList ;
00309 }
00310 } while (ocbList != NULL);
00311 }
00312 D.Out(pdExcept, "End of the KillFederate Procedure.");
00313 }
00314
00315
00317 void
00318 ObjectClassSet::publish(FederateHandle theFederateHandle,
00319 ObjectClassHandle theClassHandle,
00320 std::vector <AttributeHandle> &theAttributeList,
00321 UShort theListSize,
00322 bool PubOrUnpub)
00323 throw (ObjectClassNotDefined,
00324 AttributeNotDefined,
00325 RTIinternalError,
00326 SecurityError)
00327 {
00328
00329 ObjectClass *theClass = getObjectFromHandle(theClassHandle);
00330
00331 if (PubOrUnpub)
00332 D.Out(pdInit, "Federate %d attempts to publish Object Class %d.",
00333 theFederateHandle, theClassHandle);
00334 else
00335 D.Out(pdTerm, "Federate %d attempts to unpublish Object Class %d.",
00336 theFederateHandle, theClassHandle);
00337
00338
00339 theClass->publish(theFederateHandle,
00340 theAttributeList,
00341 theListSize,
00342 PubOrUnpub);
00343 }
00344
00345
00347 void
00348 ObjectClassSet::registerObjectInstance(FederateHandle the_federate,
00349 Object *the_object,
00350 ObjectClassHandle the_class)
00351 throw (InvalidObjectHandle,
00352 ObjectClassNotDefined,
00353 ObjectClassNotPublished,
00354 ObjectAlreadyRegistered,
00355 RTIinternalError)
00356 {
00357 ObjectClassHandle currentClass = the_class ;
00358
00359
00360 ObjectClass *theClass = getObjectFromHandle(the_class);
00361
00362
00363 ObjectClassBroadcastList *ocbList = NULL ;
00364 ocbList = theClass->registerObjectInstance(the_federate, the_object,
00365 the_class);
00366
00367
00368 if (ocbList != 0) {
00369
00370 currentClass = theClass->getSuperclass();
00371
00372 while (currentClass != 0) {
00373 D.Out(pdRegister,
00374 "Broadcasting Discover msg to parent class "
00375 "%d for instance %d.",
00376 currentClass, the_object);
00377
00378 theClass = getObjectFromHandle(currentClass);
00379
00380 theClass->broadcastClassMessage(ocbList);
00381
00382 currentClass = theClass->getSuperclass();
00383 }
00384
00385 delete ocbList ;
00386 }
00387
00388 D[pdRegister] << "Instance " << the_object << " has been registered."
00389 << endl ;
00390 }
00391
00392
00401 void
00402 ObjectClassSet::subscribe(FederateHandle federate,
00403 ObjectClassHandle class_handle,
00404 std::vector <AttributeHandle> &attributes,
00405 int nb,
00406 const RTIRegion *region)
00407 throw (ObjectClassNotDefined, AttributeNotDefined, RTIinternalError,
00408 SecurityError)
00409 {
00410 ObjectClass *object_class = getObjectFromHandle(class_handle);
00411
00412 bool need_discover = object_class->subscribe(federate, attributes, nb, region);
00413
00414 if (need_discover)
00415 object_class->recursiveDiscovering(federate, class_handle);
00416 }
00417
00418
00420 void
00421 ObjectClassSet::updateAttributeValues(FederateHandle federate,
00422 ObjectHandle object_handle,
00423 std::vector <AttributeHandle> &attributes,
00424 std::vector <AttributeValue_t> &values,
00425 UShort nb,
00426 FederationTime time,
00427 const char *tag)
00428 throw (ObjectNotKnown,
00429 AttributeNotDefined,
00430 AttributeNotOwned,
00431 RTIinternalError,
00432 InvalidObjectHandle)
00433 {
00434 Object *object = getObject(object_handle);
00435 ObjectClass *object_class = getObjectFromHandle(object->getClass());
00436 ObjectClassHandle current_class = object_class->getHandle();
00437
00438 D.Out(pdProtocol, "Federate %d Updating object %d from class %d.",
00439 federate, object_handle, current_class);
00440
00441
00442 ObjectClassBroadcastList *ocbList = NULL ;
00443 ocbList = object_class->updateAttributeValues(
00444 federate, object, attributes, values, nb, time, tag);
00445
00446
00447 current_class = object_class->getSuperclass();
00448
00449 while (current_class != 0) {
00450 D.Out(pdProtocol,
00451 "Broadcasting RAV msg to parent class %d for instance %d.",
00452 current_class, object_handle);
00453
00454
00455 object_class = getObjectFromHandle(current_class);
00456 object_class->broadcastClassMessage(ocbList, object);
00457
00458 current_class = object_class->getSuperclass();
00459 }
00460
00461 delete ocbList ;
00462 }
00463
00464
00466 void
00467 ObjectClassSet::updateAttributeValues(FederateHandle federate,
00468 ObjectHandle object_handle,
00469 std::vector <AttributeHandle> &attributes,
00470 std::vector <AttributeValue_t> &values,
00471 UShort nb,
00472 const char *tag)
00473 throw (ObjectNotKnown,
00474 AttributeNotDefined,
00475 AttributeNotOwned,
00476 RTIinternalError,
00477 InvalidObjectHandle)
00478 {
00479 Object *object = getObject(object_handle);
00480 ObjectClass *object_class = getObjectFromHandle(object->getClass());
00481 ObjectClassHandle current_class = object_class->getHandle();
00482
00483 D.Out(pdProtocol, "Federate %d Updating object %d from class %d.",
00484 federate, object_handle, current_class);
00485
00486
00487 ObjectClassBroadcastList *ocbList = NULL ;
00488 ocbList = object_class->updateAttributeValues(
00489 federate, object, attributes, values, nb, tag);
00490
00491
00492 current_class = object_class->getSuperclass();
00493
00494 while (current_class != 0) {
00495 D.Out(pdProtocol,
00496 "Broadcasting RAV msg to parent class %d for instance %d.",
00497 current_class, object_handle);
00498
00499
00500 object_class = getObjectFromHandle(current_class);
00501 object_class->broadcastClassMessage(ocbList, object);
00502
00503 current_class = object_class->getSuperclass();
00504 }
00505
00506 delete ocbList ;
00507 }
00508
00509
00511 void
00512 ObjectClassSet::
00513 negotiatedAttributeOwnershipDivestiture(FederateHandle theFederateHandle,
00514 ObjectHandle theObjectHandle,
00515 std::vector <AttributeHandle> &theAttributeList,
00516 UShort theListSize,
00517 const char *theTag)
00518 throw (ObjectNotKnown,
00519 AttributeNotDefined,
00520 AttributeNotOwned,
00521 AttributeAlreadyBeingDivested,
00522 RTIinternalError)
00523 {
00524
00525 ObjectClass *objectClass = getInstanceClass(theObjectHandle);
00526 ObjectClassHandle currentClass = objectClass->getHandle();
00527
00528
00529 ObjectClassBroadcastList *ocbList = NULL ;
00530 ocbList =
00531 objectClass->negotiatedAttributeOwnershipDivestiture(theFederateHandle,
00532 theObjectHandle,
00533 theAttributeList,
00534 theListSize,
00535 theTag);
00536
00537
00538 currentClass = objectClass->getSuperclass();
00539
00540 while (currentClass != 0) {
00541 D.Out(pdProtocol,
00542 "Broadcasting NAOD msg to parent class %d for instance %d.",
00543 currentClass, theObjectHandle);
00544
00545
00546 objectClass = getObjectFromHandle(currentClass);
00547 objectClass->broadcastClassMessage(ocbList);
00548
00549 currentClass = objectClass->getSuperclass();
00550 }
00551
00552 delete ocbList ;
00553 }
00554
00555
00557 void
00558 ObjectClassSet::
00559 attributeOwnershipAcquisitionIfAvailable(FederateHandle theFederateHandle,
00560 ObjectHandle theObjectHandle,
00561 std::vector <AttributeHandle> &theAttributeList,
00562 UShort theListSize)
00563 throw (ObjectNotKnown,
00564 ObjectClassNotPublished,
00565 AttributeNotDefined,
00566 AttributeNotPublished,
00567 FederateOwnsAttributes,
00568 AttributeAlreadyBeingAcquired,
00569 RTIinternalError)
00570 {
00571
00572 ObjectClass * objectClass = getInstanceClass(theObjectHandle);
00573
00574
00575 objectClass->attributeOwnershipAcquisitionIfAvailable(theFederateHandle,
00576 theObjectHandle,
00577 theAttributeList,
00578 theListSize);
00579 }
00580
00581
00583 void
00584 ObjectClassSet::
00585 unconditionalAttributeOwnershipDivestiture(FederateHandle theFederateHandle,
00586 ObjectHandle theObjectHandle,
00587 std::vector <AttributeHandle> &theAttributeList,
00588 UShort theListSize)
00589 throw (ObjectNotKnown,
00590 AttributeNotDefined,
00591 AttributeNotOwned,
00592 RTIinternalError)
00593 {
00594
00595 ObjectClass *objectClass = getInstanceClass(theObjectHandle);
00596 ObjectClassHandle currentClass = objectClass->getHandle();
00597
00598
00599 ObjectClassBroadcastList *ocbList = NULL ;
00600 ocbList = objectClass->
00601 unconditionalAttributeOwnershipDivestiture(theFederateHandle,
00602 theObjectHandle,
00603 theAttributeList,
00604 theListSize);
00605
00606
00607 currentClass = objectClass->getSuperclass();
00608
00609 while (currentClass != 0) {
00610 D.Out(pdProtocol,
00611 "Broadcasting UAOD msg to parent class %d for instance %d.",
00612 currentClass, theObjectHandle);
00613
00614
00615 objectClass = getObjectFromHandle(currentClass);
00616 objectClass->broadcastClassMessage(ocbList);
00617
00618 currentClass = objectClass->getSuperclass();
00619 }
00620
00621 delete ocbList ;
00622 }
00623
00624
00626 void
00627 ObjectClassSet::
00628 attributeOwnershipAcquisition(FederateHandle theFederateHandle,
00629 ObjectHandle theObjectHandle,
00630 std::vector <AttributeHandle> &theAttributeList,
00631 UShort theListSize,
00632 const char *theTag)
00633 throw (ObjectNotKnown,
00634 ObjectClassNotPublished,
00635 AttributeNotDefined,
00636 AttributeNotPublished,
00637 FederateOwnsAttributes,
00638 RTIinternalError)
00639 {
00640
00641 ObjectClass * objectClass = getInstanceClass(theObjectHandle);
00642
00643
00644 objectClass->attributeOwnershipAcquisition(theFederateHandle,
00645 theObjectHandle,
00646 theAttributeList,
00647 theListSize,
00648 theTag);
00649 }
00650
00651
00653 AttributeHandleSet * ObjectClassSet::
00654 attributeOwnershipReleaseResponse(FederateHandle theFederateHandle,
00655 ObjectHandle theObjectHandle,
00656 std::vector <AttributeHandle> &theAttributeList,
00657 UShort theListSize)
00658 throw (ObjectNotKnown,
00659 AttributeNotDefined,
00660 AttributeNotOwned,
00661 FederateWasNotAskedToReleaseAttribute,
00662 RTIinternalError)
00663 {
00664
00665 ObjectClass *objectClass = getInstanceClass(theObjectHandle);
00666
00667
00668 return(objectClass->attributeOwnershipReleaseResponse(theFederateHandle,
00669 theObjectHandle,
00670 theAttributeList,
00671 theListSize));
00672 }
00673
00674
00676 void ObjectClassSet::
00677 cancelAttributeOwnershipAcquisition(FederateHandle theFederateHandle,
00678 ObjectHandle theObjectHandle,
00679 std::vector <AttributeHandle> &theAttributeList,
00680 UShort theListSize)
00681 throw (ObjectNotKnown,
00682 AttributeNotDefined,
00683 AttributeAlreadyOwned,
00684 AttributeAcquisitionWasNotRequested,
00685 RTIinternalError)
00686 {
00687
00688 ObjectClass *objectClass = getInstanceClass(theObjectHandle);
00689
00690
00691 objectClass->cancelAttributeOwnershipAcquisition(theFederateHandle,
00692 theObjectHandle,
00693 theAttributeList,
00694 theListSize);
00695 }
00696
00697 }
00698
00699