Renamed IcmpMessagePayload to MessagePayload, so it can be used by other messages...
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sat, 13 Aug 2011 16:39:36 +0000 (13:39 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sat, 13 Aug 2011 16:39:36 +0000 (13:39 -0300)
src/CMakeLists.txt
src/host/messagepayload.cpp [moved from src/icmp/icmpmessagepayload.cpp with 87% similarity]
src/host/messagepayload.h [moved from src/icmp/icmpmessagepayload.h with 78% similarity]
src/icmp/icmpdestinationunreachablemessage.h
src/icmp/icmpechoreplymessage.h
src/icmp/icmpechorequestmessage.h

index 0f02a6a..eeb9734 100644 (file)
@@ -35,6 +35,7 @@ set(SOURCES
     dns/hostaddress.cpp
     dns/timetolive.cpp
     host/hoststatusanalyzer.cpp
+    host/messagepayload.cpp
     host/pinger.cpp
     host/pingerfactory.cpp
     host/pinginterval.cpp
@@ -46,7 +47,6 @@ set(SOURCES
     icmp/icmpgenericmessage.cpp
     icmp/icmpheader.cpp
     icmp/icmpmessage.cpp
-    icmp/icmpmessagepayload.cpp
     icmp/icmppacket.cpp
     icmp/icmppinger.cpp
     ip/ipv4header.cpp
similarity index 87%
rename from src/icmp/icmpmessagepayload.cpp
rename to src/host/messagepayload.cpp
index 7b07335..00c9a6f 100644 (file)
@@ -4,7 +4,7 @@
 // Distributed under the Boost Software License, Version 1.0.
 //    (See accompanying file LICENSE_1_0.txt or copy at
 //          http://www.boost.org/LICENSE_1_0.txt)
-#include "icmp/icmpmessagepayload.h"
+#include "host/messagepayload.h"
 
 #include <limits>
 
@@ -17,13 +17,13 @@ using boost::scoped_array;
 using I2n::Logger::GlobalLogger;
 
 //-----------------------------------------------------------------------------
-// IcmpMessagePayload
+// MessagePayload
 //-----------------------------------------------------------------------------
 
 /**
  * @param payload_size_in_bytes the size of the payload (ie the internal buffer)
  */
-IcmpMessagePayload::IcmpMessagePayload(
+MessagePayload::MessagePayload(
         const std::size_t &payload_size_in_bytes
 ) :
     PayloadSizeInBytes( payload_size_in_bytes ),
@@ -34,7 +34,7 @@ IcmpMessagePayload::IcmpMessagePayload(
     fill( Payload.get(), Payload.get() + PayloadSizeInBytes, 0 );
 }
 
-IcmpMessagePayload::~IcmpMessagePayload()
+MessagePayload::~MessagePayload()
 {
     // Payload automatically delete by smart pointer scope end
 }
@@ -43,7 +43,7 @@ IcmpMessagePayload::~IcmpMessagePayload()
  * @brief The element access operator to provide access syntax like regular
  * arrays.
  */
-const uint8_t& IcmpMessagePayload::operator[]( size_t offset ) const
+const uint8_t& MessagePayload::operator[]( size_t offset ) const
 {
     BOOST_ASSERT( offset < PayloadSizeInBytes );
 
@@ -54,7 +54,7 @@ const uint8_t& IcmpMessagePayload::operator[]( size_t offset ) const
  * @brief The element access operator to provide access syntax like regular
  * arrays.
  */
-uint8_t& IcmpMessagePayload::operator[]( size_t offset )
+uint8_t& MessagePayload::operator[]( size_t offset )
 {
     BOOST_ASSERT( offset < PayloadSizeInBytes );
 
@@ -70,7 +70,7 @@ uint8_t& IcmpMessagePayload::operator[]( size_t offset )
  * @return a concatenation of the byte indexed by left_byte with the byte
  * indexed by right_byte
  */
-uint16_t IcmpMessagePayload::decode16(
+uint16_t MessagePayload::decode16(
         const int left_byte,
         const int right_byte
 ) const
@@ -87,11 +87,12 @@ uint16_t IcmpMessagePayload::decode16(
  *
  * @param left_byte the index of the left byte
  * @param right_byte the index of the right byte
- *
  * @param value a 16 bits data be saved in the bytes indexed by left_byte and
  * right_byte.
+ *
+ * @return void
  */
-void IcmpMessagePayload::encode16(
+void MessagePayload::encode16(
         const int left_byte,
         const int right_byte,
         const uint16_t value
@@ -104,7 +105,7 @@ void IcmpMessagePayload::encode16(
 /**
  * @brief Read all the data from the payload and stores in the istream.
  */
-istream& IcmpMessagePayload::read( istream &is )
+istream& MessagePayload::read( istream &is )
 {
     char *payload_data_array = reinterpret_cast<char *> ( Payload.get() );
     (void) is.read( payload_data_array, PayloadSizeInBytes );
@@ -122,7 +123,7 @@ istream& IcmpMessagePayload::read( istream &is )
 /**
  * @brief Writes all the data present in the ostream to the payload buffer.
  */
-ostream& IcmpMessagePayload::write( ostream &os ) const
+ostream& MessagePayload::write( ostream &os ) const
 {
     const char *data_array = reinterpret_cast<const char *> ( Payload.get() );
     return os.write( data_array, PayloadSizeInBytes );
similarity index 78%
rename from src/icmp/icmpmessagepayload.h
rename to src/host/messagepayload.h
index 5388092..5bc19e2 100644 (file)
@@ -4,8 +4,8 @@
 // Distributed under the Boost Software License, Version 1.0.
 //    (See accompanying file LICENSE_1_0.txt or copy at
 //          http://www.boost.org/LICENSE_1_0.txt)
-#ifndef ICMPMESSAGEPAYLOAD_H
-#define ICMPMESSAGEPAYLOAD_H
+#ifndef MESSAGE_PAYLOAD_H
+#define MESSAGE_PAYLOAD_H
 
 #include <stdint.h>
 
     Class & operator= ( const Class & );
 
 //-----------------------------------------------------------------------------
-// IcmpMessagePayload
+// MessagePayload
 //-----------------------------------------------------------------------------
 
 /**
  * @brief This class represents the contents of the network messages. It
- * provides means for encode and decode, and also can be treated like an
- * ordinary array.
+ * provides means for encode and decode (i.e. deal with endianness), and also
+ * can be treated like an ordinary array.
  */
-class IcmpMessagePayload
+class MessagePayload
 {
 public:
-    explicit IcmpMessagePayload( const std::size_t &payload_size_in_bytes );
-    ~IcmpMessagePayload();
+    explicit MessagePayload( const std::size_t &payload_size_in_bytes );
+    ~MessagePayload();
 
     const uint8_t& operator[]( std::size_t offset ) const;
     uint8_t& operator[]( std::size_t offset );
@@ -57,7 +57,7 @@ private:
     /// the payload buffer
     boost::scoped_array<uint8_t> Payload;
 
-    NONCOPYABLE( IcmpMessagePayload )
+    NONCOPYABLE( MessagePayload )
 };
 
-#endif /* ICMPMESSAGEPAYLOAD_H */
+#endif // MESSAGE_PAYLOAD_H
index ae8dbbf..f7754f1 100644 (file)
@@ -13,7 +13,7 @@
 #include <ostream>
 
 #include "icmp/icmpmessage.h"
-#include "icmp/icmpmessagepayload.h"
+#include "host/messagepayload.h"
 
 //-----------------------------------------------------------------------------
 // IcmpDestinationUnreachableMessage
@@ -68,7 +68,7 @@ public:
 
 private:
     /// packet payload object
-    IcmpMessagePayload Payload;
+    MessagePayload Payload;
 
 };
 
index 6f47f9e..b5f9525 100644 (file)
@@ -13,7 +13,7 @@
 #include <ostream>
 
 #include "icmp/icmpmessage.h"
-#include "icmp/icmpmessagepayload.h"
+#include "host/messagepayload.h"
 
 //-----------------------------------------------------------------------------
 // IcmpEchoReplyMessage
@@ -64,7 +64,7 @@ public:
 
 private:
     /// packet payload object
-    IcmpMessagePayload Payload;
+    MessagePayload Payload;
 
 };
 
index 6546087..e9ce57f 100644 (file)
@@ -13,7 +13,7 @@
 #include <ostream>
 
 #include "icmp/icmpmessage.h"
-#include "icmp/icmpmessagepayload.h"
+#include "host/messagepayload.h"
 
 //-----------------------------------------------------------------------------
 // IcmpEchoRequestMessage
@@ -64,7 +64,7 @@ public:
 
 private:
     /// packet payload object
-    IcmpMessagePayload Payload;
+    MessagePayload Payload;
 
 };