@@ -23,6 +23,7 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
2323#include " architecture/utilities/bskLogging.h"
2424#include < typeinfo>
2525#include < stdlib.h>
26+ #include < functional>
2627
2728/* ! forward-declare sim message for use by read functor */
2829template <typename messageType>
@@ -38,6 +39,8 @@ class ReadFunctor{
3839 messageType* payloadPointer; // !< -- pointer to the incoming msg data
3940 MsgHeader *headerPointer; // !< -- pointer to the incoming msg header
4041 bool initialized; // !< -- flag indicating if the input message is connect to another message
42+ std::function<void ()> refIncCallback;
43+ std::function<void ()> refDecCallback;
4144
4245public:
4346 // !< -- BSK Logging
@@ -46,10 +49,18 @@ class ReadFunctor{
4649
4750
4851 // ! constructor
49- ReadFunctor () : initialized(false ) {};
52+ ReadFunctor () :
53+ initialized (false ),
54+ refIncCallback ([](){}),
55+ refDecCallback ([](){}) {}
5056
5157 // ! constructor
52- ReadFunctor (messageType* payloadPtr, MsgHeader *headerPtr) : payloadPointer(payloadPtr), headerPointer(headerPtr), initialized(true ){};
58+ ReadFunctor (messageType* payloadPtr, MsgHeader *headerPtr) :
59+ payloadPointer (payloadPtr),
60+ headerPointer (headerPtr),
61+ initialized (true ),
62+ refIncCallback ([](){}),
63+ refDecCallback ([](){}) {}
5364
5465 // ! constructor
5566 const messageType& operator ()(){
@@ -174,6 +185,42 @@ class ReadFunctor{
174185
175186 // ! Recorder method description
176187 Recorder<messageType> recorder (uint64_t timeDiff = 0 ){return Recorder<messageType>(this , timeDiff);}
188+
189+ /* *
190+ * @brief Set the reference counting callbacks for the source message
191+ * @param incRef Function to increment source reference count
192+ * @param decRef Function to decrement source reference count
193+ */
194+ void setSourceRef (std::function<void ()> incRef, std::function<void()> decRef) {
195+ if (refDecCallback) {
196+ refDecCallback ();
197+ }
198+ refIncCallback = incRef;
199+ refDecCallback = decRef;
200+ if (refIncCallback) {
201+ refIncCallback ();
202+ }
203+ }
204+
205+ /* ! Check if this reader is subscribed to a specific message source
206+ * @param source Pointer to message source to check
207+ * @return 1 if subscribed, 0 if not
208+ */
209+ uint8_t isSubscribedTo (const Message<messageType>* source) const {
210+ if (!source) return 0 ;
211+ return (this ->payloadPointer == source->getPayloadPtr () &&
212+ this ->headerPointer == source->getHeaderPtr ());
213+ }
214+
215+ /* ! Check if this reader is subscribed to a void pointer source
216+ * @param source Void pointer to message source to check
217+ * @return 1 if subscribed, 0 if not
218+ */
219+ uint8_t isSubscribedTo (const void * source) const {
220+ const Message<messageType>* msgSource =
221+ static_cast <const Message<messageType>*>(source);
222+ return isSubscribedTo (msgSource);
223+ }
177224};
178225
179226/* ! Write Functor */
@@ -232,6 +279,16 @@ class Message{
232279
233280 // ! Return the memory size of the payload, be careful about dynamically sized things
234281 uint64_t getPayloadSize () {return sizeof (messageType);};
282+
283+ /* ! Get pointer to message payload
284+ * @return Const pointer to payload data
285+ */
286+ const messageType* getPayloadPtr () const { return &payload; }
287+
288+ /* ! Get pointer to message header
289+ * @return Const pointer to message header
290+ */
291+ const MsgHeader* getHeaderPtr () const { return &header; }
235292};
236293
237294
0 commit comments