VR-Engage  2.2
Loading...
Searching...
No Matches
cigiPublisherBase.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies, Inc.
3** All rights reserved.
4*******************************************************************************/
5#pragma once
6
9
10#include "vreUtil/treeClass.h"
11
12#include <CigiOutgoingMsg.h>
13
14#include <memory>
15#include <string>
16
17namespace makVre
18{
19
20//! @brief Base class for CIGI Publishers
21//!
22//! Publishers manage updating CIGI data, tracking dirty state, and writing to CigiOutgoingMsg when values have
23//! changed. Publishers can be parented to other Publishers, and parent Publishers init, tick, and publish their
24//! children.
26 : public DtSpSubClass<DtCigiPublisherBase, DtTreeClass<DtCigiPublisherBase, DtCigiObjectBase>>
27{
28public:
30 virtual ~DtCigiPublisherBase() override {};
31
32 //! @brief Get pointer to shared CIGI packet data object
33 //!
34 //! Shared data allows Publishers in different Sessions publishing data for the same
35 //! Sim entity to share common data which only needs to be updated once per Sim frame.
37 DtCigiDataBase* const shared() const;
38
39 virtual bool init() override;
40
41 //! @brief Enable or disable this Publisher
42 //!
43 //! Tick and publish are suppressed when disabled.
44 virtual void setEnabled(bool enabled);
45 virtual bool enabled() const;
46
47 virtual void tick(double dt);
48
49 //! @brief Convenience wrapper for creating, naming, and adding a child Publisher instance
50 //! of type CHILD_T.
51 //!
52 //! @return Shared pointer to new child Publisher object.
53 template <class CHILD_T>
54 std::shared_ptr<CHILD_T> addNewChild(const std::string& name = "")
55 {
56 std::shared_ptr<CHILD_T> ptr = CHILD_T::createVersion(sessionVersion());
57 ptr->setName(name);
58 addChild(ptr);
59 return ptr;
60 }
61
62 //! @brief Adds publisher as child of this Publisher.
63 //!
64 //! Child will be re-parented to this. Publishers may have only one parent.
65 //!
66 //! @param child Pointer to Publisher to add as child.
67 //! @return Bool indicating success.
68 virtual bool addChild(Sptr child) override;
69
70 //! @brief Causes this Publisher to write CIGI packet data to out.
71 //!
72 //! Invokes updateCigi() to make sure data is fresh and determine dirty state
73 //! if not already dirty, then invokes write() to write data to CigiOutoingMsg
74 //! if state is dirty.
75 //!
76 //! @param out CigiOutgoingMsg to write CIGI packet data into.
77 virtual void publish(CigiOutgoingMsg& out);
78
79 //! @brief Set/get whether this Publisher should get confirmation that IG has
80 //! received the last frame where this Publisher wrote data during publish().
81 //!
82 //! Set true when this publisher writes information that does not change often
83 //! but should be delivered reliably. Publisher will be marked as dirty to
84 //! force re-sending data if the frame containing the last write is not confimed
85 //! to have been received by the IG.
86 virtual void setNeedsReceiptConfirmation(bool needs);
87 virtual bool needsReceiptConfirmation() const;
88
89 //! @brief Called when the IG reports receiving the last frame in which this Pulisher
90 //! wrote data during publish().
91 //!
92 //! This function is only called if needsReceiptConfirmation() is true.
93 virtual void receiptConfirmed() {}
94
95 //! @brief Returns the time that last update was sent during publish().
96 //! (as cgf->simulationServices()->elapsedRealTime())
97 virtual double lastSent();
98
99 //! @brief Explictly mark this publisher as dirty so that the data is guaranteed to be
100 //! written during the next publish() call.
101 virtual void markDirty(bool childrenToo = false);
102
103 //! @brief Clear the dirty flag.
104 //!
105 //! Note that this does not suppress the normal update mechanism. If the data has
106 //! changed since the last publish() call, then this Publisher will again be
107 //! marked as dirty the next time the publish() invokes updateCigi().
108 virtual void markClean(bool childrenToo = false);
109
110protected:
111 //! @brief Key to uniquely idenfity the shared data instance associated with the
112 //! Sim object represented by this Publisher.
113 //!
114 //! No shared data will be created if sharedKey returns an empty string, which
115 //! is the default behavior if not overridden by the derived Publisher class.
116 //! Derived Publishers should override this function and return a suitable key
117 //! if they will be using shared data.
118 virtual std::string sharedKey() { return ""; }
119
120 virtual void setupShared();
121 virtual bool verifySharedType() = 0;
122
123 //! @brief Derived Publisher classes should override initShared() to set inital
124 //! values in the shared CIGI data object.
125 virtual void initShared() {}
126
127 //! @brief Derived Publisher classes should override initCigi() to set initial
128 //! values in the CIGI data.
129 virtual void initCigi() {}
130
131 //! @brief Derived Publisher classes should override updateShared() to update values
132 //! in the shared CIGI data object.
133 //!
134 //! updateShared() is called only by the first Publisher for each shared data instance
135 //! to publish() during each Host frame.
136 virtual void updateShared() {}
137
138 //! @brief Derived Publisher classes should override updateCigi() to update values
139 //! in the CIGI data.
140 //!
141 //! If shared data is used, the expected pattern is to copy values from shared data
142 //! into CIGI data at this point. updateShared() is called, if necessary, before
143 //! updateCigi() so that shared data contains the most recent object state.
144 //!
145 //! updateCigi() is called during publish(), before write(). updateCigi() is expected
146 //! to set the dirty flag true if there are changes to the CIGI data. write() will be
147 //! called only if this Publisher is marked dirty.
148 virtual void updateCigi() {}
149
150 //! Internal class function invoked from publish if state is dirty. Packs CIGI data
151 //! into CigiOutgoingMsg.
152 virtual void write(CigiOutgoingMsg& out);
153
154 //! @brief Derived Publisher classes should override createChildre() to create
155 //! child Publishers, if necessary.
156 //!
157 //! createChildren() is called during init().
158 virtual void createChildren() {}
159
160 virtual void tickChildren(double dt);
161 virtual void publishChildren(CigiOutgoingMsg& out);
162
163protected:
165
169};
170
171#define UPDATE_FROM_SHARED(type, value) updateValue<type>(&cigi()->value, shared()->value)
172
173} // namespace makVre
Base CigiData class used by DtCigiDataTemplate.
Definition cigiData.h:25
std::shared_ptr< DtCigiDataBase > CigiBasePtr
Definition cigiObjectBase.h:27
virtual unsigned int sessionVersion() const
Get CIGI protocol major version number for this Session.
virtual std::string sharedKey()
Key to uniquely idenfity the shared data instance associated with the Sim object represented by this ...
Definition cigiPublisherBase.h:118
CigiBasePtr mySharedData
Definition cigiPublisherBase.h:164
double myLastSentToIg
Definition cigiPublisherBase.h:168
DtCigiDataBase *const shared() const
virtual void publish(CigiOutgoingMsg &out)
Causes this Publisher to write CIGI packet data to out.
virtual void updateCigi()
Derived Publisher classes should override updateCigi() to update values in the CIGI data.
Definition cigiPublisherBase.h:148
virtual void setEnabled(bool enabled)
Enable or disable this Publisher.
virtual void createChildren()
Derived Publisher classes should override createChildre() to create child Publishers,...
Definition cigiPublisherBase.h:158
virtual ~DtCigiPublisherBase() override
Definition cigiPublisherBase.h:30
virtual void write(CigiOutgoingMsg &out)
Internal class function invoked from publish if state is dirty. Packs CIGI data into CigiOutgoingMsg.
virtual bool addChild(Sptr child) override
Adds publisher as child of this Publisher.
bool myEnabled
Definition cigiPublisherBase.h:166
virtual void setNeedsReceiptConfirmation(bool needs)
Set/get whether this Publisher should get confirmation that IG has received the last frame where this...
virtual void updateShared()
Derived Publisher classes should override updateShared() to update values in the shared CIGI data obj...
Definition cigiPublisherBase.h:136
virtual bool verifySharedType()=0
virtual bool needsReceiptConfirmation() const
virtual double lastSent()
Returns the time that last update was sent during publish(). (as cgf->simulationServices()->elapsedRe...
virtual void markDirty(bool childrenToo=false)
Explictly mark this publisher as dirty so that the data is guaranteed to be written during the next p...
bool myNeedsConfirmation
Definition cigiPublisherBase.h:167
virtual void tick(double dt)
DtCigiDataBase * shared()
Get pointer to shared CIGI packet data object.
virtual void initShared()
Derived Publisher classes should override initShared() to set inital values in the shared CIGI data o...
Definition cigiPublisherBase.h:125
std::shared_ptr< CHILD_T > addNewChild(const std::string &name="")
Convenience wrapper for creating, naming, and adding a child Publisher instance of type CHILD_T.
Definition cigiPublisherBase.h:54
virtual void initCigi()
Derived Publisher classes should override initCigi() to set initial values in the CIGI data.
Definition cigiPublisherBase.h:129
virtual void publishChildren(CigiOutgoingMsg &out)
virtual bool enabled() const
virtual bool init() override
virtual void receiptConfirmed()
Called when the IG reports receiving the last frame in which this Pulisher wrote data during publish(...
Definition cigiPublisherBase.h:93
virtual void markClean(bool childrenToo=false)
Clear the dirty flag.
virtual void tickChildren(double dt)
virtual std::string name() const
Gets the name of this object.
Definition baseClass.h:153
std::shared_ptr< DtCigiPublisherBase > Sptr
Definition baseClass.h:184
Contains the DLL export macro.
#define CIGIHOST_DLL
Definition export.h:20
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
Provides a generic hierarchical tree structure implementation.