certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi libHLA/libhla.hh libHLA/CMakeLists.txt li...


From: certi-cvs
Subject: [certi-cvs] certi libHLA/libhla.hh libHLA/CMakeLists.txt li...
Date: Sun, 28 Mar 2010 16:08:34 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      10/03/28 16:08:34

Modified files:
        libHLA         : libhla.hh CMakeLists.txt 
        libCERTI       : M_Classes.cc CMakeLists.txt ObjectClass.hh 
                         NM_Classes.cc NM_Classes.hh BasicMessage.hh 
                         M_Classes.hh 
        test/Billard   : Billard.cc CMakeLists.txt 
        test/utility   : CMakeLists.txt 
        RTIG           : CMakeLists.txt RTIG_processing.cc 
Added files:
        libHLA         : MessageBuffer.cc MessageBuffer.hh 
                         MessageBufferTests.cc 
Removed files:
        libCERTI       : MessageBuffer.cc MessageBuffer.hh 
        test/utility   : CertiUtilTests.cc 

Log message:
        Move MessageBuffer from libCERTI to libHLA.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libHLA/libhla.hh?cvsroot=certi&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/certi/libHLA/CMakeLists.txt?cvsroot=certi&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/certi/libHLA/MessageBuffer.cc?cvsroot=certi&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/certi/libHLA/MessageBuffer.hh?cvsroot=certi&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/certi/libHLA/MessageBufferTests.cc?cvsroot=certi&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/M_Classes.cc?cvsroot=certi&r1=3.9&r2=3.10
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/CMakeLists.txt?cvsroot=certi&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/ObjectClass.hh?cvsroot=certi&r1=3.53&r2=3.54
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/NM_Classes.cc?cvsroot=certi&r1=3.24&r2=3.25
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/NM_Classes.hh?cvsroot=certi&r1=3.18&r2=3.19
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/BasicMessage.hh?cvsroot=certi&r1=3.14&r2=3.15
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/M_Classes.hh?cvsroot=certi&r1=3.9&r2=3.10
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/MessageBuffer.cc?cvsroot=certi&r1=3.20&r2=0
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/MessageBuffer.hh?cvsroot=certi&r1=3.9&r2=0
http://cvs.savannah.gnu.org/viewcvs/certi/test/Billard/Billard.cc?cvsroot=certi&r1=3.44&r2=3.45
http://cvs.savannah.gnu.org/viewcvs/certi/test/Billard/CMakeLists.txt?cvsroot=certi&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/certi/test/utility/CMakeLists.txt?cvsroot=certi&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/certi/test/utility/CertiUtilTests.cc?cvsroot=certi&r1=1.18&r2=0
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/CMakeLists.txt?cvsroot=certi&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG_processing.cc?cvsroot=certi&r1=3.99&r2=3.100

Patches:
Index: libHLA/libhla.hh
===================================================================
RCS file: /sources/certi/certi/libHLA/libhla.hh,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libHLA/libhla.hh    28 Mar 2010 12:24:00 -0000      1.4
+++ libHLA/libhla.hh    28 Mar 2010 16:08:33 -0000      1.5
@@ -16,7 +16,7 @@
 // License along with this program ; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 //
-// $Id: libhla.hh,v 1.4 2010/03/28 12:24:00 erk Exp $
+// $Id: libhla.hh,v 1.5 2010/03/28 16:08:33 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef LIBHLA_HH_INCLUDED
@@ -53,6 +53,70 @@
 #include <string>
 #include <sstream>
 
+#define LIBHLA_UINT64_SWAP_LE_BE_CONSTANT(val) ((uint64_t) ( \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x00000000000000ffU)) << 56) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x000000000000ff00U)) << 40) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x0000000000ff0000U)) << 24) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x00000000ff000000U)) <<  8) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x000000ff00000000U)) >>  8) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x0000ff0000000000U)) >> 24) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x00ff000000000000U)) >> 40) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0xff00000000000000U)) >> 56)))
+
+#ifdef HOST_IS_BIG_ENDIAN
+  #define LIBHLA_UINT64_SWAP_LE_BE(val) 
(LIBHLA_UINT64_SWAP_LE_BE_CONSTANT(val))
+  #define LIBHLA_UINT64_TO_BE(val)        (val)
+  #define LIBHLA_UINT64_TO_LE(val)        (LIBHLA_UINT64_SWAP_LE_BE (val))
+#else
+  #define LIBHLA_UINT64_SWAP_LE_BE(val) 
(LIBHLA_UINT64_SWAP_LE_BE_CONSTANT(val))
+  #define LIBHLA_UINT64_TO_BE(val)        (LIBHLA_UINT64_SWAP_LE_BE (val))
+  #define LIBHLA_UINT64_TO_LE(val)      (val)
+#endif
+
+#define LIBHLA_UINT64_FROM_BE(val)                 (LIBHLA_UINT64_TO_BE(val))
+#define LIBHLA_UINT64_FROM_LE(val)                 (LIBHLA_UINT64_TO_LE(val))
+#define LIBHLA_ENCODE_DOUBLE_TO_UINT64BE(val)    (LIBHLA_UINT64_TO_BE   
(*(uint64_t*)(val)))
+#define LIBHLA_DECODE_DOUBLE_FROM_UINT64BE(val)  (LIBHLA_UINT64_FROM_BE 
(*(uint64_t*)(val)))
+
+/*
+ * Basic bit swapping functions
+ */
+#define LIBHLA_UINT16_SWAP_BYTES(val)  ((uint16_t) ( \
+    (((uint16_t) (val) & (uint16_t) 0x00ffU) << 8) |  \
+    (((uint16_t) (val) & (uint16_t) 0xff00U) >> 8)))
+
+#define LIBHLA_UINT32_SWAP_BYTES(val)  ((uint32_t) (     \
+    (((uint32_t) (val) & (uint32_t) 0x000000ffU) << 24) | \
+    (((uint32_t) (val) & (uint32_t) 0x0000ff00U) <<  8) | \
+    (((uint32_t) (val) & (uint32_t) 0x00ff0000U) >>  8) | \
+    (((uint32_t) (val) & (uint32_t) 0xff000000U) >> 24)))
+
+#define LIBHLA_UINT64_SWAP_BYTES(val)  ((uint64_t) (                   \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x00000000000000ffU)) << 56) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x000000000000ff00U)) << 40) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x0000000000ff0000U)) << 24) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x00000000ff000000U)) <<  8) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x000000ff00000000U)) >>  8) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x0000ff0000000000U)) >> 24) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0x00ff000000000000U)) >> 40) | \
+      (((uint64_t) (val) &                                             \
+       (uint64_t) LIBHLA_INT64_CONSTANT(0xff00000000000000U)) >> 56)))
+
 /**
  * @defgroup libHLA The libHLA library.
  * @ingroup CERTI_Libraries

Index: libHLA/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libHLA/CMakeLists.txt,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- libHLA/CMakeLists.txt       28 Mar 2010 13:51:29 -0000      1.10
+++ libHLA/CMakeLists.txt       28 Mar 2010 16:08:33 -0000      1.11
@@ -29,6 +29,22 @@
 SOURCE_GROUP("Source Files\\Alloc" FILES ${LIBHLA_ALLOC_SRCS})
 ENDIF (NOT WIN32)
 
+SET(LIBHLA_MB_SRCS MessageBuffer.cc MessageBuffer.hh)
+LIST(APPEND LIBHLA_EXPORTED_INCLUDES MessageBuffer.hh)
+
+SET(LIBHLA_MB_TEST_SRCS MessageBufferTests.cc)
+
+ADD_EXECUTABLE(MessageBufferTests ${LIBHLA_MB_TEST_SRCS})
+
+TARGET_LINK_LIBRARIES(MessageBufferTests HLA)
+
+INSTALL(TARGETS MessageBufferTests
+    RUNTIME DESTINATION bin
+    LIBRARY DESTINATION lib
+    ARCHIVE DESTINATION lib)
+
+ADD_TEST(LibHLA_MB_Tests MessageBufferTests)
+
 SET(LIBHLA_CLOCK_SRCS 
     Clock.cc
     ClockFactory.cc)
@@ -88,6 +104,7 @@
     ${LIBHLA_TYPES1516_SRCS}    
     ${LIBHLA_HASH_SRCS}    
     ${LIBHLA_ALLOC_SRCS}
+    ${LIBHLA_MB_SRCS}
     ${LIBHLA_CLOCK_SRCS}
     ${LIBHLA_IPC_SRCS}
     ${LIBHLA_EXPORTED_INCLUDES}

Index: libCERTI/M_Classes.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/M_Classes.cc,v
retrieving revision 3.9
retrieving revision 3.10
diff -u -b -r3.9 -r3.10
--- libCERTI/M_Classes.cc       23 Mar 2010 08:12:39 -0000      3.9
+++ libCERTI/M_Classes.cc       28 Mar 2010 16:08:33 -0000      3.10
@@ -1,4 +1,4 @@
-// Generated on 2010 March Tue, 23 at 08:59:23 by the CERTI message generator
+// Generated on 2010 March Sun, 28 at 18:01:32 by the CERTI message generator
 #include <vector>
 #include <string>
 #include "M_Classes.hh"
@@ -4344,12 +4344,12 @@
    M_Tick_Request_Stop::~M_Tick_Request_Stop() {
    }
 
-   Message* M_Factory::create(M_Type type) throw (RTIinternalError) {
+   Message* M_Factory::create(M_Type type) throw (NetworkError, NetworkSignal) 
{
       Message* msg = NULL;
 
       switch (type) {
          case Message::NOT_USED:
-            throw RTIinternalError("NOT_USED message type should not be 
used!!");
+            throw NetworkError("NOT_USED message type should not be used!!");
             break;
          case Message::OPEN_CONNEXION:
             msg = new M_Open_Connexion();
@@ -4784,13 +4784,13 @@
             msg = new M_Tick_Request_Stop();
             break;
          case Message::LAST:
-            throw RTIinternalError("LAST message type should not be used!!");
+            throw NetworkError("LAST message type should not be used!!");
             break;
       } // end if switch (type)
       return msg;
    } /* end of M_Factory::create */
 
-   Message* M_Factory::receive(MStreamType stream) throw (RTIinternalError) {
+   Message* M_Factory::receive(MStreamType stream) throw (NetworkError, 
NetworkSignal) {
       // FIXME This is not thread safe
       static MessageBuffer msgBuffer;
       Message  msgGen;

Index: libCERTI/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libCERTI/CMakeLists.txt,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- libCERTI/CMakeLists.txt     28 Mar 2010 11:42:34 -0000      1.33
+++ libCERTI/CMakeLists.txt     28 Mar 2010 16:08:33 -0000      1.34
@@ -1,3 +1,5 @@
+# LibCERTI now depends on libHLA
+include_directories(${CERTI_SOURCE_DIR}/libHLA)
 
 ##################################################################
 # Lib CERTI
@@ -73,7 +75,6 @@
 AuditFile.cc AuditFile.hh
 AuditLine.cc AuditLine.hh
 BasicMessage.cc BasicMessage.hh
-MessageBuffer.cc MessageBuffer.hh
 M_Classes.cc M_Classes.hh
 Message.cc Message_RW.cc Message.hh 
 NetworkMessage.cc NetworkMessage_RW.cc NetworkMessage.hh
@@ -100,7 +101,6 @@
 )
 
 if (WIN32)
-    include_directories(${CERTI_SOURCE_DIR}/libHLA)
     ADD_DEFINITIONS(-DDEBUG)
 
     SET(CERTI_SOCKET_SHM_SRC
@@ -110,7 +110,6 @@
 
     LIST(APPEND CERTI_SOCKET_SRCS ${CERTI_SOCKET_SHM_SRC})
 else(WIN32)
-    include_directories(${CERTI_SOURCE_DIR}/libHLA)
     ADD_DEFINITIONS(-DDEBUG)
 
     SET(CERTI_SOCKET_SHM_SRC

Index: libCERTI/ObjectClass.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/ObjectClass.hh,v
retrieving revision 3.53
retrieving revision 3.54
diff -u -b -r3.53 -r3.54
--- libCERTI/ObjectClass.hh     19 Mar 2010 13:54:03 -0000      3.53
+++ libCERTI/ObjectClass.hh     28 Mar 2010 16:08:33 -0000      3.54
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: ObjectClass.hh,v 3.53 2010/03/19 13:54:03 erk Exp $
+// $Id: ObjectClass.hh,v 3.54 2010/03/28 16:08:33 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef _CERTI_OBJECT_CLASS_HH
@@ -336,11 +336,11 @@
         */
        ObjectClassSet*   subClasses;
        /* The message buffer used to send Network messages */
-       MessageBuffer NM_msgBufSend;
+       libhla::MessageBuffer NM_msgBufSend;
 };
 
 } // namespace certi
 
 #endif // _CERTI_OBJECT_CLASS_HH
 
-// $Id: ObjectClass.hh,v 3.53 2010/03/19 13:54:03 erk Exp $
+// $Id: ObjectClass.hh,v 3.54 2010/03/28 16:08:33 erk Exp $

Index: libCERTI/NM_Classes.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/NM_Classes.cc,v
retrieving revision 3.24
retrieving revision 3.25
diff -u -b -r3.24 -r3.25
--- libCERTI/NM_Classes.cc      23 Mar 2010 08:12:39 -0000      3.24
+++ libCERTI/NM_Classes.cc      28 Mar 2010 16:08:33 -0000      3.25
@@ -1,4 +1,4 @@
-// Generated on 2010 March Tue, 23 at 08:56:31 by the CERTI message generator
+// Generated on 2010 March Sun, 28 at 18:01:32 by the CERTI message generator
 #include <vector>
 #include <string>
 #include "NM_Classes.hh"
@@ -2629,12 +2629,12 @@
       out << "(opt) tag =" << tag << " "       << std::endl;
       out << "[New_NetworkMessage -End]" << std::endl;   }
 
