WSF
WsfCommEvent.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#ifndef WSFCOMMEVENT_HPP
13#define WSFCOMMEVENT_HPP
14
15#include "wsf_export.h"
16
17#include <cstddef> // for size_t
18#include <functional>
19#include <memory>
20
21#include "WsfEvent.hpp"
22
23namespace wsf
24{
25namespace comm
26{
27
28class Comm;
29class Message;
30
32
34{
35public:
36 Event(double aSimTime, Comm* aXmtrPtr);
37 ~Event() override;
38
39 EventDisposition Execute() override;
40
41 static void ScheduleDeliverMessageEvent(double aSimTime, Comm* aXmtrPtr, Comm* aRcvrPtr, Message* aCommMessagePtr);
42
43private:
47 size_t mXmtrPlatformIndex;
48
51 size_t mRcvrPlatformIndex;
52
55 Comm* mXmtrPtr;
56
59 Comm* mRcvrPtr;
60
66 double mLastStatusChangeTime;
67
69 Message* mCommMessagePtr;
70};
71
72template<class T>
74{
75public:
76 GenericEvent(double aSimTime, const std::shared_ptr<T>& aContextPtr, const std::function<void()>& aFunc)
77 : WsfEvent(aSimTime)
78 , mContextPtr{aContextPtr}
79 , mFunction{aFunc}
80 {
81 }
82 ~GenericEvent() override = default;
83
85 {
86 if (!mContextPtr.expired())
87 {
88 mFunction();
89 }
90 return WsfEvent::cDELETE;
91 }
92
93private:
94 std::weak_ptr<T> mContextPtr;
95 std::function<void()> mFunction;
96};
97
98
99} // namespace comm
100} // namespace wsf
101
102#endif
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
WsfEvent()=default
EventDisposition
Definition WsfEvent.hpp:37
@ cDELETE
Delete the event from the event queue.
Definition WsfEvent.hpp:38
Definition WsfComm.hpp:43
static void ScheduleDeliverMessageEvent(double aSimTime, Comm *aXmtrPtr, Comm *aRcvrPtr, Message *aCommMessagePtr)
Definition WsfCommEvent.cpp:80
Event(double aSimTime, Comm *aXmtrPtr)
Definition WsfCommEvent.cpp:34
EventDisposition Execute() override
Definition WsfCommEvent.cpp:55
GenericEvent(double aSimTime, const std::shared_ptr< T > &aContextPtr, const std::function< void()> &aFunc)
Definition WsfCommEvent.hpp:76
EventDisposition Execute() override
Definition WsfCommEvent.hpp:84
~GenericEvent() override=default
Definition WsfCommMessage.hpp:51
Definition WsfComm.cpp:34
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Copyrights Multiple, All Rights Reserved