O2 2.0
A communication protocol for interactive music and media applications.
processes.h
1/* processes.h - manage o2 processes and their service lists */
2
3/* Roger B. Dannenberg
4 * April 2020
5 */
6
7#ifndef O2_NO_HUB
8// hub flags are used to tell receiver of /dy message what to do.
9typedef enum hub_type {
10 O2_NOT_HUB = 0, // sender is normal discovery broadcast
11 O2_BE_MY_HUB = 1, // receiver is the hub
12 O2_HUB_CALL_ME_BACK = 2, // receiver is the hub, but hub needs to close
13 // socket and connect to sender
14 O2_I_AM_HUB = 3, // sender is the hub (and client), OR if this
15 // is an o2n_info.proc.hub
16 O2_HUB_REMOTE = 4 // remote is HUB
17} hub_type;
18#endif
19
20class Proc_info : public Proxy_info {
21public:
22 // store process name in key, e.g. "@128.2.1.100:55765". This is used
23 // so that when we add a service, we can enumerate all the processes and
24 // send them updates. Updates are addressed using this name field.
25 // name is "owned" by this process_info struct and will be deleted
26 // when the struct is freed:
27#ifndef O2_NO_HUB
28 // hub_remote indicates this remote process is our hub
29 // i_am_hub means this remote process treats local process as hub
30 // no_hub means neither case is true
31 hub_type uses_hub;
32#endif
33 Net_address udp_address;
34
35 Proc_info() : Proxy_info(NULL, O2TAG_PROC) {
36#ifndef O2_NO_HUB
37 uses_hub = O2_NOT_HUB;
38#endif
39 memset(&udp_address, 0, sizeof udp_address);
40 }
41 virtual ~Proc_info();
42
43 O2err send(bool block);
44
45 // Implement the Net_interface:
46 O2err accepted(Fds_info *conn);
47 O2err connected();
48 // O2err deliver(); is inherited from Proxy_info
49
50 bool local_is_synchronized() { o2_send_clocksync_proc(this);
51 return IS_SYNCED(this); }
52 virtual O2status status(const char **process) {
53 if (!(fds_info->net_tag & (NET_TCP_SERVER | NET_TCP_CLIENT |
54 NET_TCP_CONNECTION))) {
55 return O2_UNKNOWN; // maybe still connecting
56 }
57 if (process) {
58 *process = get_proc_name();
59 }
60 return (o2_clock_is_synchronized && IS_SYNCED(this)) ?
61 (this == o2_ctx->proc ? O2_LOCAL : O2_REMOTE) :
62 (this == o2_ctx->proc ? O2_LOCAL_NOTIME : O2_REMOTE_NOTIME);
63 }
64
65 const char *get_proc_name() {
66 if (key) return key;
67 if (this == o2_ctx->proc) return "_o2";
68 return NULL;
69 }
70
71 // send() is inherited from Proxy_info
72
73#ifndef O2_NO_DEBUG
74 void show(int indent);
75#endif
76
77 static Proc_info *create_tcp_proc(int tag, const char *ip, int *port);
78
79};
80
81
82#ifdef O2_NO_DEBUG
83#define TO_PROC_INFO(node) ((Proc_info *) (node))
84#else
85#define TO_PROC_INFO(node) (assert(ISA_PROC((Proc_info *) (node))), \
86 ((Proc_info *) (node)))
87void o2_show_sockets(void);
88
89#endif
90
91
92void o2_processes_initialize(void);
Definition: o2network.h:147
Definition: o2network.h:105
Definition: processes.h:20
Definition: o2node.h:291
bool o2_clock_is_synchronized
A variable indicating that the clock is the reference or is synchronized to the reference.
Definition: clock.cpp:26
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_LOCAL
local service with clock sync.
Definition: o2.h:496
@ O2_REMOTE_NOTIME
remote service but no clock sync yet
Definition: o2.h:453
@ O2_UNKNOWN
status is unknown, e.g. service does not exist
Definition: o2.h:438
@ O2_REMOTE
remote service with clock sync.
Definition: o2.h:502
@ O2_LOCAL_NOTIME
local service, no clock sync yet.
Definition: o2.h:445