-   NetworkMessage* NM_Factory::create(NM_Type type) throw (RTIinternalError) {
+   NetworkMessage* NM_Factory::create(NM_Type type) throw (NetworkError, 
NetworkSignal) {
       NetworkMessage* msg = NULL;
 
       switch (type) {
          case NetworkMessage::NOT_USED:
-            throw RTIinternalError("NOT_USED message type should not be 
used!!");
+            throw NetworkError("NOT_USED message type should not be used!!");
             break;
          case NetworkMessage::CLOSE_CONNEXION:
             msg = new NM_Close_Connexion();
@@ -2907,13 +2907,13 @@
             msg = new NM_Stop_Registration_For_Object_Class();
             break;
          case NetworkMessage::LAST:
-            throw RTIinternalError("LAST message type should not be used!!");
+            throw NetworkError("LAST message type should not be used!!");
             break;
       } // end if switch (type)
       return msg;
    } /* end of NM_Factory::create */
 
-   NetworkMessage* NM_Factory::receive(NMStreamType stream) throw 
(RTIinternalError) {
+   NetworkMessage* NM_Factory::receive(NMStreamType stream) throw 
(NetworkError, NetworkSignal) {
       // FIXME This is not thread safe
       static MessageBuffer msgBuffer;
       NetworkMessage  msgGen;

Index: libCERTI/NM_Classes.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/NM_Classes.hh,v
retrieving revision 3.18
retrieving revision 3.19
diff -u -b -r3.18 -r3.19
--- libCERTI/NM_Classes.hh      23 Mar 2010 08:12:39 -0000      3.18
+++ libCERTI/NM_Classes.hh      28 Mar 2010 16:08:33 -0000      3.19
@@ -1,4 +1,4 @@
-// Generated on 2010 March Tue, 23 at 08:56:33 by the CERTI message generator
+// Generated on 2010 March Sun, 28 at 18:01:32 by the CERTI message generator
 #ifndef NM_CLASSES_HH
 #define NM_CLASSES_HH
 // ****-**** Global System includes ****-****
@@ -1889,8 +1889,8 @@
 
    class CERTI_EXPORT NM_Factory {
       public:
-         static NetworkMessage* create(NM_Type type) throw (RTIinternalError);
-         static NetworkMessage* receive(NMStreamType stream) throw 
(RTIinternalError);
+         static NetworkMessage* create(NM_Type type) throw (NetworkError, 
NetworkSignal);
+         static NetworkMessage* receive(NMStreamType stream) throw 
(NetworkError, NetworkSignal);
       protected:
       private:
    };

Index: libCERTI/BasicMessage.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/BasicMessage.hh,v
retrieving revision 3.14
retrieving revision 3.15
diff -u -b -r3.14 -r3.15
--- libCERTI/BasicMessage.hh    27 Feb 2010 16:53:36 -0000      3.14
+++ libCERTI/BasicMessage.hh    28 Mar 2010 16:08:33 -0000      3.15
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: BasicMessage.hh,v 3.14 2010/02/27 16:53:36 erk Exp $
+// $Id: BasicMessage.hh,v 3.15 2010/03/28 16:08:33 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef LIBCERTI_BASIC_MESSAGE
@@ -27,6 +27,7 @@
 
 
 #include "MessageBuffer.hh"
+using libhla::MessageBuffer;
 #include "FedTimeD.hh"
 #include "BaseRegion.hh"
 #include "Extent.hh"
@@ -162,4 +163,4 @@
 
 #endif // LIBCERTI_BASIC_MESSAGE
 
-// $Id: BasicMessage.hh,v 3.14 2010/02/27 16:53:36 erk Exp $
+// $Id: BasicMessage.hh,v 3.15 2010/03/28 16:08:33 erk Exp $

Index: libCERTI/M_Classes.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/M_Classes.hh,v
retrieving revision 3.9
retrieving revision 3.10
diff -u -b -r3.9 -r3.10
--- libCERTI/M_Classes.hh       23 Mar 2010 08:12:39 -0000      3.9
+++ libCERTI/M_Classes.hh       28 Mar 2010 16:08:33 -0000      3.10
@@ -1,4 +1,4 @@
-// Generated on 2010 March Tue, 23 at 08:59:14 by the CERTI message generator
+// Generated on 2010 March Sun, 28 at 18:01:32 by the CERTI message generator
 #ifndef M_CLASSES_HH
 #define M_CLASSES_HH
 // ****-**** Global System includes ****-****
@@ -2900,8 +2900,8 @@
 
    class CERTI_EXPORT M_Factory {
       public:
-         static Message* create(M_Type type) throw (RTIinternalError);
-         static Message* receive(MStreamType stream) throw (RTIinternalError);
+         static Message* create(M_Type type) throw (NetworkError, 
NetworkSignal);
+         static Message* receive(MStreamType stream) throw (NetworkError, 
NetworkSignal);
       protected:
       private:
    };

Index: test/Billard/Billard.cc
===================================================================
RCS file: /sources/certi/certi/test/Billard/Billard.cc,v
retrieving revision 3.44
retrieving revision 3.45
diff -u -b -r3.44 -r3.45
--- test/Billard/Billard.cc     19 Mar 2010 13:54:03 -0000      3.44
+++ test/Billard/Billard.cc     28 Mar 2010 16:08:34 -0000      3.45
@@ -638,7 +638,7 @@
 Billard::sendInteraction(double dx, double dy, const RTI::FedTime& 
InteractionTime,
                         RTI::ObjectHandle id)
 {
-    certi::MessageBuffer buffer;
+    libhla::MessageBuffer buffer;
     RTI::ParameterHandleValuePairSet *parameterSet=NULL ;
 
     parameterSet = RTI::ParameterSetFactory::create(3);
@@ -700,7 +700,7 @@
 Billard::sendUpdate(double x, double y, int color, const RTI::FedTime& 
UpdateTime,
                    RTI::ObjectHandle id)
 {    
-    certi::MessageBuffer buffer;
+    libhla::MessageBuffer buffer;
     RTI::AttributeHandleValuePairSet *attributeSet ;
 
     attributeSet = RTI::AttributeSetFactory::create(3);
@@ -844,7 +844,7 @@
            RTI::InvalidFederationTime,
            RTI::FederateInternalError)
 {
-       certi::MessageBuffer buffer;
+       libhla::MessageBuffer buffer;
     RTI::ULong valueLength ;
     int dx1 = 0 ;
     int dy1 = 0 ;
@@ -915,7 +915,7 @@
 {
     D.Out(pdTrace, "reflectAttributeValues with time");
 
-    certi::MessageBuffer buffer;
+    libhla::MessageBuffer buffer;
     float x1 = 0 ;
     float y1 = 0 ;
 
@@ -981,7 +981,7 @@
 
     float x1 = 0 ;
     float y1 = 0 ;
-    certi::MessageBuffer buffer;
+    libhla::MessageBuffer buffer;
 
     RTI::ULong valueLength ;   
 

Index: test/Billard/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/test/Billard/CMakeLists.txt,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- test/Billard/CMakeLists.txt 7 Dec 2008 20:16:17 -0000       1.8
+++ test/Billard/CMakeLists.txt 28 Mar 2010 16:08:34 -0000      1.9
@@ -2,6 +2,7 @@
   ${CMAKE_SOURCE_DIR}/libCERTI 
   ${CMAKE_SOURCE_DIR}/test/libgraphc
   )
+include_directories(${CERTI_SOURCE_DIR}/libHLA)
 
 IF (WIN32)
 ADD_DEFINITIONS(-DHAVE_STRING_H)

Index: test/utility/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/test/utility/CMakeLists.txt,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- test/utility/CMakeLists.txt 28 Mar 2010 11:42:35 -0000      1.6
+++ test/utility/CMakeLists.txt 28 Mar 2010 16:08:34 -0000      1.7
@@ -3,21 +3,6 @@
   ${CMAKE_SOURCE_DIR}/libHLA
   )
 
-SET(CertiUtil_SRCS
-  CertiUtilTests.cc 
-  )
-
-ADD_EXECUTABLE(CertiUtilTests ${CertiUtil_SRCS})
-
-TARGET_LINK_LIBRARIES(CertiUtilTests CERTI RTI FedTime)
-
-INSTALL(TARGETS CertiUtilTests
-    RUNTIME DESTINATION bin
-    LIBRARY DESTINATION lib
-    ARCHIVE DESTINATION lib)
-
-ADD_TEST(CertiUtilTests CertiUtilTests)
-
 ADD_EXECUTABLE(CertiProcessus_A Main_SocketSHM.cc SharedStruct.hh)
 IF(WIN32)
     TARGET_LINK_LIBRARIES(CertiProcessus_A CERTI HLA)

Index: RTIG/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/RTIG/CMakeLists.txt,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- RTIG/CMakeLists.txt 31 Aug 2009 14:18:55 -0000      1.7
+++ RTIG/CMakeLists.txt 28 Mar 2010 16:08:34 -0000      1.8
@@ -1,3 +1,4 @@
+include_directories(${CERTI_SOURCE_DIR}/libHLA)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/libCERTI)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/libRTI)
 

Index: RTIG/RTIG_processing.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG_processing.cc,v
retrieving revision 3.99
retrieving revision 3.100
diff -u -b -r3.99 -r3.100
--- RTIG/RTIG_processing.cc     23 Mar 2010 13:15:34 -0000      3.99
+++ RTIG/RTIG_processing.cc     28 Mar 2010 16:08:34 -0000      3.100
@@ -18,7 +18,7 @@
 // along with this program ; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 //
-// $Id: RTIG_processing.cc,v 3.99 2010/03/23 13:15:34 erk Exp $
+// $Id: RTIG_processing.cc,v 3.100 2010/03/28 16:08:34 erk Exp $
 // ----------------------------------------------------------------------------
 
 #include <config.h>
@@ -251,6 +251,7 @@
 {
        NM_Destroy_Federation_Execution rep ;
 
+       req->show(std::cerr);
        std::string federation = req->getFederationName();
 
        G.Out(pdGendoc,"enter RTIG::processDestroyFederation");
@@ -292,6 +293,7 @@
        }
        G.Out(pdGendoc,"processDestroyFederation===>write DFE to RTIA");
 
+       rep.show(std::cerr);
        rep.send(link,NM_msgBufSend);
 
        G.Out(pdGendoc,"END ** DESTROY FEDERATION SERVICE **");
@@ -1466,4 +1468,4 @@
 
 }} // namespace certi/rtig
 
-// $Id: RTIG_processing.cc,v 3.99 2010/03/23 13:15:34 erk Exp $
+// $Id: RTIG_processing.cc,v 3.100 2010/03/28 16:08:34 erk Exp $

Index: libHLA/MessageBuffer.cc
===================================================================
RCS file: libHLA/MessageBuffer.cc
diff -N libHLA/MessageBuffer.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ libHLA/MessageBuffer.cc     28 Mar 2010 16:08:33 -0000      1.1
@@ -0,0 +1,479 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002-2005 ONERA
+//
+// This program is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+//
+// ----------------------------------------------------------------------------
+
+#include "MessageBuffer.hh"
+#include <cassert>
+#include <iomanip>
+#include <cstring>
+#include <cstdio>
+
+namespace libhla {
+
+const bool
+MessageBuffer::HostIsBigEndian() {
+#ifdef HOST_IS_BIG_ENDIAN
+       return true;
+#else
+       return false;
+#endif
+}
+
+const bool
+MessageBuffer::HostIsLittleEndian() {
+#ifdef HOST_IS_BIG_ENDIAN
+       return false;
+#else
+       return true;
+#endif
+}
+
+void
+MessageBuffer::show(const void* data, uint32_t n) {
+   uint32_t i;
+   const uint8_t* u8data = reinterpret_cast<const uint8_t*>(data);
+   for (i=0;i<n;++i) {
+          if ((0==(i%2))&&(i>0)) {
+                          printf(" ");
+          }
+          printf("%02X",u8data[i]);
+   }
+}
+
+const uint8_t MessageBuffer::reservedBytes = 5;
+
+void MessageBuffer::initialize() {
+       buffer = NULL;
+       bufferMaxSize = DEFAULT_MESSAGE_BUFFER_SIZE;
+       bufferHasMyEndianness = true;
+       writeOffset  = reservedBytes;
+       readOffset   = reservedBytes;
+} /* end of MessageBuffer::initialize() */
+
+MessageBuffer::MessageBuffer() {
+       initialize();
+       reallocate(DEFAULT_MESSAGE_BUFFER_SIZE);
+       memset(buffer,0,bufferMaxSize);
+} /* end of MessageBuffer::MessageBuffer() */
+
+MessageBuffer::MessageBuffer(uint32_t n) {
+       initialize();
+       reallocate(n);
+       memset(buffer,0,bufferMaxSize);
+} /* end of MessageBuffer::MessageBuffer(uint32_t) */
+
+/*
+ * FIXME we may put a COMPILED FLAG here in order
+ * to prevent reallocation beside the first one (when buffer==NULL)
+ */
+void MessageBuffer::reallocate(uint32_t n) {
+       uint8_t* oldbuf = buffer;
+       /* (re)allocation is done iff
+        *  - buffer is NULL (never allocated)
+        *  or
+        *  - requested size exceed current bufferMaxSize
+        */
+       if ((NULL==buffer) || (n > bufferMaxSize)) {
+               // FIXME should try/catch for alloc error
+               // ands wrap-up inside RTIinternalError
+               buffer = new uint8_t[n];
+               bufferMaxSize = n;
+               /*
+                * If oldbuf wasn't null then copy
+                * oldbuf in the new buf
+                * the writeOffset should be valid.
+                */
+               if (NULL!=oldbuf) {
+                       memcpy(buffer, oldbuf, writeOffset);
+                       delete[] oldbuf;
+                       oldbuf = NULL;
+               } else {
+                       updateReservedBytes();
+               }
+       }
+} /* end of MessageBuffer::MessageBuffer(uint32_t) */
+
+MessageBuffer::~MessageBuffer() {
+       if (NULL!=buffer) {
+               delete[] buffer;
+       }
+} /* end of MessageBuffer::~MessageBuffer() */
+
+uint32_t MessageBuffer::size() const {
+       return writeOffset;
+}
+
+uint32_t MessageBuffer::maxSize() const {
+       return bufferMaxSize;
+}
+
+void MessageBuffer::assumeBufferIsBigEndian() {
+       this->bufferHasMyEndianness = HostIsBigEndian();
+       buffer[0] = 0x01;
+} /* end of MessageBuffer::assumeBufferIsBigEndian() */
+
+void MessageBuffer::assumeBufferIsLittleEndian() {
+       this->bufferHasMyEndianness = HostIsLittleEndian();
+       buffer[0] = 0x00;
+} /* end of MessageBuffer::assumeBufferIsLittleEndian() */
+
+void MessageBuffer::reset() {
+       bufferHasMyEndianness = true;
+       writeOffset           = reservedBytes;
+       readOffset            = reservedBytes;
+       updateReservedBytes();
+} /* MessageBuffer::resetBuffer() */
+
+uint32_t MessageBuffer::resize(uint32_t newSize) {
+       reallocate(newSize);
+       return bufferMaxSize;
+}
+
+void MessageBuffer::assumeSize(uint32_t size) {
+       /* This is done in order to overflow
+        * buffer max size but this may well be
+        * an error (FIXME should throw an exception ?)
+        */
+       if (size <= bufferMaxSize) {
+               writeOffset       = size;
+       } else {
+           writeOffset       = bufferMaxSize;
+       }
+}
+
+void MessageBuffer::assumeSizeFromReservedBytes() {
+       uint32_t toBeAssumedSize;
+       /* verify endianity from reserved byte 0 */
+       if (buffer[0]==0x01) {
+               assumeBufferIsBigEndian();
+       } else {
+               assumeBufferIsLittleEndian();
+       }
+       /* read size from reserved bytes 1..4 */
+       readOffset = 1;
+       toBeAssumedSize = this->read_uint32();
+       /* reallocation may be needed */
+       reallocate(toBeAssumedSize);
+       assumeSize(toBeAssumedSize);
+} /* end of assumeSizeFromReservedBytes */
+
+void MessageBuffer::setSizeInReservedBytes(uint32_t n) {
+       uint32_t oldWR_Offset;
+       /* backup write Offset */
+       oldWR_Offset = writeOffset;
+       /* update size in reserved bytes */
+       writeOffset  = 1;
+       //std::cerr  << "setSizeInReservedBytes(" << n << ")" << std::endl;
+       write_uint32(n);
+       /* restore writeOffset */
+       writeOffset  = oldWR_Offset;
+} /* end of setSizeInReservedBytes */
+
+int32_t MessageBuffer::write_uint8s(const uint8_t* data, uint32_t n) {
+       //std::cerr  << "write_uint8s(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+       if (n >= (bufferMaxSize - writeOffset)) {
+               /* reallocate buffer on-demand */
+               reallocate(bufferMaxSize+ (n-(bufferMaxSize-writeOffset))
+                               + DEFAULT_MESSAGE_BUFFER_SIZE);
+       }
+       /* copy data */
+       memcpy(buffer+writeOffset, data, n);
+       /* update write offset */
+       writeOffset += n;
+       return (writeOffset-n);
+} /* end of MessageBuffer::write_uint8s(uint8_t*, uint32_t) */
+
+int32_t MessageBuffer::read_uint8s(uint8_t* data, uint32_t n) {
+       if (n + readOffset > writeOffset) {
+               throw MessageBufferError(stringize()
+                       << "read_uint8s::invalid read of size <" << n
+                       << "> inside a buffer of readable size <"
+                       << (int32_t)writeOffset-readOffset << "> (writeOffset="
+                       << writeOffset << ",readOffset="<<readOffset <<").");
+       }
+
+       memcpy(data, buffer+readOffset, n);
+       readOffset += n;
+       //std::cerr << "read_uint8s(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+       return (readOffset-n);
+} /* end of MessageBuffer::read_uint8s(uint8_t*, uint32_t) */
+
+int32_t MessageBuffer::write_uint16s(const uint16_t* data, uint32_t n) {
+       uint32_t i;
+       uint16_t an_uint16;
+       //std::cerr  << "write_uint16s(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+       
+       if ((2*n) >= (bufferMaxSize - writeOffset)) {
+               /* reallocate buffer on-demand */
+               reallocate(bufferMaxSize+ (2*n)-(bufferMaxSize - writeOffset)
+                               + DEFAULT_MESSAGE_BUFFER_SIZE);
+       }
+
+       /* do not swap byte if it is not necessary */
+       if (bufferHasMyEndianness) {
+               memcpy(buffer+writeOffset, data, 2*n);
+               writeOffset += 2*n;
+       } else {
+               for (i=0; i<n; ++i) {
+                       an_uint16 = LIBHLA_UINT16_SWAP_BYTES(data[i]);
+                       memcpy(buffer+writeOffset, &an_uint16, 2);
+                       writeOffset += 2;
+               }
+       }
+       return (writeOffset-2*n);
+} /* end of MessageBuffer::write_uint16s(uint16_t*, uint32_t) */
+
+int32_t MessageBuffer::read_uint16s(uint16_t* data, uint32_t n) {
+       uint32_t i;
+       uint16_t an_uint16;
+
+       if (2*n + readOffset > writeOffset) {
+               throw MessageBufferError(stringize()
+                       << "read_uint16s::invalid read of size <" << 2*n
+                       << "> inside a buffer of readable size <"
+                       << (int32_t)writeOffset-readOffset << "> (writeOffset="
+                       << writeOffset << ",readOffset="<<readOffset <<").");
+       }
+
+       /* do not swap byte if it is not necessary */
+       if (bufferHasMyEndianness) {
+               memcpy(data, buffer+readOffset, 2*n);
+               readOffset += 2*n;
+       } else {
+               for (i=0; i<n; ++i) {
+                       memcpy(&an_uint16, buffer+readOffset,2);
+                       data[i] = LIBHLA_UINT16_SWAP_BYTES(an_uint16);
+                       readOffset += 2;
+               }
+       }
+       
+       //std::cerr  << "read_uint16s(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+       return (readOffset-2*n);
+} /* end of MessageBuffer::read_uint16s(uint16_t*, uint32_t) */
+
+int32_t MessageBuffer::write_uint32s(const uint32_t* data, uint32_t n) {
+       uint32_t i;
+       uint32_t an_uint32;
+       //std::cerr  << "write_uint32s(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+       
+       if ((4*n) >= (bufferMaxSize - writeOffset)) {
+               /* reallocate buffer on-demand */
+               reallocate(bufferMaxSize+ (4*n)-(bufferMaxSize - writeOffset)
+                               + DEFAULT_MESSAGE_BUFFER_SIZE);
+       }
+
+       /* do not swap byte if it is not necessary */
+       if (bufferHasMyEndianness) {
+               memcpy(buffer+writeOffset, data, 4*n);
+               writeOffset += 4*n;
+       } else {
+               for (i=0; i<n; ++i) {
+                       an_uint32 = LIBHLA_UINT32_SWAP_BYTES(data[i]);
+                       memcpy(buffer+writeOffset,&an_uint32,4);
+                       writeOffset += 4;
+               }
+       }
+       return (writeOffset-4*n);
+} /* end of write_uint32s */
+
+int32_t MessageBuffer::read_uint32s(uint32_t* data, uint32_t n) {
+       uint32_t i;
+       uint32_t an_uint32;
+
+       if (4*n + readOffset > writeOffset) {
+               throw MessageBufferError(stringize()
+                       << "read_uint32s::invalid read of size <" << 4*n
+                       << "> inside a buffer of readable size <"
+                       << (int32_t)writeOffset-readOffset << "> (writeOffset="
+                       << writeOffset << ",readOffset="<<readOffset <<").");
+       }
+
+       /* do not swap byte if it is not necessary */
+       if (bufferHasMyEndianness) {
+               memcpy(data, buffer+readOffset, 4*n);
+               readOffset += 4*n;
+       } else {
+               for (i=0; i<n; ++i) {
+                       memcpy(&an_uint32,buffer+readOffset,4);
+                       data[i] = LIBHLA_UINT32_SWAP_BYTES(an_uint32);
+                       readOffset += 4;
+               }
+       }
+       //std::cerr  << "read_uint32s(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+       return (readOffset-4*n);
+} /* end of read_uint32s */
+
+int32_t MessageBuffer::write_uint64s(const uint64_t* data, uint32_t n) {
+       uint32_t i;
+       union deux32 {
+               uint32_t    ui32[2];
+               uint64_t    ui64;
+       } a_deux32;
+       uint32_t an_uint32;
+
+       //std::cerr  << "write_uint64s(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+
+       if ((8*n) >= (bufferMaxSize - writeOffset)) {
+               /* reallocate buffer on-demand */
+               reallocate(bufferMaxSize+ (8*n)-(bufferMaxSize - writeOffset)
+                               + DEFAULT_MESSAGE_BUFFER_SIZE);
+       }
+
+       /* do not swap byte if it is not necessary */
+       if (bufferHasMyEndianness) {
+               memcpy(buffer+writeOffset, data, 8*n);
+               writeOffset += 8*n;
+       } else {
+               for (i=0; i<n; ++i) {
+                       a_deux32.ui64 = data[i];
+                       an_uint32 = LIBHLA_UINT32_SWAP_BYTES(a_deux32.ui32[1]);
+                       memcpy(buffer+writeOffset,&an_uint32,4);
+                       writeOffset += 4;
+                       an_uint32 = LIBHLA_UINT32_SWAP_BYTES(a_deux32.ui32[0]);
+                       memcpy(buffer+writeOffset,&an_uint32,4);
+                       writeOffset += 4;
+               }
+       }
+       return (writeOffset-8*n);
+} /* end of write_uint64s */
+
+int32_t MessageBuffer::read_uint64s(uint64_t* data, uint32_t n) {
+       uint32_t i;
+       union deux32 {
+                       uint32_t    ui32[2];
+                       uint64_t    ui64;
+       } a_deux32;
+       uint32_t an_uint32;
+       //std::cerr  << "read_uint64s(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+
+       if (8*n + readOffset > writeOffset) {
+               throw MessageBufferError(stringize()
+                       << "read_uint64s::invalid read of size <" << 4*n
+                       << "> inside a buffer of readable size <"
+                       << (int32_t)writeOffset-readOffset << "> (writeOffset="
+                       << writeOffset << ",readOffset="<<readOffset <<").");
+       }
+
+       /* do not swap byte if it is not necessary */
+       if (bufferHasMyEndianness) {
+               memcpy(data, buffer+readOffset, 8*n);
+               readOffset += 8*n;
+       } else {
+               for (i=0; i<n; ++i) {
+                       memcpy(&an_uint32,buffer+readOffset,4);
+                       a_deux32.ui32[1] = LIBHLA_UINT32_SWAP_BYTES(an_uint32);
+                       readOffset += 4;
+
+                       memcpy(&an_uint32,buffer+readOffset,4);
+                       a_deux32.ui32[0] = LIBHLA_UINT32_SWAP_BYTES(an_uint32);
+                       readOffset += 4;
+
+                       data[i] = a_deux32.ui64;
+               }
+       }
+       return (readOffset-8*n);
+}
+
+int32_t MessageBuffer::write_floats(const float* data, uint32_t n) {
+       const uint32_t* data32;
+        //std::cerr << "write_floats(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+       data32 = reinterpret_cast<const uint32_t*>(data);       
+       return write_uint32s(data32,n);
+}
+
+int32_t MessageBuffer::read_floats(float* data, uint32_t n) {
+       uint32_t* data32;
+        //std::cerr << "read_floats(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+       data32 = reinterpret_cast<uint32_t*>(data);
+       return read_uint32s(data32,n);
+}
+
+int32_t MessageBuffer::write_doubles(const double* data, uint32_t n) {
+       const uint64_t* data64;
+        //std::cerr << "write_doubles(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+       data64 = reinterpret_cast<const uint64_t*>(data);       
+       return write_uint64s(data64,n); 
+}
+
+int32_t MessageBuffer::read_doubles(double* data, uint32_t n) {
+       uint64_t* data64;
+       //std::cerr << "read_doubles(" << data << " = [" << (n ? data[0] : 0) 
<<" ...], " << n << ")" << std::endl;
+       data64 = reinterpret_cast<uint64_t*>(data);
+       return read_uint64s(data64,n);
+}
+
+int32_t
+MessageBuffer::write_string(const std::string& str) {
+    write_int32(str.length());
+    return write_chars(str.data(),str.length());
+} /* end of write_string */
+
+std::string
+MessageBuffer::read_string() {
+    std::string retval;
+    read_string(retval);
+    return retval;
+} /* end of read_string */
+
+void
+MessageBuffer::read_string(std::string& s)
+{
+    int32_t len = read_int32();
+
+    if (len + readOffset > writeOffset) {
+        throw MessageBufferError(stringize()
+            << "read_string::invalid read of size <" << len
+            << "> inside a buffer of readable size <"
+            << (int32_t)writeOffset-readOffset << "> (writeOffset="
+            << writeOffset << ",readOffset="<<readOffset <<").");
+    }
+
+    s.assign(reinterpret_cast<const char*>(buffer + readOffset), len);
+    readOffset += len;
+} /* end of read_string */
+
+void MessageBuffer::updateReservedBytes() {
+       /* set up buffer endianess */
+       if ((HostIsBigEndian() && bufferHasMyEndianness) ||
+           (HostIsLittleEndian() && !bufferHasMyEndianness)) {
+          buffer[0] = 0x01;
+       } else {
+          buffer[0] = 0x00;
+       }
+    /* set up size */
+       setSizeInReservedBytes(size());
+} /* end of updateReservedBytes */
+
+void*
+MessageBuffer::operator ()(uint32_t offset) {
+       return buffer+offset;
+}
+
+//MessageBuffer::operator const void*(){
+//     return buffer;
+//}
+//
+//MessageBuffer::operator void*() {
+//     return buffer;
+//}
+
+
+} // certi
+

