O2 2.0
A communication protocol for interactive music and media applications.
bridge.h
1// o2_bridge.h -- headers to support extensions for non-IP transports
2//
3// Roger B. Dannenberg
4// April 2018
5
102#ifndef O2_NO_BRIDGES
103
104#ifdef O2_NO_DEBUG
105#define TO_BRIDGE_INFO(node) ((Bridge_info *) (node))
106#else
107#define TO_BRIDGE_INFO(node) (assert(ISA_BRIDGE(((Bridge_info *) (node)))),\
108 ((Bridge_info *) (node)))
109#endif
110
111class Bridge_info;
112
113extern int o2_bridge_next_id;
114
115class Bridge_protocol : public O2obj {
116public:
117 char protocol[8];
118 Bridge_protocol(const char *name);
119
120 // Bridge_info that share this protocol.
121 Vec<Bridge_info *> instances;
122
123 virtual ~Bridge_protocol();
124
125 virtual O2err bridge_poll() { return O2_SUCCESS; }
126
127 O2err remove_services(Bridge_info *bi);
128
129 int find_loc(int id);
130
131 Bridge_info *find(int id) {
132 int i = find_loc(id);
133 return (i < 0 ? NULL : instances[i]);
134 }
135
136 void remove_instance(int id) {
137 int loc = find_loc(id);
138 if (loc >= 0) {
139 instances.remove(loc);
140 }
141 }
142
143};
144
145
146class Bridge_info : public Proxy_info {
147public:
148 int id; // a unique id for the bridged process
149 Bridge_protocol *proto; // this could almost be information returned
150 // by a virtual method rather than allocating a pointer in every
151 // instance, but we need it for the destructor, where you cannot
152 // call virtual methods.
153
155 Proxy_info(NULL, O2TAG_BRIDGE) {
156 proto = proto_;
157 id = o2_bridge_next_id++;
158 proto->instances.push_back(this);
159 }
160 virtual ~Bridge_info() { proto->remove_instance(id); }
161
162 virtual O2err send(bool block) = 0;
163
164 O2err send_to_taps(O2message_ptr msg);
165
166#ifndef O2_NO_DEBUG
167 virtual void show(int indent);
168#endif
169 virtual bool local_is_synchronized() { return IS_SYNCED(this); }
170 O2status status(const char **process) {
171 if (process) {
172 *process = get_proc_name();
173 }
174 return (o2_clock_is_synchronized && IS_SYNCED(this)) ?
176 }
177};
178
179void o2_bridge_csget_handler(o2_msg_data_ptr msgdata, int seqno,
180 const char *replyto);
181void o2_bridge_cscs_handler();
182void o2_bridge_cscs_handler(o2_msg_data_ptr msgdata, const char *types,
183 O2arg_ptr *argv, int argc, const void *user_data);
184void o2_bridge_sv_handler(o2_msg_data_ptr msgdata, const char *types,
185 O2arg_ptr *argv, int argc, const void *user_data);
186void o2_bridge_st_handler(o2_msg_data_ptr msgdata, const char *types,
187 O2arg_ptr *argv, int argc, const void *user_data);
188void o2_bridge_ls_handler(o2_msg_data_ptr msgdata, const char *types,
189 O2arg_ptr *argv, int argc, const void *user_data);
190
192void o2_bridge_show(Bridge_info *bridge);
193
194int o2_bridge_find_protocol(const char *protocol_name,
195 Bridge_protocol **protocol);
196
197int o2_poll_bridges(void);
198
199void o2_bridges_initialize(void);
200
201void o2_bridges_finish(void);
202
203extern Bridge_protocol *o2lite_protocol;
204
205#endif
Definition: bridge.h:146
Definition: bridge.h:115
Definition: o2obj.h:9
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
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_BRIDGE
connected with clock sync.
Definition: o2.h:512
@ O2_BRIDGE_NOTIME
service is connected but no clock sync yet.
Definition: o2.h:468
@ O2_SUCCESS
function was successful
Definition: o2.h:332
an O2 message container
Definition: o2.h:690
data part of an O2 message
Definition: o2.h:638
union of all O2 parameter types
Definition: o2.h:764