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
11
13class Notifier;
14class CommandWorker;
15namespace ctpl {
16class thread_pool;
17}
18
19class Machine {
20 public:
26 void add_message(IncomingMachineMessage &incoming_machine_message);
27
34 virtual void execute(uint64_t pending_signals) = 0;
35
41 virtual void abort_client_requests(const std::string &connection_id) = 0;
42
55
62 virtual bool done() = 0;
63
64 protected:
65 Machine(VirtualDeviceManager &vdm, ctpl::thread_pool &thread_pool,
66 Notifier &notifier,
67 moodycamel::ReaderWriterQueue<OutgoingMachineMessage>
68 &outgoing_machine_message_queue);
69
70 virtual ~Machine();
71
73 ctpl::thread_pool &thread_pool_;
74 std::queue<IncomingMachineMessage> incoming_message_queue_;
76
82 void start_command_worker(IncomingMachineMessage &incoming_machine_message);
83
90 std::function<void(CommandWorker *)> process = nullptr);
91
100 std::string connection_id,
101 motionmaster::MotionMasterMessage &message);
102
103 private:
104 moodycamel::ReaderWriterQueue<OutgoingMachineMessage>
105 &outgoing_machine_message_queue_;
106 std::list<CommandWorker *> command_workers_;
107};
Definition: command_worker.h:16
Definition: incoming_machine_message.h:5
Protocol
Definition: machine_message.h:9
Definition: machine.h:19
Notifier & notifier_
Definition: machine.h:75
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:73
VirtualDeviceManager & vdm_
Definition: machine.h:72
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:74
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:9
Definition: virtual_device_manager.h:16
Definition: machine.h:15