Index: libHLA/MessageBuffer.hh
===================================================================
RCS file: libHLA/MessageBuffer.hh
diff -N libHLA/MessageBuffer.hh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ libHLA/MessageBuffer.hh     28 Mar 2010 16:08:33 -0000      1.1
@@ -0,0 +1,344 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002-2005  ONERA
+//
+// This program is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// ----------------------------------------------------------------------------
+
+#ifndef LIBHLA_MESSAGE_BUFFER_HH
+#define LIBHLA_MESSAGE_BUFFER_HH
+
+#include "libhla.hh"
+#include <string>
+
+#define DEFAULT_MESSAGE_BUFFER_SIZE 255
+
+namespace libhla {
+
+/**
+ * MessageBuffer is a class managing a byte buffer for
+ * portable heterogeneous Message exchange.
+ * It provides member functions to read and write basics types
+ * [unsigned] int 8/16/32/64, float, double, byte etc...
+ * The message buffer will encode the written [type] data with proper
+ * byte ordering and padding.
+ * A message buffer handles heterogeneous write/read pair, in fact
+ * it the central class for heterogeneity handling.
+ * One must read from the buffer in the exact order the write was done.
+ * MessageBuffer is dynamically sized, however reallocation are
+ * only done when needed.
+ */
+class HLA_EXPORT MessageBuffer
+{
+public:
+
+       /**
+        * Return true if the host is BidEndian
+        */
+       static const bool HostIsBigEndian();
+
+       /**
+        * Return true if the host is LittleEndian
+        */
+       static const bool HostIsLittleEndian();
+
+       /**
+        * Show n bytes of data content in hexa on stdout. 
+        */
+       static void show(const void* data, uint32_t n);
+       
+       /* 
+        * We reserve 5 bytes at the beginning of the buffer
+        * The first byte is a bitset which is used to 
+        * to tell if the buffer is big or little endian
+        * The 4 following bytes is for an uint32_t which
+        * may be used to store the buffer size
+        */ 
+       static const uint8_t reservedBytes;
+
+       LIBHLA_EXCEPTION(MessageBufferError)
+
+       /**
+        * Default message buffer constructor.
+        * The default message buffer size is DEFAULT_MESSAGE_BUFFER_SIZE.
+        */
+       MessageBuffer();
+
+       /**
+        * Constructor with size.
+        * Build a MessageBuffer with provisionned bufSize buffer.
+        * @param[in] bufferMaxSize, the [initial] maixmum size of the buffer
+        */
+       MessageBuffer(uint32_t bufferMaxSize);
+
+       /**
+        * Destructor 
+        */
+       ~MessageBuffer();
+
+       /**
+        * Return the current buffer size (in bytes).
+        * This is the size in bytes 
+        * of the element that were written to the buffer.
+        * @return the current buffer size
+        */
+       uint32_t size() const;
+
+       /**
+        * Return the current maximum buffer size (in bytes).
+        * This is the size of the allocated buffer.
+        * @return the current buffer maximum size
+        */
+       uint32_t maxSize() const;
+
+       /**
+        * Assume the buffer is big endian.
+        */
+       void
+       assumeBufferIsBigEndian();
+
+       /**
+        * Assume the buffer is little endian.
+        */
+       void
+       assumeBufferIsLittleEndian();
+
+       /**
+        * Reset buffer state
+        * This method should be called if ones want
+        * to re-use a buffer in order to avoid reallocation.
+        */
+       void
+       reset();
+
+       /**
+        * Seek buffer in order to write at specified place
+        * Will set the write pointer to the seeked offset.
+        */
+       void seek_write(uint32_t offset);
+
+       /**
+        * Resize the current maximum buffer size (in bytes).
+        * This is the size of the allocated buffer.
+        * @param[in] the new buffer maximum size
+        * @return the new buffer maximum size
+        */
+       uint32_t resize(uint32_t newSize);
+
+       /**
+        * Assume that the underlying buffer has 
+        * the specified size.
+        * This may be used after ones get raw pointer 
+        * to the underlying buffer and has written to the buffer
+        * using memcpy/recv.
+        * @param[in] size the assumed size
+        */
+       void assumeSize(uint32_t size);
+       
+       /**
+        * Assume that the underlying buffer has the size
+        * specified by the reserved bytes header.
+        * The method will checked the endianity of the buffer
+        * from the first reserved byte and then assume that
+        * the buffer has size specified by the following 4 bytes.
+        * A reallocation of the underlying memory buffer will
+        * be done if necessary.
+        */
+       void assumeSizeFromReservedBytes();
+
+#define DECLARE_SIGNED(type)                           \
+       int32_t                                         \
+       write_##type##s(const type##_t* data, uint32_t n) {             \
+       return write_u##type##s(reinterpret_cast<const u##type##_t*>(data),n);  
\
+}                                                      \
+\
+int32_t                                                \
+read_##type##s(type##_t* data, uint32_t n) {           \
+       return read_u##type##s(reinterpret_cast<u##type##_t*>(data),n); \
+}                                                      \
+
+
+#define DECLARE_SINGLE_READ_WRITE(type,suffix)     \
+DECLARE_SINGLE_READ_WRITE_(type,type##suffix)
+
+#define DECLARE_SINGLE_READ_WRITE2(type)     \
+DECLARE_SINGLE_READ_WRITE_(type,type)
+
+
+#define DECLARE_SINGLE_READ_WRITE_(type,datatype)     \
+       int32_t                                         \
+       write_##type(const datatype data) {             \
+       return write_##type##s(&data,1);        \
+}                                                      \
+\
+int32_t                                                \
+read_##type(datatype* data) {          \
+       return read_##type##s(data,1);  \
+}                                    \
+\
+datatype read_##type() {\
+       datatype retval;     \
+       read_##type##s(&retval,1);\
+       return retval; \
+} 
+
+
+       int32_t
+       write_uint8s(const uint8_t* data, uint32_t n);
+
+       int32_t
+       read_uint8s(uint8_t* data, uint32_t n);
+
+       DECLARE_SINGLE_READ_WRITE(uint8,_t)
+       DECLARE_SIGNED(int8)
+       DECLARE_SINGLE_READ_WRITE(int8,_t)
+
+       int32_t
+       write_chars(const char* data, uint32_t n) {
+               return write_uint8s(reinterpret_cast<const uint8_t*>(data),n);
+       }
+
+       int32_t
+       read_chars(char* data, uint32_t n) {
+               return read_uint8s(reinterpret_cast<uint8_t*>(data),n);
+       }
+       DECLARE_SINGLE_READ_WRITE2(char)
+
+#define write_bytes  write_chars
+#define read_bytes   read_chars
+#define write_byte   write_char
+#define read_byte    read_char
+
+       int32_t
+       write_uint16s(const uint16_t* data, uint32_t n);
+       int32_t
+       read_uint16s(uint16_t* data, uint32_t n);
+
+       DECLARE_SINGLE_READ_WRITE(uint16,_t)
+       DECLARE_SIGNED(int16)
+       DECLARE_SINGLE_READ_WRITE(int16,_t)
+
+       int32_t
+       write_uint32s(const uint32_t* data, uint32_t n);
+
+       int32_t
+       read_uint32s(uint32_t* data, uint32_t n);
+
+       DECLARE_SINGLE_READ_WRITE(uint32,_t)
+       DECLARE_SIGNED(int32)
+       DECLARE_SINGLE_READ_WRITE(int32,_t)
+
+       int32_t
+       write_uint64s(const uint64_t* data, uint32_t n);
+       int32_t
+       read_uint64s(uint64_t* data, uint32_t n);
+
+       DECLARE_SINGLE_READ_WRITE(uint64,_t)
+       DECLARE_SIGNED(int64)
+       DECLARE_SINGLE_READ_WRITE(int64,_t)
+
+       int32_t
+       write_floats(const float* data, uint32_t n);
+       int32_t
+       read_floats(float* data, uint32_t n);
+
+       DECLARE_SINGLE_READ_WRITE2(float)
+
+       int32_t
+       write_doubles(const double* data, uint32_t n);
+       int32_t
+       read_doubles(double* data, uint32_t n);
+
+       DECLARE_SINGLE_READ_WRITE2(double)
+
+       int32_t
+       write_string(const std::string& str);
+
+       std::string
+       read_string();
+
+        void
+       read_string(std::string&);
+       
+       int32_t
+       write_bool(const bool toggle) {
+               if(toggle) {
+                       return write_uint8(1);
+               } else {
+                       return write_uint8(0);
+               }
+       };
+       
+       bool
+       read_bool() {   
+               return (1==read_uint8());
+       };
+
+       MessageBuffer& operator<<(const uint8_t data) {
+               this->write_uint8(data);
+               return *this;
+       }
+       
+       /**
+        * Update the reserved bytes area.
+        * @post the reserved bytes are up-to-date.
+        */
+       void updateReservedBytes();
+       
+       /*
+        * Pseudo index operator.
+        * This will be used in send/receive socket call.
+        * @return address of the underlying buffer + offset.
+        */
+       void* operator ()(uint32_t offset);
+       
+private:
+
+       /** The buffer itself */
+       uint8_t* buffer;
+       /** The provisioned buffer size */
+       uint32_t bufferMaxSize;
+       /** Endianness toggle */
+       bool bufferHasMyEndianness;     
+       /** 
+        * The write offset is the offset of the buffer
+        * where the next write operation will write to.
+        */
+       uint32_t writeOffset;   
+
+       /** 
+        * The read offset is the offset of the buffer
+        * where the next read operation will read from.
+        */
+       uint32_t readOffset;    
+
+       void initialize();
+       /**
+        * Reallocate the underlying buffer to size n.
+        * Reallocation will be done only if it is necessary.
+        */
+       void reallocate(uint32_t n);
+
+       /**
+        * Update reserved bytes in order to indicate
+        * the actual size of the buffer.
+        */
+       void setSizeInReservedBytes(uint32_t n);
+};
+
+} // libhla
+
+#endif // LIBHLA_MESSAGE_BUFFER_HH

