O2 2.0
A communication protocol for interactive music and media applications.
o2base.h
1// o2base.h -- core programming definitions
2
3
8#ifdef __cplusplus
9#include <cstddef>
10#include <cstdint>
11using std::size_t;
12using std::int32_t;
13
14extern "C" {
15#else
16#include <stddef.h>
17#include <stdint.h>
18#include <stdbool.h>
19#endif
20
21#ifndef streql
22#define streql(a, b) (strcmp((a), (b)) == 0)
23#endif
24
31void o2_sleep(int n);
32
33
41unsigned int o2_hex_to_int(const char *hex);
42
43
57void o2_hex_to_dot(const char *hex, char *dot);
58
59
60
61// room for longest string/address of the form:
62// /_publicIP:localIP:port + padding_to_int32_boundary
63#define O2_MAX_PROCNAME_LEN 32
64
65// limit on ensemble name length
66#define O2_MAX_NAME_LEN 63
67
68extern void *((*o2_malloc_ptr)(size_t size));
69extern void ((*o2_free_ptr)(void *));
70
86#ifndef O2_MALLOC
87#ifdef O2_NO_DEBUG
88#define O2_MALLOC(x) (*o2_malloc_ptr)(x)
89#define O2_MALLOCNT(n, typ) ((typ *) ((*o2_malloc_ptr)((n) * sizeof(typ))))
90#else
91void *o2_dbg_malloc(size_t size, const char *file, int line);
92#define O2_MALLOC(x) o2_dbg_malloc(x, __FILE__, __LINE__)
93#endif
94#endif
95
96#ifndef O2_MALLOCNT
97#define O2_MALLOCNT(n, typ) ((typ *) O2_MALLOC((n) * sizeof(typ)))
98#endif
99
100#ifndef O2_MALLOCT
101#define O2_MALLOCT(typ) O2_MALLOCNT(1, typ)
102#endif
103
105#ifndef O2_FREE
106#ifdef O2_NO_DEBUG
107#define O2_FREE(x) (*o2_free_ptr)(x)
108#else
109void o2_dbg_free(void *obj, const char *file, int line);
110#define O2_FREE(x) o2_dbg_free(x, __FILE__, __LINE__)
111#endif
112#endif
113
114
116#ifndef O2_CALLOC
117#ifdef O2_NO_DEBUG
118void *o2_calloc(size_t n, size_t s);
119#define O2_CALLOC(n, s) o2_calloc(n, s)
120#define O2_CALLOCNT(n, typ) ((typ *) o2_calloc(n, sizeof(typ)))
121#else
122void *o2_dbg_calloc(size_t n, size_t s, const char *file, int line);
123#define O2_CALLOC(n, s) o2_dbg_calloc(n, s, __FILE__, __LINE__)
124#endif
125#endif
126
127#ifndef O2_CALLOCNT
128#define O2_CALLOCNT(n, typ) ((typ *) O2_CALLOC(n, sizeof(typ)))
129#endif
130
131#ifndef O2_CALLOCT
132#define O2_CALLOCT(typ) O2_CALLOCNT(1, typ)
133#endif
134
135// if debugging is on, default is O2MEM_DEBUG
136#ifndef O2MEM_DEBUG
137#ifdef O2_NO_DEBUG
138// set to 0 for no memory debug mode
139#define O2MEM_DEBUG 0
140#else
141// set this to 2 to get verbose memory information
142#define O2MEM_DEBUG 1
143#endif
144#endif
145
146
147// if O2_MEMDEBUG, extra checks are made for memory consistency,
148// and you can check any pointer using o2_mem_check(ptr):
149#if O2MEM_DEBUG
150void o2_mem_check(void *ptr);
151#else // make #o2_mem_check a noop
152#define o2_mem_check(ptr) 0
153#endif
154
155
156#ifdef __cplusplus
157}
158#endif
159 // end of Basics
void o2_sleep(int n)
Suspend for n milliseconds.
Definition: o2sleep.c:46
void * o2_dbg_malloc(size_t size, const char *file, int line)
allocate memory
Definition: o2dbmem.cpp:15
void o2_hex_to_dot(const char *hex, char *dot)
Convert from hex format to dot format IP address.
Definition: hostipimpl.h:156
void * o2_dbg_calloc(size_t n, size_t s, const char *file, int line)
allocate and zero memory (see #O2_MALLOC)
Definition: o2dbmem.cpp:52
unsigned int o2_hex_to_int(const char *hex)
Convert hex string to integer.
Definition: hostipimpl.h:142
void o2_dbg_free(void *obj, const char *file, int line)
free memory allocated by #O2_MALLOC
Definition: o2mem.cpp:157