VR-Engage  2.2
Loading...
Searching...
No Matches
rfxMessage.h
Go to the documentation of this file.
1// ******************************************************************************
2// ** Copyright (c) 2025 MAK Technologies
3// ** All rights reserved.
4// ******************************************************************************
5
6
7//! \file rfxMessage.h
8//! \brief Defines the base message class for RadarFX client-server communication
9//! \ingroup vreRadarFxShared
10//!
11//! This file contains the base message class used for all communications
12//! between RadarFX clients and servers
13
14
15#pragma once
16
17#include "export.h"
18#include "byteStream.h"
19#include "rfxMessageTypes.h"
20
21#include <string>
22
23namespace makRadarFx
24{
25//! \brief Base class for all RadarFX messages
26//!
27//! This abstract base class defines the interface and common functionality
28//! for all messages exchanged between RadarFX clients and servers. It provides
29//! serialization/deserialization capabilities and handles message identification
30//! through types, request IDs, and requester identification.
31//!
32//! All derived message classes must implement the clone() method and may override
33//! the serialize() and deserialize() methods to add custom data fields.
35{
36public:
37 //! \brief Default constructor
38 //!
39 //! Initializes a new message with default values for message type,
40 //! requester ID, and request ID
42
43 //! \brief Virtual destructor
44 //!
45 //! Ensures proper cleanup of derived message classes
46 virtual ~DtBaseMessage();
47
48 //! \brief Gets the message type identifier
49 //! \return Numeric identifier for the message type
50 //!
51 //! Returns the type identifier for this message, which is used for
52 //! message routing and handling
53 virtual unsigned int messageType() const;
54
55 //! \brief Encodes the message into a byte array
56 //! \return Pointer to the encoded byte array
57 //!
58 //! Converts the message into a byte array suitable for network transmission.
59 //! The caller is responsible for calling delete[] on the returned byte array
60 //! when it is no longer needed.
61 virtual unsigned char* encode();
62
63 //! \brief Decoding function prototype for derived classes
64 //!
65 //! Each derived message class should implement a static decode function:
66 //! static DtDerivedMessage* decode(unsigned char* buffer, int length);
67 //!
68 //! This function creates a new message instance from the encoded byte array
69 // static DtBaseMessage* decode(unsigned char* buffer, int length);
70
71 //! \brief Gets the size of the encoded message in bytes
72 //! \return Size of the message in bytes when encoded
73 //!
74 //! Calculates the total size required to encode this message
75 virtual int messageSize();
76
77 //! \brief Creates a deep copy of this message
78 //! \return Pointer to a new instance that is a copy of this message
79 //!
80 //! Creates a new message instance that is an exact copy of this message.
81 //! The caller is responsible for managing the memory of the returned object.
82 //! This is a pure virtual method that must be implemented by all derived classes.
83 virtual DtBaseMessage* clone() = 0;
84
85 //! \brief Sets the requester identifier for this message
86 //! \param requestor String identifier for the requester
87 //!
88 //! Sets the identifier of the entity sending this message. If left empty,
89 //! the DtRadarFxConnector will automatically assign a requester ID when the
90 //! message is sent using its requesterName() method.
91 virtual void setRequestorId(const std::string& requestor);
92
93 //! \brief Gets the requester identifier for this message
94 //! \return String identifier of the requester
95 //!
96 //! Returns the identifier of the entity that sent this message
97 virtual std::string requestorId();
98
99 //! \brief Sets the request identifier for this message
100 //! \param id Numeric identifier for the request
101 //!
102 //! Sets a unique identifier for this message request. If left at 0 (default),
103 //! the DtRadarFxConnector will automatically assign a request ID when the
104 //! message is sent using its nextId() method.
105 virtual void setRequestId(int id);
106
107 //! \brief Gets the request identifier for this message
108 //! \return Numeric identifier of the request
109 //!
110 //! Returns the unique identifier for this message request
111 virtual int requestId();
112
113protected:
114 //! \brief Serializes the message data to a stream writer
115 //! \param writer Reference to the stream writer to write the data to
116 //!
117 //! Writes the message data to the provided stream writer. Derived classes
118 //! should call the base class implementation before adding their own fields.
119 virtual void serialize(DtStreamWriter& writer);
120
121 //! \brief Deserializes message data from a stream reader
122 //! \param reader Reference to the stream reader to read the data from
123 //!
124 //! Reads the message data from the provided stream reader. Derived classes
125 //! should call the base class implementation before reading their own fields.
126 virtual void deserialize(DtStreamReader& reader);
127
128 //! \brief Message type identifier
129 unsigned int myMessageType;
130
131 //! \brief Identifier of the message sender
132 std::string myRequestorId;
133
134 //! \brief Unique identifier for this request
136};
137} // namespace makRadarFx
virtual void setRequestorId(const std::string &requestor)
Sets the requester identifier for this message.
unsigned int myMessageType
Message type identifier.
Definition rfxMessage.h:129
virtual ~DtBaseMessage()
Virtual destructor.
virtual int messageSize()
Decoding function prototype for derived classes.
virtual int requestId()
Gets the request identifier for this message.
std::string myRequestorId
Identifier of the message sender.
Definition rfxMessage.h:132
virtual void serialize(DtStreamWriter &writer)
Serializes the message data to a stream writer.
virtual unsigned int messageType() const
Gets the message type identifier.
DtBaseMessage()
Default constructor.
virtual void setRequestId(int id)
Sets the request identifier for this message.
virtual void deserialize(DtStreamReader &reader)
Deserializes message data from a stream reader.
virtual std::string requestorId()
Gets the requester identifier for this message.
int myRequestId
Unique identifier for this request.
Definition rfxMessage.h:135
virtual DtBaseMessage * clone()=0
Creates a deep copy of this message.
virtual unsigned char * encode()
Encodes the message into a byte array.
Stream reader for decoding values from a byte array in little endian format.
Definition byteStream.h:32
Stream writer for encoding values into a byte array in little endian format.
Definition byteStream.h:159
Defines export macros for the RadarFx Shared library.
#define RFX_DLL_SHARED
Export/import macro for non-Windows platforms (empty)
Definition export.h:25
Definition radarFxConnectorDriver.h:21
Defines the message type identifiers for all standard RadarFX messages.
Defines stream readers and writers for encoding and decoding messages from byte arrays.