O2 2.0
A communication protocol for interactive music and media applications.
mqtt.h
1// mqtt.h -- MQTT protocol extension
2//
3// Roger B. Dannenberg
4// August 2020
5
6/* This extension provides discovery and communication between O2 processes
7that are not on the same LAN and are possibly behind NAT. See o2/doc/mqtt.txt
8for design details. */
9
10#ifndef O2_NO_MQTT
11
12class MQTT_info : public Proxy_info {
13public:
14 O2time timeout;
15 MQTT_info(const char *key, int tag) : Proxy_info(key, tag) {
16 timeout = o2_local_time() + 5;
17 }
18 ~MQTT_info();
19
20 // Implement the Net_interface:
21 // do nothing, just start receiving messages:
22 virtual O2err connected() { return O2_SUCCESS; }
23 virtual O2err accepted(Fds_info *conn) { return O2_FAIL; } // not a server
24 virtual O2err deliver(O2netmsg_ptr msg);
25
26 bool local_is_synchronized() { o2_send_clocksync_proc(this);
27 return IS_SYNCED(this); }
28 virtual O2status status(const char **process) {
29 if (process) {
30 *process = get_proc_name();
31 }
32 return (o2_clock_is_synchronized && IS_SYNCED(this)) ?
34 }
35 virtual O2err send(bool block);
36#ifndef O2_NO_DEBUG
37 void show(int indent) {
38 O2node::show(indent);
39 printf("\n");
40 }
41#endif
42};
43
44extern Vec<MQTT_info *> o2_mqtt_procs;
45
46extern bool o2_mqtt_waiting_for_public_ip;
47
48O2err o2_mqtt_send_disc();
49
50O2err o2_mqtt_initialize();
51
52O2err o2_mqtt_finish();
53
54void o2_mqtt_disc_handler(char *payload, int payload_len);
55
56O2err o2_mqtt_can_send();
57
58#endif
Definition: o2network.h:147
Definition: mqtt.h:12
Definition: o2node.h:291
Definition: vec.h:6
bool o2_clock_is_synchronized
A variable indicating that the clock is the reference or is synchronized to the reference.
Definition: clock.cpp:26
O2time o2_local_time()
Get the real time using the local O2 clock.
Definition: clock.cpp:644
double O2time
O2 timestamps are doubles representing seconds since the approximate start time of the ensemble.
Definition: o2.h:625
O2status
Status return codes for the o2_status function.
Definition: o2.h:435
O2err
return values used generally by O2 functions
Definition: o2.h:329
@ O2_REMOTE_NOTIME
remote service but no clock sync yet
Definition: o2.h:453
@ O2_REMOTE
remote service with clock sync.
Definition: o2.h:502
@ O2_SUCCESS
function was successful
Definition: o2.h:332
@ O2_FAIL
a non-specific error occurred.
Definition: o2.h:339
Definition: o2network.h:57