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.h108
1 files changed, 42 insertions, 66 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 2e3d39fd4..0b4b253a8 100644
--- a/src/components/protocol_handler/include/protocol_handler/protocol_packet.h
+++ b/src/components/protocol_handler/include/protocol_handler/protocol_packet.h
@@ -35,67 +35,45 @@
#include "utils/macro.h"
#include "protocol/common.h"
-#include "protocol/common.h"
+#include "transport_manager/common.h"
/**
*\namespace protocol_handlerHandler
*\brief Namespace for SmartDeviceLink ProtocolHandler related functionality.
*/
namespace protocol_handler {
+
+typedef transport_manager::ConnectionUID ConnectionID;
/**
* \class ProtocolPacket
* \brief Class for forming/parsing protocol headers of the message and
* handling multiple frames of the message.
*/
class ProtocolPacket {
- private:
+ public:
/**
* \struct ProtocolData
* \brief Used for storing message and its size.
*/
struct ProtocolData {
- ProtocolData()
- : data(0), totalDataBytes(0x00) {
- }
+ ProtocolData();
+ ~ProtocolData();
uint8_t *data;
uint32_t totalDataBytes;
};
/**
- * \struct ProtocolHeader
+ * \class ProtocolHeader
* \brief Used for storing protocol header of a message.
*/
- struct ProtocolHeader {
- /**
- * \brief Constructor
- */
- ProtocolHeader()
- : version(0x00),
- protection_flag(PROTECTION_OFF),
- frameType(0x00),
- serviceType(0x00),
- frameData(0x00),
- sessionId(0x00),
- dataSize(0x00),
- messageId(0x00) {
- }
- /**
- * \brief Constructor
- */
+ class ProtocolHeader {
+ public:
+ ProtocolHeader();
ProtocolHeader(uint8_t version, bool protection,
uint8_t frameType,
uint8_t serviceType,
uint8_t frameData, uint8_t sessionID,
- uint32_t dataSize, uint32_t messageID)
- : version(version),
- protection_flag(protection),
- frameType(frameType),
- serviceType(serviceType),
- frameData(frameData),
- sessionId(sessionID),
- dataSize(dataSize),
- messageId(messageID) {
- }
+ uint32_t dataSize, uint32_t messageID);
uint8_t version;
bool protection_flag;
uint8_t frameType;
@@ -104,9 +82,28 @@ class ProtocolPacket {
uint8_t sessionId;
uint32_t dataSize;
uint32_t messageId;
+ void deserialize(const uint8_t *message, const size_t messageSize);
+ };
+ /**
+ * \class ProtocolHeaderValidator
+ * \brief Used for ProtocolHeader validation
+ */
+ class ProtocolHeaderValidator {
+ public:
+ ProtocolHeaderValidator();
+ /**
+ * \brief Setter/getter maximum payload size of packets
+ */
+ void set_max_payload_size(const size_t max_payload_size);
+ size_t max_payload_size() const;
+ /**
+ * \brief Check ProtocolHeader according to protocol requiements
+ */
+ RESULT_CODE validate(const ProtocolHeader& header) const;
+ private:
+ size_t max_payload_size_;
};
- public:
/**
* \brief Default constructor
*/
@@ -115,14 +112,9 @@ class ProtocolPacket {
/**
* \brief Constructor
*
- * \param connectionKey Identifier of connection within wich message
- * is transferred
* \param connection_id - Connection Identifier
- * \param data Message string
- * \param dataSize Message size
*/
- ProtocolPacket(uint8_t connection_id, uint8_t *data,
- uint32_t dataSize);
+ explicit ProtocolPacket(ConnectionID connection_id);
/**
* \brief Constructor
@@ -137,18 +129,12 @@ class ProtocolPacket {
* \param dataSize Size of message string
* \param messageID ID of message or hash code - only for second protocol
* \param data Message string if provided
- * \param packet_id - ID for multiframe messages
*/
- ProtocolPacket(uint8_t connection_id,
+ 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,
- uint32_t packet_id = 0);
- /**
- * \brief Destructor
- */
- ~ProtocolPacket();
+ uint32_t messageID, const uint8_t *data = 0);
/*Serialization*/
/**
@@ -171,14 +157,10 @@ class ProtocolPacket {
*/
size_t packet_size() const;
- /**
- * \brief Getter of message ID
- * \return uint32_t message ID
- */
- uint32_t packet_id() const;
-
/*End of Serialization*/
+ bool operator==(const protocol_handler::ProtocolPacket& other) const;
+
/*Deserialization*/
/**
@@ -189,7 +171,7 @@ class ProtocolPacket {
* \return \saRESULT_CODE Status of serialization
*/
RESULT_CODE deserializePacket(const uint8_t *message,
- uint32_t messageSize);
+ const size_t messageSize);
/**
* \brief Getter of protocol version.
@@ -285,22 +267,16 @@ class ProtocolPacket {
uint32_t payload_size_;
/**
- *\brief Offset for multiframe messages
- */
- uint32_t data_offset_;
-
- /**
- *\brief ID for multiframe messages
- */
- uint32_t packet_id_;
-
- /**
* \brief Connection Identifier
* Obtained from connection_handler
*/
- uint8_t connection_id_;
+ ConnectionID connection_id_;
DISALLOW_COPY_AND_ASSIGN(ProtocolPacket);
};
} // namespace protocol_handler
+/**
+ * @brief Type definition for variable that hold shared pointer to protocolol packet
+ */
+typedef utils::SharedPtr<protocol_handler::ProtocolPacket> ProtocolFramePtr;
#endif // SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_PACKET_H_