VR-Engage  2.2
Loading...
Searching...
No Matches
rfxMessageFactory.h
Go to the documentation of this file.
1/*********************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*********************************************************************************/
5
6//! \file rfxMessageFactory.h
7//! \brief Defines a factory for creating and decoding RadarFX messages
8//! \ingroup vreRadarFxShared
9//!
10//! This file contains the message factory for creating DtBaseMessage instances from
11//! encoded byte arrays, supporting the serialization/deserialization system
12
13#pragma once
14
15#include "export.h"
16
17#include <vector>
18#include <map>
19
20namespace makRadarFx
21{
22
23//! \brief Forward declaration of the base message class
24class DtBaseMessage;
25
26//! \brief Function pointer type for message decoder functions
27//! \param bytes Pointer to the encoded byte array
28//! \param length Length of the encoded byte array
29//! \return Pointer to the newly created message instance
30//!
31//! This type defines the signature for message decoder functions that
32//! convert encoded byte arrays back into message objects
33typedef DtBaseMessage* (*Decoder)(unsigned char* bytes, int length);
34
35//! \brief Factory for creating RadarFX message objects from encoded data
36//!
37//! This class manages the creation of message objects from encoded byte arrays.
38//! It maintains a registry of message types and their corresponding decoder functions,
39//! allowing the system to dynamically create the appropriate message object
40//! based on the message type found in the encoded data.
42{
43public:
44 //! \brief Constructor with initialization options
45 //! \param initializeDefaults Whether to automatically register default message decoders
46 //! \param isBigEndian Whether the encoded data is in big-endian format
47 //!
48 //! Creates a new message factory. If initializeDefaults is true, the factory
49 //! will be automatically populated with decoders for all standard RadarFX messages.
50 DtVreMessageFactory(bool initializeDefaults = true, bool isBigEndian = false);
51
52 //! \brief Virtual destructor
53 //!
54 //! Cleans up factory resources
56
57 //! \brief Creates a message from encoded bytes
58 //! \param bytes Pointer to the encoded byte array
59 //! \param length Length of the encoded byte array
60 //! \return Pointer to the newly created message instance, or nullptr on error
61 //!
62 //! Decodes the message type from the byte array and creates the appropriate
63 //! message object. Returns nullptr if there is no decoder registered for the
64 //! message type or if decoding fails.
65 virtual DtBaseMessage* create(unsigned char* bytes, int length);
66
67 //! \brief Creates a message from encoded bytes with known message type
68 //! \param msgType The type of message to create
69 //! \param bytes Pointer to the encoded byte array
70 //! \param length Length of the encoded byte array
71 //! \return Pointer to the newly created message instance, or nullptr on error
72 //!
73 //! Creates a message object for the specified message type. Returns nullptr
74 //! if there is no decoder registered for the message type or if decoding fails.
75 virtual DtBaseMessage* create(int msgType, unsigned char* bytes, int length);
76
77 //! \brief Registers a message decoder function
78 //! \param type Message type identifier
79 //! \param decoder Function pointer to the decoder function
80 //!
81 //! Associates a message decoder function with a specific message type.
82 //! The decoder will be used to create message objects of that type when
83 //! decoding encoded data.
84 virtual void registerCreator(unsigned int type, Decoder decoder);
85
86 //! \brief Initializes the factory with decoders for standard message types
87 //!
88 //! Registers decoder functions for all the standard RadarFX message types.
89 //! This is automatically called by the constructor if initializeDefaults is true.
91
92 //! \brief Clears all registered decoders
93 //!
94 //! Removes all decoder registrations from the factory, effectively
95 //! resetting it to an empty state.
96 virtual void clear();
97
98protected:
99 //! \brief Type definition for the map of message types to decoder functions
100 typedef std::map<unsigned int, Decoder> DecoderMap;
101
102 //! \brief Map of message types to their corresponding decoder functions
104
105 //! \brief Flag indicating if the encoded data is in big-endian format
107};
108
109} // namespace makRadarFx
Base class for all RadarFX messages.
Definition rfxMessage.h:35
virtual DtBaseMessage * create(unsigned char *bytes, int length)
Creates a message from encoded bytes.
virtual ~DtVreMessageFactory()
Virtual destructor.
DecoderMap myCreatorMap
Map of message types to their corresponding decoder functions.
Definition rfxMessageFactory.h:103
DtVreMessageFactory(bool initializeDefaults=true, bool isBigEndian=false)
Constructor with initialization options.
bool myIsBigEndian
Flag indicating if the encoded data is in big-endian format.
Definition rfxMessageFactory.h:106
virtual void registerCreator(unsigned int type, Decoder decoder)
Registers a message decoder function.
virtual void clear()
Clears all registered decoders.
virtual void initializeDefaultMessages()
Initializes the factory with decoders for standard message types.
std::map< unsigned int, Decoder > DecoderMap
Type definition for the map of message types to decoder functions.
Definition rfxMessageFactory.h:100
virtual DtBaseMessage * create(int msgType, unsigned char *bytes, int length)
Creates a message from encoded bytes with known message type.
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
DtBaseMessage *(* Decoder)(unsigned char *bytes, int length)
Function pointer type for message decoder functions.
Definition rfxMessageFactory.h:33