# ObjectClassAttribute.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: ObjectClassAttribute.cc,v 3.31 2008/12/16 07:08:29 approx Exp $
    00023 // ----------------------------------------------------------------------------
    00024
    00025 #include "ObjectClassAttribute.hh"
    00026 #include "ObjectClassBroadcastList.hh"
    00027 #include "SecurityServer.hh"
    00028 #include "PrettyDebug.hh"
    00029 #include "helper.hh"
    00030
    00031 #include <iostream>
    00032 #include <list>
    00033 #include <assert.h>
    00034
    00035 using std::list ;
    00036 using std::cout ;
    00037 using std::endl ;
    00038
    00039 namespace certi {
    00040
    00041 static pdCDebug D("OBJECTCLASSATTRIBUTE", "(Obj.Cl.Attr) ");
    00042
    00043 ObjectClassAttribute::ObjectClassAttribute(const std::string theName, TransportType theTransport, OrderType theOrder)
    00044  : order(theOrder), transport(theTransport) {
    00045     setName(theName);
    00046
    00047 }
    00048 // ----------------------------------------------------------------------------
    00050
    00052 ObjectClassAttribute::ObjectClassAttribute()
    00053     : level(PublicLevelID), order(RECEIVE),
    00054       transport(BEST_EFFORT), server(0), handle(0), space(0)
    00055 {
    00056 }
    00057
    00058 // ----------------------------------------------------------------------------
    00060 ObjectClassAttribute::ObjectClassAttribute(ObjectClassAttribute *source)
    00061 {
    00062     if (source == 0)
    00063         throw RTIinternalError("NULL Attribute when copying it.");
    00064
    00065     handle = source->getHandle();
    00066     level = source->level ;
    00067     space = source->getSpace();
    00068     setName(source->getName());
    00069     order = source->order ;
    00070     transport = source->transport ;
    00071     server = source->server ;
    00072 }
    00073
    00074 // ----------------------------------------------------------------------------
    00076 ObjectClassAttribute::~ObjectClassAttribute()
    00077 {
    00078 }
    00079
    00080 // ----------------------------------------------------------------------------
    00084 void
    00085 ObjectClassAttribute::checkFederateAccess(FederateHandle fed,
    00086                       const char *reason) const
    00087 {
    00088     if (server && !server->canFederateAccessData(fed, level)) {
    00089         cout << "Attribute " << handle << " : SecurityError for federate "
    00090              << fed << '(' << reason << ")." << endl ;
    00091         throw SecurityError("Federate should not access ObjectClassAttribute.");
    00092     }
    00093 }
    00094
    00095 // ----------------------------------------------------------------------------
    00097 void
    00098 ObjectClassAttribute::deletePublisher(FederateHandle fed)
    00099 {
    00100     PublishersList_t::iterator it = publishers.find(fed);
    00101     if (it != publishers.end())
    00102     publishers.erase(it);
    00103 }
    00104
    00105 // ----------------------------------------------------------------------------
    00107 void
    00108 ObjectClassAttribute::display() const
    00109 {
    00110     cout << " Attribute " << handle << ':' ;
    00111
    00112     if (name.length() > 0)
    00113         cout << '\"' << name << '\"' ;
    00114     else
    00115         cout << "(no name)" ;
    00116
    00117     cout << "[Level " << level << ']' << endl ;
    00118 }
    00119
    00120 // ----------------------------------------------------------------------------
    00122 bool
    00123 ObjectClassAttribute::isPublishing(FederateHandle fed) const
    00124 {
    00125     return publishers.find(fed) != publishers.end();
    00126 }
    00127
    00128 // ----------------------------------------------------------------------------
    00130 void
    00131 ObjectClassAttribute::publish(FederateHandle fed)
    00132     throw (RTIinternalError, SecurityError)
    00133 {
    00134     if (!isPublishing(fed)) {
    00135         checkFederateAccess(fed, "Publish");
    00136         D[pdInit] << "Attribute " << handle << ": Added Federate " << fed
    00137           << " to publishers list." << endl ;
    00138     publishers.insert(fed);
    00139     }
    00140     else
    00141         D[pdError] << "Attribute " << handle
    00142            << ": Inconsistent publish request from Federate "
    00143            << fed << endl ;
    00144 }
    00145
    00146 // ----------------------------------------------------------------------------
    00148 void
    00149 ObjectClassAttribute::unpublish(FederateHandle fed)
    00150     throw (RTIinternalError, SecurityError)
    00151 {
    00152     if (isPublishing(fed)) {
    00153         D[pdTerm] << "Attribute " << handle << ": Removed Federate " << fed
    00154           << " from publishers list." << endl ;
    00155         deletePublisher(fed);
    00156     }
    00157
    00158     else
    00159         D[pdError] << "Attribute " << handle
    00160            << ": Inconsistent publish request from Federate "
    00161            << fed << endl ;
    00162 }
    00163
    00164 // ----------------------------------------------------------------------------
    00165 void
    00166 ObjectClassAttribute::setHandle(AttributeHandle h)
    00167 {
    00168     handle = h ;
    00169 }
    00170
    00171 // ----------------------------------------------------------------------------
    00172 AttributeHandle
    00173 ObjectClassAttribute::getHandle() const
    00174 {
    00175     return handle ;
    00176 }
    00177
    00178 // ----------------------------------------------------------------------------
    00179 void
    00180 ObjectClassAttribute::setSpace(SpaceHandle h)
    00181 {
    00182     space = h ;
    00183 }
    00184
    00185 // ----------------------------------------------------------------------------
    00186 SpaceHandle
    00187 ObjectClassAttribute::getSpace() const
    00188 {
    00189     return space ;
    00190 }
    00191
    00192
    00193 // ----------------------------------------------------------------------------
    00195 void
    00196 ObjectClassAttribute::updateBroadcastList(ObjectClassBroadcastList *ocblist,
    00197                       const RTIRegion *region)
    00198 {
    00199     switch(ocblist->message->getType()) {
    00200
    00201       case NetworkMessage::REFLECT_ATTRIBUTE_VALUES: {
    00202       addFederatesIfOverlap(*ocblist, region, handle);
    00203       } break ;
    00204       case NetworkMessage::REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION: {
    00205           PublishersList_t::iterator i ;
    00206           for (i = publishers.begin(); i != publishers.end(); i++) {
    00207               ocblist->addFederate(*i, handle);
    00208           }
    00209       } break ;
    00210
    00211       default: ; // nothing done
    00212     }
    00213 }
    00214
    00215 ObjectClassAttribute::PublishersList_t
    00216 ObjectClassAttribute::getPublishers(void) {
    00217     return publishers;
    00218 }
    00219
    00220 } // namespace
    00221
    00222 // $Id: ObjectClassAttribute.cc,v 3.31 2008/12/16 07:08:29 approx Exp $