WSF
WsfDisIO_Thread.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 WSFDISIO_THREAD_HPP
16#define WSFDISIO_THREAD_HPP
17
18#include "wsf_export.h"
19
20#include <list>
21#include <mutex>
22
23class DisPdu;
24
25class UtInput;
26#include "UtWallClock.hpp"
27class WsfDisInterface;
28#include "WsfThread.hpp"
29
32{
33public:
41
43 WsfDisIO_Thread(WsfDisInterface* aInterfacePtr);
44 ~WsfDisIO_Thread() override;
45
46 // Implementation of abstract base class methods.
47
48 FunctionType DoWork() override;
49 FunctionType Pause() override { return AVAILABLE; }
50
51 DisPdu* GetPdu();
52
53 void ImmediatePutPdu(double aSimTime, DisPdu* aPduPtr);
54
55 void PutPdu(double aSimTime, std::unique_ptr<DisPdu> aPduPtr);
56
57 void SendPduOnDevices(double aSimTime, DisPdu& aPdu);
58
59 void AdvanceTime(double aSimTime);
60 void Initialize(bool aAutostart);
61
62 void SimulationComplete();
63 void SimulationStarting();
64
65 void SetReceivePDUs(bool aReceivePDUs) { mReceivePDUs = aReceivePDUs; }
66 void SetOutboundPDUs(bool aSendOutboundPDUs) { mSendOutboundPDUs = aSendOutboundPDUs; }
67
68 void WaitForStartPDU(bool aWaitForStartPDU) { mWaitForStartPDU = aWaitForStartPDU; }
69
70private:
71 void TransitionState();
72 void ReceivePDUs();
73 void SendOutboundPDUs();
74
75 struct PDU
76 {
77 double mSimTime;
78 std::unique_ptr<DisPdu> mPduPtr;
79 };
80
81 // Mutex for handling thread access to the worker queue
82 // WsfDisInterface adds PDUs to the queue
83 // WsfDisIO_Thread reads and removes PDUs from the queue
84 std::recursive_mutex mIncomingMutex;
85 std::recursive_mutex mOutboundMutex;
86
87 WsfDisInterface* mInterfacePtr;
88
89 ThreadState mThreadState;
90
91 bool mSendOutboundPDUs;
92 bool mReceivePDUs;
93
94 std::list<DisPdu*> mIncomingPDUs;
95 std::list<PDU> mOutboundPDUs;
96
97 bool mWaitForStartPDU;
98
99 double mSimTime;
100
101 double mLastUpdate;
102 bool mTimedOut;
103
104 bool mIsRealTime;
105 UtWallClock mWallClock;
106};
107
108#endif
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
DIS interface implementation of worker thread.
Definition WsfDisIO_Thread.hpp:32
ThreadState
Definition WsfDisIO_Thread.hpp:35
@ IDLE
Definition WsfDisIO_Thread.hpp:36
@ WORK_COMPLETE
Definition WsfDisIO_Thread.hpp:39
@ SEND_OUTBOUND
Definition WsfDisIO_Thread.hpp:37
@ RCV_INCOMING
Definition WsfDisIO_Thread.hpp:38
WsfDisIO_Thread(WsfDisInterface *aInterfacePtr)
Constructor and destructor.
Definition WsfDisIO_Thread.cpp:31
void WaitForStartPDU(bool aWaitForStartPDU)
Definition WsfDisIO_Thread.hpp:68
void SetReceivePDUs(bool aReceivePDUs)
Definition WsfDisIO_Thread.hpp:65
FunctionType Pause() override
Definition WsfDisIO_Thread.hpp:49
void SetOutboundPDUs(bool aSendOutboundPDUs)
Definition WsfDisIO_Thread.hpp:66
Definition WsfDisInterface.hpp:83
WsfThread()=default
virtual FunctionType DoWork()=0
FunctionType
Definition WsfThread.hpp:26
@ AVAILABLE
Definition WsfThread.hpp:28
Copyrights Multiple, All Rights Reserved