00001 // ---------------------------------------------------------------------------- 00002 // CERTI - HLA RunTime Infrastructure 00003 // Copyright (C) 2002-2006 ONERA 00004 // 00005 // This program is free software ; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public License 00007 // as published by the Free Software Foundation ; either version 2 of 00008 // the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, but 00011 // WITHOUT ANY WARRANTY ; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this program ; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 // 00019 // $Id: RTItypes.cc,v 1.4 2009/04/04 13:30:54 gotthardp Exp $ 00020 // ---------------------------------------------------------------------------- 00021 00022 #include "Exception.hh" 00023 #include "PrettyDebug.hh" 00024 #include <assert.h> 00025 #include <sstream> 00026 #include <cstdlib> 00027 #include <cstring> 00028 00029 // static members for HLA Exceptions 00030 const char *RTI::ArrayIndexOutOfBounds::_ex = "ArrayIndexOutOfBounds" ; 00031 const char *RTI::AsynchronousDeliveryAlreadyDisabled::_ex = "AsynchronousDeliveryAlreadyDisabled" ; 00032 const char *RTI::AsynchronousDeliveryAlreadyEnabled::_ex = "AsynchronousDeliveryAlreadyEnabled" ; 00033 const char *RTI::AttributeAcquisitionWasNotRequested::_ex = "AttributeAcquisitionWasNotRequested" ; 00034 const char *RTI::AttributeAcquisitionWasNotCanceled::_ex = "AttributeAcquisitionWasNotCanceled" ; 00035 const char *RTI::AttributeAlreadyBeingAcquired::_ex = "AttributeAlreadyBeingAcquired" ; 00036 const char *RTI::AttributeAlreadyBeingDivested::_ex = "AttributeAlreadyBeingDivested" ; 00037 const char *RTI::AttributeAlreadyOwned::_ex = "AttributeAlreadyOwned" ; 00038 const char *RTI::AttributeDivestitureWasNotRequested::_ex = "AttributeDivestitureWasNotRequested" ; 00039 const char *RTI::AttributeNotDefined::_ex = "AttributeNotDefined" ; 00040 const char *RTI::AttributeNotKnown::_ex = "AttributeNotKnown" ; 00041 const char *RTI::AttributeNotOwned::_ex = "AttributeNotOwned" ; 00042 const char *RTI::AttributeNotPublished::_ex = "AttributeNotPublished" ; 00043 const char *RTI::ConcurrentAccessAttempted::_ex = "ConcurrentAccessAttempted" ; 00044 const char *RTI::CouldNotDiscover::_ex = "CouldNotDiscover" ; 00045 const char *RTI::CouldNotOpenFED::_ex = "CouldNotOpenFED" ; 00046 const char *RTI::CouldNotRestore::_ex = "CouldNotRestore" ; 00047 const char *RTI::DeletePrivilegeNotHeld::_ex = "DeletePrivilegeNotHeld" ; 00048 const char *RTI::DimensionNotDefined::_ex = "DimensionNotDefined" ; 00049 const char *RTI::EnableTimeConstrainedPending::_ex = "EnableTimeConstrainedPending" ; 00050 const char *RTI::EnableTimeConstrainedWasNotPending::_ex = "EnableTimeConstrainedWasNotPending" ; 00051 const char *RTI::EnableTimeRegulationPending::_ex = "EnableTimeRegulationPending" ; 00052 const char *RTI::EnableTimeRegulationWasNotPending::_ex = "EnableTimeRegulationWasNotPending" ; 00053 const char *RTI::ErrorReadingFED::_ex = "ErrorReadingFED" ; 00054 const char *RTI::EventNotKnown::_ex = "EventNotKnown" ; 00055 const char *RTI::FederateAlreadyExecutionMember::_ex = "FederateAlreadyExecutionMember" ; 00056 const char *RTI::FederateInternalError::_ex = "FederateInternalError" ; 00057 const char *RTI::FederateLoggingServiceCalls::_ex = "FederateLoggingServiceCalls" ; 00058 const char *RTI::FederateNotExecutionMember::_ex = "FederateNotExecutionMember" ; 00059 const char *RTI::FederateOwnsAttributes::_ex = "FederateOwnsAttributes" ; 00060 const char *RTI::FederateWasNotAskedToReleaseAttribute::_ex = "FederateWasNotAskedToReleaseAttribute" ; 00061 const char *RTI::FederatesCurrentlyJoined::_ex = "FederatesCurrentlyJoined" ; 00062 const char *RTI::FederationExecutionAlreadyExists::_ex = "FederationExecutionAlreadyExists" ; 00063 const char *RTI::FederationExecutionDoesNotExist::_ex = "FederationExecutionDoesNotExist" ; 00064 const char *RTI::FederationTimeAlreadyPassed::_ex = "FederationTimeAlreadyPassed" ; 00065 const char *RTI::HandleValuePairMaximumExceeded::_ex = "HandleValuePairMaximumExceeded" ; 00066 const char *RTI::InteractionClassNotDefined::_ex = "InteractionClassNotDefined" ; 00067 const char *RTI::InteractionClassNotKnown::_ex = "InteractionClassNotKnown" ; 00068 const char *RTI::InteractionClassNotPublished::_ex = "InteractionClassNotPublished" ; 00069 const char *RTI::InteractionClassNotSubscribed::_ex = "InteractionClassNotSubscribed" ; 00070 const char *RTI::InteractionParameterNotDefined::_ex = "InteractionParameterNotDefined" ; 00071 const char *RTI::InteractionParameterNotKnown::_ex = "InteractionParameterNotKnown" ; 00072 const char *RTI::InvalidExtents::_ex = "InvalidExtents" ; 00073 const char *RTI::InvalidFederationTime::_ex = "InvalidFederationTime" ; 00074 const char *RTI::InvalidHandleValuePairSetContext::_ex = "InvalidHandleValuePairSetContext" ; 00075 const char *RTI::InvalidLookahead::_ex = "InvalidLookahead" ; 00076 const char *RTI::InvalidOrderingHandle::_ex = "InvalidOrderingHandle" ; 00077 const char *RTI::InvalidRegionContext::_ex = "InvalidRegionContext" ; 00078 const char *RTI::InvalidResignAction::_ex = "InvalidResignAction" ; 00079 const char *RTI::InvalidRetractionHandle::_ex = "InvalidRetractionHandle" ; 00080 const char *RTI::InvalidTransportationHandle::_ex = "InvalidTransportationHandle" ; 00081 const char *RTI::MemoryExhausted::_ex = "MemoryExhausted" ; 00082 const char *RTI::NameNotFound::_ex = "NameNotFound" ; 00083 const char *RTI::ObjectClassNotDefined::_ex = "ObjectClassNotDefined" ; 00084 const char *RTI::ObjectClassNotKnown::_ex = "ObjectClassNotKnown" ; 00085 const char *RTI::ObjectClassNotPublished::_ex = "ObjectClassNotPublished" ; 00086 const char *RTI::ObjectClassNotSubscribed::_ex = "ObjectClassNotSubscribed" ; 00087 const char *RTI::ObjectNotKnown::_ex = "ObjectNotKnown" ; 00088 const char *RTI::ObjectAlreadyRegistered::_ex = "ObjectAlreadyRegistered" ; 00089 const char *RTI::OwnershipAcquisitionPending::_ex = "OwnershipAcquisitionPending" ; 00090 const char *RTI::RegionInUse::_ex = "RegionInUse" ; 00091 const char *RTI::RegionNotKnown::_ex = "RegionNotKnown" ; 00092 const char *RTI::RestoreInProgress::_ex = "RestoreInProgress" ; 00093 const char *RTI::RestoreNotRequested::_ex = "RestoreNotRequested" ; 00094 const char *RTI::RTIinternalError::_ex = "RTIinternalError" ; 00095 const char *RTI::SpaceNotDefined::_ex = "SpaceNotDefined" ; 00096 const char *RTI::SaveInProgress::_ex = "SaveInProgress" ; 00097 const char *RTI::SaveNotInitiated::_ex = "SaveNotInitiated" ; 00098 const char *RTI::SpecifiedSaveLabelDoesNotExist::_ex = "SpecifiedSaveLabelDoesNotExist" ; 00099 const char *RTI::SynchronizationPointLabelWasNotAnnounced::_ex = "SynchronizationPointLabelWasNotAnnounced" ; 00100 const char *RTI::TimeAdvanceAlreadyInProgress::_ex = "TimeAdvanceAlreadyInProgress" ; 00101 const char *RTI::TimeAdvanceWasNotInProgress::_ex = "TimeAdvanceWasNotInProgress" ; 00102 const char *RTI::TimeConstrainedAlreadyEnabled::_ex = "TimeConstrainedAlreadyEnabled" ; 00103 const char *RTI::TimeConstrainedWasNotEnabled::_ex = "TimeConstrainedWasNotEnabled" ; 00104 const char *RTI::TimeRegulationAlreadyEnabled::_ex = "TimeRegulationAlreadyEnabled" ; 00105 const char *RTI::TimeRegulationWasNotEnabled::_ex = "TimeRegulationWasNotEnabled" ; 00106 const char *RTI::UnableToPerformSave::_ex = "UnableToPerformSave" ; 00107 const char *RTI::ValueCountExceeded::_ex = "ValueCountExceeded" ; 00108 const char *RTI::ValueLengthExceeded::_ex = "ValueLengthExceeded" ; 00109 00110 // TypeException managing (how to obtain TypeException from Exception name ?) 00111 long RTI::ArrayIndexOutOfBounds::type = certi::e_ArrayIndexOutOfBounds ; 00112 long RTI::AsynchronousDeliveryAlreadyDisabled::type = certi::e_AsynchronousDeliveryAlreadyDisabled ; 00113 long RTI::AsynchronousDeliveryAlreadyEnabled::type = certi::e_AsynchronousDeliveryAlreadyEnabled ; 00114 long RTI::AttributeAcquisitionWasNotRequested::type = certi::e_AttributeAcquisitionWasNotRequested ; 00115 long RTI::AttributeAcquisitionWasNotCanceled::type = certi::e_AttributeAcquisitionWasNotCanceled ; 00116 long RTI::AttributeAlreadyBeingAcquired::type = certi::e_AttributeAlreadyBeingAcquired ; 00117 long RTI::AttributeAlreadyBeingDivested::type = certi::e_AttributeAlreadyBeingDivested ; 00118 long RTI::AttributeAlreadyOwned::type = certi::e_AttributeAlreadyOwned ; 00119 long RTI::AttributeDivestitureWasNotRequested::type = certi::e_AttributeDivestitureWasNotRequested ; 00120 long RTI::AttributeNotDefined::type = certi::e_AttributeNotDefined ; 00121 long RTI::AttributeNotKnown::type = certi::e_AttributeNotKnown ; 00122 long RTI::AttributeNotOwned::type = certi::e_AttributeNotOwned ; 00123 long RTI::AttributeNotPublished::type = certi::e_AttributeNotPublished ; 00124 long RTI::ConcurrentAccessAttempted::type = certi::e_ConcurrentAccessAttempted ; 00125 long RTI::CouldNotDiscover::type = certi::e_CouldNotDiscover ; 00126 long RTI::CouldNotOpenFED::type = certi::e_CouldNotOpenFED ; 00127 long RTI::CouldNotRestore::type = certi::e_CouldNotRestore ; 00128 long RTI::DeletePrivilegeNotHeld::type = certi::e_DeletePrivilegeNotHeld ; 00129 long RTI::DimensionNotDefined::type = certi::e_DimensionNotDefined ; 00130 long RTI::EnableTimeConstrainedPending::type = certi::e_EnableTimeConstrainedPending ; 00131 long RTI::EnableTimeConstrainedWasNotPending::type = certi::e_EnableTimeConstrainedWasNotPending ; 00132 long RTI::EnableTimeRegulationPending::type = certi::e_EnableTimeRegulationPending ; 00133 long RTI::EnableTimeRegulationWasNotPending::type = certi::e_EnableTimeRegulationWasNotPending ; 00134 long RTI::ErrorReadingFED::type = certi::e_ErrorReadingFED ; 00135 long RTI::EventNotKnown::type = certi::e_EventNotKnown ; 00136 long RTI::FederateAlreadyExecutionMember::type = certi::e_FederateAlreadyExecutionMember ; 00137 long RTI::FederateInternalError::type = certi::e_FederateInternalError ; 00138 long RTI::FederateLoggingServiceCalls::type = certi::e_FederateLoggingServiceCalls ; 00139 long RTI::FederateNotExecutionMember::type = certi::e_FederateNotExecutionMember ; 00140 long RTI::FederateOwnsAttributes::type = certi::e_FederateOwnsAttributes ; 00141 long RTI::FederateWasNotAskedToReleaseAttribute::type = certi::e_FederateWasNotAskedToReleaseAttribute ; 00142 long RTI::FederatesCurrentlyJoined::type = certi::e_FederatesCurrentlyJoined ; 00143 long RTI::FederationExecutionAlreadyExists::type = certi::e_FederationExecutionAlreadyExists ; 00144 long RTI::FederationExecutionDoesNotExist::type = certi::e_FederationExecutionDoesNotExist ; 00145 long RTI::FederationTimeAlreadyPassed::type = certi::e_FederationTimeAlreadyPassed ; 00146 long RTI::HandleValuePairMaximumExceeded::type = certi::e_HandleValuePairMaximumExceeded ; 00147 long RTI::InteractionClassNotDefined::type = certi::e_InteractionClassNotDefined ; 00148 long RTI::InteractionClassNotKnown::type = certi::e_InteractionClassNotKnown ; 00149 long RTI::InteractionClassNotPublished::type = certi::e_InteractionClassNotPublished ; 00150 long RTI::InteractionClassNotSubscribed::type = certi::e_InteractionClassNotSubscribed ; 00151 long RTI::InteractionParameterNotDefined::type = certi::e_InteractionParameterNotDefined ; 00152 long RTI::InteractionParameterNotKnown::type = certi::e_InteractionParameterNotKnown ; 00153 long RTI::InvalidExtents::type = certi::e_InvalidExtents ; 00154 long RTI::InvalidFederationTime::type = certi::e_InvalidFederationTime ; 00155 long RTI::InvalidHandleValuePairSetContext::type = certi::e_InvalidHandleValuePairSetContext ; 00156 long RTI::InvalidLookahead::type = certi::e_InvalidLookahead ; 00157 long RTI::InvalidOrderingHandle::type = certi::e_InvalidOrderingHandle ; 00158 long RTI::InvalidRegionContext::type = certi::e_InvalidRegionContext ; 00159 long RTI::InvalidResignAction::type = certi::e_InvalidResignAction ; 00160 long RTI::InvalidRetractionHandle::type = certi::e_InvalidRetractionHandle ; 00161 long RTI::InvalidTransportationHandle::type = certi::e_InvalidTransportationHandle ; 00162 long RTI::MemoryExhausted::type = certi::e_MemoryExhausted ; 00163 long RTI::NameNotFound::type = certi::e_NameNotFound ; 00164 long RTI::ObjectClassNotDefined::type = certi::e_ObjectClassNotDefined ; 00165 long RTI::ObjectClassNotKnown::type = certi::e_ObjectClassNotKnown ; 00166 long RTI::ObjectClassNotPublished::type = certi::e_ObjectClassNotPublished ; 00167 long RTI::ObjectClassNotSubscribed::type = certi::e_ObjectClassNotSubscribed ; 00168 long RTI::ObjectNotKnown::type = certi::e_ObjectNotKnown ; 00169 long RTI::ObjectAlreadyRegistered::type = certi::e_ObjectAlreadyRegistered ; 00170 long RTI::OwnershipAcquisitionPending::type = certi::e_OwnershipAcquisitionPending ; 00171 long RTI::RegionInUse::type = certi::e_RegionInUse ; 00172 long RTI::RegionNotKnown::type = certi::e_RegionNotKnown ; 00173 long RTI::RestoreInProgress::type = certi::e_RestoreInProgress ; 00174 long RTI::RestoreNotRequested::type = certi::e_RestoreNotRequested ; 00175 long RTI::RTIinternalError::type = certi::e_RTIinternalError ; 00176 long RTI::SpaceNotDefined::type = certi::e_SpaceNotDefined ; 00177 long RTI::SaveInProgress::type = certi::e_SaveInProgress ; 00178 long RTI::SaveNotInitiated::type = certi::e_SaveNotInitiated ; 00179 long RTI::SpecifiedSaveLabelDoesNotExist::type = certi::e_SpecifiedSaveLabelDoesNotExist ; 00180 long RTI::SynchronizationPointLabelWasNotAnnounced::type = certi::e_SynchronizationPointLabelWasNotAnnounced ; 00181 long RTI::TimeAdvanceAlreadyInProgress::type = certi::e_TimeAdvanceAlreadyInProgress ; 00182 long RTI::TimeAdvanceWasNotInProgress::type = certi::e_TimeAdvanceWasNotInProgress ; 00183 long RTI::TimeConstrainedAlreadyEnabled::type = certi::e_TimeConstrainedAlreadyEnabled ; 00184 long RTI::TimeConstrainedWasNotEnabled::type = certi::e_TimeConstrainedWasNotEnabled ; 00185 long RTI::TimeRegulationAlreadyEnabled::type = certi::e_TimeRegulationAlreadyEnabled ; 00186 long RTI::TimeRegulationWasNotEnabled::type = certi::e_TimeRegulationWasNotEnabled ; 00187 long RTI::UnableToPerformSave::type = certi::e_UnableToPerformSave ; 00188 long RTI::ValueCountExceeded::type = certi::e_ValueCountExceeded ; 00189 long RTI::ValueLengthExceeded::type = certi::e_ValueLengthExceeded ; 00190 00191 static PrettyDebug PD_RTIException("RTI_EXCEPTION",__FILE__); 00192 00193 RTI::Exception::~Exception() 00194 { 00195 if (NULL!=_reason) { 00196 free(_reason); 00197 } 00198 } 00199 00200 RTI::Exception::Exception(const char *reason) 00201 { 00202 _reason = (reason == NULL)?NULL:strdup(reason); 00203 _serial = 0 ; 00204 } 00205 00206 RTI::Exception::Exception(ULong serial, const char *reason) 00207 { 00208 _serial = serial ; 00209 _reason = (reason == NULL)?NULL:strdup(reason); 00210 } 00211 00212 00213 RTI::Exception::Exception(const Exception &toCopy) 00214 { 00215 _serial = toCopy._serial ; 00216 _reason = ( toCopy._reason== NULL)?NULL:strdup(toCopy._reason) ; 00217 _name = toCopy._name ; 00218 } 00219 00220 RTI::Exception& RTI::Exception::operator=(const Exception &toCopy) 00221 { 00222 _serial = toCopy._serial ; 00223 _reason = (toCopy._reason == NULL)?NULL:strdup(toCopy._reason) ; 00224 _name = toCopy._name ; 00225 return *this ; 00226 } 00227 00228 const std::string RTI::Exception::displayMe() const 00229 { 00230 std::stringstream msg; 00231 00232 msg << "RTI::Exception ["; 00233 if (NULL!=_name) { 00234 msg <<_name; 00235 } else { 00236 msg<<"<noname>"; 00237 } 00238 msg <<",0x"<<std::hex<<_serial<<"]"; 00239 msg << " - reason="; 00240 if (NULL !=_reason) { 00241 msg << _reason; 00242 } else { 00243 msg << "<noreason>"; 00244 } 00245 msg << std::endl; 00246 msg << std::flush; 00247 00248 PD_RTIException[pdExcept] << msg.str().c_str(); 00249 return msg.str(); 00250 } 00251 00252 RTI_STD::ostream & 00253 operator<<(RTI_STD::ostream &os, RTI::Exception const &ex) 00254 { 00255 // FIXME 00256 return os << ex.displayMe(); 00257 } 00258 00259 RTI_STD::ostream & 00260 operator<<(RTI_STD::ostream &os, RTI::Exception *ex) 00261 { 00262 assert(ex); 00263 return os<<(*ex); 00264 } 00265 00266 // $Id: RTItypes.cc,v 1.4 2009/04/04 13:30:54 gotthardp Exp $