From: Guilherme Maciel Ferreira Date: Sat, 13 Aug 2011 16:39:36 +0000 (-0300) Subject: Renamed IcmpMessagePayload to MessagePayload, so it can be used by other messages... X-Git-Tag: v1.1^2~19 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=4939ed75d0d371b7a46a5bc94c8366eaeb58f75a;p=pingcheck Renamed IcmpMessagePayload to MessagePayload, so it can be used by other messages types --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f02a6a..eeb9734 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/icmp/icmpmessagepayload.cpp b/src/host/messagepayload.cpp similarity index 87% rename from src/icmp/icmpmessagepayload.cpp rename to src/host/messagepayload.cpp index 7b07335..00c9a6f 100644 --- a/src/icmp/icmpmessagepayload.cpp +++ b/src/host/messagepayload.cpp @@ -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 @@ -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 ( 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 ( Payload.get() ); return os.write( data_array, PayloadSizeInBytes ); diff --git a/src/icmp/icmpmessagepayload.h b/src/host/messagepayload.h similarity index 78% rename from src/icmp/icmpmessagepayload.h rename to src/host/messagepayload.h index 5388092..5bc19e2 100644 --- a/src/icmp/icmpmessagepayload.h +++ b/src/host/messagepayload.h @@ -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 @@ -21,19 +21,19 @@ 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 Payload; - NONCOPYABLE( IcmpMessagePayload ) + NONCOPYABLE( MessagePayload ) }; -#endif /* ICMPMESSAGEPAYLOAD_H */ +#endif // MESSAGE_PAYLOAD_H diff --git a/src/icmp/icmpdestinationunreachablemessage.h b/src/icmp/icmpdestinationunreachablemessage.h index ae8dbbf..f7754f1 100644 --- a/src/icmp/icmpdestinationunreachablemessage.h +++ b/src/icmp/icmpdestinationunreachablemessage.h @@ -13,7 +13,7 @@ #include #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; }; diff --git a/src/icmp/icmpechoreplymessage.h b/src/icmp/icmpechoreplymessage.h index 6f47f9e..b5f9525 100644 --- a/src/icmp/icmpechoreplymessage.h +++ b/src/icmp/icmpechoreplymessage.h @@ -13,7 +13,7 @@ #include #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; }; diff --git a/src/icmp/icmpechorequestmessage.h b/src/icmp/icmpechorequestmessage.h index 6546087..e9ce57f 100644 --- a/src/icmp/icmpechorequestmessage.h +++ b/src/icmp/icmpechorequestmessage.h @@ -13,7 +13,7 @@ #include #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; };