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 #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
00045 server = security_server ;
00046 }
00047
00048 InteractionSet::~InteractionSet() {
00049
00050 }
00051
00052 void
00053 InteractionSet::addClass(Interaction *newClass, Interaction *parentClass) {
00054
00055 D.Out(pdInit, "Adding new interaction class %d, ", newClass->getHandle());
00056
00057 newClass->server = server ;
00058 add(newClass,parentClass);
00059 }
00060
00061
00063 void
00064 InteractionSet::broadcastInteraction(FederateHandle federate_handle,
00065 InteractionClassHandle interaction_handle,
00066 std::vector <ParameterHandle> ¶meter_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
00080
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
00093 if (ibList != NULL) {
00094
00095
00096
00097
00098
00099
00100 delete ibList ;
00101 }
00102 else
00103
00104 throw RTIinternalError("BroadcastInteraction called by RTIA.");
00105
00106 G.Out(pdGendoc,"exit InteractionSet::broadcastInteraction with time") ;
00107
00108 }
00109
00110
00112 void
00113 InteractionSet::broadcastInteraction(FederateHandle federate_handle,
00114 InteractionClassHandle interaction_handle,
00115 std::vector <ParameterHandle> ¶meter_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
00128
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
00140 if (ibList != NULL) {
00141
00142
00143
00144
00145
00146
00147 delete ibList ;
00148 }
00149 else
00150
00151 throw RTIinternalError("BroadcastInteraction called by RTIA.");
00152
00153 G.Out(pdGendoc,"exit InteractionSet::broadcastInteraction without time") ;
00154 }
00155
00156
00158 InteractionClassHandle
00159 InteractionSet::getInteractionClassHandle(const std::string& class_name) const
00160 throw (NameNotFound) {
00161 return getHandleFromName(class_name);
00162 }
00163
00164
00166 std::string
00167 InteractionSet::getInteractionClassName(InteractionClassHandle the_handle) const
00168 throw (InteractionClassNotDefined)
00169 {
00170 return getNameFromHandle(+the_handle);
00171 }
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
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
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> ¶m_array,
00212 UShort param_array_size)
00213 throw (FederateNotPublishing,
00214 InteractionClassNotDefined,
00215 InteractionParameterNotDefined,
00216 RTIinternalError)
00217 {
00218
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
00232 i->second->killFederate(the_federate);
00233 }
00234
00235 }
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
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
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 }
00277
00278