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,96 @@
#ifndef MESSAGE
#define MESSAGE
#include <CommService/transmittable.hpp>
#include <string>
#include <vector>
namespace CommService {
enum messageTopic : std::uint16_t {
/// udp client joins
LOCAL_JOIN,
/// local udp clients leave
LOCAL_LEAVE,
/// remote participant joins the sim
JOIN,
/// remote participant leave the sim
LEAVE,
/// sends id to participant
ID_MESSAGE
};
enum deviceMajorType : std::uint16_t {
ID_SERVICE,
GATEWAY,
CIVIL_SHIP,
WAR_SHIP,
RADAR,
SONAR,
WEAPON
};
class Message : public transmittable{
public:
// the device id of the device/endpoint sending this Message
std::uint16_t sourceID;
/// the major type of the device/endpoint transmitting this message
deviceMajorType srcMajorType;
/// the minor type of the device/endpoint transmitting this message
std::string srcMinorType;
/// which topic does this message have ? helps identifying the transmitted datatype
messageTopic topic;
Message();
/**
* @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
*/
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);
void setData(const transmittable &d){data=d.toByteVector();}
/**
* @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 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;}
private:
std::vector<unsigned char> data;
};
};
#endif