Index: libHLA/MessageBufferTests.cc
===================================================================
RCS file: libHLA/MessageBufferTests.cc
diff -N libHLA/MessageBufferTests.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ libHLA/MessageBufferTests.cc        28 Mar 2010 16:08:33 -0000      1.1
@@ -0,0 +1,238 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002-2005  ONERA
+//
+// This file is part of CERTI
+//
+// CERTI is free software ; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation ; either version 2 of the License, or
+// (at your option) any later version.
+//
+// CERTI is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// ----------------------------------------------------------------------------
+#include <iostream>
+using std::cout;
+using std::cerr;
+using std::endl;
+
+#include "config.h"
+#include "MessageBuffer.hh"
+#include <cassert>
+#include <string>
+#include <cstring>
+#include <cstdio>
+
+void messageBufferTests(libhla::MessageBuffer& MsgBuf) {
+       libhla::MessageBuffer MsgBuf2;
+       std::string    stdstr = "a std:string";
+       const char*   str = "a char* string";
+       uint8_t  u8   =  232;
+       int8_t   i8   = -125;
+       uint16_t u16  = 0xFFAA;
+       int16_t  i16  = -576;
+       uint32_t u32  = 0xFFAAEEBB;
+       int32_t  i32  = -9999;
+       uint64_t u64  = 0xFFEEDDCC;
+       int64_t  i64  = -1000000000;
+       float    f32  = 3.1415927f;
+       double   d64  = 2.7182818;
+       bool     trueBool  = true;
+       bool     falseBool = false;
+       char*    vstr = NULL;
+       std::string  vstdstr;
+       uint8_t  vu8   = 0;
+       int8_t   vi8   = 0;
+       uint16_t vu16  = 0;
+       int16_t  vi16  = 0;
+       uint32_t vu32  = 0;
+       int32_t  vi32  = 0;
+       uint64_t vu64  = 0;
+       int64_t  vi64  = 0;
+       float    vf32  = 0.0;
+       double   vd64  = 0.0;
+       bool     vtrueBool  = false;
+       bool     vfalseBool = true;
+       cout << "Testing MessageBuffer class BEGIN..."<<endl;
+       cout << "    Current (Default) MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
+       cout << "    Current (initially void) MessageBuffer size = "<< 
MsgBuf.size()<<endl;
+       cout << "    Encoding to buffer..." <<endl;
+       cout << "    bytes string = " << str << endl;
+       MsgBuf.write_uint32(strlen(str));
+       MsgBuf.write_bytes(str,strlen(str));
+       MsgBuf.write_uint8(u8);
+       MsgBuf.write_uint16(u16);
+       MsgBuf.write_uint32(u32);
+       MsgBuf.write_uint64(u64);
+       MsgBuf.write_int8(i8);
+       MsgBuf.write_int16(i16);
+       MsgBuf.write_int32(i32);
+       MsgBuf.write_int64(i64);
+       MsgBuf.write_float(f32);
+       MsgBuf.write_double(d64);
+       MsgBuf.write_bool(trueBool);
+       MsgBuf.write_bool(falseBool);
+       cout << "    std::string = " << stdstr << endl;
+       MsgBuf.write_string(stdstr);
+       cout << "    Current MessageBuffer size                  = "<< 
MsgBuf.size()<<endl;
+       cout << "    Decoding from buffer..." <<endl;
+       MsgBuf.read_uint32(&vu32);
+       vstr = new char[vu32+1];
+       memset(vstr,'\0',vu32+1);
+       MsgBuf.read_bytes(vstr,vu32);
+       cout << "    bytes string = " << vstr << endl; 
assert(0==strcmp(str,vstr));
+       MsgBuf.read_uint8(&vu8); assert(vu8==u8);
+       MsgBuf.read_uint16(&vu16); assert(vu16==u16);
+       MsgBuf.read_uint32(&vu32); assert(vu32==u32);
+       MsgBuf.read_uint64(&vu64); assert(vu64==u64);
+       MsgBuf.read_int8(&vi8); assert(vi8==i8);
+       MsgBuf.read_int16(&vi16); assert(vi16==i16);
+       MsgBuf.read_int32(&vi32); assert(vi32==i32);
+       MsgBuf.read_int64(&vi64); assert(vi64==i64);
+       MsgBuf.read_float(&vf32); assert(vf32==f32);
+       MsgBuf.read_double(&vd64); assert(vd64==d64);
+       vtrueBool = MsgBuf.read_bool(); assert(trueBool==vtrueBool);
+       vfalseBool = MsgBuf.read_bool(); assert(falseBool==vfalseBool);
+       vstdstr  = MsgBuf.read_string(); assert(vstdstr==stdstr);
+       cout << "    std::string = " << vstdstr << endl;
+       cout << "    All encoded/decoded values are equal." << endl;
+       cout << "    Now reset buffer." << endl;
+       MsgBuf.reset();
+       cout << "    Re-write on buffer..." << endl;
+       MsgBuf.write_uint8(u8);
+       MsgBuf.write_uint16(u16);
+       MsgBuf.write_uint32(u32);
+       MsgBuf.write_uint64(u64);
+       MsgBuf.write_int8(i8);
+       MsgBuf.write_int16(i16);
+       MsgBuf.write_int32(i32);
+       MsgBuf.write_int64(i64);
+       MsgBuf.write_float(f32);
+       MsgBuf.write_double(d64);
+       cout << "   Read using alternative method..." <<endl;
+       vu8  = MsgBuf.read_uint8(); assert(vu8==u8);
+       vu16 = MsgBuf.read_uint16(); assert(vu16==u16);
+       vu32 = MsgBuf.read_uint32(); assert(vu32==u32);
+       vu64 = MsgBuf.read_uint64(); assert(vu64==u64);
+       vi8  = MsgBuf.read_int8(); assert(vi8==i8);
+       vi16 = MsgBuf.read_int16(); assert(vi16==i16);
+       vi32 = MsgBuf.read_int32(); assert(vi32==i32);
+       vi64 = MsgBuf.read_int64(); assert(vi64==i64);
+       vf32 = MsgBuf.read_float(); assert(vf32==f32);
+       vd64 = MsgBuf.read_double(); assert(vd64==d64);
+       cout << "    All encoded/decoded values are equal." << endl;
+       cout << "    Now reset buffer." << endl;
+       MsgBuf.reset();
+       cout << "    Re-write on buffer..." << endl;
+       MsgBuf.write_uint8(u8);  cout << "        Written <"; 
libhla::MessageBuffer::show(&u8,1); cout << ">" << endl;
+       MsgBuf.write_uint16(u16);cout << "        Written <"; 
libhla::MessageBuffer::show(&u16,2); cout << ">" << endl;
+       MsgBuf.write_uint32(u32);cout << "        Written <"; 
libhla::MessageBuffer::show(&u32,4); cout << ">" << endl;
+       MsgBuf.write_uint64(u64);cout << "        Written <"; 
libhla::MessageBuffer::show(&u64,8); cout << ">" << endl;
+       MsgBuf.write_int8(i8);cout << "        Written <"; 
libhla::MessageBuffer::show(&i8,1); cout << ">" << endl;
+       MsgBuf.write_int16(i16);cout << "        Written <"; 
libhla::MessageBuffer::show(&i16,2); cout << ">" << endl;
+       MsgBuf.write_int32(i32);cout << "        Written <"; 
libhla::MessageBuffer::show(&i32,4); cout << ">" << endl;
+       MsgBuf.write_int64(i64);cout << "        Written <"; 
libhla::MessageBuffer::show(&i64,8); cout << ">" << endl;
+       MsgBuf.write_float(f32);cout << "        Written <"; 
libhla::MessageBuffer::show(&f32,4); cout << ">" << endl;
+       MsgBuf.write_double(d64);cout << "        Written <"; 
libhla::MessageBuffer::show(&d64,8); cout << ">" << endl;
+
+       cout << "    ...and assume it is ";
+       if (libhla::MessageBuffer::HostIsBigEndian()) {
+               cout << "Little Endian";
+               MsgBuf.assumeBufferIsLittleEndian();
+               cout << " whereas the host was big" << endl;
+       }
+       if (libhla::MessageBuffer::HostIsLittleEndian()) {
+               cout << "Big Endian";
+               MsgBuf.assumeBufferIsBigEndian();
+               cout << " whereas the host was little" << endl;
+       }
+       MsgBuf.read_uint8(&vu8);   cout << "        Read  <"; 
libhla::MessageBuffer::show(&vu8,1); cout << ">" << endl;
+       MsgBuf.read_uint16(&vu16); cout << "        Read <"; 
libhla::MessageBuffer::show(&vu16,2); cout << ">" << endl;
+       MsgBuf.read_uint32(&vu32); cout << "        Read <"; 
libhla::MessageBuffer::show(&vu32,4); cout << ">" << endl;
+       MsgBuf.read_uint64(&vu64); cout << "        Read <"; 
libhla::MessageBuffer::show(&vu64,8); cout << ">" << endl;
+       MsgBuf.read_int8(&vi8);    cout << "        Read <"; 
libhla::MessageBuffer::show(&vi8,1); cout << ">" << endl;
+       MsgBuf.read_int16(&vi16);  cout << "        Read <"; 
libhla::MessageBuffer::show(&vi16,2); cout << ">" << endl;
+       MsgBuf.read_int32(&vi32);  cout << "        Read <"; 
libhla::MessageBuffer::show(&vi32,4); cout << ">" << endl;
+       MsgBuf.read_int64(&vi64);  cout << "        Read <"; 
libhla::MessageBuffer::show(&vi64,8); cout << ">" << endl;
+       MsgBuf.read_float(&vf32);  cout << "        Read <"; 
libhla::MessageBuffer::show(&vf32,4); cout << ">" << endl;
+       MsgBuf.read_double(&vd64); cout << "        Read <"; 
libhla::MessageBuffer::show(&vd64,8); cout << ">" << endl;
+       delete[] vstr;
+
+       cout << "    Trying to overload the buffer..." <<endl;
+       cout << "    Current (Default) MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
+       MsgBuf.reset();
+       u32 = MsgBuf.maxSize()*2;
+       vstr = new char[u32+1];
+       vstr[u32]='\0';
+       memset(vstr,'A',u32);
+       MsgBuf.write_uint32(u32);
+       MsgBuf.write_chars(vstr,u32);
+       cout << "    Written char* is " << vstr << endl;
+       u32 = MsgBuf.size();
+       delete[] vstr;
+       cout << "    Current           MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
+       vstdstr = MsgBuf.read_string();
+       cout << "    Read String is   " << vstdstr << endl;
+       cout << "    Forcibly resize the buffer to "<< MsgBuf.maxSize()*2 << 
endl;
+       MsgBuf.resize(MsgBuf.maxSize()*2);
+       cout << "    Current           MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
+    cout << "    Now reset buffer and assume size is                   = "<< 
u32 << endl;
+       MsgBuf.reset();
+       MsgBuf.assumeSize(u32);
+       vstdstr = "";
+       vstdstr = MsgBuf.read_string();
+       cout << "    (re)Read String is   " << vstdstr << endl;
+
+       cout << "    preparing a buffer for network send..." <<endl;
+       MsgBuf.reset();
+       MsgBuf.write_uint32(u32);
+       MsgBuf.write_uint8(u8);
+       MsgBuf.write_uint16(u16);
+       MsgBuf.updateReservedBytes();
+       cout << "    now (pseudo) sending a buffer of size " << MsgBuf.size() 
<< " bytes ..." << endl;
+       memcpy(MsgBuf2(0),MsgBuf(0),MsgBuf.reservedBytes);
+       printf("MsgBuf = 
");MsgBuf.show(MsgBuf(0),MsgBuf.reservedBytes);printf("\n");
+       printf("MsgBuf = 
");MsgBuf2.show(MsgBuf(0),MsgBuf2.reservedBytes);printf("\n");
+       cout << "    now (pseudo) receiving buffer header of " << (uint32_t) 
MsgBuf.reservedBytes << " bytes ..." << endl;
+       cout << "    reconstruct receive buffer size from buffer header ..." 
<<endl;
+       MsgBuf2.assumeSizeFromReservedBytes();
+       cout << "    seems to contain " << MsgBuf2.size() << " bytes..."<<endl;
+       cout << "    now (pseudo) receiving buffer content ..." <<endl;
+       
memcpy(MsgBuf2(MsgBuf.reservedBytes),MsgBuf(MsgBuf.reservedBytes),MsgBuf2.size());
+       cout << "    reading buffer content..." <<endl;
+       vu32 = MsgBuf.read_uint32(); assert(vu32==u32);
+       vu8  = MsgBuf.read_uint8(); assert(vu8==u8);
+       vu16 = MsgBuf.read_uint16(); assert(vu16==u16);
+       cout << "Testing MessageBuffer class END."<<endl;
+} /* end of messageBufferTests */
+
+int
+main(int argc, char **argv)
+{
+
+       libhla::MessageBuffer MsgBuf;
+
+       cout << "LibHLA MessageBuffer Tests->BEGIN..."<< endl ;
+
+       cout << "    Host is ";
+       if (libhla::MessageBuffer::HostIsBigEndian()) {
+               cout << "Big Endian";
+       }
+       if (libhla::MessageBuffer::HostIsLittleEndian()) {
+               cout << "Little Endian";
+       }
+       cout << endl;
+       messageBufferTests(MsgBuf);
+
+       cout << "LibHLA MessageBuffer Test->END." <<endl;
+    /* getchar(); */
+       return 0;
+}

Index: libCERTI/MessageBuffer.cc
===================================================================
RCS file: libCERTI/MessageBuffer.cc
diff -N libCERTI/MessageBuffer.cc
--- libCERTI/MessageBuffer.cc   23 Mar 2010 08:11:55 -0000      3.20
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,483 +0,0 @@
-// ----------------------------------------------------------------------------
-// CERTI - HLA RunTime Infrastructure
-// Copyright (C) 2002-2005 ONERA
-//
-// This program is free software ; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public License
-// as published by the Free Software Foundation ; either version 2 of
-// the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY ; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this program ; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-// USA
-//
-// ----------------------------------------------------------------------------
-
-#include "MessageBuffer.hh"
-#include "Exception.hh"
-#include "PrettyDebug.hh"
-#include <cassert>
-#include <iomanip>
-#include <cstring>
-#include <cstdio>
-
-namespace certi {
-
-static PrettyDebug D("MB","MB::");
-
-const bool
-MessageBuffer::HostIsBigEndian() {
-#ifdef HOST_IS_BIG_ENDIAN
-       return true;
-#else
-       return false;
-#endif
-}
-
-const bool
-MessageBuffer::HostIsLittleEndian() {
-#ifdef HOST_IS_BIG_ENDIAN
-       return false;
-#else
-       return true;
-#endif
-}
-
-void
-MessageBuffer::show(const void* data, uint32_t n) {
-   uint32_t i;
-   const uint8_t* u8data = reinterpret_cast<const uint8_t*>(data);
-   for (i=0;i<n;++i) {
-          if ((0==(i%2))&&(i>0)) {
-                          printf(" ");
-          }
-          printf("%02X",u8data[i]);
-   }
-}
-
-const uint8_t MessageBuffer::reservedBytes = 5;
-
-void MessageBuffer::initialize() {
-       buffer = NULL;
-       bufferMaxSize = DEFAULT_MESSAGE_BUFFER_SIZE;
-       bufferHasMyEndianness = true;
-       writeOffset  = reservedBytes;
-       readOffset   = reservedBytes;
-} /* end of MessageBuffer::initialize() */
-
-MessageBuffer::MessageBuffer() {
-       initialize();
-       reallocate(DEFAULT_MESSAGE_BUFFER_SIZE);
-       memset(buffer,0,bufferMaxSize);
-} /* end of MessageBuffer::MessageBuffer() */
-
-MessageBuffer::MessageBuffer(uint32_t n) {
-       initialize();
-       reallocate(n);
-       memset(buffer,0,bufferMaxSize);
-} /* end of MessageBuffer::MessageBuffer(uint32_t) */
-
-/*
- * FIXME we may put a COMPILED FLAG here in order
- * to prevent reallocation beside the first one (when buffer==NULL)
- */
-void MessageBuffer::reallocate(uint32_t n) {
-       uint8_t* oldbuf = buffer;
-       /* (re)allocation is done iff
-        *  - buffer is NULL (never allocated)
-        *  or
-        *  - requested size exceed current bufferMaxSize
-        */
-       if ((NULL==buffer) || (n > bufferMaxSize)) {
-               // FIXME should try/catch for alloc error
-               // ands wrap-up inside RTIinternalError
-               buffer = new uint8_t[n];
-               bufferMaxSize = n;
-               /*
-                * If oldbuf wasn't null then copy
-                * oldbuf in the new buf
-                * the writeOffset should be valid.
-                */
-               if (NULL!=oldbuf) {
-                       memcpy(buffer, oldbuf, writeOffset);
-                       delete[] oldbuf;
-                       oldbuf = NULL;
-               } else {
-                       updateReservedBytes();
-               }
-       }
-} /* end of MessageBuffer::MessageBuffer(uint32_t) */
-
-MessageBuffer::~MessageBuffer() {
-       if (NULL!=buffer) {
-               delete[] buffer;
-       }
-} /* end of MessageBuffer::~MessageBuffer() */
-
-uint32_t MessageBuffer::size() const {
-       return writeOffset;
-}
-
-uint32_t MessageBuffer::maxSize() const {
-       return bufferMaxSize;
-}
-
-void MessageBuffer::assumeBufferIsBigEndian() {
-       this->bufferHasMyEndianness = HostIsBigEndian();
-       buffer[0] = 0x01;
-} /* end of MessageBuffer::assumeBufferIsBigEndian() */
-
-void MessageBuffer::assumeBufferIsLittleEndian() {
-       this->bufferHasMyEndianness = HostIsLittleEndian();
-       buffer[0] = 0x00;
-} /* end of MessageBuffer::assumeBufferIsLittleEndian() */
-
-void MessageBuffer::reset() {
-       bufferHasMyEndianness = true;
-       writeOffset           = reservedBytes;
-       readOffset            = reservedBytes;
-       updateReservedBytes();
-} /* MessageBuffer::resetBuffer() */
-
-uint32_t MessageBuffer::resize(uint32_t newSize) {
-       reallocate(newSize);
-       return bufferMaxSize;
-}
-
-void MessageBuffer::assumeSize(uint32_t size) {
-       /* This is done in order to overflow
-        * buffer max size but this may well be
-        * an error (FIXME should throw an exception ?)
-        */
-       if (size <= bufferMaxSize) {
-               writeOffset       = size;
-       } else {
-           writeOffset       = bufferMaxSize;
-       }
-}
-
-void MessageBuffer::assumeSizeFromReservedBytes() {
-       uint32_t toBeAssumedSize;
-       /* verify endianity from reserved byte 0 */
-       if (buffer[0]==0x01) {
-               assumeBufferIsBigEndian();
-       } else {
-               assumeBufferIsLittleEndian();
-       }
-       /* read size from reserved bytes 1..4 */
-       readOffset = 1;
-       toBeAssumedSize = this->read_uint32();
-       /* reallocation may be needed */
-       reallocate(toBeAssumedSize);
-       assumeSize(toBeAssumedSize);
-} /* end of assumeSizeFromReservedBytes */
-
-void MessageBuffer::setSizeInReservedBytes(uint32_t n) {
-       uint32_t oldWR_Offset;
-       /* backup write Offset */
-       oldWR_Offset = writeOffset;
-       /* update size in reserved bytes */
-       writeOffset  = 1;
-       Debug(D, pdTrace) << "setSizeInReservedBytes(" << n << ")" << std::endl;
-       write_uint32(n);
-       /* restore writeOffset */
-       writeOffset  = oldWR_Offset;
-} /* end of setSizeInReservedBytes */
-
-int32_t MessageBuffer::write_uint8s(const uint8_t* data, uint32_t n) {
-       Debug(D, pdTrace) << "write_uint8s(" << data << " = [" << (n ? data[0] 
: 0) <<" ...], " << n << ")" << std::endl;
-       if (n >= (bufferMaxSize - writeOffset)) {
-               /* reallocate buffer on-demand */
-               reallocate(bufferMaxSize+ (n-(bufferMaxSize-writeOffset))
-                               + DEFAULT_MESSAGE_BUFFER_SIZE);
-       }
-       /* copy data */
-       memcpy(buffer+writeOffset, data, n);
-       /* update write offset */
-       writeOffset += n;
-       return (writeOffset-n);
-} /* end of MessageBuffer::write_uint8s(uint8_t*, uint32_t) */
-
-int32_t MessageBuffer::read_uint8s(uint8_t* data, uint32_t n) {
-       if (n + readOffset > writeOffset) {
-               throw RTIinternalError(stringize()
-                       << "read_uint8s::invalid read of size <" << n
-                       << "> inside a buffer of readable size <"
-                       << (int32_t)writeOffset-readOffset << "> (writeOffset="
-                       << writeOffset << ",readOffset="<<readOffset <<").");
-       }
-
-       memcpy(data, buffer+readOffset, n);
-       readOffset += n;
-        Debug(D, pdTrace) << "read_uint8s(" << data << " = [" << (n ? data[0] 
: 0) <<" ...], " << n << ")" << std::endl;
-       return (readOffset-n);
-} /* end of MessageBuffer::read_uint8s(uint8_t*, uint32_t) */
-
-int32_t MessageBuffer::write_uint16s(const uint16_t* data, uint32_t n) {
-       uint32_t i;
-       uint16_t an_uint16;
-        Debug(D, pdTrace) << "write_uint16s(" << data << " = [" << (n ? 
data[0] : 0) <<" ...], " << n << ")" << std::endl;
-       
-       if ((2*n) >= (bufferMaxSize - writeOffset)) {
-               /* reallocate buffer on-demand */
-               reallocate(bufferMaxSize+ (2*n)-(bufferMaxSize - writeOffset)
-                               + DEFAULT_MESSAGE_BUFFER_SIZE);
-       }
-
-       /* do not swap byte if it is not necessary */
-       if (bufferHasMyEndianness) {
-               memcpy(buffer+writeOffset, data, 2*n);
-               writeOffset += 2*n;
-       } else {
-               for (i=0; i<n; ++i) {
-                       an_uint16 = CERTI_UINT16_SWAP_BYTES(data[i]);
-                       memcpy(buffer+writeOffset, &an_uint16, 2);
-                       writeOffset += 2;
-               }
-       }
-       return (writeOffset-2*n);
-} /* end of MessageBuffer::write_uint16s(uint16_t*, uint32_t) */
-
-int32_t MessageBuffer::read_uint16s(uint16_t* data, uint32_t n) {
-       uint32_t i;
-       uint16_t an_uint16;
-
-       if (2*n + readOffset > writeOffset) {
-               throw RTIinternalError(stringize()
-                       << "read_uint16s::invalid read of size <" << 2*n
-                       << "> inside a buffer of readable size <"
-                       << (int32_t)writeOffset-readOffset << "> (writeOffset="
-                       << writeOffset << ",readOffset="<<readOffset <<").");
-       }
-
-       /* do not swap byte if it is not necessary */
-       if (bufferHasMyEndianness) {
-               memcpy(data, buffer+readOffset, 2*n);
-               readOffset += 2*n;
-       } else {
-               for (i=0; i<n; ++i) {
-                       memcpy(&an_uint16, buffer+readOffset,2);
-                       data[i] = CERTI_UINT16_SWAP_BYTES(an_uint16);
-                       readOffset += 2;
-               }
-       }
-       
-        Debug(D, pdTrace) << "read_uint16s(" << data << " = [" << (n ? data[0] 
: 0) <<" ...], " << n << ")" << std::endl;
-       return (readOffset-2*n);
-} /* end of MessageBuffer::read_uint16s(uint16_t*, uint32_t) */
-
-int32_t MessageBuffer::write_uint32s(const uint32_t* data, uint32_t n) {
-       uint32_t i;
-       uint32_t an_uint32;
-        Debug(D, pdTrace) << "write_uint32s(" << data << " = [" << (n ? 
data[0] : 0) <<" ...], " << n << ")" << std::endl;
-       
-       if ((4*n) >= (bufferMaxSize - writeOffset)) {
-               /* reallocate buffer on-demand */
-               reallocate(bufferMaxSize+ (4*n)-(bufferMaxSize - writeOffset)
-                               + DEFAULT_MESSAGE_BUFFER_SIZE);
-       }
-
-       /* do not swap byte if it is not necessary */
-       if (bufferHasMyEndianness) {
-               memcpy(buffer+writeOffset, data, 4*n);
-               writeOffset += 4*n;
-       } else {
-               for (i=0; i<n; ++i) {
-                       an_uint32 = CERTI_UINT32_SWAP_BYTES(data[i]);
-                       memcpy(buffer+writeOffset,&an_uint32,4);
-                       writeOffset += 4;
-               }
-       }
-       return (writeOffset-4*n);
-} /* end of write_uint32s */
-
-int32_t MessageBuffer::read_uint32s(uint32_t* data, uint32_t n) {
-       uint32_t i;
-       uint32_t an_uint32;
-
-       if (4*n + readOffset > writeOffset) {
-               throw RTIinternalError(stringize()
-                       << "read_uint32s::invalid read of size <" << 4*n
-                       << "> inside a buffer of readable size <"
-                       << (int32_t)writeOffset-readOffset << "> (writeOffset="
-                       << writeOffset << ",readOffset="<<readOffset <<").");
-       }
-
-       /* do not swap byte if it is not necessary */
-       if (bufferHasMyEndianness) {
-               memcpy(data, buffer+readOffset, 4*n);
-               readOffset += 4*n;
-       } else {
-               for (i=0; i<n; ++i) {
-                       memcpy(&an_uint32,buffer+readOffset,4);
-                       data[i] = CERTI_UINT32_SWAP_BYTES(an_uint32);
-                       readOffset += 4;
-               }
-       }
-        Debug(D, pdTrace) << "read_uint32s(" << data << " = [" << (n ? data[0] 
: 0) <<" ...], " << n << ")" << std::endl;
-       return (readOffset-4*n);
-} /* end of read_uint32s */
-
-int32_t MessageBuffer::write_uint64s(const uint64_t* data, uint32_t n) {
-       uint32_t i;
-       union deux32 {
-               uint32_t    ui32[2];
-               uint64_t    ui64;
-       } a_deux32;
-       uint32_t an_uint32;
-
-        Debug(D, pdTrace) << "write_uint64s(" << data << " = [" << (n ? 
data[0] : 0) <<" ...], " << n << ")" << std::endl;
-
-       if ((8*n) >= (bufferMaxSize - writeOffset)) {
-               /* reallocate buffer on-demand */
-               reallocate(bufferMaxSize+ (8*n)-(bufferMaxSize - writeOffset)
-                               + DEFAULT_MESSAGE_BUFFER_SIZE);
-       }
-
-       /* do not swap byte if it is not necessary */
-       if (bufferHasMyEndianness) {
-               memcpy(buffer+writeOffset, data, 8*n);
-               writeOffset += 8*n;
-       } else {
-               for (i=0; i<n; ++i) {
-                       a_deux32.ui64 = data[i];
-                       an_uint32 = CERTI_UINT32_SWAP_BYTES(a_deux32.ui32[1]);
-                       memcpy(buffer+writeOffset,&an_uint32,4);
-                       writeOffset += 4;
-                       an_uint32 = CERTI_UINT32_SWAP_BYTES(a_deux32.ui32[0]);
-                       memcpy(buffer+writeOffset,&an_uint32,4);
-                       writeOffset += 4;
-               }
-       }
-       return (writeOffset-8*n);
-} /* end of write_uint64s */
-
-int32_t MessageBuffer::read_uint64s(uint64_t* data, uint32_t n) {
-       uint32_t i;
-       union deux32 {
-                       uint32_t    ui32[2];
-                       uint64_t    ui64;
-       } a_deux32;
-       uint32_t an_uint32;
-        Debug(D, pdTrace) << "read_uint64s(" << data << " = [" << (n ? data[0] 
: 0) <<" ...], " << n << ")" << std::endl;
-
-       if (8*n + readOffset > writeOffset) {
-               throw RTIinternalError(stringize()
-                       << "read_uint64s::invalid read of size <" << 4*n
-                       << "> inside a buffer of readable size <"
-                       << (int32_t)writeOffset-readOffset << "> (writeOffset="
-                       << writeOffset << ",readOffset="<<readOffset <<").");
-       }
-
-       /* do not swap byte if it is not necessary */
-       if (bufferHasMyEndianness) {
-               memcpy(data, buffer+readOffset, 8*n);
-               readOffset += 8*n;
-       } else {
-               for (i=0; i<n; ++i) {
-                       memcpy(&an_uint32,buffer+readOffset,4);
-                       a_deux32.ui32[1] = CERTI_UINT32_SWAP_BYTES(an_uint32);
-                       readOffset += 4;
-
-                       memcpy(&an_uint32,buffer+readOffset,4);
-                       a_deux32.ui32[0] = CERTI_UINT32_SWAP_BYTES(an_uint32);
-                       readOffset += 4;
-
-                       data[i] = a_deux32.ui64;
-               }
-       }
-       return (readOffset-8*n);
-}
-
-int32_t MessageBuffer::write_floats(const float* data, uint32_t n) {
-       const uint32_t* data32;
-        Debug(D, pdTrace) << "write_floats(" << data << " = [" << (n ? data[0] 
: 0) <<" ...], " << n << ")" << std::endl;
-       data32 = reinterpret_cast<const uint32_t*>(data);       
-       return write_uint32s(data32,n);
-}
-
-int32_t MessageBuffer::read_floats(float* data, uint32_t n) {
-       uint32_t* data32;
-        Debug(D, pdTrace) << "read_floats(" << data << " = [" << (n ? data[0] 
: 0) <<" ...], " << n << ")" << std::endl;
-       data32 = reinterpret_cast<uint32_t*>(data);
-       return read_uint32s(data32,n);
-}
-
-int32_t MessageBuffer::write_doubles(const double* data, uint32_t n) {
-       const uint64_t* data64;
-        Debug(D, pdTrace) << "write_doubles(" << data << " = [" << (n ? 
data[0] : 0) <<" ...], " << n << ")" << std::endl;
-       data64 = reinterpret_cast<const uint64_t*>(data);       
-       return write_uint64s(data64,n); 
-}
-
-int32_t MessageBuffer::read_doubles(double* data, uint32_t n) {
-       uint64_t* data64;
-        Debug(D, pdTrace) << "read_doubles(" << data << " = [" << (n ? data[0] 
: 0) <<" ...], " << n << ")" << std::endl;
-       data64 = reinterpret_cast<uint64_t*>(data);
-       return read_uint64s(data64,n);
-}
-
-int32_t
-MessageBuffer::write_string(const std::string& str) {
-    write_int32(str.length());
-    return write_chars(str.data(),str.length());
-} /* end of write_string */
-
-std::string
-MessageBuffer::read_string() {
-    std::string retval;
-    read_string(retval);
-    return retval;
-} /* end of read_string */
-
-void
-MessageBuffer::read_string(std::string& s)
-{
-    int32_t len = read_int32();
-
-    if (len + readOffset > writeOffset) {
-        throw RTIinternalError(stringize()
-            << "read_string::invalid read of size <" << len
-            << "> inside a buffer of readable size <"
-            << (int32_t)writeOffset-readOffset << "> (writeOffset="
-            << writeOffset << ",readOffset="<<readOffset <<").");
-    }
-
-    s.assign(reinterpret_cast<const char*>(buffer + readOffset), len);
-    readOffset += len;
-} /* end of read_string */
-
-void MessageBuffer::updateReservedBytes() {
-       /* set up buffer endianess */
-       if ((HostIsBigEndian() && bufferHasMyEndianness) ||
-           (HostIsLittleEndian() && !bufferHasMyEndianness)) {
-          buffer[0] = 0x01;
-       } else {
-          buffer[0] = 0x00;
-       }
-    /* set up size */
-       setSizeInReservedBytes(size());
-} /* end of updateReservedBytes */
-
-void*
-MessageBuffer::operator ()(uint32_t offset) {
-       return buffer+offset;
-}
-
-//MessageBuffer::operator const void*(){
-//     return buffer;
-//}
-//
-//MessageBuffer::operator void*() {
-//     return buffer;
-//}
-
-
-} // certi
-

Index: libCERTI/MessageBuffer.hh
===================================================================
RCS file: libCERTI/MessageBuffer.hh
diff -N libCERTI/MessageBuffer.hh
--- libCERTI/MessageBuffer.hh   24 Nov 2009 19:11:37 -0000      3.9
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,318 +0,0 @@
-// ----------------------------------------------------------------------------
-// CERTI - HLA RunTime Infrastructure
-// Copyright (C) 2002-2005  ONERA
-//
-// This program is free software ; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public License
-// as published by the Free Software Foundation ; either version 2 of
-// the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY ; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this program ; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// ----------------------------------------------------------------------------
-
-#ifndef LIBCERTI_MESSAGE_BUFFER_HH
-#define LIBCERTI_MESSAGE_BUFFER_HH
-
-#include "certi.hh"
-#include <string>
-
-#define DEFAULT_MESSAGE_BUFFER_SIZE 255
-
-namespace certi {
-
-/**
- * MessageBuffer is a class managing a byte buffer for Message exchange.
- * It provides member functions to read and write basics types
- * [unsigned] int 8/16/32/64, float, double, byte etc...
- * The message buffer will encode the written [type] data with proper
- * byte ordering and padding.
- * A message buffer handles heterogeneous write/read pair, in fact
- * it the central class for heterogeneity handling.
- * One must read from the buffer in the exact order the write was done.
- * MessageBuffer is dynamically sized.
- */
-class CERTI_EXPORT MessageBuffer
-{
-public:
-
-       /**
-        * Return true if the host is BidEndian
-        */
-       static const bool HostIsBigEndian();
-
-       /**
-        * Return true if the host is LittleEndian
-        */
-       static const bool HostIsLittleEndian();
-
-       /**
-        * Show n bytes of data content in hexa on stdout. 
-        */
-       static void show(const void* data, uint32_t n);
-       
-       /* 
-        * We reserve 5 bytes at the beginning of the buffer
-        * The first byte is a bitset which is used to 
-        * to tell if the buffer is big or little endian
-        * The 4 following bytes is for an uint32_t which
-        * may be used to store the buffer size
-        */ 
-       static const uint8_t reservedBytes;
-
-       /**
-        * Default message buffer constructor.
-        * The default message buffer size is DEFAULT_MESSAGE_BUFFER_SIZE.
-        */
-       MessageBuffer();
-
-       /**
-        * Constructor with size.
-        * Build a MessageBuffer with provisionned bufSize buffer.
-        * @param[in] bufferMaxSize, the [initial] maixmum size of the buffer
-        */
-       MessageBuffer(uint32_t bufferMaxSize);
-
-       /**
-        * Destructor 
-        */
-       ~MessageBuffer();
-
-       /**
-        * Return the current buffer size (in bytes).
-        * This is the size in bytes 
-        * of the element that were written to the buffer.
-        * @return the current buffer size
-        */
-       uint32_t size() const;
-
-       /**
-        * Return the current maximum buffer size (in bytes).
-        * This is the size of the allocated buffer.
-        * @return the current buffer maximum size
-        */
-       uint32_t maxSize() const;
-
-       /**
-        * Assume the buffer is big endian.
-        */
-       void
-       assumeBufferIsBigEndian();
-
-       /**
-        * Assume the buffer is little endian.
-        */
-       void
-       assumeBufferIsLittleEndian();
-
-       /**
-        * Reset buffer state
-        * This method should be called if ones want
-        * to re-use a buffer in order to avoid reallocation.
-        */
-       void
-       reset();
-
-       /**
-        * Seek buffer in order to write at specified place
-        * Will set the write pointer to the seeked offset.
-        */
-       void seek_write(uint32_t offset);
-
-       /**
-        * Resize the current maximum buffer size (in bytes).
-        * This is the size of the allocated buffer.
-        * @param[in] the new buffer maximum size
-        * @return the new buffer maximum size
-        */
-       uint32_t resize(uint32_t newSize);
-
-       /**
-        * Assume that the underlying buffer has 
-        * the specified size.
-        * This may be used after ones get raw pointer 
-        * to the underlying buffer and has written to the buffer
-        * using memcpy/recv.
-        * @param[in] size the assumed size
-        */
-       void assumeSize(uint32_t size);
-       
-       void assumeSizeFromReservedBytes();
-
-#define DECLARE_SIGNED(type)                           \
-       int32_t                                         \
-       write_##type##s(const type##_t* data, uint32_t n) {             \
-       return write_u##type##s(reinterpret_cast<const u##type##_t*>(data),n);  
\
-}                                                      \
-\
-int32_t                                                \
-read_##type##s(type##_t* data, uint32_t n) {           \
-       return read_u##type##s(reinterpret_cast<u##type##_t*>(data),n); \
-}                                                      \
-
-
-#define DECLARE_SINGLE_READ_WRITE(type,suffix)     \
-DECLARE_SINGLE_READ_WRITE_(type,type##suffix)
-
-#define DECLARE_SINGLE_READ_WRITE2(type)     \
-DECLARE_SINGLE_READ_WRITE_(type,type)
-
-
-#define DECLARE_SINGLE_READ_WRITE_(type,datatype)     \
-       int32_t                                         \
-       write_##type(const datatype data) {             \
-       return write_##type##s(&data,1);        \
-}                                                      \
-\
-int32_t                                                \
-read_##type(datatype* data) {          \
-       return read_##type##s(data,1);  \
-}                                    \
-\
-datatype read_##type() {\
-       datatype retval;     \
-       read_##type##s(&retval,1);\
-       return retval; \
-} 
-
-
-       int32_t
-       write_uint8s(const uint8_t* data, uint32_t n);
-
-       int32_t
-       read_uint8s(uint8_t* data, uint32_t n);
-
-       DECLARE_SINGLE_READ_WRITE(uint8,_t)
-       DECLARE_SIGNED(int8)
-       DECLARE_SINGLE_READ_WRITE(int8,_t)
-
-       int32_t
-       write_chars(const char* data, uint32_t n) {
-               return write_uint8s(reinterpret_cast<const uint8_t*>(data),n);
-       }
-
-       int32_t
-       read_chars(char* data, uint32_t n) {
-               return read_uint8s(reinterpret_cast<uint8_t*>(data),n);
-       }
-       DECLARE_SINGLE_READ_WRITE2(char)
-
-#define write_bytes  write_chars
-#define read_bytes   read_chars
-#define write_byte   write_char
-#define read_byte    read_char
-
-       int32_t
-       write_uint16s(const uint16_t* data, uint32_t n);
-       int32_t
-       read_uint16s(uint16_t* data, uint32_t n);
-
-       DECLARE_SINGLE_READ_WRITE(uint16,_t)
-       DECLARE_SIGNED(int16)
-       DECLARE_SINGLE_READ_WRITE(int16,_t)
-
-       int32_t
-       write_uint32s(const uint32_t* data, uint32_t n);
-
-       int32_t
-       read_uint32s(uint32_t* data, uint32_t n);
-
-       DECLARE_SINGLE_READ_WRITE(uint32,_t)
-       DECLARE_SIGNED(int32)
-       DECLARE_SINGLE_READ_WRITE(int32,_t)
-
-       int32_t
-       write_uint64s(const uint64_t* data, uint32_t n);
-       int32_t
-       read_uint64s(uint64_t* data, uint32_t n);
-
-       DECLARE_SINGLE_READ_WRITE(uint64,_t)
-       DECLARE_SIGNED(int64)
-       DECLARE_SINGLE_READ_WRITE(int64,_t)
-
-       int32_t
-       write_floats(const float* data, uint32_t n);
-       int32_t
-       read_floats(float* data, uint32_t n);
-
-       DECLARE_SINGLE_READ_WRITE2(float)
-
-       int32_t
-       write_doubles(const double* data, uint32_t n);
-       int32_t
-       read_doubles(double* data, uint32_t n);
-
-       DECLARE_SINGLE_READ_WRITE2(double)
-
-       int32_t
-       write_string(const std::string& str);
-
-       std::string
-       read_string();
-
-        void
-       read_string(std::string&);
-       
-       int32_t
-       write_bool(const bool toggle) {
-               if(toggle) {
-                       return write_uint8(1);
-               } else {
-                       return write_uint8(0);
-               }
-       };
-       
-       bool
-       read_bool() {   
-               return (1==read_uint8());
-       };
-
-       MessageBuffer& operator<<(const uint8_t data) {
-               this->write_uint8(data);
-               return *this;
-       }
-       
-       void updateReservedBytes();
-       
-       /*
-        * Pseudo index operator.
-        * This will be used in send/receive socket call.
-        * @return address of the underlying buffer + offset.
-        */
-       void* operator ()(uint32_t offset);
-       
-private:
-
-       /** The buffer itself */
-       uint8_t* buffer;
-       /** The provisioned buffer size */
-       uint32_t bufferMaxSize;
-       /** Endianness toggle */
-       bool bufferHasMyEndianness;     
-       /** 
-        * The write offset is the offset of the buffer
-        * where the next write operation will write to.
-        */
-       uint32_t writeOffset;   
-
-       /** 
-        * The read offset is the offset of the buffer
-        * where the next read operation will read from.
-        */
-       uint32_t readOffset;    
-
-       void initialize();
-       void reallocate(uint32_t n);
-       void setSizeInReservedBytes(uint32_t n);
-};
-
-} // certi
-
-#endif // LIBCERTI_MESSAGE_BUFFER_HH

