Motion Master
Loading...
Searching...
No Matches
machine.h
Go to the documentation of this file.
1#pragma once
2
3#include <readerwriterqueue/readerwriterqueue.h>
4
5#include <functional>
6#include <list>
7#include <queue>
8#include <zmq.hpp>
9
12
14class Notifier;
15class CommandWorker;
16namespace ctpl {
17class thread_pool;
18}
19
20class Machine {
21 public:
27 void add_message(IncomingMachineMessage &incoming_machine_message);
28
35 virtual void execute(uint64_t pending_signals) = 0;
36
42 virtual void abort_client_requests(const std::string &connection_id) = 0;
43
56
63 virtual bool done() = 0;
64
65 protected:
66 Machine(VirtualDeviceManager &vdm, ctpl::thread_pool &thread_pool,
67 Notifier &notifier,
68 moodycamel::ReaderWriterQueue<OutgoingMachineMessage>
69 &outgoing_machine_message_queue);
70
71 virtual ~Machine();
72
74 ctpl::thread_pool &thread_pool_;
75 std::queue<IncomingMachineMessage> incoming_message_queue_;
77
83 void start_command_worker(IncomingMachineMessage &incoming_machine_message);
84
91 std::function<void(CommandWorker *)> process = nullptr);
92
101 std::string connection_id,
102 motionmaster::MotionMasterMessage &message);
103
104 private:
105 moodycamel::ReaderWriterQueue<OutgoingMachineMessage>
106 &outgoing_machine_message_queue_;
107 std::list<CommandWorker *> command_workers_;
108};
Definition: command_worker.h:17
Definition: incoming_machine_message.h:5
Protocol
Definition: machine_message.h:9
Definition: machine.h:20
Notifier & notifier_
Definition: machine.h:76
void process_command_workers(std::function< void(CommandWorker *)> process=nullptr)
Process all of the available Command Workers.
Definition: machine.cc:30
ctpl::thread_pool & thread_pool_
Definition: machine.h:74
VirtualDeviceManager & vdm_
Definition: machine.h:73
virtual void abort_client_requests(const std::string &connection_id)=0
Abort all of the requests a certain client has issues.
Definition: machine.cc:70
virtual ~Machine()
Definition: machine.cc:15
virtual bool done()=0
Check if all of the machine started processes are done (including the Command Workers)
std::queue< IncomingMachineMessage > incoming_message_queue_
Definition: machine.h:75
void send_response(MachineMessage::Protocol protocol, std::string connection_id, motionmaster::MotionMasterMessage &message)
Send the response (Status protobuf message) to the proper client.
Definition: machine.cc:80
virtual void execute(uint64_t pending_signals)=0
Execute the machine.
void start_command_worker(IncomingMachineMessage &incoming_machine_message)
Definition: machine.cc:61
void add_message(IncomingMachineMessage &incoming_machine_message)
Add a new incoming machine message to the queue.
Definition: machine.cc:57
bool command_workers_done()
Check if all started Command Workers are done.
Definition: machine.cc:78
Definition: notifier.h:10
Definition: virtual_device_manager.h:16
Definition: machine.h:16