summaryrefslogtreecommitdiff
path: root/src/components/protocol_handler/include/protocol_handler/protocol_packet.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/protocol_handler/include/protocol_handler/protocol_packet.h')
-rw-r--r--src/components/protocol_handler/include/protocol_handler/protocol_packet.h90
1 files changed, 71 insertions, 19 deletions
diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_packet.h b/src/components/protocol_handler/include/protocol_handler/protocol_packet.h
index 0b4b253a84..f8696c46a0 100644
--- a/src/components/protocol_handler/include/protocol_handler/protocol_packet.h
+++ b/src/components/protocol_handler/include/protocol_handler/protocol_packet.h
@@ -33,6 +33,7 @@
#ifndef SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_PACKET_H_
#define SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_PACKET_H_
+#include <list>
#include "utils/macro.h"
#include "protocol/common.h"
#include "transport_manager/common.h"
@@ -58,7 +59,7 @@ class ProtocolPacket {
struct ProtocolData {
ProtocolData();
~ProtocolData();
- uint8_t *data;
+ uint8_t* data;
uint32_t totalDataBytes;
};
@@ -69,11 +70,14 @@ class ProtocolPacket {
class ProtocolHeader {
public:
ProtocolHeader();
- ProtocolHeader(uint8_t version, bool protection,
+ ProtocolHeader(uint8_t version,
+ bool protection,
uint8_t frameType,
uint8_t serviceType,
- uint8_t frameData, uint8_t sessionID,
- uint32_t dataSize, uint32_t messageID);
+ uint8_t frameData,
+ uint8_t sessionID,
+ uint32_t dataSize,
+ uint32_t messageID);
uint8_t version;
bool protection_flag;
uint8_t frameType;
@@ -82,7 +86,7 @@ class ProtocolPacket {
uint8_t sessionId;
uint32_t dataSize;
uint32_t messageId;
- void deserialize(const uint8_t *message, const size_t messageSize);
+ void deserialize(const uint8_t* message, const size_t messageSize);
};
/**
* \class ProtocolHeaderValidator
@@ -100,6 +104,7 @@ class ProtocolPacket {
* \brief Check ProtocolHeader according to protocol requiements
*/
RESULT_CODE validate(const ProtocolHeader& header) const;
+
private:
size_t max_payload_size_;
};
@@ -131,10 +136,15 @@ class ProtocolPacket {
* \param data Message string if provided
*/
ProtocolPacket(ConnectionID connection_id,
- uint8_t version, bool protection, uint8_t frameType,
- uint8_t serviceType, uint8_t frameData,
- uint8_t sessionId, uint32_t dataSize,
- uint32_t messageID, const uint8_t *data = 0);
+ uint8_t version,
+ bool protection,
+ uint8_t frameType,
+ uint8_t serviceType,
+ uint8_t frameData,
+ uint8_t sessionId,
+ uint32_t dataSize,
+ uint32_t messageID,
+ const uint8_t* data = 0);
/*Serialization*/
/**
@@ -149,7 +159,7 @@ class ProtocolPacket {
* \param chunkDataSize Size of current message string
* \return \saRESULT_CODE Status of serialization
*/
- RESULT_CODE appendData(uint8_t *chunkData, uint32_t chunkDataSize);
+ RESULT_CODE appendData(uint8_t* chunkData, uint32_t chunkDataSize);
/**
* \brief Getter of message size including protocol header
@@ -170,7 +180,7 @@ class ProtocolPacket {
* \param messageSize Incoming message size
* \return \saRESULT_CODE Status of serialization
*/
- RESULT_CODE deserializePacket(const uint8_t *message,
+ RESULT_CODE deserializePacket(const uint8_t* message,
const size_t messageSize);
/**
@@ -199,10 +209,13 @@ class ProtocolPacket {
uint8_t service_type() const;
/**
- *\brief Getter of frame data (start/end session, number of frame etc)
+ *\brief Getter and setter of frame data (start/end session, number of frame
+ *etc)
*/
uint8_t frame_data() const;
+ void set_frame_data(const uint8_t frame_data);
+
/**
*\brief Getter of session number
*/
@@ -221,7 +234,7 @@ class ProtocolPacket {
/**
*\brief Getter of message string
*/
- uint8_t *data() const;
+ uint8_t* data() const;
/**
*\brief Setter for size of multiframe message
@@ -231,8 +244,7 @@ class ProtocolPacket {
/**
*\brief Setter for new data
*/
- void set_data(const uint8_t *const new_data,
- const size_t new_data_size);
+ void set_data(const uint8_t* const new_data, const size_t new_data_size);
/**
*\brief Getter for size of multiframe message
@@ -243,13 +255,18 @@ class ProtocolPacket {
/**
* \brief Getter for Connection Identifier
*/
- uint8_t connection_id() const;
+ ConnectionID connection_id() const;
/**
* \brief Getter for data payload size
*/
uint32_t payload_size() const;
+ /**
+ * \brief Getter for full header information
+ */
+ const ProtocolHeader& packet_header() const;
+
private:
/**
*\brief Protocol header
@@ -275,8 +292,43 @@ class ProtocolPacket {
DISALLOW_COPY_AND_ASSIGN(ProtocolPacket);
};
} // namespace protocol_handler
-/**
- * @brief Type definition for variable that hold shared pointer to protocolol packet
- */
+ /**
+ * @brief Type definition for variable that hold shared pointer to protocolol
+ * packet
+ */
typedef utils::SharedPtr<protocol_handler::ProtocolPacket> ProtocolFramePtr;
+typedef std::list<ProtocolFramePtr> ProtocolFramePtrList;
+
+template <typename _CharT>
+std::basic_ostream<_CharT>& operator<<(
+ std::basic_ostream<_CharT>& stream,
+ const protocol_handler::ProtocolPacket::ProtocolHeader& header) {
+ stream << "Version: " << static_cast<uint32_t>(header.version)
+ << ", Protection: " << (header.protection_flag ? "ON" : "OFF")
+ << ", FrameType: " << static_cast<uint32_t>(header.frameType)
+ << ", ServiceType: " << static_cast<uint32_t>(header.serviceType)
+ << ", FrameData: " << static_cast<uint32_t>(header.frameData)
+ << ", SessionId: " << static_cast<uint32_t>(header.sessionId)
+ << ", DataSize: " << static_cast<uint32_t>(header.dataSize)
+ << ", MessageId: " << static_cast<uint32_t>(header.messageId);
+ return stream;
+}
+template <typename _CharT>
+std::basic_ostream<_CharT>& operator<<(
+ std::basic_ostream<_CharT>& stream,
+ const protocol_handler::ProtocolPacket& packet) {
+ stream << packet.packet_header()
+ << ", ConnectionID: " << static_cast<uint32_t>(packet.connection_id())
+ << ", TotalDataBytes: " << (packet.total_data_bytes())
+ << ", Data: " << static_cast<void*>(packet.data());
+ return stream;
+}
+template <typename _CharT>
+std::basic_ostream<_CharT>& operator<<(std::basic_ostream<_CharT>& stream,
+ const ProtocolFramePtr packet_ptr) {
+ if (packet_ptr) {
+ return stream << *packet_ptr;
+ }
+ return stream << "empty smart pointer";
+}
#endif // SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_PACKET_H_