O2 2.0
A communication protocol for interactive music and media applications.
services.h
1/* services.h -- mapping from names to lists of services */
2
3/* Roger B. Dannenberg
4 * April 2020
5 */
6
7// see services.c for discussion on creating/deleting services
8
10 public:
11 O2node *service;
12 // if service is a Proc_info or MQTT_info ptr, here are properties
13 char *properties;
14};
15
17 public:
18 O2string tapper; // redirect copy of message to this service
19 Proxy_info *proc; // send the message copy to this process
20 O2tap_send_mode send_mode;
21};
22
23
24class Services_entry : public O2node {
25 public:
26 Vec<Service_provider> services;
27 // dynamic array of type Service_provider
28 // links to offers of this service. First in list
29 // is the service to send to. Here "offers" means a hash_node
30 // (local service), handler_entry (local service with just one
31 // handler for all messages), proc_info (for remote
32 // service), osc_info (for service delegated to OSC), or
33 // bridge_inst (for a bridge over alternate non-IP transport).
34 // Valid tags for services in this array are:
35 // O2TAG_HASH, O2TAG_HANDLER, O2TAG_BRIDGE,
36 // O2TAG_OSC_TCP_CLIENT, O2TAG_OSC_UDP_CLIENT,
37 // O2TAG_TCP_NOMSGYET, O2TAG_PROC, O2TAG__EMPTY
38 Vec<Service_tap> taps; // the "taps" on this service -- these are of type
39 // service_tap and indicate services that should get copies
40 // of messages sent to the service named by key.
41 Services_entry(const char *service_name) :
42 O2node(service_name, O2TAG_SERVICES), services(1), taps(0) { }
43 virtual ~Services_entry();
44#ifndef O2_NO_DEBUG
45 void show(int indent);
46#endif
48 Service_provider *proc_service_find(Proxy_info *proc) {
49 int index = proc_service_index(proc);
50 return index >= 0 ? &services[index] : NULL;
51 }
52 bool add_service(O2string our_ip_port, O2node *service, char *properties);
53 O2err service_remove(const char *srv_name, int index, Proxy_info *proc);
54 O2err insert_tap(O2string tapper, Proxy_info *proxy,
55 O2tap_send_mode send_mode);
56 O2err tap_remove(Proxy_info *proc, const char *tapper);
57 void pick_service_provider();
58 void remove_if_empty();
59
60 static Services_entry **find(const char *service_name);
61 static Service_provider *find_local_entry(const char *service_name);
62
63
74 static O2node *service_find(const char *service_name,
75 Services_entry **services);
76 static Services_entry **find_from_msg(O2message_ptr msg);
77 static Services_entry *must_get_services(O2string service_name);
78 static O2err service_new(O2string padded_name);
79 static O2err service_provider_new(O2string name, const char *properties,
80 O2node *service, Proxy_info *proc);
81 static O2err service_provider_replace(const char *service_name,
82 O2node **node_ptr, O2node *new_service);
83 static O2err proc_service_remove(const char *service_name,
84 Proxy_info *proc, Services_entry *ss, int index);
85 static void list_services(Vec<Services_entry *> &list);
86 static O2err remove_services_by(Proxy_info *proc);
87};
88
89#ifdef O2_NO_DEBUG
90#define TO_SERVICES_ENTRY(node) ((Services_entry *) node)
91#else
92#define TO_SERVICES_ENTRY(node) (assert(ISA_SERVICES(node)), \
93 (Services_entry *) node)
94#endif
95
96O2err o2_service_free(const char *service_name);
Definition: o2node.h:132
Definition: o2obj.h:9
Definition: o2node.h:291
Definition: services.h:9
Definition: services.h:16
Definition: services.h:24
static O2node * service_find(const char *service_name, Services_entry **services)
Use initial part of an O2 address to find an o2_service using a hash table lookup.
Definition: services.cpp:223
int proc_service_index(Proxy_info *proc)
Definition: services.cpp:278
static O2err service_provider_replace(const char *service_name, O2node **node_ptr, O2node *new_service)
Definition: services.cpp:343
Definition: vec.h:6
O2err o2_service_free(const char *service_name)
Remove a local service.
Definition: services.cpp:568
O2err
return values used generally by O2 functions
Definition: o2.h:329
an O2 message container
Definition: o2.h:690