Message.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // CERTI - HLA RunTime Infrastructure
00003 // Copyright (C) 2002-2005  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
00020 
00021 
00022 
00023 #include "Message.hh"
00024 #include "certi.hh"
00025 #include "PrettyDebug.hh"
00026 
00027 #include <stdlib.h>
00028 #include <cstdio>
00029 #include <cstring>
00030 #include <assert.h>
00031 
00032 using std::vector ;
00033 
00034 namespace certi {
00035 
00036 static PrettyDebug G("GENDOC",__FILE__) ;
00037 
00038 #define NONE -1
00039 
00040 Message::Message()
00041 {
00042     fed_time.setZero();
00043     exception = e_NO_EXCEPTION ;
00044     exceptionReason[0] = '\0' ;
00045     federateName[0] = '\0' ;
00046     //federationName = NULL ;is now a string then...
00047     tag = "" ;
00048     name[0] = '\0' ;
00049     label[0] = '\0' ;
00050     handleArraySize = 0 ;
00051     objectClass = 0 ; 
00052     object = 0 ;
00053     boolean = false ;
00054     type = NOT_USED ;
00055     lookahead = 0 ;
00056     federate = 0 ;
00057     resignAction = RTI::NO_ACTION ;
00058     idCount = 0 ;
00059     firstId = 0 ;
00060     lastId = 0 ;
00061     interactionClass = 0 ;
00062     attribute = 0 ;
00063     parameter = 0 ;
00064     transport = 0 ;
00065     order = 0 ;
00066     space = 0 ;
00067     dimension = 0 ;
00068     number = 0 ;
00069     region = 0 ;
00070     //FEDid = NULL ;now string
00071     valueArray.empty() ;
00072 }
00073 
00074 // ----------------------------------------------------------------------------
00077 std::vector <ParameterValue_t>
00078 Message::getValueArray()
00079 {
00080     G.Out(pdGendoc,"enter Message::getValueArray");
00081     int i ;
00082 
00083     std::vector <ParameterValue_t> NewValueArray;
00084     NewValueArray.resize(handleArraySize) ;
00085 
00086     for (i = 0 ; i < handleArraySize ; i++)
00087         {
00088         NewValueArray[i] = valueArray[i];
00089         }
00090 
00091     G.Out(pdGendoc,"return Message::getValueArray");
00092     return NewValueArray ;
00093 }
00094 
00095 // ----------------------------------------------------------------------------
00099 void
00100 Message::setLabel(std::string NewLabel)
00101 {
00102     label = NewLabel ;
00103 }
00104 
00105 // ----------------------------------------------------------------------------
00106 void
00107 Message::setName(const char *NewName)
00108 {
00109    name = NewName ;
00110 }
00111 
00112 // ----------------------------------------------------------------------------
00113 void
00114 Message::setType(Type t)
00115 {
00116     type = t ;
00117 }
00118 // ----------------------------------------------------------------------------
00119 void
00120 Message::setNumber(unsigned long nb)
00121 {
00122     number = nb ;
00123 }
00124 
00125 // ----------------------------------------------------------------------------
00126 void
00127 Message::setSpace(SpaceHandle handle)
00128 {
00129     space = handle ;
00130 }
00131 
00132 // ----------------------------------------------------------------------------
00133 void
00134 Message::setRegion(long handle)
00135 {
00136     region = handle ;
00137 }
00138 
00139 // ----------------------------------------------------------------------------
00140 void
00141 Message::setMinTickTime(RTI::TickTime time)
00142 {
00143     minTickTime = time;
00144 }
00145 
00146 // ----------------------------------------------------------------------------
00147 void
00148 Message::setMaxTickTime(RTI::TickTime time)
00149 {
00150     maxTickTime = time;
00151 }
00152 
00153 // ----------------------------------------------------------------------------
00154 void
00155 Message::setDimension(DimensionHandle handle)
00156 {
00157     dimension = handle ;
00158 }
00159 
00160 // ----------------------------------------------------------------------------
00161 void
00162 Message::setInteractionClass(InteractionClassHandle handle)
00163 {
00164     interactionClass = handle ;
00165 }
00166 
00167 // ----------------------------------------------------------------------------
00168 void
00169 Message::setObjectClass(ObjectClassHandle handle)
00170 {
00171     objectClass = handle ;
00172 }
00173 
00174 // ----------------------------------------------------------------------------
00175 void
00176 Message::setAttribute(AttributeHandle handle)
00177 {
00178     attribute = handle ;
00179 }
00180 
00181 // ----------------------------------------------------------------------------
00182 void
00183 Message::setResignAction(RTI::ResignAction the_action)
00184 {
00185     resignAction = the_action ;
00186 }
00187 
00188 // ----------------------------------------------------------------------------
00189 void
00190 Message::setFederationTimeDelta(FederationTimeDelta the_lookahead)
00191 {
00192     lookahead = the_lookahead ;
00193 }
00194 
00195 // ----------------------------------------------------------------------------
00199 void
00200 Message::setFedTime(const double the_time)
00201 {
00202     fed_time = the_time;
00203 }
00204 
00205 // ----------------------------------------------------------------------------
00206 void
00207 Message::setLookahead(const double the_lookahead)
00208 {
00209     lookahead = the_lookahead;
00210 }
00211 
00212 // ----------------------------------------------------------------------------
00213 void
00214 Message::setFederationTime(FederationTime the_time)
00215 {
00216     fed_time = the_time;
00217 }
00218 
00219 // ----------------------------------------------------------------------------
00223 void
00224 Message::setBoolean(bool the_bool)
00225 {
00226     boolean = the_bool ;
00227 }
00228 
00229 // ----------------------------------------------------------------------------
00233 void
00234 Message::setObject(ObjectHandle the_object)
00235 {
00236     object = the_object ;
00237 }
00238 
00239 // ----------------------------------------------------------------------------
00240 void
00241 Message::setTransportation(TransportType the_transport)
00242 {
00243     transport = the_transport;
00244 }
00245 
00246 // ----------------------------------------------------------------------------
00247 void
00248 Message::setOrdering(OrderType the_ordering)
00249 {
00250     order = the_ordering;
00251 }
00252 
00253 // ----------------------------------------------------------------------------
00254 void
00255 Message::setEventRetraction(EventRetractionHandle the_event)
00256 {
00257     eventRetraction = the_event ;
00258 }
00259 
00260 // ----------------------------------------------------------------------------
00261 void
00262 Message::setParameter(ParameterHandle the_parameter)
00263 {
00264     parameter = the_parameter ;
00265 }
00266 
00267 // ----------------------------------------------------------------------------
00272 void
00273 Message::setException(TypeException the_exception,
00274                       const std::string& the_reason)
00275 {
00276     exception = the_exception ;
00277     exceptionReason = the_reason;
00278 }
00279 
00280 // ----------------------------------------------------------------------------
00281 void
00282 Message::setFederate(FederateHandle the_federate)
00283 {
00284     federate = the_federate ;
00285 }
00286 
00287 // ----------------------------------------------------------------------------
00288 const std::vector<AttributeHandle>&
00289 Message::getAHS() const
00290 {
00291     return handleArray;
00292 }
00293 
00294 // ----------------------------------------------------------------------------
00295 void
00296 Message::setAHS(const std::vector<AttributeHandle> &the_attributes)
00297 {
00298     G.Out(pdGendoc,"enter Message::setAHS");
00299     handleArraySize = the_attributes.size();
00300     handleArray.resize(handleArraySize);
00301 
00302     for (unsigned int i = 0 ; i < the_attributes.size(); ++i) {
00303         handleArray[i] = the_attributes[i];
00304     }
00305     G.Out(pdGendoc,"exit  Message::setAHS");
00306 }
00307 
00308 // ----------------------------------------------------------------------------
00309 void
00310 Message::setAHS(const AttributeHandle *attr, int size)
00311 {
00312     G.Out(pdGendoc,"enter Message::setAHS with size");
00313     handleArraySize = size ;
00314     handleArray.resize(handleArraySize);
00315 
00316     for (int i = 0 ; i < size ; ++i) {
00317         handleArray[i] = attr[i] ;
00318     }
00319     G.Out(pdGendoc,"exit  Message::setAHS with size");
00320 }
00321 
00322 // ----------------------------------------------------------------------------
00323 std::vector<std::pair<AttributeHandle, AttributeValue_t> >
00324 Message::getAHVPS() const
00325 {
00326     std::vector<std::pair<AttributeHandle, AttributeValue_t> > result;
00327     result.resize(handleArraySize);
00328 
00329     for (int i = 0 ; i < handleArraySize ; i++) {
00330         result[i].first = handleArray[i];
00331         result[i].second.assign(valueArray[i].data(), valueArray[i].length());
00332     }
00333 
00334     return result;
00335 }
00336 
00337 // ----------------------------------------------------------------------------
00341 void
00342 Message::setAHVPS(const std::vector<std::pair<AttributeHandle, AttributeValue_t> > &the_attributes)
00343 {
00344     G.Out(pdGendoc,"enter Message::setAHVPS");
00345 
00346     unsigned long size ;
00347 
00348     size = the_attributes.size() ;
00349     handleArraySize = size ;
00350     handleArray.resize(handleArraySize);
00351     valueArray.resize(size) ;
00352 
00353     for (unsigned long i = 0 ; i < size ; i++) {
00354         handleArray[i] = the_attributes[size-1-i].first;
00355         valueArray[i] = the_attributes[size-1-i].second;
00356     }
00357     G.Out(pdGendoc,"exit  Message::setAHVPS");
00358 }
00359 
00360 // ----------------------------------------------------------------------------
00361 std::vector<std::pair<ParameterHandle, ParameterValue_t> >
00362 Message::getPHVPS() const
00363 {
00364     std::vector<std::pair<ParameterHandle, ParameterValue_t> > result;
00365     result.resize(handleArraySize);
00366 
00367     for (int i = 0 ; i < handleArraySize ; i++) {
00368         result[i].first = handleArray[i];
00369         result[i].second.assign(valueArray[i].data(), valueArray[i].length());
00370     }
00371 
00372     return result;
00373 }
00374 
00375 // ----------------------------------------------------------------------------
00376 void
00377 Message::setPHVPS(const std::vector<std::pair<ParameterHandle, ParameterValue_t> > &the_parameters)
00378 {
00379     G.Out(pdGendoc,"enter Message::setPHVPS");
00380 
00381     unsigned long size ;
00382 
00383     size = the_parameters.size() ;
00384     handleArraySize = size ;
00385     handleArray.resize(handleArraySize);
00386     valueArray.resize(size) ;
00387 
00388     for (unsigned long i = 0 ; i < size ; i++) {
00389         handleArray[i] = the_parameters[size-1-i].first;
00390         valueArray[i] = the_parameters[size-1-i].second;
00391     }
00392     G.Out(pdGendoc,"exit  Message::setPHVPS");
00393 }
00394 
00395 // ----------------------------------------------------------------------------
00396 void
00397 Message::setAttributes(std::vector <AttributeHandle> &the_attributes, ushort the_size)
00398 {
00399     handleArraySize = the_size ;
00400     handleArray.resize(handleArraySize);
00401 
00402     for (int i = 0 ; i < the_size ; i++) {
00403         handleArray[i] = the_attributes[i] ;
00404     }
00405 }
00406 
00407 // ----------------------------------------------------------------------------
00408 // setAttributes
00409 // store attributes into handleArray
00410 // store values     into valueArray
00411 void
00412 Message::setAttributes(std::vector <AttributeHandle> &the_attributes,
00413                        std::vector <AttributeValue_t> &the_values,
00414                        ushort the_size)
00415 {
00416     G.Out(pdGendoc,"enter Message::setAttributes");
00417     handleArraySize = the_size ;
00418     handleArray.resize(handleArraySize);
00419     valueArray.resize(the_size) ;
00420 
00421     for (int i = 0 ; i < the_size ; i++) {
00422         handleArray[i] = the_attributes[i] ;
00423         valueArray[i] = the_values[i] ;
00424     }
00425     G.Out(pdGendoc,"exit  Message::setAttributes");
00426 }
00427 
00428 // ----------------------------------------------------------------------------
00429 // setParameters
00430 // store parameters into handleArray
00431 // store values     into valueArray
00432 void
00433 Message::setParameters(std::vector <ParameterHandle> & the_parameters,
00434                        std::vector <ParameterValue_t> & the_values,
00435                        ushort the_size)
00436 
00437 {
00438     handleArraySize = the_size ;
00439     handleArray.resize(handleArraySize);
00440     valueArray.resize(the_size) ;
00441 
00442     for (int i = 0 ; i < the_size ; i++) {
00443         handleArray[i] = the_parameters[i] ;
00444         valueArray[i] = the_values[i] ;
00445     }
00446 }
00447 
00448 // ----------------------------------------------------------------------------
00450 void Message::setFederationName(std::string NewNomFederation)
00451 {
00452     federationName = NewNomFederation ;
00453 }
00454 
00455 
00456 // ----------------------------------------------------------------------------
00457 // setFederateName
00458 //
00459 void
00460 Message::setFederateName(std::string NewNomFedere)
00461 {
00462     federateName = NewNomFedere ;
00463 }
00464 
00465 // ----------------------------------------------------------------------------
00466 // setTag
00470 void
00471 Message::setTag(std::string new_tag)
00472 {
00473     tag = new_tag ;
00474 }
00475 
00476 // ----------------------------------------------------------------------------
00477 // setFEDid
00478 //
00479 void
00480 Message::setFEDid(std::string NewFEDid)
00481 {
00482     FEDid = NewFEDid;
00483 }
00484 
00485 // ----------------------------------------------------------------------------
00486 // operator=
00487 //
00488 Message &
00489 Message::operator=(const Message& msg)
00490 {
00491     type = msg.type ;
00492     fed_time = msg.fed_time ;
00493     boolean = msg.boolean ;
00494     lookahead = msg.lookahead ;
00495     exception = msg.exception ;
00496 
00497     exceptionReason = msg.exceptionReason;
00498     federateName = msg.federateName ;
00499 
00500     federationName = msg.federationName ;
00501 
00502     federate = msg.federate ;
00503     resignAction = msg.resignAction ;
00504     idCount = msg.idCount ;
00505     firstId = msg.firstId ;
00506     lastId = msg.lastId ;
00507 
00508     objectClass = msg.objectClass ;
00509     interactionClass = msg.interactionClass ;
00510     attribute = msg.attribute ;
00511     parameter = msg.parameter ;
00512     object = msg.object ;
00513     space = msg.space ;
00514     dimension = msg.dimension ;
00515     // transportation = msg.transportation ;
00516     // ordering = msg.ordering ;
00517     minTickTime = msg.minTickTime ;
00518     maxTickTime = msg.maxTickTime ;
00519 
00520     tag = msg.tag ;
00521     name = msg.name ;
00522 
00523     transport = msg.transport ;
00524     order = msg.order ;
00525 
00526     eventRetraction.theSerialNumber = msg.eventRetraction.theSerialNumber ;
00527     eventRetraction.sendingFederate = msg.eventRetraction.sendingFederate ;
00528 
00529     label = msg.label ;
00530 
00531     handleArraySize = msg.handleArraySize ;
00532     handleArray.resize(handleArraySize);
00533     valueArray.resize(handleArraySize) ;
00534 
00535     int i ;
00536     for (i=0 ; i < handleArraySize ; i++)
00537         handleArray[i] = msg.handleArray[i] ;
00538 
00539     for (i=0 ; i < handleArraySize ; i++)
00540         valueArray[i] = msg.valueArray[i] ;
00541 
00542     FEDid = msg.FEDid ;
00543 
00544     return *this ;
00545 }
00546 
00547 // ----------------------------------------------------------------------------
00548 // display
00549 //
00550 void
00551 Message::display(char *s)
00552 {
00553     printf(" -- MESSAGE - %s -", s);
00554     if ( type == CREATE_FEDERATION_EXECUTION )
00555       printf("CREATE_FEDERATION_EXECUTION : federationName %s : filename %s federateHandle %ld \n",
00556              ((federationName.c_str()==NULL)?"empty":federationName.c_str()),((FEDid.c_str()==NULL)?"empty":FEDid.c_str()),federate) ;
00557     if ( type == DESTROY_FEDERATION_EXECUTION )
00558       printf("DESTROY_FEDERATION_EXECUTION : federation %s : federate %ld\n",
00559              ((federationName.c_str()==NULL)?"empty":federationName.c_str()),federate) ;
00560     else if ( type == JOIN_FEDERATION_EXECUTION )
00561       printf("JOIN_FEDERATION_EXECUTION : federate number %ld federation name %s federate name %s\n",
00562              federate,((federationName.c_str()==NULL)?"empty":federationName.c_str()),federateName.c_str()) ;
00563     else if (type == FEDERATE_SAVE_COMPLETE )
00564         printf("FEDERATE_SAVE_COMPLETE : federationName %s : federatehandle %ld \n",federationName.c_str(),federate);
00565     else if (type == FEDERATE_RESTORE_COMPLETE )
00566         printf("FEDERATE_RESTORE_COMPLETE : federationName %s : federatehandle %ld \n",federationName.c_str(),federate);
00567     else if (type == REQUEST_OBJECT_ATTRIBUTE_VALUE_UPDATE )
00568         printf("REQUEST_OBJECT_ATTRIBUTE_VALUE_UPDATE : \n");
00569     else
00570         printf(" type=%d :", type);
00571     printf(" date=%f: ", fed_time.getTime());
00572     if (exception == 0 )
00573         printf("NO_EXCEPTION ");
00574     else
00575         printf(" exception=%d: ",exception);
00576     printf(" reason=%s: ",(exceptionReason.empty()?"empty":exceptionReason.c_str()));
00577     printf(" objectClass=%ld: ", objectClass);
00578     printf(" interactionClass=%ld:\n", interactionClass);
00579     printf(" attribute=%ld:\n", attribute);
00580     printf(" parameter=%ld:\n", parameter);
00581     printf(" object=%ld:", object);
00582     printf(" handleArraySize=%d:", handleArraySize);
00583     printf(" space %ld:", space);
00584     printf(" dimension %ld:\n", dimension);
00585     // printf(" transportation %d:\n", transportation);
00586     // printf(" ordering %d:\n", ordering);
00587 }
00588 
00589 // ----------------------------------------------------------------------------
00590 void
00591 Message::displayvalueArray(char *titre)
00592 {
00593 printf("(%s) valueArray size=%d\n",titre,(int)valueArray.size());
00594 for (int i=0; i<(int)valueArray.size();i++)
00595    {
00596    printf("%d : length=%d : value=",i,(int)(valueArray[i].length()));
00597    for (int k=0; k<(int)valueArray[i].length() ;k++)
00598       {
00599       if (isprint(valueArray[i][k]) == 0 )
00600          {
00601          printf(" %x",valueArray[i][k]);
00602          }
00603       else
00604          {
00605          printf("%c",valueArray[i][k]);
00606          }
00607       }
00608 printf("\n");
00609    }
00610 }
00611 } // namespace certi

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