InteractionSet.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: InteractionSet.cc,v 3.28 2008/11/08 01:11:23 erk Exp $
00023 // ----------------------------------------------------------------------------
00024 
00025 #include "Interaction.hh"
00026 #include "InteractionSet.hh"
00027 #include "InteractionBroadcastList.hh"
00028 #include "PrettyDebug.hh"
00029 
00030 #include <iostream>
00031 
00032 using std::cout ;
00033 using std::endl ;
00034 using std::list ;
00035 
00036 namespace certi {
00037 
00038 static pdCDebug D("INTERACTIONSET", "(InterSet) - ");
00039 static PrettyDebug G("GENDOC",__FILE__) ;
00040 
00041 
00042 InteractionSet::InteractionSet(SecurityServer *security_server, bool isRootClassSet)
00043 : TreeNamedAndHandledSet<Interaction>("Interaction Classes",isRootClassSet) {
00044     // It can be NULL on the RTIA.
00045     server = security_server ;
00046 }
00047 
00048 InteractionSet::~InteractionSet() {
00049 
00050 } /* end of ~InteractionSet */
00051 
00052 void
00053 InteractionSet::addClass(Interaction *newClass, Interaction *parentClass) {
00054 
00055     D.Out(pdInit, "Adding new interaction class %d, ", newClass->getHandle());
00056     /* link to server */
00057     newClass->server = server ;
00058     add(newClass,parentClass);
00059 } /* end of addClass */
00060 
00061 // ----------------------------------------------------------------------------
00063 void
00064 InteractionSet::broadcastInteraction(FederateHandle federate_handle,
00065         InteractionClassHandle interaction_handle,
00066         std::vector <ParameterHandle> &parameter_list,
00067         std::vector <ParameterValue_t> &value_list,
00068         UShort list_size,
00069         FederationTime the_time,
00070         const RTIRegion *region,
00071         const char *the_tag)
00072 throw (FederateNotPublishing,
00073         InteractionClassNotDefined,
00074         InteractionParameterNotDefined,
00075         RTIinternalError) {
00076 
00077     G.Out(pdGendoc,"enter InteractionSet::broadcastInteraction with time") ;
00078 
00079     // It may throw InteractionClassNotDefined.
00080     //InteractionClassHandle currentClass = interaction_handle ;
00081     Interaction *theInteraction = getObjectFromHandle(interaction_handle);
00082 
00083     InteractionBroadcastList *ibList ;
00084     ibList = theInteraction->sendInteraction(federate_handle,
00085             parameter_list,
00086             value_list,
00087             list_size,
00088             the_time,
00089             region,
00090             the_tag);
00091 
00092     // Pass the Message(and its BroadcastList) to the Parent Classes.
00093     if (ibList != NULL) {
00094         //currentClass = theInteraction->parent ;
00095         //while (CurrentClass != 0) {
00096         // theInteraction = getObjectFromHandle(CurrentClass);
00097         // theInteraction->broadcastInteractionMessage(List);
00098         // CurrentClass = theInteraction->Father ;
00099         //}
00100         delete ibList ;
00101     }
00102     else
00103         // BroadcastInteraction should not be called on the RTIA(see IsReady)
00104         throw RTIinternalError("BroadcastInteraction called by RTIA.");
00105 
00106     G.Out(pdGendoc,"exit InteractionSet::broadcastInteraction with time") ;
00107 
00108 } /* end of broadcastInteraction (with time) */
00109 
00110 // ----------------------------------------------------------------------------
00112 void
00113 InteractionSet::broadcastInteraction(FederateHandle federate_handle,
00114         InteractionClassHandle interaction_handle,
00115         std::vector <ParameterHandle> &parameter_list,
00116         std::vector <ParameterValue_t> &value_list,
00117         UShort list_size,
00118         const RTIRegion *region,
00119         const char *the_tag)
00120 throw (FederateNotPublishing,
00121         InteractionClassNotDefined,
00122         InteractionParameterNotDefined,
00123         RTIinternalError) {
00124 
00125     G.Out(pdGendoc,"enter InteractionSet::broadcastInteraction without time") ;
00126 
00127     // It may throw InteractionClassNotDefined.
00128     //InteractionClassHandle currentClass = interaction_handle ;
00129     Interaction *theInteraction = getObjectFromHandle(interaction_handle);
00130 
00131     InteractionBroadcastList *ibList ;
00132     ibList = theInteraction->sendInteraction(federate_handle,
00133             parameter_list,
00134             value_list,
00135             list_size,
00136             region,
00137             the_tag);
00138 
00139     // Pass the Message(and its BroadcastList) to the Parent Classes.
00140     if (ibList != NULL) {
00141         //currentClass = theInteraction->parent ;
00142         //while (CurrentClass != 0) {
00143         // theInteraction = getObjectFromHandle(CurrentClass);
00144         // theInteraction->broadcastInteractionMessage(List);
00145         // CurrentClass = theInteraction->Father ;
00146         //}
00147         delete ibList ;
00148     }
00149     else
00150         // BroadcastInteraction should not be called on the RTIA(see IsReady)
00151         throw RTIinternalError("BroadcastInteraction called by RTIA.");
00152 
00153     G.Out(pdGendoc,"exit InteractionSet::broadcastInteraction without time") ;
00154 } /* end of broadcastInteraction (WITHOUT time) */
00155 
00156 // ----------------------------------------------------------------------------
00158 InteractionClassHandle
00159 InteractionSet::getInteractionClassHandle(const std::string& class_name) const
00160 throw (NameNotFound)  {
00161     return getHandleFromName(class_name);
00162 } /* end of getInteractionClassHandle */
00163 
00164 // ----------------------------------------------------------------------------
00166 std::string
00167 InteractionSet::getInteractionClassName(InteractionClassHandle the_handle) const
00168 throw (InteractionClassNotDefined)
00169 {
00170     return getNameFromHandle(+the_handle);
00171 } /* end of getInteractionClassName */
00172 
00173 // ----------------------------------------------------------------------------
00175 ParameterHandle
00176 InteractionSet::getParameterHandle(const char *the_name,
00177         InteractionClassHandle the_class)
00178 throw (NameNotFound,
00179         InteractionClassNotDefined,
00180         RTIinternalError)
00181         {
00182     if (the_name == NULL)
00183         throw RTIinternalError("");
00184 
00185     // It may throw InteractionClassNotDefined
00186     Interaction *interaction = getObjectFromHandle(the_class);
00187     return interaction->getParameterHandle(the_name);
00188         }
00189 
00190 // ----------------------------------------------------------------------------
00192 const std::string&
00193 InteractionSet::getParameterName(ParameterHandle the_handle,
00194         InteractionClassHandle the_class)
00195 throw (InteractionParameterNotDefined,
00196         InteractionClassNotDefined,
00197         RTIinternalError)
00198         {
00199     // It may throw InteractionClassNotDefined
00200     Interaction *interaction = getObjectFromHandle(the_class);
00201     return interaction->getParameterName(the_handle);
00202         }
00203 
00204 // ----------------------------------------------------------------------------
00208 void
00209 InteractionSet::isReady(FederateHandle federate_handle,
00210         InteractionClassHandle the_interaction,
00211         std::vector <ParameterHandle> &param_array,
00212         UShort param_array_size)
00213 throw (FederateNotPublishing,
00214         InteractionClassNotDefined,
00215         InteractionParameterNotDefined,
00216         RTIinternalError)
00217         {
00218     // It may throw InteractionClassNotDefined
00219     Interaction *interaction = getObjectFromHandle(the_interaction);
00220     interaction->isReady(federate_handle, param_array, param_array_size);
00221         }
00222 
00223 // ----------------------------------------------------------------------------
00225 void
00226 InteractionSet::killFederate(FederateHandle the_federate)
00227 throw () {
00228     handled_const_iterator i;
00229 
00230     for (i = handled_begin(); i != handled_end(); ++i) {
00231         // Call KillFederate on that class until it returns NULL.
00232         i->second->killFederate(the_federate);
00233     }
00234 
00235 } /* end of killFederate */
00236 
00237 // ----------------------------------------------------------------------------
00239 void
00240 InteractionSet::publish(FederateHandle federate_handle,
00241         InteractionClassHandle interaction_handle,
00242         bool publish)
00243 throw (FederateNotPublishing,
00244         InteractionClassNotDefined,
00245         RTIinternalError,
00246         SecurityError)
00247         {
00248     // It may throw InteractionClassNotDefined
00249     Interaction *interaction = getObjectFromHandle(interaction_handle);
00250     if (publish)
00251         interaction->publish(federate_handle);
00252     else
00253         interaction->unpublish(federate_handle);
00254         }
00255 
00256 // ----------------------------------------------------------------------------
00258 void
00259 InteractionSet::subscribe(FederateHandle federate_handle,
00260         InteractionClassHandle interaction_handle,
00261         const RTIRegion *region,
00262         bool subscribe)
00263 throw (FederateNotSubscribing,
00264         InteractionClassNotDefined,
00265         RTIinternalError,
00266         SecurityError)
00267         {
00268     // It may throw InteractionClassNotDefined
00269     Interaction *interaction = getObjectFromHandle(interaction_handle);
00270     if (subscribe)
00271         interaction->subscribe(federate_handle, region);
00272     else
00273         interaction->unsubscribe(federate_handle, region);
00274         }
00275 
00276 } // namespace certi
00277 
00278 // $Id: InteractionSet.cc,v 3.28 2008/11/08 01:11:23 erk Exp $

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