# NetworkMessage.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: NetworkMessage.cc,v 3.38 2008/09/21 16:46:25 gotthardp Exp $
    00020 // ----------------------------------------------------------------------------
    00021
    00022
    00023
    00024 #include "NetworkMessage.hh"
    00025 #include "PrettyDebug.hh"
    00026
    00027 #include <cstdlib>
    00028 #include <cstdio>
    00029 #include <cstring>
    00030 #include <cassert>
    00031
    00032 using std::vector ;
    00033
    00034 namespace certi {
    00035 static PrettyDebug G("GENDOC",__FILE__);
    00036
    00037 // ----------------------------------------------------------------------------
    00038 NetworkMessage::NetworkMessage()
    00039     : exception(e_NO_EXCEPTION),
    00040       type(NOT_USED),
    00041       _isDated(false),
    00042       _isLabelled(false),
    00043       _isTagged(false)
    00044 {
    00045     name               = std::string("NetworkMessage (generic)");
    00046     exceptionReason    = std::string("") ;
    00047     number             = 0 ;
    00048
    00049     federation         = 0 ;
    00050     federate           = 0 ;
    00051
    00052     federationName = std::string("") ;
    00053     federateName   = std::string("") ;
    00054
    00055     label          = std::string("") ;
    00056     FEDid          = std::string("") ;
    00057
    00058     bestEffortPeer = -1 ;
    00059     bestEffortAddress = 0 ;
    00060     numberOfRegulators = 0;
    00061     multicastAddress = 0;
    00062
    00063     date             = 0.0;
    00064
    00065     object           = 0 ;
    00066     objectClass      = 0 ;
    00067     interactionClass = 0 ;
    00068
    00069     handleArraySize  = 0 ;
    00070     valueArray.empty();
    00071
    00072 } /* end of NetworkMessage() */
    00073
    00074 NetworkMessage::~NetworkMessage() {
    00075
    00076 }
    00077
    00078 // ----------------------------------------------------------------------------
    00079 std::vector <AttributeValue_t>
    00080 NetworkMessage::getAttribValueArray()
    00081 {
    00082     std::vector <std::string> NewValueArray ;
    00083
    00084     NewValueArray.resize(handleArraySize) ;
    00085
    00086     for (int i = 0 ; i <handleArraySize ; i++)
    00087         NewValueArray[i] = valueArray[i] ;
    00088
    00089     return NewValueArray ;
    00090 }
    00091
    00092 // ----------------------------------------------------------------------------
    00093 std::vector <ParameterValue_t>
    00094 NetworkMessage::getParamValueArray()
    00095 {
    00096     std::vector <std::string> NewValueArray ;
    00097
    00098     NewValueArray.resize(handleArraySize) ;
    00099
    00100     for (int i = 0 ; i < handleArraySize ; i++)
    00101         NewValueArray[i] = valueArray[i] ;
    00102
    00103     return NewValueArray ;
    00104 }
    00105
    00106 // ----------------------------------------------------------------------------
    00107 void
    00108 NetworkMessage::removeAttribute(UShort Rank)
    00109 {
    00110     if (Rank >= valueArray.size())
    00111         throw RTIinternalError("Bad Rank while removing Nmessage attribute.");
    00112
    00113     handleArray.erase(handleArray.begin() + Rank);
    00114     valueArray.erase(valueArray.begin() + Rank);
    00115
    00116     handleArraySize -- ;
    00117 }
    00118
    00119 // ----------------------------------------------------------------------------
    00120 void
    00121 NetworkMessage::removeParameter(UShort Rank)
    00122 {
    00123     if (Rank >= valueArray.size())
    00124         throw RTIinternalError("Bad Rank while removing Nmessage parameter.");
    00125
    00126     handleArray.erase(handleArray.begin() + Rank);
    00127     valueArray.erase(valueArray.begin() + Rank);
    00128
    00129     handleArraySize -- ;
    00130 }
    00131
    00132 // ----------------------------------------------------------------------------
    00133 void
    00134 NetworkMessage::setAHS(const std::vector <AttributeHandle> &attr, int size)
    00135 {
    00136     handleArraySize = size ;
    00137     handleArray.resize(size) ;
    00138     for (int i = 0 ; i < size ; ++i) {
    00139         handleArray[i] = attr[i] ;
    00140     }
    00141 }
    00142 // ----------------------------------------------------------------------------
    00143 void
    00144 NetworkMessage::sizeValueArray(int size)
    00145 {
    00146 valueArray.resize(size) ;
    00147 }
    00148 // ----------------------------------------------------------------------------
    00149 void
    00150 NetworkMessage::displayValueArray(char *titre)
    00151 {
    00152     printf("(%s) valueArray size=%d\n",titre,(int)valueArray.size());
    00153     for (int i=0; i<(int)valueArray.size();i++)
    00154     {
    00155         printf("%d : length=%d : value=",i,(int)(valueArray[i].length()));
    00156
    00157         for(int k=0; k<(int)valueArray[i].length(); k++)
    00158             if (isprint(valueArray[i][k]) == 0 )
    00159                 printf(" %x",valueArray[i][k]);
    00160             else
    00161                 printf("%c",valueArray[i][k]);
    00162
    00163         printf("\n");
    00164     }
    00165 }
    00166
    00167 } // namespace certi
    00168
    00169 // $Id: NetworkMessage.cc,v 3.38 2008/09/21 16:46:25 gotthardp Exp $