Squashed 'libs/CommService/' content from commit 7ccc0fc

git-subtree-dir: libs/CommService
git-subtree-split: 7ccc0fce88bbc5969df060058cf0fb57abe3bcf9
This commit is contained in:
Henry Winkel
2022-09-15 09:53:53 +02:00
commit cc67e4840f
799 changed files with 179487 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
#ifndef __LIBBC_BC_MESSAGE_HPP__
#define __LIBBC_BC_MESSAGE_HPP__
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/**
* @file
* @brief header file for the battle-com message class
* @author Dominik Meyer <dmeyer@hsu-hh.de>
* @date 2018-11-23
* @copyright 2018 no yet defined
*/
#include <BC/BC.hpp>
#include <BC/transmittable.hpp>
#include <vector>
#include <memory>
namespace BC
{
/**
* @brief simple datatype to combine all information of a message distributed through the publish subscriber system of libbattle-com++
*/
class Message : public BC::transmittable
{
private:
/// vector representing the object to transmit
std::vector<unsigned char> data;
public:
/// the device id of the device/endpoint sending this Message
BC::DataTypes::deviceIdType sourceID;
/// the device id of the device/endpoint which should receive this Message BC::Constants::allDevices for broadcast
BC::DataTypes::deviceIdType destinationID = BC::Constants::allDevices;
/// the major type of the device/endpoint transmitting this message
BC::DataTypes::deviceMajorType srcMajorType;
/// the minor type of the device/endpoint transmitting this message
std::string srcMinorType;
/// the time this Message was transmitted by calling the publish method of the PubSubService
BC::DataTypes::BCTimeType transmissionTime;
/// the time this Message was received by calling the subscribed method
BC::DataTypes::BCTimeType receptionTime;
/// the domain this message resides in
std::string domain;
/// which topic does this message have ? helps identifying the transmitted datatype
std::string topic;
/**
* @brief set the data object to transmit through the battle-com service
*
* @prarma d - an object implementing the transmittable interface
*/
void setData(const BC::transmittable &d){data=d.toByteVector();}
/**
* @brief set the data object to transmit through the battle-com service
*
* @param d - the object already converted to a byte vector
*/
void setData(const std::vector<unsigned char> &d){data=d;}
/**
* @brief return the raw byte vector of the data object, required for data reception
*
* @return the std::vector<unsigned char>
*/
std::vector<unsigned char> getRawData() const {return data;}
Message() : sourceID(0), destinationID(0), srcMajorType(BC::DataTypes::UNKNOWN), srcMinorType(""),
transmissionTime(0), receptionTime(0), domain(""), topic(""){}
virtual ~Message()=default;
/**
* @brief Constructor for generationg a Message object from a received std::vector<unsiged char>
*
* @param v - the std::vector<unsigned char> representing a message object
*/
explicit Message(std::vector<unsigned char>);
/**
* @brief Copy constructor of the Message class
*
* creates a copy of the object, including copies of all data
*
* @param obj - the object from which to copy everything
*/
Message(const Message &obj);
/**
* @brief returns the size in bytes of the whole message
*
*/
const uint64_t size() const;
/**
* @brief converts the whole message information into a byte vector
*
* all information of the message class is converted into a byte vector for transmission
* through any kind of network.
*
* @param payload - returns the byte vector by call by reference
*/
std::vector<unsigned char> toByteVector() const override;
/**
* @brief fills the message class with information from the given byte vector
*
* the message is filled with all the information from the provided
* byte vector, except the data attribute. The byte vector identifying the
* data is returned to the caller. The caller has to call the appropriate
* factory to generate the right object
*
* @param payload - provides the byte vector representing the message
* @param data - returns the byte vector representing the data attribute by call by reference
*/
void fromByteVector(std::vector<unsigned char> &payload, std::vector<unsigned char> &data);
};
}; // namespace BC
#endif