1 // Asynchronous communicator
10 #include "msg_thread.h"
17 // Send a message to the "dest" mailbox
18 void ctrl_send(const char* dest, message* msg) {
19 ctrl_sent.push_back(real_send(dest, msg));
21 void data_send(const char* dest, message* msg) {
22 data_sent.push_back(real_send(dest, msg));
25 // Try to flush pending sending communications.
26 // If "wait" is true, blocks until success.
27 void ctrl_flush(bool wait) {
28 real_flush(ctrl_sent, wait);
30 void data_flush(bool wait) {
31 real_flush(data_sent, wait);
34 // Flush all sending_communications. Blocking.
37 // Try to get a message. Returns true on success.
38 // Parameter "timeout" may be 0 for non-blocking operation, -1 for
39 // infinite waiting, or any positive timeout.
40 bool ctrl_recv(message*& msg, m_host_t& from, double timeout) {
41 return ctrl_received.pop(msg, from, timeout);
43 bool data_recv(message*& msg, m_host_t& from, double timeout) {
44 return data_received.pop(msg, from, timeout);
51 // List of pending send communications
52 typedef std::vector<msg_comm_t> sent_comm_type;
53 sent_comm_type ctrl_sent;
54 sent_comm_type data_sent;
56 msg_comm_t real_send(const char* dest, message* msg);
57 void real_flush(sent_comm_type& sent_comm, bool wait);
59 // Queues of received messages
60 message_queue ctrl_received;
61 message_queue data_received;
63 // Handling of receiving thread
64 msg_thread* receiver_thread;
67 // Used to chek if a communication is successfull before destroying it
68 static void comm_check_n_destroy(msg_comm_t comm);
69 // If comm is over, call comm_check_n_destroy(comm), and return true
70 static bool comm_test_n_destroy(msg_comm_t comm);
73 #endif // !COMMUNICATOR_H