RootObject.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-libCERTI
00006 //
00007 // CERTI-libCERTI is free software ; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public License
00009 // as published by the Free Software Foundation ; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // CERTI-libCERTI is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY ; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015 // Lesser General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU Lesser General Public
00018 // License along with this program ; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00020 // USA
00021 //
00022 // $Id: RootObject.cc,v 3.40 2008/11/08 11:36:05 erk Exp $
00023 // ----------------------------------------------------------------------------
00024 
00025 #include "Object.hh"
00026 #include "ObjectSet.hh"
00027 #include "ObjectAttribute.hh"
00028 #include "ObjectClass.hh"
00029 #include "ObjectClassSet.hh"
00030 #include "ObjectClassAttribute.hh"
00031 #include "Interaction.hh"
00032 #include "InteractionSet.hh"
00033 #include "RTIRegion.hh"
00034 #include "RoutingSpace.hh"
00035 #include "RootObject.hh"
00036 #include "PrettyDebug.hh"
00037 #include "helper.hh"
00038 
00039 #include <string>
00040 #include <stdio.h>
00041 #include <cstring>
00042 #include <cassert>
00043 #include <algorithm>
00044 
00045 using std::vector ;
00046 using std::cout ;
00047 using std::endl ;
00048 using std::string ;
00049 using std::list ;
00050 
00051 
00052 namespace certi {
00053 
00054 static pdCDebug D("ROOTOBJECT", "(RootObject) ");
00055 static PrettyDebug G("GENDOC",__FILE__);
00056 
00057 
00058 RootObject::RootObject(SecurityServer *security_server)
00059     : server(security_server), regionHandles(1)
00060 {
00061     /* this object class set is the root one */
00062     ObjectClasses = new ObjectClassSet(server,true);
00063     /* this interaction class set is the root one */
00064     Interactions  = new InteractionSet(server,true);
00065     objects       = new ObjectSet(server);
00066 }
00067 
00068 RootObject::~RootObject()
00069 {
00070     delete ObjectClasses ;
00071     delete Interactions ;
00072     delete objects ;
00073 }
00074 
00075 // ----------------------------------------------------------------------------
00077 void
00078 RootObject::display() const
00079 {
00080     cout << endl << "Root Object Tree :" << endl ;
00081     cout << ObjectClasses;
00082     cout << Interactions;
00083     if (spaces.size() > 0) {
00084         cout << "+ Routing Spaces :" << endl ;
00085     vector<RoutingSpace>::const_iterator it ;
00086         for (it = spaces.begin(); it != spaces.end(); ++it) {
00087             it->display();
00088         }
00089     }
00090 }
00091 
00092 SecurityLevelID
00093 RootObject::getSecurityLevelID(const std::string& levelName)
00094 {
00095     return server ? server->getLevelIDWithName(levelName.c_str()) : PublicLevelID;
00096 }
00097 
00098 // ----------------------------------------------------------------------------
00100 void
00101 RootObject::registerFederate(const std::string& the_federate,
00102                              SecurityLevelID the_level_id)
00103 {
00104     if (server != NULL)
00105         server->registerFederate(the_federate.c_str(), the_level_id);
00106 }
00107 
00108 // ----------------------------------------------------------------------------
00113 void
00114 RootObject::addRoutingSpace(const RoutingSpace &rs)
00115 {
00116     spaces.push_back(rs);
00117     spaces.back().setHandle(spaces.size());
00118 }
00119 
00120 // ----------------------------------------------------------------------------
00122 SpaceHandle
00123 RootObject::getRoutingSpaceHandle(std::string rs)
00124     throw (NameNotFound)
00125 {
00126     vector<RoutingSpace>::const_iterator i = std::find_if(
00127     spaces.begin(),
00128     spaces.end(),
00129     NameComparator<RoutingSpace>(rs));
00130 
00131     if (i == spaces.end()) throw NameNotFound("");
00132     else return i->getHandle();
00133 }
00134 
00135 // ----------------------------------------------------------------------------
00137 string
00138 RootObject::getRoutingSpaceName(SpaceHandle handle)
00139     throw (SpaceNotDefined)
00140 {
00141     if (handle <= 0 || (size_t) handle > spaces.size())
00142     throw SpaceNotDefined("");
00143     else
00144     return spaces[handle - 1].getName();
00145 }
00146 
00147 // ----------------------------------------------------------------------------
00149 RoutingSpace &
00150 RootObject::getRoutingSpace(SpaceHandle handle)
00151     throw (SpaceNotDefined)
00152 {
00153     if (handle <= 0 || (size_t) handle > spaces.size())
00154     throw SpaceNotDefined("");
00155     else
00156     return spaces[handle - 1] ;
00157 }
00158 
00159 // ----------------------------------------------------------------------------
00161 void
00162 RootObject::addRegion(RTIRegion *region)
00163 {
00164     regions.push_back(region);
00165 }
00166 
00167 // ----------------------------------------------------------------------------
00169 RegionHandle
00170 RootObject::createRegion(SpaceHandle handle, unsigned long nb_extents)
00171     throw (SpaceNotDefined)
00172 {
00173     RTIRegion *region = new RTIRegion(regionHandles.provide(),
00174                       getRoutingSpace(handle),
00175                       nb_extents);
00176     addRegion(region);
00177 
00178     assert(region->getNumberOfExtents() == nb_extents);
00179     return region->getHandle();
00180 }
00181 
00182 // ----------------------------------------------------------------------------
00183 // modify a region
00184 void
00185 RootObject::modifyRegion(RegionHandle handle, const std::vector<Extent> &extents)
00186     throw (RegionNotKnown, InvalidExtents)
00187 {
00188     RTIRegion *region = getRegion(handle);
00189     region->replaceExtents(extents);
00190 }
00191 
00192 // ----------------------------------------------------------------------------
00196 void
00197 RootObject::deleteRegion(RegionHandle region_handle)
00198     throw (RegionNotKnown, RegionInUse)
00199 {
00200     list<RTIRegion *>::iterator it = std::find_if(
00201     regions.begin(),
00202     regions.end(),
00203     HandleComparator<RTIRegion>(region_handle));
00204 
00205     if (it == regions.end()) throw RegionNotKnown("");
00206     else {
00207     // TODO: check RegionInUse
00208     regions.remove(*it);
00209     regionHandles.free((*it)->getHandle());
00210     delete *it ;
00211     }
00212 }
00213 
00214 // ----------------------------------------------------------------------------
00219 RTIRegion *
00220 RootObject::getRegion(RegionHandle handle)
00221     throw (RegionNotKnown)
00222 {
00223     list<RTIRegion *>::iterator it = std::find_if(
00224     regions.begin(),
00225     regions.end(),
00226     HandleComparator<RTIRegion>(handle));
00227 
00228     if (it == regions.end()) throw RegionNotKnown("");
00229     else return *it ;
00230 }
00231 
00232 // ----------------------------------------------------------------------------
00233 void
00234 RootObject::registerObjectInstance(FederateHandle the_federate,
00235                                    ObjectClassHandle the_class,
00236                                    ObjectHandle the_object,
00237                                    const char *the_object_name)
00238     throw (InvalidObjectHandle,
00239            ObjectClassNotDefined,
00240            ObjectClassNotPublished,
00241            ObjectAlreadyRegistered,
00242            RTIinternalError)
00243 {
00244     D.Out(pdRegister,
00245           "Federate %d attempts to register instance %d in class %d.",
00246           the_federate, the_object, the_class);
00247 
00248     Object *object ;
00249     object = objects->registerObjectInstance(the_federate, the_class,
00250                          the_object, the_object_name);
00251 
00252     ObjectClasses->registerObjectInstance(the_federate, object, the_class);
00253 }
00254 
00255 // ----------------------------------------------------------------------------
00256 void
00257 RootObject::deleteObjectInstance(FederateHandle the_federate,
00258                                  ObjectHandle the_object,
00259                  FederationTime theTime,
00260                                  std::string the_tag)
00261     throw (DeletePrivilegeNotHeld, ObjectNotKnown, RTIinternalError)
00262 {
00263     ObjectClasses->deleteObject(the_federate, the_object, theTime, the_tag);
00264     objects->deleteObjectInstance(the_federate, the_object, the_tag);
00265 }
00266 
00267 // ----------------------------------------------------------------------------
00268 void
00269 RootObject::deleteObjectInstance(FederateHandle the_federate,
00270                                  ObjectHandle the_object,
00271                                  std::string the_tag)
00272     throw (DeletePrivilegeNotHeld, ObjectNotKnown, RTIinternalError)
00273 {
00274     ObjectClasses->deleteObject(the_federate, the_object, the_tag);
00275     objects->deleteObjectInstance(the_federate, the_object, the_tag);
00276 }
00277 
00278 // ----------------------------------------------------------------------------
00279 void
00280 RootObject::killFederate(FederateHandle the_federate)
00281     throw (RTIinternalError)
00282 {
00283     ObjectClasses->killFederate(the_federate);
00284     Interactions->killFederate(the_federate);
00285     objects->killFederate(the_federate);
00286 }
00287 
00288 // ----------------------------------------------------------------------------
00289 // getObjectClassAttribute
00290 ObjectClassAttribute *
00291 RootObject::getObjectClassAttribute(ObjectHandle object,
00292                     AttributeHandle attribute)
00293 {
00294     return objects->getObject(object)->getAttribute(attribute)
00295     ->getObjectClassAttribute();
00296 }
00297 
00298 // ----------------------------------------------------------------------------
00299 // getObjectAttribute
00300 ObjectAttribute *
00301 RootObject::getObjectAttribute(ObjectHandle object,
00302                    AttributeHandle attribute)
00303 {
00304     return objects->getObject(object)->getAttribute(attribute);
00305 }
00306 
00307 // ----------------------------------------------------------------------------
00308 // getObject
00309 Object *
00310 RootObject::getObject(ObjectHandle object)
00311 {
00312     return objects->getObject(object);
00313 }
00314 
00315 // ----------------------------------------------------------------------------
00316 // getObjectClass
00317 ObjectClass *
00318 RootObject::getObjectClass(ObjectClassHandle class_handle)
00319 {
00320     return ObjectClasses->getObjectFromHandle(class_handle);
00321 }
00322 
00323 // ----------------------------------------------------------------------------
00324 // getInteractionClass
00325 Interaction *
00326 RootObject::getInteractionClass(InteractionClassHandle the_class)
00327 {
00328     return Interactions->getObjectFromHandle(the_class);
00329 }
00330 // ----------------------------------------------------------------------------
00331 // requestObjectInstance
00332 FederateHandle
00333 RootObject::requestObjectOwner(FederateHandle theFederateHandle, ObjectHandle theObject)
00334         throw (ObjectNotKnown)
00335 {
00336     G.Out(pdGendoc,"into RootObject::requestObjectOwner");
00337 
00338     return(objects->requestObjectOwner(theFederateHandle, theObject));
00339 
00340 }
00341 
00342 void
00343 RootObject::addObjectClass(ObjectClass* currentOC,ObjectClass* parentOC) {
00344     ObjectClasses->addClass(currentOC,parentOC);
00345 } /* end of addObjectClass */
00346 
00347 void
00348 RootObject::addInteractionClass(Interaction* currentIC, Interaction* parentIC) {
00349     Interactions->addClass(currentIC,parentIC);
00350 } /* end of addInteractionClass */
00351 
00352 } // namespace certi
00353 
00354 // $Id: RootObject.cc,v 3.40 2008/11/08 11:36:05 erk Exp $

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