10#define O2_VERSION 0x020000
12#ifdef O2_NO_O2DISCOVERY
15#if defined(O2_NO_O2DISCOVERY) && defined(O2_NO_ZEROCONF)
16#error O2_NO_O2DISCOVERY and O2_NO_ZEROCONF are defined, therefore no discovery
18#if !defined(O2_NO_O2DISCOVERY) && !defined(O2_NO_ZEROCONF)
19#warning O2DISCOVERY and ZEROCONF are *both* enabled
541#define O2_MARKER_A (void *) 0xdeadbeefdeadbeefL
542#define O2_MARKER_B (void *) 0xf00baa23f00baa23L
664#define O2MEM_ALIGNUP(s) ( ((s)+(O2MEM_ALIGN-1)) & ~(O2MEM_ALIGN-1) )
665#define O2MEM_BIT32_ALIGN_PTR(p) ((char *) (((size_t) (p)) & ~3))
667#define O2_MSG_DATA_END(data) (PTR(&(data)->misc) + (data)->length)
670const char *o2_next_o2string(
const char *str);
672#define o2_msg_data_types(data) (o2_next_o2string((data)->address) + 1)
673#define o2_msg_types(msg) o2_msg_data_types(&msg->data)
675#define o2_msg_data_params(types) \
676 o2_next_o2string((const char *) ((intptr_t) (types) & ~3))
699#define O2_MSG_PAYLOAD(msg) PTR(&(msg)->data.misc)
882 const void *user_data);
961int o2_memory(
void *((*malloc)(
size_t size)),
void ((*free)(
void *)),
962 char *first_chunk, int64_t size,
bool mallocp);
1036O2err o2_hub(
int version,
const char *public_ip,
const char *internal_ip,
1037 int tcp_port,
int udp_port);
1115 char *internal_ip,
int *port);
1354typedef enum {TAP_KEEP, TAP_RELIABLE, TAP_BEST_EFFORT} O2tap_send_mode;
1421O2err o2_tap(
const char *tappee,
const char *tapper, O2tap_send_mode send_mode);
1485 bool coerce,
bool parse);
1829#define o2_send(path, time, ...) \
1830 o2_send_marker(path, time, false, \
1831 __VA_ARGS__, O2_MARKER_A, O2_MARKER_B)
1834O2err o2_send_marker(
const char *path,
double time,
int tcp_flag,
1835 const char *typestring, ...);
1868#define o2_send_cmd(path, time, ...) \
1869 o2_send_marker(path, time, true, \
1870 __VA_ARGS__, O2_MARKER_A, O2_MARKER_B)
2005 int port_num,
int tcp_flag);
2231#define o2_add_symbol(s) o2_add_string_or_symbol(O2_SYMBOL, s)
2234#define o2_add_string(s) o2_add_string_or_symbol(O2_STRING, s)
2252#define o2_add_double(d) o2_add_double_or_time(O2_DOUBLE, d)
2255#define o2_add_time(t) o2_add_double_or_time(O2_TIME, t)
2262#define o2_add_int32(i) o2_add_int32_or_char(O2_INT32, i)
2265#define o2_add_char(c) o2_add_int32_or_char(O2_CHAR, c)
2276#define o2_add_true() o2_add_only_typecode(O2_TRUE);
2279#define o2_add_false() o2_add_only_typecode(O2_FALSE);
2284#define o2_add_tf(x) o2_add_only_typecode((x) != 0 ? O2_TRUE : O2_FALSE)
2287#define o2_add_bool(x) o2_add_int32_or_char(O2_BOOL, (x) != 0)
2290#define o2_add_nil() o2_add_only_typecode(O2_NIL);
2293#define o2_add_infinitum() o2_add_only_typecode(O2_INFINITUM);
2296#define o2_add_start_array() o2_add_only_typecode(O2_ARRAY_START);
2299#define o2_add_end_array() o2_add_only_typecode(O2_ARRAY_END);
2310 int length,
void *data);
2312#ifndef O2_NO_BUNDLES
2364 const char *service,
const char *address,
bool tcp_flag);
2521#define O2_SCHED_TABLE_LEN 128
2524typedef struct O2sched {
2528} O2sched, *O2sched_ptr;
2606#ifndef O2_NO_BRIDGES
2688#ifndef O2_NO_SHAREDMEM
2689O2err o2_shmem_initialize();
2693#ifndef O2_NO_WEBSOCKETS
2695#error WEBSOCKETS feature depends on BRIDGES
2696#error You must define O2_NO_WEBSOCKETS or undefine O2_NO_BRIDGES
2704#define O2_NO_HOSTNAME "\001"
O2err o2_network_enable(bool enable)
Disable external nework connections.
Definition: o2.cpp:987
void o2_message_print(O2message_ptr msg)
print an O2 message to stdout
struct O2blob O2blob
The structure for binary large object.
const char * o2_ensemble_name
Definition: o2.cpp:935
struct O2message O2message
an O2 message container
O2time(* o2_time_callback)(void *rock)
signature for callback that defines the reference clock
Definition: o2.h:1771
O2err o2_service_new(const char *service_name)
Add a service to the current process.
Definition: o2.cpp:1227
O2type
An enumeration of the O2 message types.
Definition: o2.h:717
const char * o2_service_properties(int i)
get the properties string from a saved list of services
Definition: properties.cpp:130
O2err o2_get_addresses(const char **public_ip, const char **internal_ip, int *port)
Get IP address and TCP connection port number.
Definition: o2.cpp:1097
bool o2_stop_flag
set this flag to stop o2_run
Definition: o2.cpp:1342
void o2_msg_data_print(o2_msg_data_ptr msg)
print a message from msg_data_ptr to stdout
O2sched o2_gtsched
Scheduler that schedules according to global (reference) clock time.
Definition: o2sched.cpp:68
void o2_drop_message(const char *warn, bool free_the_msg)
Tell world that a message was dropped.
Definition: msgsend.cpp:209
bool o2_clock_is_synchronized
A variable indicating that the clock is the reference or is synchronized to the reference.
Definition: clock.cpp:26
const char * o2_service_getprop(int i, const char *attr)
get a property value from a saved list of services
Definition: properties.cpp:198
int o2_parse_name(const char *name, char *public_ip, char *internal_ip, int *port)
Parse Public:Local:Port string and extract fields.
Definition: discovery.cpp:83
O2time o2_time_get(void)
Get the estimated synchronized global O2 time.
Definition: clock.cpp:672
int o2_status(const char *service)
Check the status of the service.
Definition: o2.cpp:1359
void o2_message_drop_warning(const char *warn, o2_msg_data_ptr msg)
Default dropped message alert.
Definition: o2.cpp:1242
O2err o2_message_send(O2message_ptr msg)
Send an O2 message. (See also macros o2_send and o2_send_cmd).
Definition: msgsend.cpp:579
const char * o2_service_tapper(int i)
get a tapper name from a saved list of services
Definition: properties.cpp:117
O2err o2_services_list(void)
list known services and taps
Definition: properties.cpp:26
int o2_memory(void *((*malloc)(size_t size)), void((*free)(void *)), char *first_chunk, int64_t size, bool mallocp)
Tell O2 how to allocate/free memory.
Definition: o2mem.cpp:334
const char * o2_status_to_string(int status)
retrieve text version of an O2status
Definition: o2.cpp:1467
O2err o2_can_send(const char *service)
Test if send_cmd will block.
Definition: o2.cpp:1372
O2err o2_internet_enable(bool enable)
Disable Internet connections.
Definition: o2.cpp:974
const char * o2_service_process(int i)
get a process name from a saved list of services
Definition: properties.cpp:108
const char * o2_get_proc_name(void)
Get Public:Local:Port service name string.
Definition: o2.cpp:1110
int o2_version(char *version)
get O2 version number
Definition: o2.cpp:1541
O2err o2_service_free(const char *service_name)
Remove a local service.
Definition: services.cpp:568
struct O2msg_data O2msg_data
data part of an O2 message
O2err o2_service_set_property(const char *service, const char *attr, const char *value)
set an attribute and value property for a service
Definition: properties.cpp:345
O2time o2_local_time(void)
Get the real time using the local O2 clock.
Definition: clock.cpp:644
const char * o2_service_name(int i)
get a service name from a saved list of services
Definition: properties.cpp:90
O2time o2_set_discovery_period(O2time period)
Set discovery period.
Definition: discovery.cpp:73
O2err o2_finish(void)
release the memory and shut down O2.
Definition: o2.cpp:1477
int o2_run(int rate)
Run O2.
Definition: o2.cpp:1344
O2err o2_untap(const char *tappee, const char *tapper)
remove tap from service
Definition: o2.cpp:1288
int o2_service_type(int i)
get a type from a saved list of services
Definition: properties.cpp:99
void o2_message_warnings(void(*warning)(const char *warn, o2_msg_data_ptr msg))
Enable/Disable warnings for dropped messages.
Definition: o2.cpp:1254
int o2_service_search(int i, const char *attr, const char *value)
find a service matching attribute/value pair
Definition: properties.cpp:225
O2err o2_poll(void)
Process current O2 messages.
Definition: o2.cpp:1309
O2err o2_method_new(const char *path, const char *typespec, O2method_handler h, const void *user_data, bool coerce, bool parse)
Add a handler for an address.
Definition: o2.cpp:1261
O2err o2_hub(int version, const char *public_ip, const char *internal_ip, int tcp_port, int udp_port)
Connect to a hub.
Definition: discovery.cpp:789
void(* O2method_handler)(const o2_msg_data_ptr msg, const char *types, O2arg_ptr *argv, int argc, const void *user_data)
callback function to receive an O2 message
Definition: o2.h:880
O2err o2_service_property_free(const char *service, const char *attr)
remove an attribute and value property from a service
Definition: properties.cpp:357
O2err o2_services_list_free(void)
free the list of known services and taps
Definition: properties.cpp:69
O2sched_ptr o2_active_sched
Current scheduler.
Definition: o2sched.cpp:69
O2err o2_schedule_msg(O2sched_ptr scheduler, O2message_ptr msg)
Definition: o2sched.cpp:151
int o2_clock_set(o2_time_callback gettime, void *rock)
Provide a time reference to O2.
Definition: clock.cpp:606
O2err o2_initialize(const char *ensemble_name)
Start O2.
Definition: o2.cpp:1000
double O2time
O2 timestamps are doubles representing seconds since the approximate start time of the ensemble.
Definition: o2.h:625
O2err o2_tap(const char *tappee, const char *tapper, O2tap_send_mode send_mode)
install tap to copy messages from one service to another
Definition: o2.cpp:1276
O2err o2_method_free(const char *path)
remove a path – remove a path and associated handler
Definition: pathtree.cpp:452
O2sched o2_ltsched
Scheduler that schedules according to local clock time.
Definition: o2sched.cpp:68
int o2_roundtrip(double *mean, double *min)
Get network round-trip information.
Definition: clock.cpp:439
@ O2_ARRAY_END
End array or tuple.
Definition: o2.h:724
@ O2_BLOB
Binary Large OBject (BLOB) type.
Definition: o2.h:722
@ O2_FALSE
Symbol representing the value False.
Definition: o2.h:734
@ O2_TRUE
Symbol representing the value True.
Definition: o2.h:733
@ O2_INFINITUM
Symbol representing the value Infinitum.
Definition: o2.h:736
@ O2_VECTOR
Prefix to indicate a vector.
Definition: o2.h:740
@ O2_FLOAT
32 bit IEEE-754 float.
Definition: o2.h:720
@ O2_MIDI
4 byte MIDI packet.
Definition: o2.h:732
@ O2_DOUBLE
64 bit IEEE-754 double.
Definition: o2.h:729
@ O2_TIME
OSC time type.
Definition: o2.h:728
@ O2_CHAR
8bit char variable (Standard C).
Definition: o2.h:731
@ O2_INT32
32 bit signed integer.
Definition: o2.h:719
@ O2_ARRAY_START
Start array or tuple.
Definition: o2.h:723
@ O2_NIL
Symbol representing the value Nil.
Definition: o2.h:735
@ O2_INT64
64 bit signed integer.
Definition: o2.h:727
@ O2_BOOL
Boolean value returned as either 0 or 1.
Definition: o2.h:739
@ O2_SYMBOL
Used to distinguish strings and symbols.
Definition: o2.h:730
@ O2_STRING
NULL terminated string (Standard C).
Definition: o2.h:721
O2err o2lite_initialize()
enable O2lite protocol connections to this proces
Definition: bridge.cpp:538
void o2_debug_flags(const char *flags)
Enable debugging output.
Definition: debug.cpp:19
const char * o2_error_to_string(O2err i)
Return text representation of an O2 error.
Definition: o2.cpp:1445
O2err http_initialize(int port, const char *root)
Enable HTTP and Websocket access to an O2 host.
Definition: websock.cpp:208
int o2_extract_start(o2_msg_data_ptr msg)
initialize internal state to parse, extract, and coerce message arguments.
Definition: message.cpp:869
O2arg_ptr o2_get_next(O2type type_code)
get the next message parameter
Definition: message.cpp:1018
O2err o2_add_midi(uint32_t m)
add a short midi message to the message (see o2_send_start)
Definition: message.cpp:243
O2err o2_send_start(void)
Prepare to build a message.
Definition: message.cpp:135
O2message_ptr o2_service_message_finish(O2time time, const char *service, const char *address, bool tcp_flag)
finish and return a message, prepending service name
Definition: message.cpp:293
O2err o2_add_blob_data(uint32_t size, void *data)
add an O2blob to the message (see o2_send_start), where the blob is specified by a size and a data ad...
Definition: message.cpp:224
O2err o2_add_vector(O2type element_type, int length, void *data)
add a vector
O2err o2_add_int64(int64_t i)
add an int64 to the message (see o2_send_start)
Definition: message.cpp:159
O2err o2_add_only_typecode(O2type typecode)
This function supports o2_add_true, o2_add_false, o2_add_bool, o2_add_nil, o2_add_infinitum,...
Definition: message.cpp:195
O2err o2_add_float(float f)
add a float to the message (see o2_send_start)
Definition: message.cpp:147
O2message_ptr o2_message_finish(O2time time, const char *address, bool tcp_flag)
finish and return the message.
Definition: message.cpp:283
O2err o2_send_finish(O2time time, const char *address, bool tcp_flag)
send a message allocated by o2_send_start.
Definition: message.cpp:858
O2err o2_add_double_or_time(O2type tchar, double d)
This function supports o2_add_double and o2_add_time Normally, you should not call this directly.
Definition: message.cpp:183
O2err o2_add_string_or_symbol(O2type tcode, const char *s)
This function suppports o2_add_symbol and o2_add_string Normally, you should not call this directly.
Definition: message.cpp:206
O2err o2_add_int32_or_char(O2type tcode, int32_t i)
This function supports o2_add_int32 and o2_add_char Normally, you should not call this directly.
Definition: message.cpp:171
O2blob_ptr o2_blob_new(uint32_t size)
Allocate a blob.
Definition: message.cpp:512
O2err o2_add_message(O2message_ptr msg)
add a message to a bundle
Definition: message.cpp:270
O2err o2_add_blob(O2blob_ptr b)
add an O2blob to the message (see o2_send_start), where the blob is given as a pointer to an O2blob o...
O2err o2_mqtt_enable(const char *broker, int port_num)
Enable MQTT to form wide-area-network connections between O2 processes.
Definition: mqtt.cpp:48
O2err o2_osc_port_new(const char *service_name, int port_num, int tcp_flag)
Create a port to receive OSC messages.
Definition: o2osc.cpp:168
uint64_t o2_osc_time_offset(uint64_t offset)
Set the OSC time offset.
Definition: o2osc.cpp:133
O2err o2_osc_delegate(const char *service_name, const char *ip, int port_num, int tcp_flag)
Create a service that forwards O2 messages to an OSC server.
Definition: o2osc.cpp:263
O2err o2_osc_port_free(int port_num)
Remove a port receiving OSC messages.
Definition: o2osc.cpp:234
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_TAP
tag value for o2_services_list
Definition: o2.h:532
@ O2_REMOTE_NOTIME
remote service but no clock sync yet
Definition: o2.h:453
@ O2_BRIDGE
connected with clock sync.
Definition: o2.h:512
@ O2_UNKNOWN
status is unknown, e.g. service does not exist
Definition: o2.h:438
@ O2_BRIDGE_NOTIME
service is connected but no clock sync yet.
Definition: o2.h:468
@ O2_REMOTE
remote service with clock sync.
Definition: o2.h:502
@ O2_LOCAL_NOTIME
local service, no clock sync yet.
Definition: o2.h:445
@ O2_TO_OSC_NOTIME
service is connected but no clock sync yet.
Definition: o2.h:487
@ O2_TO_OSC
connected with clock sync.
Definition: o2.h:528
@ O2_BAD_NAME
invalid ensemble name parameter
Definition: o2.h:366
@ O2_NO_CLOCK
timed message but time is unknown
Definition: o2.h:394
@ O2_HOSTNAME_TO_NETADDR_FAIL
inet_pton() failed to convert a string to an IP address
Definition: o2.h:383
@ O2_BAD_ARGS
mismatched types and arguments
Definition: o2.h:375
@ O2_NO_PORT
unable to allocate a discovery port
Definition: o2.h:423
@ O2_SEND_FAIL
could not write to socket or send datagram
Definition: o2.h:406
@ O2_BLOCKED
TCP send would block.
Definition: o2.h:419
@ O2_NO_SERVICE
path to handler specifies non-existant service
Definition: o2.h:349
@ O2_SUCCESS
function was successful
Definition: o2.h:332
@ O2_NO_HANDLER
no handler for an address
Definition: o2.h:398
@ O2_NO_MEMORY
process is out of free memory
Definition: o2.h:353
@ O2_NO_NETWORK
networking is disabled
Definition: o2.h:429
@ O2_TCP_HUP
in o2_initialize, the socket is closed.
Definition: o2.h:379
@ O2_NOT_INITIALIZED
O2 has not been initialized.
Definition: o2.h:414
@ O2_TCP_CONNECT_FAIL
attempt to make a TCP connection failed
Definition: o2.h:387
@ O2_BAD_TYPE
in o2_add_vector, invalid element type
Definition: o2.h:370
@ O2_INVALID_MSG
an O2 message is invalid
Definition: o2.h:402
@ O2_SOCKET_ERROR
SOCKET_ERROR in select call.
Definition: o2.h:410
@ O2_SERVICE_EXISTS
not (re)creating service
Definition: o2.h:345
@ O2_ALREADY_RUNNING
o2_initialize called, but O2 is already running.
Definition: o2.h:357
@ O2_FAIL
a non-specific error occurred.
Definition: o2.h:339
void o2_complete_delivery()
Definition: msgsend.cpp:236
O2message_ptr o2_postpone_delivery()
Definition: msgsend.cpp:245
O2message_ptr o2_current_message()
Definition: msgsend.cpp:228
The structure for binary large object.
Definition: o2.h:708
uint32_t size
size of data
Definition: o2.h:709
char data[4]
the data, actually of variable length
Definition: o2.h:710
an O2 message container
Definition: o2.h:690
struct O2message * next
links used for free list and scheduler
Definition: o2.h:692
int64_t pad_if_needed
make sure allocated is 8-byte aligned
Definition: o2.h:693
data part of an O2 message
Definition: o2.h:638
O2time timestamp
the message delivery time (0 for immediate)
Definition: o2.h:646
char address[4]
the message address string
Definition: o2.h:655
union of all O2 parameter types
Definition: o2.h:764
float f32
an alias for f
Definition: o2.h:770
O2blob b
a blob (unstructured bytes)
Definition: o2.h:781
float * vf
vector of IEEE-754 floats
Definition: o2.h:791
int c
Standard C, 8 bit, char, stored as int.
Definition: o2.h:777
int64_t i64
64 bit signed integer.
Definition: o2.h:767
int32_t * vi
vector of 32-bit signed integers
Definition: o2.h:788
int64_t h
an alias for i64
Definition: o2.h:768
double f64
an alias for d
Definition: o2.h:772
O2time t
TimeTag value.
Definition: o2.h:780
int32_t len
IMPORTANT: divide by 4 or 8 to get length in elements.
Definition: o2.h:784
float f
32 bit IEEE-754 float.
Definition: o2.h:769
double * vd
vector of IEEE-754 doubles
Definition: o2.h:790
int32_t B
a boolean value, either 0 or 1
Definition: o2.h:782
int32_t i
an alias for i32
Definition: o2.h:766
int32_t typ
type of vector elements
Definition: o2.h:786
int64_t * vh
vector of 64-bit signed integers
Definition: o2.h:789
int32_t i32
32 bit signed integer.
Definition: o2.h:765
uint32_t m
Definition: o2.h:778
double d
64 bit IEEE-754 double.
Definition: o2.h:771