WSF
WsfMessage.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11// ****************************************************************************
12// Updated by Infoscitex, a DCS Company
13// ****************************************************************************
14
15#ifndef WSFMESSAGE_HPP
16#define WSFMESSAGE_HPP
17
18#include "wsf_export.h"
19
20#include <iosfwd>
21#include <vector>
22
23#include "UtReferenceTracked.hpp"
24#include "UtScriptAccessible.hpp"
25#include "WsfAuxDataEnabled.hpp"
26#include "WsfCommAddress.hpp"
27class WsfPlatform;
28class WsfSimulation;
29#include "WsfStringId.hpp"
30
32class WSF_EXPORT WsfMessage : public UtScriptAccessible, public UtReferenceTracked, public WsfAuxDataEnabled
33{
34public:
35 // Although this isn't guaranteed, it's fixed for simulation purposes.
36 static constexpr size_t cBITS_IN_BYTE = 8U;
37
38 WsfMessage(WsfStringId aType); // For XIO Serialization
39
40 WsfMessage(WsfStringId aType, const wsf::comm::Address& aSrcAddr, WsfSimulation& aSimulation);
41 WsfMessage(WsfPlatform* aPlatformPtr);
42 WsfMessage(WsfStringId aType, WsfPlatform* aPlatformPtr);
43 WsfMessage(WsfStringId aType, WsfStringId aSubType, WsfPlatform* aPlatformPtr);
44 WsfMessage(WsfSimulation& aSimulation);
45 WsfMessage& operator=(const WsfMessage& aRhs) = default;
46 ~WsfMessage() override;
47
48 virtual WsfMessage* Clone() const;
49
50 const char* GetScriptClassName() const override;
51
52 static WsfStringId GetTypeId();
53
55 WsfSimulation* GetSimulation() const { return mSimulationPtr; }
56
60 void SetSimulation(WsfSimulation* aSimulationPtr) { mSimulationPtr = aSimulationPtr; }
61
64 WsfStringId GetOriginator() const { return mOriginator; }
65
67 void SetOriginator(WsfPlatform* aPlatformPtr);
68
71 size_t GetOriginatorIndex() const { return mOriginatorIndex; }
72
75 int GetSizeBits() const { return mSizeBits; }
76
79 void SetSizeBits(int aSizeBits) { mSizeBits = aSizeBits; }
80
83 int GetSizeBytes() const { return (mSizeBits / cBITS_IN_BYTE); }
84
87 void SetSizeBytes(int aSizeBytes) { mSizeBits = aSizeBytes * cBITS_IN_BYTE; }
88
91 unsigned int GetSerialNumber() const { return mSerialNumber; }
92
96 void SetSerialNumber(unsigned int aSerialNumber) { mSerialNumber = aSerialNumber; }
97
104 double GetDataTag() const { return mDataTag; }
105
108 void SetDataTag(double aDataTag) { mDataTag = aDataTag; }
109
113 WsfStringId GetStaticType() const { return mStaticType; }
114
117 WsfStringId GetType() const { return mType; }
118
121 void SetType(WsfStringId aType) { mType = aType; }
122
125 WsfStringId GetSubType() const { return mSubType; }
126
129 void SetSubType(WsfStringId aSubType) { mSubType = aSubType; }
130
134 int GetPriority() const { return mPriority; }
135
138 void SetPriority(int aPriority) { mPriority = aPriority; }
139
142 const wsf::comm::Address& GetSrcAddr() const { return mSrcAddr; }
143
146 /*void SetSrcAddr(const WsfCommAddress& aSrcAddr);*/
147 void SetSrcAddr(const wsf::comm::Address& aSrcAddr);
148
151 const wsf::comm::Address& GetDstAddr() const { return mDstAddr; }
152
155 void SetDstAddr(const wsf::comm::Address& aDstAddr) { mDstAddr = aDstAddr; }
156
159 const wsf::comm::Address& GetNextHopAddr() const { return mNextHopAddr; }
160
163 /*void SetNextHopAddr(const WsfCommAddress& aNextHopAddr);*/
164 void SetNextHopAddr(const wsf::comm::Address& aNextHopAddr);
165
166 virtual bool CanBeReplacedBy(const WsfMessage& aMessage) const;
167
174
175
176 virtual WsfStringId GetComponentNameId() const { return WsfStringId(); }
178 virtual WsfStringId GetComponentTypeId() const { return WsfStringId(); }
180 virtual WsfStringId GetComponentModeId() const { return WsfStringId(); }
182
191
192 WsfStringId GetGroup() const { return mGroup; }
193
195 void SetGroup(WsfStringId aGroup) const { mGroup = aGroup; }
197
198 friend WSF_EXPORT std::ostream& operator<<(std::ostream& aOut, const WsfMessage& aMessage);
199
203 void PrintDataTagPrecise(std::ostream& aStream, std::streamsize aPrecision) const;
204
206 template<typename T>
207 void Serialize(T& aBuff)
208 {
209 aBuff& mStaticType& mType& mSubType& mDataTag& mSerialNumber& mSizeBits& mPriority;
210 aBuff& mOriginator& mOriginatorIndex;
211 aBuff& mSrcAddr& mDstAddr& mNextHopAddr;
212 aBuff& mGroup;
214 }
215
216protected:
217 WsfMessage(const WsfMessage& aSrc) = default;
218
219private:
220 WsfSimulation* mSimulationPtr;
221 WsfStringId mStaticType;
222
223 WsfStringId mType;
224 WsfStringId mSubType;
225 double mDataTag;
226 unsigned int mSerialNumber;
227 int mSizeBits;
228 int mPriority;
229
230 WsfStringId mOriginator;
231 size_t mOriginatorIndex;
232
233 wsf::comm::Address mSrcAddr;
234 wsf::comm::Address mDstAddr;
235 wsf::comm::Address mNextHopAddr;
236
237 // Provided for legacy support of communications - expected removal for AFSIM 3.0.
238 mutable WsfStringId mGroup;
239};
240
241#endif
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
std::ostream & operator<<(std::ostream &aStream, const WsfTSPI &aTSPI)
Stream out operator (typically, to a file); units are converted on output.
Definition WsfTSPI.cpp:92
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
void Serialize(T &aBuff)
(De)serialization for XIO
Definition WsfAuxDataEnabled.hpp:68
WsfAuxDataEnabled()=default
A base class for messages sent among simulation communication objects, processors and sensors.
Definition WsfMessage.hpp:33
void SetSubType(WsfStringId aSubType)
Definition WsfMessage.hpp:129
const wsf::comm::Address & GetSrcAddr() const
Definition WsfMessage.hpp:142
virtual WsfStringId GetComponentModeId() const
Definition WsfMessage.hpp:180
void SetSimulation(WsfSimulation *aSimulationPtr)
Definition WsfMessage.hpp:60
const wsf::comm::Address & GetDstAddr() const
Definition WsfMessage.hpp:151
void SetType(WsfStringId aType)
Definition WsfMessage.hpp:121
static constexpr size_t cBITS_IN_BYTE
Definition WsfMessage.hpp:36
WsfStringId GetStaticType() const
Definition WsfMessage.hpp:113
void SetSizeBytes(int aSizeBytes)
Definition WsfMessage.hpp:87
WsfMessage(WsfStringId aType)
Constructor for XIO (de)serialization.
Definition WsfMessage.cpp:25
WsfMessage & operator=(const WsfMessage &aRhs)=default
void SetGroup(WsfStringId aGroup) const
Definition WsfMessage.hpp:195
void Serialize(T &aBuff)
(De)serializer for XIO
Definition WsfMessage.hpp:207
WsfStringId GetType() const
Definition WsfMessage.hpp:117
const char * GetScriptClassName() const override
Definition WsfMessage.cpp:235
void SetSerialNumber(unsigned int aSerialNumber)
Definition WsfMessage.hpp:96
void SetPriority(int aPriority)
Definition WsfMessage.hpp:138
const wsf::comm::Address & GetNextHopAddr() const
Definition WsfMessage.hpp:159
void SetDstAddr(const wsf::comm::Address &aDstAddr)
Definition WsfMessage.hpp:155
int GetSizeBytes() const
Definition WsfMessage.hpp:83
size_t GetOriginatorIndex() const
Definition WsfMessage.hpp:71
void SetDataTag(double aDataTag)
Definition WsfMessage.hpp:108
int GetSizeBits() const
Definition WsfMessage.hpp:75
unsigned int GetSerialNumber() const
Definition WsfMessage.hpp:91
static WsfStringId GetTypeId()
Definition WsfMessage.cpp:159
WsfStringId GetOriginator() const
Definition WsfMessage.hpp:64
virtual WsfMessage * Clone() const
Definition WsfMessage.cpp:150
WsfMessage(const WsfMessage &aSrc)=default
WsfStringId GetSubType() const
Definition WsfMessage.hpp:125
void SetSizeBits(int aSizeBits)
Definition WsfMessage.hpp:79
int GetPriority() const
Definition WsfMessage.hpp:134
virtual WsfStringId GetComponentNameId() const
Definition WsfMessage.hpp:176
WsfStringId GetGroup() const
Definition WsfMessage.hpp:192
double GetDataTag() const
Definition WsfMessage.hpp:104
virtual WsfStringId GetComponentTypeId() const
Definition WsfMessage.hpp:178
WsfSimulation * GetSimulation() const
Get the simulation that owns the message.
Definition WsfMessage.hpp:55
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfCommAddress.hpp:57
Copyrights Multiple, All Rights Reserved