Index: test/utility/CertiUtilTests.cc
===================================================================
RCS file: test/utility/CertiUtilTests.cc
diff -N test/utility/CertiUtilTests.cc
--- test/utility/CertiUtilTests.cc      21 Mar 2010 17:10:11 -0000      1.18
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,239 +0,0 @@
-// ----------------------------------------------------------------------------
-// CERTI - HLA RunTime Infrastructure
-// Copyright (C) 2002-2005  ONERA
-//
-// This file is part of CERTI
-//
-// CERTI is free software ; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation ; either version 2 of the License, or
-// (at your option) any later version.
-//
-// CERTI is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY ; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program ; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// ----------------------------------------------------------------------------
-#include <iostream>
-using std::cout;
-using std::cerr;
-using std::endl;
-
-#include "config.h"
-#include "PrettyDebug.hh"
-#include "MessageBuffer.hh"
-#include <cassert>
-#include <string>
-#include <cstring>
-#include <cstdio>
-
-void messageBufferTests(certi::MessageBuffer& MsgBuf) {
-       certi::MessageBuffer MsgBuf2;
-       std::string    stdstr = "a std:string";
-       const char*   str = "a char* string";
-       uint8_t  u8   =  232;
-       int8_t   i8   = -125;
-       uint16_t u16  = 0xFFAA;
-       int16_t  i16  = -576;
-       uint32_t u32  = 0xFFAAEEBB;
-       int32_t  i32  = -9999;
-       uint64_t u64  = 0xFFEEDDCC;
-       int64_t  i64  = -1000000000;
-       float    f32  = 3.1415927f;
-       double   d64  = 2.7182818;
-       bool     trueBool  = true;
-       bool     falseBool = false;
-       char*    vstr = NULL;
-       std::string  vstdstr;
-       uint8_t  vu8   = 0;
-       int8_t   vi8   = 0;
-       uint16_t vu16  = 0;
-       int16_t  vi16  = 0;
-       uint32_t vu32  = 0;
-       int32_t  vi32  = 0;
-       uint64_t vu64  = 0;
-       int64_t  vi64  = 0;
-       float    vf32  = 0.0;
-       double   vd64  = 0.0;
-       bool     vtrueBool  = false;
-       bool     vfalseBool = true;
-       cout << "Testing MessageBuffer class BEGIN..."<<endl;
-       cout << "    Current (Default) MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
-       cout << "    Current (initially void) MessageBuffer size = "<< 
MsgBuf.size()<<endl;
-       cout << "    Encoding to buffer..." <<endl;
-       cout << "    bytes string = " << str << endl;
-       MsgBuf.write_uint32(strlen(str));
-       MsgBuf.write_bytes(str,strlen(str));
-       MsgBuf.write_uint8(u8);
-       MsgBuf.write_uint16(u16);
-       MsgBuf.write_uint32(u32);
-       MsgBuf.write_uint64(u64);
-       MsgBuf.write_int8(i8);
-       MsgBuf.write_int16(i16);
-       MsgBuf.write_int32(i32);
-       MsgBuf.write_int64(i64);
-       MsgBuf.write_float(f32);
-       MsgBuf.write_double(d64);
-       MsgBuf.write_bool(trueBool);
-       MsgBuf.write_bool(falseBool);
-       cout << "    std::string = " << stdstr << endl;
-       MsgBuf.write_string(stdstr);
-       cout << "    Current MessageBuffer size                  = "<< 
MsgBuf.size()<<endl;
-       cout << "    Decoding from buffer..." <<endl;
-       MsgBuf.read_uint32(&vu32);
-       vstr = new char[vu32+1];
-       memset(vstr,'\0',vu32+1);
-       MsgBuf.read_bytes(vstr,vu32);
-       cout << "    bytes string = " << vstr << endl; 
assert(0==strcmp(str,vstr));
-       MsgBuf.read_uint8(&vu8); assert(vu8==u8);
-       MsgBuf.read_uint16(&vu16); assert(vu16==u16);
-       MsgBuf.read_uint32(&vu32); assert(vu32==u32);
-       MsgBuf.read_uint64(&vu64); assert(vu64==u64);
-       MsgBuf.read_int8(&vi8); assert(vi8==i8);
-       MsgBuf.read_int16(&vi16); assert(vi16==i16);
-       MsgBuf.read_int32(&vi32); assert(vi32==i32);
-       MsgBuf.read_int64(&vi64); assert(vi64==i64);
-       MsgBuf.read_float(&vf32); assert(vf32==f32);
-       MsgBuf.read_double(&vd64); assert(vd64==d64);
-       vtrueBool = MsgBuf.read_bool(); assert(trueBool==vtrueBool);
-       vfalseBool = MsgBuf.read_bool(); assert(falseBool==vfalseBool);
-       vstdstr  = MsgBuf.read_string(); assert(vstdstr==stdstr);
-       cout << "    std::string = " << vstdstr << endl;
-       cout << "    All encoded/decoded values are equal." << endl;
-       cout << "    Now reset buffer." << endl;
-       MsgBuf.reset();
-       cout << "    Re-write on buffer..." << endl;
-       MsgBuf.write_uint8(u8);
-       MsgBuf.write_uint16(u16);
-       MsgBuf.write_uint32(u32);
-       MsgBuf.write_uint64(u64);
-       MsgBuf.write_int8(i8);
-       MsgBuf.write_int16(i16);
-       MsgBuf.write_int32(i32);
-       MsgBuf.write_int64(i64);
-       MsgBuf.write_float(f32);
-       MsgBuf.write_double(d64);
-       cout << "   Read using alternative method..." <<endl;
-       vu8  = MsgBuf.read_uint8(); assert(vu8==u8);
-       vu16 = MsgBuf.read_uint16(); assert(vu16==u16);
-       vu32 = MsgBuf.read_uint32(); assert(vu32==u32);
-       vu64 = MsgBuf.read_uint64(); assert(vu64==u64);
-       vi8  = MsgBuf.read_int8(); assert(vi8==i8);
-       vi16 = MsgBuf.read_int16(); assert(vi16==i16);
-       vi32 = MsgBuf.read_int32(); assert(vi32==i32);
-       vi64 = MsgBuf.read_int64(); assert(vi64==i64);
-       vf32 = MsgBuf.read_float(); assert(vf32==f32);
-       vd64 = MsgBuf.read_double(); assert(vd64==d64);
-       cout << "    All encoded/decoded values are equal." << endl;
-       cout << "    Now reset buffer." << endl;
-       MsgBuf.reset();
-       cout << "    Re-write on buffer..." << endl;
-       MsgBuf.write_uint8(u8);  cout << "        Written <"; 
certi::MessageBuffer::show(&u8,1); cout << ">" << endl;
-       MsgBuf.write_uint16(u16);cout << "        Written <"; 
certi::MessageBuffer::show(&u16,2); cout << ">" << endl;
-       MsgBuf.write_uint32(u32);cout << "        Written <"; 
certi::MessageBuffer::show(&u32,4); cout << ">" << endl;
-       MsgBuf.write_uint64(u64);cout << "        Written <"; 
certi::MessageBuffer::show(&u64,8); cout << ">" << endl;
-       MsgBuf.write_int8(i8);cout << "        Written <"; 
certi::MessageBuffer::show(&i8,1); cout << ">" << endl;
-       MsgBuf.write_int16(i16);cout << "        Written <"; 
certi::MessageBuffer::show(&i16,2); cout << ">" << endl;
-       MsgBuf.write_int32(i32);cout << "        Written <"; 
certi::MessageBuffer::show(&i32,4); cout << ">" << endl;
-       MsgBuf.write_int64(i64);cout << "        Written <"; 
certi::MessageBuffer::show(&i64,8); cout << ">" << endl;
-       MsgBuf.write_float(f32);cout << "        Written <"; 
certi::MessageBuffer::show(&f32,4); cout << ">" << endl;
-       MsgBuf.write_double(d64);cout << "        Written <"; 
certi::MessageBuffer::show(&d64,8); cout << ">" << endl;
-
-       cout << "    ...and assume it is ";
-       if (certi::MessageBuffer::HostIsBigEndian()) {
-               cout << "Little Endian";
-               MsgBuf.assumeBufferIsLittleEndian();
-               cout << " whereas the host was big" << endl;
-       }
-       if (certi::MessageBuffer::HostIsLittleEndian()) {
-               cout << "Big Endian";
-               MsgBuf.assumeBufferIsBigEndian();
-               cout << " whereas the host was little" << endl;
-       }
-       MsgBuf.read_uint8(&vu8);   cout << "        Read  <"; 
certi::MessageBuffer::show(&vu8,1); cout << ">" << endl;
-       MsgBuf.read_uint16(&vu16); cout << "        Read <"; 
certi::MessageBuffer::show(&vu16,2); cout << ">" << endl;
-       MsgBuf.read_uint32(&vu32); cout << "        Read <"; 
certi::MessageBuffer::show(&vu32,4); cout << ">" << endl;
-       MsgBuf.read_uint64(&vu64); cout << "        Read <"; 
certi::MessageBuffer::show(&vu64,8); cout << ">" << endl;
-       MsgBuf.read_int8(&vi8);    cout << "        Read <"; 
certi::MessageBuffer::show(&vi8,1); cout << ">" << endl;
-       MsgBuf.read_int16(&vi16);  cout << "        Read <"; 
certi::MessageBuffer::show(&vi16,2); cout << ">" << endl;
-       MsgBuf.read_int32(&vi32);  cout << "        Read <"; 
certi::MessageBuffer::show(&vi32,4); cout << ">" << endl;
-       MsgBuf.read_int64(&vi64);  cout << "        Read <"; 
certi::MessageBuffer::show(&vi64,8); cout << ">" << endl;
-       MsgBuf.read_float(&vf32);  cout << "        Read <"; 
certi::MessageBuffer::show(&vf32,4); cout << ">" << endl;
-       MsgBuf.read_double(&vd64); cout << "        Read <"; 
certi::MessageBuffer::show(&vd64,8); cout << ">" << endl;
-       delete[] vstr;
-
-       cout << "    Trying to overload the buffer..." <<endl;
-       cout << "    Current (Default) MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
-       MsgBuf.reset();
-       u32 = MsgBuf.maxSize()*2;
-       vstr = new char[u32+1];
-       vstr[u32]='\0';
-       memset(vstr,'A',u32);
-       MsgBuf.write_uint32(u32);
-       MsgBuf.write_chars(vstr,u32);
-       cout << "    Written char* is " << vstr << endl;
-       u32 = MsgBuf.size();
-       delete[] vstr;
-       cout << "    Current           MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
-       vstdstr = MsgBuf.read_string();
-       cout << "    Read String is   " << vstdstr << endl;
-       cout << "    Forcibly resize the buffer to "<< MsgBuf.maxSize()*2 << 
endl;
-       MsgBuf.resize(MsgBuf.maxSize()*2);
-       cout << "    Current           MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
-    cout << "    Now reset buffer and assume size is                   = "<< 
u32 << endl;
-       MsgBuf.reset();
-       MsgBuf.assumeSize(u32);
-       vstdstr = "";
-       vstdstr = MsgBuf.read_string();
-       cout << "    (re)Read String is   " << vstdstr << endl;
-
-       cout << "    preparing a buffer for network send..." <<endl;
-       MsgBuf.reset();
-       MsgBuf.write_uint32(u32);
-       MsgBuf.write_uint8(u8);
-       MsgBuf.write_uint16(u16);
-       MsgBuf.updateReservedBytes();
-       cout << "    now (pseudo) sending a buffer of size " << MsgBuf.size() 
<< " bytes ..." << endl;
-       memcpy(MsgBuf2(0),MsgBuf(0),MsgBuf.reservedBytes);
-       printf("MsgBuf = 
");MsgBuf.show(MsgBuf(0),MsgBuf.reservedBytes);printf("\n");
-       printf("MsgBuf = 
");MsgBuf2.show(MsgBuf(0),MsgBuf2.reservedBytes);printf("\n");
-       cout << "    now (pseudo) receiving buffer header of " << (uint32_t) 
MsgBuf.reservedBytes << " bytes ..." << endl;
-       cout << "    reconstruct receive buffer size from buffer header ..." 
<<endl;
-       MsgBuf2.assumeSizeFromReservedBytes();
-       cout << "    seems to contain " << MsgBuf2.size() << " bytes..."<<endl;
-       cout << "    now (pseudo) receiving buffer content ..." <<endl;
-       
memcpy(MsgBuf2(MsgBuf.reservedBytes),MsgBuf(MsgBuf.reservedBytes),MsgBuf2.size());
-       cout << "    reading buffer content..." <<endl;
-       vu32 = MsgBuf.read_uint32(); assert(vu32==u32);
-       vu8  = MsgBuf.read_uint8(); assert(vu8==u8);
-       vu16 = MsgBuf.read_uint16(); assert(vu16==u16);
-       cout << "Testing MessageBuffer class END."<<endl;
-} /* end of messageBufferTests */
-
-int
-main(int argc, char **argv)
-{
-
-       certi::MessageBuffer MsgBuf;
-
-       cout << "CERTI Utility Tests->BEGIN..."<< endl ;
-
-       cout << "    Host is ";
-       if (certi::MessageBuffer::HostIsBigEndian()) {
-               cout << "Big Endian";
-       }
-       if (certi::MessageBuffer::HostIsLittleEndian()) {
-               cout << "Little Endian";
-       }
-       cout << endl;
-       messageBufferTests(MsgBuf);
-
-       cout << "CERTI Utility Test->END." <<endl;
-    /* getchar(); */
-       return 0;
-}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]