10 #include <dpsim-models/Attribute.h>
11 #include <dpsim-models/Logger.h>
12 #include <dpsim-models/Task.h>
13 #include <dpsim/Config.h>
14 #include <dpsim/Definitions.h>
15 #include <dpsim/Interface.h>
16 #include <dpsim/Scheduler.h>
18 #include <readerwriterqueue.h>
22 class InterfaceWorker;
27 typedef std::shared_ptr<InterfaceQueued> Ptr;
29 using AttributePacket =
struct AttributePacket {
36 enum AttributePacketFlags {
38 PACKET_CLOSE_INTERFACE = 1,
41 InterfaceQueued(std::shared_ptr<InterfaceWorker> intf,
const String &name =
"", UInt downsampling = 1) :
Interface(name), mInterfaceWorker(intf), mDownsampling(downsampling) {
42 mQueueDpsimToInterface = std::make_shared<moodycamel::BlockingReaderWriterQueue<AttributePacket>>();
43 mQueueInterfaceToDpsim = std::make_shared<moodycamel::BlockingReaderWriterQueue<AttributePacket>>();
46 virtual void open()
override;
47 virtual void close()
override;
51 virtual void pushDpsimAttrsToQueue();
54 virtual void popDpsimAttrsFromQueue(
bool isSync =
false);
57 virtual void syncExports()
override;
61 virtual CPS::Task::List getTasks()
override;
63 virtual void setLogger(CPS::Logger::Log log)
override;
71 std::shared_ptr<InterfaceWorker> mInterfaceWorker;
73 std::thread mInterfaceWriterThread;
74 std::thread mInterfaceReaderThread;
76 std::shared_ptr<moodycamel::BlockingReaderWriterQueue<AttributePacket>> mQueueDpsimToInterface;
77 std::shared_ptr<moodycamel::BlockingReaderWriterQueue<AttributePacket>> mQueueInterfaceToDpsim;
82 std::shared_ptr<moodycamel::BlockingReaderWriterQueue<AttributePacket>> mQueueDpsimToInterface;
83 std::shared_ptr<InterfaceWorker> mInterfaceWorker;
86 WriterThread(std::shared_ptr<moodycamel::BlockingReaderWriterQueue<AttributePacket>> queueDpsimToInterface, std::shared_ptr<InterfaceWorker> intf)
87 : mQueueDpsimToInterface(queueDpsimToInterface), mInterfaceWorker(intf){};
88 void operator()()
const;
93 std::shared_ptr<moodycamel::BlockingReaderWriterQueue<AttributePacket>> mQueueInterfaceToDpsim;
94 std::shared_ptr<InterfaceWorker> mInterfaceWorker;
95 std::atomic<bool> &mOpened;
98 ReaderThread(std::shared_ptr<moodycamel::BlockingReaderWriterQueue<AttributePacket>> queueInterfaceToDpsim, std::shared_ptr<InterfaceWorker> intf, std::atomic<bool> &opened)
99 : mQueueInterfaceToDpsim(queueInterfaceToDpsim), mInterfaceWorker(intf), mOpened(opened){};
100 void operator()()
const;
106 for (
const auto &[attr, _seqId, _blockOnRead, _syncOnStart] : intf.mImportAttrsDpsim) {
107 mModifiedAttributes.push_back(attr);
111 void execute(Real time, Int timeStepCount)
override;
120 for (
const auto &[attr, _seqId] : intf.mExportAttrsDpsim) {
121 mAttributeDependencies.push_back(attr);
123 mModifiedAttributes.push_back(Scheduler::external);
126 void execute(Real time, Int timeStepCount)
override;
Tasks to be defined by every component.
virtual void syncImports() override
Function called by the Simulation to perform interface synchronization.