lo_cpp.h
Go to the documentation of this file.
#ifndef _LO_CPP_H_
#define _LO_CPP_H_
#include <lo/lo.h>
#include <lo/lo_throw.h>
#include <functional>
#include <memory>
#include <list>
#include <algorithm>
#include <unordered_map>
#include <string>
#if __cplusplus >= 201703L
#include <string_view>
#endif
#include <initializer_list>
#ifndef LO_USE_EXCEPTIONS
#include <cassert>
#endif
#define LO_ADD_METHOD_RT(ht, argtypes, args, rt, r, r1, r2) \
template <typename H> \
Method add_method(const string_type path, const string_type types, \
H&& h, rt* _unused=0) \
{ \
std::string key(path.s() + "," + types.s()); \
_handlers[key].push_front( \
std::unique_ptr<handler>(new handler_type<r ht>(h))); \
lo_method m = _add_method(path, types, \
[](const char *path, const char *types, \
lo_arg **argv, int argc, lo_message msg, \
void *data)->int \
{ \
r1 (*static_cast<handler_type<r ht>*>(data)) args; \
r2; \
}, _handlers[key].front().get()); \
_handlers[key].front()->method = m; \
return m; \
}
#define RT_INT(argtypes) \
typename std::enable_if<std::is_same<decltype(h argtypes), int>::value, void>::type
#define RT_VOID(argtypes) \
typename std::enable_if<std::is_same<decltype(h argtypes), void>::value, void>::type
#define LO_ADD_METHOD(ht, argtypes, args) \
LO_ADD_METHOD_RT(ht, argtypes, args, \
RT_INT(argtypes), int, return,); \
LO_ADD_METHOD_RT(ht, argtypes, args, \
RT_VOID(argtypes), void, , return 0)
namespace lo {
// Helper classes to allow polymorphism on "const char *",
// "std::string", and "int".
class string_type {
public:
string_type(const string_type& s) { _s = s._s; }
string_type(const char *s=0) { _s = s; }
string_type(const std::string &s) { _s = s.c_str(); }
#if __cplusplus >= 201703L
string_type(const std::string_view& s) {
if (s[s.length()]==0) _s = s.data();
else { _p.reset(new std::string(s)); _s = _p->c_str(); }
}
#endif
operator const char*() const { return _s; }
std::string s() const { return _s?_s:""; }
const char *_s;
std::unique_ptr<std::string> _p;
};
class num_string_type : public string_type {
public:
num_string_type(const char *s) : string_type(s) {}
num_string_type(const std::string &s) : string_type(s) {}
#if __cplusplus >= 201703L
num_string_type(const std::string_view& s) : string_type(s) {}
#endif
num_string_type(int n)
{_p.reset(new std::string(std::to_string(n))); _s = _p->c_str(); }
};
/*
* Error handling:
*
* Define LO_USE_EXCEPTIONS to throw the following exceptions instead
* of aborting on error. The alternative (and default) is that
* assert() will crash your program in debug mode, and you should
* check is_valid() before operations that might break the assertion.
*
* Note that in the latter case, the program may return a C++ class
* that will not contain a valid liblo object, this is why
* LO_CHECK_AFTER does not do anything; it is up to user code to check
* is_valid() after constructing Server() and ServerThread(). On the
* contrary, when LO_USE_EXCEPTIONS is enabled, an Error exception
* will be thrown if the object was not successfully created.
*
* Rules:
*
* - Constructors that create underlying liblo objects shall either
* fail silently, depending on calling code to check is_valid(), or
* throw lo::Error() in the case of LO_USE_EXCEPTIONS.
*
* - Constructors that receive an existing liblo object do not throw
* any exceptions if the passed in object is nullptr.
*
* - All other functions shall assert() or throw lo::Invalid() if the
* underlying liblo object is not valid.
*
*/
#ifdef LO_USE_EXCEPTIONS
struct Invalid {};
struct Error {};
#define LO_CHECK_BEFORE if (!is_valid()) throw Invalid();
#define LO_CHECK_AFTER if (!is_valid()) throw Error();
#else
#define LO_CHECK_BEFORE assert(is_valid());
#define LO_CHECK_AFTER
#endif
class ServerThread;
class Method
{
public:
Method(lo_method m) : method(m) {}
operator lo_method() const
{ return method; }
protected:
lo_method method;
};
class Address
{
public:
Address(const string_type &host, const num_string_type &port,
int proto=LO_UDP)
{ address = lo_address_new_with_proto(proto, host, port); owned=true;
LO_CHECK_AFTER; }
Address(const string_type &url)
{ address = lo_address_new_from_url(url); owned=true; LO_CHECK_AFTER; }
Address(lo_address a, bool _owned=true)
{ address = a; owned=_owned; LO_CHECK_AFTER; }
~Address()
{ if (address && owned) lo_address_free(address); }
Address& operator=(Address b) { b.swap(*this); return *this; }
void swap(Address& b) throw () { std::swap(this->address, b.address); }
bool is_valid() const { return address!=nullptr; }
int ttl() const
{ LO_CHECK_BEFORE; return lo_address_get_ttl(address); }
void set_ttl(int ttl)
{ LO_CHECK_BEFORE; lo_address_set_ttl(address, ttl); }
int send(const string_type &path) const
{ LO_CHECK_BEFORE; return lo_send(address, path, ""); }
// In these functions we append "$$" to the type string, which
// simply instructs lo_message_add_varargs() not to use
// LO_MARKER checking at the end of the argument list.
int send(const string_type &path, const string_type type, ...) const
{
LO_CHECK_BEFORE;
va_list q;
va_start(q, type);
lo_message m = lo_message_new();
std::string t = type.s() + "$$";
lo_message_add_varargs(m, t.c_str(), q);
int r = lo_send_message(address, path, m);
lo_message_free(m);
va_end(q);
return r;
}
int send(lo_timetag ts, const string_type &path,
const string_type type, ...) const
{
LO_CHECK_BEFORE;
va_list q;
va_start(q, type);
lo_message m = lo_message_new();
std::string t = std::string(type) + "$$";
lo_message_add_varargs(m, t.c_str(), q);
lo_bundle b = lo_bundle_new(ts);
lo_bundle_add_message(b, path, m);
int r = lo_send_bundle(address, b);
lo_bundle_free_messages(b);
va_end(q);
return r;
}
int send(const string_type &path, lo_message m) const
{ LO_CHECK_BEFORE; return lo_send_message(address, path, m); }
int send(lo_bundle b)
{ LO_CHECK_BEFORE; return lo_send_bundle(address, b); }
int send_from(lo::ServerThread &from, const string_type &path,
const string_type type, ...) const;
int send_from(lo_server from, const string_type &path,
const string_type type, ...) const
{
LO_CHECK_BEFORE;
va_list q;
va_start(q, type);
lo_message m = lo_message_new();
std::string t = std::string(type) + "$$";
lo_message_add_varargs(m, t.c_str(), q);
int r = lo_send_message_from(address, from, path, m);
lo_message_free(m);
va_end(q);
return r;
}
int send_from(lo_server from, lo_timetag ts,
const string_type &path,
const string_type type, ...) const
{
LO_CHECK_BEFORE;
va_list q;
va_start(q, type);
lo_message m = lo_message_new();
std::string t = std::string(type) + "$$";
lo_message_add_varargs(m, t.c_str(), q);
lo_bundle b = lo_bundle_new(ts);
lo_bundle_add_message(b, path, m);
int r = lo_send_bundle_from(address, from, b);
lo_bundle_free_messages(b);
va_end(q);
return r;
}
int send_from(lo_server from, const string_type &path, lo_message m) const
{ LO_CHECK_BEFORE; return lo_send_message_from(address, from, path, m); }
int send_from(lo::ServerThread &from, lo_bundle b) const;
int send_from(lo_server from, lo_bundle b) const
{ LO_CHECK_BEFORE; return lo_send_bundle_from(address, from, b); }
int get_errno() const
{ LO_CHECK_BEFORE; return lo_address_errno(address); }
std::string errstr() const
{ LO_CHECK_BEFORE; auto s(lo_address_errstr(address)); return std::string(s?s:""); }
std::string hostname() const
{ LO_CHECK_BEFORE; auto s(lo_address_get_hostname(address)); return std::string(s?s:""); }
std::string port() const
{ LO_CHECK_BEFORE; auto s(lo_address_get_port(address)); return std::string(s?s:""); }
int protocol() const
{ LO_CHECK_BEFORE; return lo_address_get_protocol(address); }
std::string url() const
{
LO_CHECK_BEFORE;
char* s(lo_address_get_url(address));
std::string result(s?s:"");
free(s);
return result;
}
std::string iface() const
{ LO_CHECK_BEFORE; auto s(lo_address_get_iface(address)); return std::string(s?s:""); }
void set_iface(const string_type &iface, const string_type &ip)
{ LO_CHECK_BEFORE; lo_address_set_iface(address, iface, ip); }
int set_tcp_nodelay(int enable)
{ LO_CHECK_BEFORE; return lo_address_set_tcp_nodelay(address, enable); }
int set_stream_slip(lo_slip_encoding encoding)
{ LO_CHECK_BEFORE; return lo_address_set_stream_slip(address, encoding); }
operator lo_address() const
{ return address; }
protected:
lo_address address;
bool owned;
};
class Message
{
public:
Message()
: message(lo_message_new()) { if (message) lo_message_incref(message); LO_CHECK_AFTER; }
Message(lo_message m)
: message(m) { if (m) { lo_message_incref(m); } }
Message(const Message &m)
: message(m.message) { if (m.message)
lo_message_incref(m.message); }
Message(const string_type types, ...)
{
message = lo_message_new();
if (message) {
lo_message_incref(message);
va_list q;
va_start(q, types);
std::string t(std::string(types)+"$$");
add_varargs(t.c_str(), q);
va_end(q);
}
LO_CHECK_AFTER;
}
~Message()
{ if (message) lo_message_free(message); }
Message& operator=(Message m) { m.swap(*this); return *this; }
void swap(Message& m) throw () { std::swap(this->message, m.message); }
bool is_valid() const { return message!=nullptr; }
int add(const string_type types, ...)
{
LO_CHECK_BEFORE;
va_list q;
va_start(q, types);
std::string t(std::string(types)+"$$");
int ret = add_varargs(t.c_str(), q);
va_end(q);
return ret;
}
int add_varargs(const string_type &types, va_list ap)
{ LO_CHECK_BEFORE; return lo_message_add_varargs(message, types, ap); }
int add_int32(int32_t a)
{ LO_CHECK_BEFORE; return lo_message_add_int32(message, a); }
int add_float(float a)
{ LO_CHECK_BEFORE; return lo_message_add_float(message, a); }
int add_string(const string_type &a)
{ LO_CHECK_BEFORE; return lo_message_add_string(message, a); }
int add_blob(lo_blob a)
{ LO_CHECK_BEFORE; return lo_message_add_blob(message, a); }
int add_int64(int64_t a)
{ LO_CHECK_BEFORE; return lo_message_add_int64(message, a); }
int add_timetag(lo_timetag a)
{ LO_CHECK_BEFORE; return lo_message_add_timetag(message, a); }
int add_double(double a)
{ LO_CHECK_BEFORE; return lo_message_add_double(message, a); }
int add_symbol(const string_type &a)
{ LO_CHECK_BEFORE; return lo_message_add_symbol(message, a); }
int add_char(char a)
{ LO_CHECK_BEFORE; return lo_message_add_char(message, a); }
int add_midi(uint8_t a[4])
{ LO_CHECK_BEFORE; return lo_message_add_midi(message, a); }
int add_bool(bool b)
{ LO_CHECK_BEFORE;
if (b)
return lo_message_add_true(message);
else
return lo_message_add_false(message); }
int add_true()
{ LO_CHECK_BEFORE; return lo_message_add_true(message); }
int add_false()
{ LO_CHECK_BEFORE; return lo_message_add_false(message); }
int add_nil()
{ LO_CHECK_BEFORE; return lo_message_add_nil(message); }
int add_infinitum()
{ LO_CHECK_BEFORE; return lo_message_add_infinitum(message); }
// Note, for polymorphic versions of "add", below, we can't do
// this for "string" or "symbol" types, since it is ambiguous
// with "add(types, ...)" above.
int add(int32_t a)
{ LO_CHECK_BEFORE; return lo_message_add_int32(message, a); }
int add(float a)
{ LO_CHECK_BEFORE; return lo_message_add_float(message, a); }
int add(lo_blob a)
{ LO_CHECK_BEFORE; return lo_message_add_blob(message, a); }
int add(int64_t a)
{ LO_CHECK_BEFORE; return lo_message_add_int64(message, a); }
int add(lo_timetag a)
{ LO_CHECK_BEFORE; return lo_message_add_timetag(message, a); }
int add(double a)
{ LO_CHECK_BEFORE; return lo_message_add_double(message, a); }
int add(char a)
{ LO_CHECK_BEFORE; return lo_message_add_char(message, a); }
int add(uint8_t a[4])
{ LO_CHECK_BEFORE; return lo_message_add_midi(message, a); }
int add(bool b)
{ LO_CHECK_BEFORE;
if (b)
return lo_message_add_true(message);
else
return lo_message_add_false(message); }
Address source() const
{ LO_CHECK_BEFORE; return Address(lo_message_get_source(message), false); }
lo_timetag timestamp() const
{ LO_CHECK_BEFORE; return lo_message_get_timestamp(message); }
std::string types() const
{ LO_CHECK_BEFORE;
auto s(lo_message_get_types(message)); return std::string(s?s:""); }
int argc() const
{ LO_CHECK_BEFORE; return lo_message_get_argc(message); }
lo_arg **argv() const
{ LO_CHECK_BEFORE; return lo_message_get_argv(message); }
size_t length(const string_type &path) const
{ LO_CHECK_BEFORE; return lo_message_length(message, path); }
void *serialise(const string_type &path, void *to, size_t *size) const
{ LO_CHECK_BEFORE; return lo_message_serialise(message, path, to, size); }
typedef std::pair<int, Message> maybe;
static
maybe deserialise(void *data, size_t size)
{ int result = 0;
lo_message m = lo_message_deserialise(data, size, &result);
return maybe(result, m); }
void print() const
{ LO_CHECK_BEFORE; lo_message_pp(message); }
lo::Message clone() const
{ LO_CHECK_BEFORE; return lo::Message(lo_message_clone(message)); }
Message& clear()
{ lo_message_clear(message); return *this; }
operator lo_message() const
{ return message; }
protected:
lo_message message;
};
class Server
{
public:
Server(lo_server s) : server(s) {}
template <typename E>
Server(const num_string_type &port, E&& e)
: Server(lo_server_new(port,
[](int num, const char *msg, const char *where){
auto h = static_cast<handler_error*>(lo_error_get_context());
if (h) (*h)(num, msg, where);
}))
{
if (server) {
lo_server_set_error_context(server,
(_error_handler = std::unique_ptr<handler>(
new handler_error(e))).get());
}
LO_CHECK_AFTER;
}
template <typename E>
Server(const num_string_type &port, int proto, E&& e=0)
: Server(lo_server_new_with_proto(port, proto,
[](int num, const char *msg, const char *where){
auto h = static_cast<handler_error*>(lo_error_get_context());
(*h)(num, msg, where);
}))
{
if (server) {
lo_server_set_error_context(server,
(_error_handler = std::unique_ptr<handler>(
new handler_error(e))).get());
}
LO_CHECK_AFTER;
}
template <typename E>
Server(const string_type &group, const num_string_type &port,
const string_type &iface=0, const string_type &ip=0, E&& e=0)
: Server((!iface._s || !ip._s)
? lo_server_new_multicast_iface(group, port, iface, ip,
[](int num, const char *msg, const char *where){
auto h = static_cast<handler_error*>(lo_error_get_context());
(*h)(num, msg, where);
})
: lo_server_new_multicast(group, port,
[](int num, const char *msg, const char *where){
auto h = static_cast<handler_error*>(lo_error_get_context());
(*h)(num, msg, where);
}))
{
if (server) {
lo_server_set_error_context(server,
(_error_handler = std::unique_ptr<handler>(
new handler_error(e))).get());
}
LO_CHECK_AFTER;
}
Server(const num_string_type &port, lo_err_handler err_h=0)
: Server(lo_server_new(port, err_h)) { LO_CHECK_AFTER; }
Server(const num_string_type &port, int proto, lo_err_handler err_h=0)
: Server(lo_server_new_with_proto(port, proto, err_h))
{ LO_CHECK_AFTER; }
Server(const string_type &group, const num_string_type &port,
const string_type &iface="", const string_type &ip="", lo_err_handler err_h=0)
: Server((iface._s || ip._s)
? lo_server_new_multicast_iface(group, port,
iface, ip, err_h)
: lo_server_new_multicast(group, port, err_h))
{ LO_CHECK_AFTER; }
virtual ~Server()
{ if (server) lo_server_free(server); }
bool is_valid() const { return server!=nullptr; }
// Regular old liblo method handlers
Method add_method(const string_type &path, const string_type &types,
lo_method_handler h, void *data) const
{ LO_CHECK_BEFORE; return _add_method(path, types, h, data); }
// Alternative callback prototypes
LO_ADD_METHOD( (const char*, const char*, lo_arg**, int),
((char*)0, (char*)0, (lo_arg**)0, (int)0),
(path, types, argv, argc) );
LO_ADD_METHOD( (const char*, lo_arg**, int),
((char*)0, (lo_arg**)0, (int)0),
(types, argv, argc) );
LO_ADD_METHOD( (const char*, lo_arg**, int, const Message&),
((char*)0, (lo_arg**)0, (int)0, Message((lo_message)0)),
(types, argv, argc, Message(msg)) );
LO_ADD_METHOD( (const char*, const Message&),
((char*)0, Message((lo_message)0)),
(path, Message(msg)) );
LO_ADD_METHOD( (lo_arg**, int), ((lo_arg**)0, (int)0), (argv, argc) )
LO_ADD_METHOD( (lo_arg**, int, const Message& ),
((lo_arg**)0, (int)0, Message((lo_message)0)),
(argv, argc, Message(msg)) );
LO_ADD_METHOD( (const Message&),
(Message((lo_message)0)),
(Message(msg)) );
LO_ADD_METHOD( (), (), () );
int del_method(const string_type &path, const string_type &typespec)
{
LO_CHECK_BEFORE;
_handlers.erase(path.s() + "," + typespec.s());
lo_server_del_method(server, path, typespec);
return 0;
}
int del_method(const lo_method& m)
{
LO_CHECK_BEFORE;
for (auto &i : _handlers) {
auto it = std::remove_if(i.second.begin(), i.second.end(),
[&](std::unique_ptr<handler>& h){return h->method == m;});
i.second.erase(it, i.second.end());
}
return lo_server_del_lo_method(server, m);
}
int dispatch_data(void *data, size_t size)
{ LO_CHECK_BEFORE; return lo_server_dispatch_data(server, data, size); }
int wait(int timeout)
{ LO_CHECK_BEFORE; return lo_server_wait(server, timeout); }
int recv()
{ LO_CHECK_BEFORE; return lo_server_recv(server); }
int recv(int timeout)
{ LO_CHECK_BEFORE; return lo_server_recv_noblock(server, timeout); }
int add_bundle_handlers(lo_bundle_start_handler sh,
lo_bundle_end_handler eh,
void *user_data)
{
LO_CHECK_BEFORE;
return lo_server_add_bundle_handlers(server, sh, eh, user_data);
}
template <typename S, typename E>
int add_bundle_handlers(S&& s, E&& e)
{
_bundle_handlers.reset(new std::pair<handler_bundle_start,
handler_bundle_end>(
handler_bundle_start(s),
handler_bundle_end(e)));
return lo_server_add_bundle_handlers(
server,
[](lo_timetag time, void *user_data)->int{
auto h = (std::pair<handler_bundle_start,
handler_bundle_end>*) user_data;
h->first(time);
return 0;
},
[](void *user_data)->int{
auto h = (std::pair<handler_bundle_start,
handler_bundle_end>*) user_data;
h->second();
return 0;
},
_bundle_handlers.get());
}
int socket_fd() const
{ LO_CHECK_BEFORE; return lo_server_get_socket_fd(server); }
int port() const
{ LO_CHECK_BEFORE; return lo_server_get_port(server); }
int protocol() const
{ LO_CHECK_BEFORE; return lo_server_get_protocol(server); }
std::string url() const
{
LO_CHECK_BEFORE;
char* s(lo_server_get_url(server));
std::string result(s?s:"");
free(s);
return result;
}
int enable_queue(int queue_enabled,
int dispatch_remaining=1)
{ LO_CHECK_BEFORE;
return lo_server_enable_queue(server,
queue_enabled,
dispatch_remaining); }
int events_pending() const
{ LO_CHECK_BEFORE; return lo_server_events_pending(server); }
double next_event_delay() const
{ LO_CHECK_BEFORE; return lo_server_next_event_delay(server); }
operator lo_server() const
{ return server; }
protected:
lo_server server;
friend class ServerThread;
struct handler { Method method; handler(Method m):method(m){} };
template <typename T>
class handler_type : public handler, public std::function<T> {
public: template<typename H>handler_type(H&& h, Method m=0)
: handler(m), std::function<T>(h) {}
};
typedef handler_type<void(int, const char *, const char *)> handler_error;
typedef handler_type<void(int, const std::string&, const std::string&)> handler_error_s;
typedef handler_type<void(lo_timetag)> handler_bundle_start;
typedef handler_type<void()> handler_bundle_end;
// Keep std::functions here so they are freed correctly
std::unordered_map<std::string,
std::list<std::unique_ptr<handler>>> _handlers;
std::unique_ptr<handler> _error_handler;
std::unique_ptr<std::pair<handler_bundle_start,
handler_bundle_end>> _bundle_handlers;
virtual Method _add_method(const char *path, const char *types,
lo_method_handler h, void *data) const
{
LO_CHECK_BEFORE;
return lo_server_add_method(server, path, types, h, data);
}
};
class ServerThread : public Server
{
public:
ServerThread(const num_string_type &port, lo_err_handler err_h=0)
: Server(0)
{ server_thread = lo_server_thread_new(port, err_h);
if (server_thread)
server = lo_server_thread_get_server(server_thread);
LO_CHECK_AFTER; }
template <typename E>
ServerThread(const num_string_type &port, E&& e)
: Server(0)
{
server_thread = lo_server_thread_new(port,
[](int num, const char *msg, const char *where){
auto h = static_cast<handler_error*>(lo_error_get_context());
// TODO: Can't call "e" yet since error context is not yet
// provided, port unavailable errors will not be reported!
if (h) (*h)(num, msg, where);});
if (server_thread) {
server = lo_server_thread_get_server(server_thread);
auto h = new handler_error(e);
_error_handler.reset(h);
lo_server_thread_set_error_context(server_thread, h);
lo_server_set_error_context(server,
(_error_handler = std::unique_ptr<handler>(
new handler_error(e))).get());
}
LO_CHECK_AFTER;
}
ServerThread(const num_string_type &port, int proto, lo_err_handler err_h)
: Server(0)
{ server_thread = lo_server_thread_new_with_proto(port, proto, err_h);
if (server_thread)
server = lo_server_thread_get_server(server_thread);
LO_CHECK_AFTER;
}
template <typename E>
ServerThread(const num_string_type &port, int proto, E&& e)
: Server(0)
{
server_thread = lo_server_thread_new_with_proto(port, proto,
[](int num, const char *msg, const char *where){
auto h = static_cast<handler_error*>(lo_error_get_context());
// TODO: Can't call "e" yet since error context is not yet
// provided, port unavailable errors will not be reported!
if (h) (*h)(num, msg, where);});
if (server_thread) {
server = lo_server_thread_get_server(server_thread);
auto h = new handler_error(e);
_error_handler.reset(h);
lo_server_thread_set_error_context(server_thread, h);
lo_server_set_error_context(server,
(_error_handler = std::unique_ptr<handler>(
new handler_error(e))).get());
}
LO_CHECK_AFTER;
}
ServerThread(const string_type &group, const num_string_type &port,
const string_type &iface, const string_type &ip,
lo_err_handler err_h=0) : Server(0)
{ if (iface._s || ip._s)
server_thread = lo_server_thread_new_multicast_iface(group, port,
iface, ip, err_h);
else
server_thread = lo_server_thread_new_multicast(group, port, err_h);
if (server_thread)
server = lo_server_thread_get_server(server_thread);
LO_CHECK_AFTER;
}
virtual ~ServerThread()
{ server = 0;
if (server_thread) lo_server_thread_free(server_thread); }
template <typename I, typename C>
auto set_callbacks(I&& init, C&& cleanup)
-> typename std::enable_if<
std::is_same<decltype(init()), int>::value, void>::type
{
LO_CHECK_BEFORE;
if (server_thread) {
_cb_handlers.reset(new handler_cb_pair(init, cleanup));
lo_server_thread_set_callbacks(server_thread,
[](lo_server_thread s, void *c){
auto cb = (handler_cb_pair*)c;
return (cb->first)();
},
[](lo_server_thread s, void *c){
auto cb = (handler_cb_pair*)c;
(cb->second)();
}, _cb_handlers.get());
}
}
template <typename I, typename C>
auto set_callbacks(I&& init, C&& cleanup)
-> typename std::enable_if<
std::is_same<decltype(init()), void>::value, void>::type
{
if (server_thread) {
_cb_handlers.reset(
(handler_cb_pair*)new handler_cb_pair_void(init, cleanup));
lo_server_thread_set_callbacks(server_thread,
[](lo_server_thread s, void *c){
auto cb = (handler_cb_pair_void*)c;
(cb->first)(); return 0;
},
[](lo_server_thread s, void *c){
auto cb = (handler_cb_pair_void*)c;
(cb->second)();
}, _cb_handlers.get());
}
}
void start() { LO_CHECK_BEFORE; lo_server_thread_start(server_thread); }
void stop() { LO_CHECK_BEFORE; lo_server_thread_stop(server_thread); }
operator lo_server_thread() const
{ return server_thread; }
protected:
lo_server_thread server_thread;
typedef std::pair<handler_type<int()>,handler_type<void()>> handler_cb_pair;
typedef std::pair<handler_type<void()>,handler_type<void()>> handler_cb_pair_void;
std::unique_ptr<handler_cb_pair> _cb_handlers;
// Regular old liblo method handlers
virtual Method _add_method(const char *path, const char *types,
lo_method_handler h, void *data) const
{
LO_CHECK_BEFORE;
return lo_server_thread_add_method(server_thread, path, types, h, data);
}
};
// This function needed since lo::ServerThread doesn't
// properly auto-upcast to lo::Server -> lo_server. (Because
// both lo_server and lo_serverthread are typedef'd as void*)
inline
int Address::send_from(lo::ServerThread &from, const string_type &path,
const string_type type, ...) const
{
LO_CHECK_BEFORE;
va_list q;
va_start(q, type);
lo_message m = lo_message_new();
std::string t = std::string(type) + "$$";
lo_message_add_varargs(m, t.c_str(), q);
lo_server s = static_cast<lo::Server&>(from);
int r = lo_send_message_from(address, s, path, m);
lo_message_free(m);
va_end(q);
return r;
}
inline
int Address::send_from(lo::ServerThread &from, lo_bundle b) const
{
LO_CHECK_BEFORE;
lo_server s = static_cast<lo::Server&>(from);
return lo_send_bundle_from(address, s, b);
}
class Blob
{
public:
Blob(int32_t size, const void *data=0)
: blob(lo_blob_new(size, data)) { LO_CHECK_AFTER; }
template <typename T>
Blob(const T &t)
: blob(lo_blob_new(t.size()*sizeof(t[0]), &t[0])) { LO_CHECK_AFTER; }
virtual ~Blob()
{ lo_blob_free(blob); }
Blob& operator=(Blob b) { b.swap(*this); return *this; }
void swap(Blob& b) throw () { std::swap(this->blob, b.blob); }
bool is_valid() const { return blob!=nullptr; }
uint32_t datasize() const
{ LO_CHECK_BEFORE; return lo_blob_datasize(blob); }
void *dataptr() const
{ LO_CHECK_BEFORE; return lo_blob_dataptr(blob); }
uint32_t size() const
{ LO_CHECK_BEFORE; return lo_blobsize(blob); }
operator lo_blob() const
{ return blob; };
protected:
lo_blob blob;
};
struct PathMsg
{
PathMsg() {}
PathMsg(const string_type _path, const Message& _msg)
: path(_path), msg(_msg) {}
std::string path;
Message msg;
};
class Bundle
{
public:
template <typename T>
struct ElementT
{
ElementT()
: type((lo_element_type)0), pm("", 0), bundle((lo_bundle)0) {}
ElementT(const string_type _path, const Message& _msg)
: type(LO_ELEMENT_MESSAGE),
pm(PathMsg(_path, _msg)),
bundle((lo_bundle)0) {}
ElementT(const T& _bundle)
: type(LO_ELEMENT_BUNDLE), pm("", 0), bundle(_bundle) {}
lo_element_type type;
PathMsg pm;
T bundle;
};
typedef ElementT<Bundle> Element;
Bundle() { bundle = lo_bundle_new(LO_TT_IMMEDIATE);
if (bundle) lo_bundle_incref(bundle);
LO_CHECK_AFTER; }
Bundle(lo_timetag tt)
: bundle(lo_bundle_new(tt)) { if (bundle) lo_bundle_incref(bundle);
LO_CHECK_AFTER; }
Bundle(lo_bundle b)
: bundle(b) { if (b) { lo_bundle_incref(b); } }
Bundle(const string_type &path, lo_message m,
lo_timetag tt=LO_TT_IMMEDIATE)
: bundle(lo_bundle_new(tt))
{
if (bundle) {
lo_bundle_incref(bundle);
lo_bundle_add_message(bundle, path, m);
}
LO_CHECK_AFTER;
}
Bundle(const std::initializer_list<Element> &elements,
lo_timetag tt=LO_TT_IMMEDIATE)
: bundle(lo_bundle_new(tt))
{
if (bundle) {
lo_bundle_incref(bundle);
for (auto const &e : elements) {
if (e.type == LO_ELEMENT_MESSAGE) {
lo_bundle_add_message(bundle, e.pm.path.c_str(), e.pm.msg);
}
else if (e.type == LO_ELEMENT_BUNDLE) {
lo_bundle_add_bundle(bundle, e.bundle);
}
}
}
LO_CHECK_AFTER;
}
Bundle(const Bundle &b)
: Bundle((lo_bundle)b) {}
~Bundle()
{ if (bundle) lo_bundle_free_recursive(bundle); }
Bundle& operator=(Bundle b) { b.swap(*this); return *this; }
void swap(Bundle& b) throw () { std::swap(this->bundle, b.bundle); }
bool is_valid() const { return bundle!=nullptr; }
int add(const string_type &path, lo_message m)
{ LO_CHECK_BEFORE; return lo_bundle_add_message(bundle, path, m); }
int add(const lo_bundle b)
{ LO_CHECK_BEFORE; return lo_bundle_add_bundle(bundle, b); }
size_t length() const
{ LO_CHECK_BEFORE; return lo_bundle_length(bundle); }
unsigned int count() const
{ LO_CHECK_BEFORE; return lo_bundle_count(bundle); }
lo_message get_message(int index, const char **path=0) const
{ LO_CHECK_BEFORE; return lo_bundle_get_message(bundle, index, path); }
Message get_message(int index, std::string &path) const
{ LO_CHECK_BEFORE;
const char *p;
lo_message m=lo_bundle_get_message(bundle, index, &p);
path = p?p:0;
return Message(m); }
PathMsg get_message(int index) const
{ LO_CHECK_BEFORE;
const char *p;
lo_message m = lo_bundle_get_message(bundle, index, &p);
return PathMsg(p?p:0, m); }
Bundle get_bundle(int index) const
{ LO_CHECK_BEFORE; return lo_bundle_get_bundle(bundle, index); }
Element get_element(int index, const char **path=0) const
{
LO_CHECK_BEFORE;
switch (lo_bundle_get_type(bundle, index)) {
case LO_ELEMENT_MESSAGE: {
const char *p;
lo_message m = lo_bundle_get_message(bundle, index, &p);
return Element(p, m);
}
case LO_ELEMENT_BUNDLE:
return Element(lo_bundle_get_bundle(bundle, index));
default:
return Element();
}
}
lo_timetag timestamp()
{ LO_CHECK_BEFORE; return lo_bundle_get_timestamp(bundle); }
Bundle& set_timestamp(lo_timetag t)
{ LO_CHECK_BEFORE; lo_bundle_set_timestamp(bundle, t); return *this; }
void *serialise(void *to, size_t *size) const
{ LO_CHECK_BEFORE; return lo_bundle_serialise(bundle, to, size); }
void print() const
{ LO_CHECK_BEFORE; lo_bundle_pp(bundle); }
operator lo_bundle() const
{ return bundle; }
Bundle& clear()
{ LO_CHECK_BEFORE; lo_bundle_clear(bundle); return *this; }
protected:
lo_bundle bundle;
};
inline std::string version() {
char str[32];
lo_version(str, 32, 0, 0, 0, 0, 0, 0, 0);
return std::string(str);
}
inline lo_timetag now() { lo_timetag tt; lo_timetag_now(&tt); return tt; }
inline lo_timetag immediate() { return LO_TT_IMMEDIATE; }
};
#endif // _LO_CPP_H_
lo::Address
Class representing an OSC destination address, proxy for lo_address.
Definition lo_cpp.h:163
lo::Message
Class representing an OSC message, proxy for lo_message.
Definition lo_cpp.h:323
lo::Method
Class representing an OSC method, proxy for lo_method.
Definition lo_cpp.h:151
lo::ServerThread
Class representing a server thread, proxy for lo_server_thread.
Definition lo_cpp.h:758
lo::Server
Class representing a local OSC server, proxy for lo_server.
Definition lo_cpp.h:503
lo::Server::~Server
virtual ~Server()
Definition lo_cpp.h:587
lo::Server::Server
Server(const string_type &group, const num_string_type &port, const string_type &iface="", const string_type &ip="", lo_err_handler err_h=0)
Definition lo_cpp.h:578
lo::Server::Server
Server(const num_string_type &port, lo_err_handler err_h=0)
Definition lo_cpp.h:568
lo::Server::Server
Server(const num_string_type &port, int proto, lo_err_handler err_h=0)
Definition lo_cpp.h:572
lo::Server::Server
Server(const num_string_type &port, int proto, E &&e=0)
Definition lo_cpp.h:527
lo::Server::Server
Server(const num_string_type &port, E &&e)
Definition lo_cpp.h:510
lo::Server::LO_ADD_METHOD
LO_ADD_METHOD((const char *, lo_arg **, int),((char *) 0,(lo_arg **) 0,(int) 0),(types, argv, argc))
lo::Server::Server
Server(const string_type &group, const num_string_type &port, const string_type &iface=0, const string_type &ip=0, E &&e=0)
Definition lo_cpp.h:545
lo::Server::LO_ADD_METHOD
LO_ADD_METHOD((const char *, const char *, lo_arg **, int),((char *) 0,(char *) 0,(lo_arg **) 0,(int) 0),(path, types, argv, argc))
lo::Server::Server
Server(lo_server s)
Definition lo_cpp.h:506
lo::Server::add_method
Method add_method(const string_type &path, const string_type &types, lo_method_handler h, void *data) const
Definition lo_cpp.h:596
lo_element_type
lo_element_type
An enumeration of bundle element types liblo can handle.
Definition lo_osc_types.h:48
lo_address_new_from_url
lo_address lo_address_new_from_url(const char *url)
Create a lo_address object from an OSC URL.
lo_address_get_ttl
int lo_address_get_ttl(lo_address t)
Get the Time-to-Live value for a given target address.
lo_address_errno
int lo_address_errno(lo_address a)
Return the error number from the last failed lo_send() or lo_address_new() call.
lo_address_free
void lo_address_free(lo_address t)
Free the memory used by the lo_address object.
lo_blob_free
void lo_blob_free(lo_blob b)
Free the memory taken by a blob.
lo_blob_datasize
uint32_t lo_blob_datasize(lo_blob b)
Return the amount of valid data in a lo_blob object.
lo_blob_dataptr
void * lo_blob_dataptr(lo_blob b)
Return a pointer to the start of the blob data to allow contents to be changed.
lo_address_set_ttl
void lo_address_set_ttl(lo_address t, int ttl)
Set the Time-to-Live value for a given target address.
lo_address_new_with_proto
lo_address lo_address_new_with_proto(int proto, const char *host, const char *port)
Declare an OSC destination, given IP address and port number, specifying protocol.
lo_version
void lo_version(char *verstr, int verstr_size, int *major, int *minor, char *extra, int extra_size, int *lt_major, int *lt_minor, int *lt_bug)
Get information on the version of liblo current in use.
lo_send
int lo_send(lo_address targ, const char *path, const char *type,...)
Send a OSC formatted message to the address specified.
LO_TT_IMMEDIATE
#define LO_TT_IMMEDIATE
A timetag constant representing "now".
Definition lo_osc_types.h:151
lo_address_errstr
const char * lo_address_errstr(lo_address a)
Return the error string from the last failed lo_send() or lo_address_new() call.
lo_blob_new
lo_blob lo_blob_new(int32_t size, const void *data)
Create a new OSC blob type.
LO_ELEMENT_BUNDLE
@ LO_ELEMENT_BUNDLE
Definition lo_osc_types.h:52
LO_ELEMENT_MESSAGE
@ LO_ELEMENT_MESSAGE
Definition lo_osc_types.h:50
lo_message_serialise
void * lo_message_serialise(lo_message m, const char *path, void *to, size_t *size)
Serialise the lo_message object to an area of memory and return a pointer to the serialised form....
lo_message_add_timetag
int lo_message_add_timetag(lo_message m, lo_timetag a)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_server_events_pending
int lo_server_events_pending(lo_server s)
Return true if there are scheduled events (eg. from bundles) waiting to be dispatched by the server.
lo_message_length
size_t lo_message_length(lo_message m, const char *path)
Return the length of a message in bytes.
lo_address_get_hostname
const char * lo_address_get_hostname(lo_address a)
Return the hostname of a lo_address object.
lo_server_add_bundle_handlers
int lo_server_add_bundle_handlers(lo_server s, lo_bundle_start_handler sh, lo_bundle_end_handler eh, void *user_data)
Add bundle notification handlers to the specified server.
lo_message_get_timestamp
lo_timetag lo_message_get_timestamp(lo_message m)
Returns the timestamp (lo_timetag *) of a bundled incoming message.
lo_send_message
int lo_send_message(lo_address targ, const char *path, lo_message msg)
Send a lo_message object to target targ.
lo_server_get_url
char * lo_server_get_url(lo_server s)
Return an OSC URL that can be used to contact the server.
lo_bundle_get_message
lo_message lo_bundle_get_message(lo_bundle b, int index, const char **path)
Gets a message contained within a bundle.
lo_message_add_false
int lo_message_add_false(lo_message m)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_bundle_add_message
int lo_bundle_add_message(lo_bundle b, const char *path, lo_message m)
Adds an OSC message to an existing bundle.
lo_message_new
lo_message lo_message_new(void)
Create a new lo_message object.
lo_message_get_source
lo_address lo_message_get_source(lo_message m)
Returns the source (lo_address) of an incoming message.
lo_blobsize
uint32_t lo_blobsize(lo_blob b)
A function to calculate the amount of OSC message space required by a lo_blob object.
lo_bundle_free_messages
void lo_bundle_free_messages(lo_bundle b)
Obsolete, use lo_bundle_free_recursive instead.
lo_message_add_int64
int lo_message_add_int64(lo_message m, int64_t a)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_message_get_types
char * lo_message_get_types(lo_message m)
Return the message type tag string.
lo_bundle_clear
void lo_bundle_clear(lo_bundle b)
Clear elements from a lo_bundle but do not free allocated memory.
lo_message_deserialise
lo_message lo_message_deserialise(void *data, size_t size, int *result)
Deserialise a raw OSC message and return a new lo_message object. Opposite of lo_message_serialise().
lo_slip_encoding
lo_slip_encoding
Used with lo_address_set_stream_slip() to specify whether sent messages should be encoded with SLIP,...
Definition lo_lowlevel.h:85
lo_bundle_new
lo_bundle lo_bundle_new(lo_timetag tt)
Create a new bundle object.
lo_server_wait
int lo_server_wait(lo_server s, int timeout)
Wait for an OSC message to be received.
lo_server_enable_queue
int lo_server_enable_queue(lo_server s, int queue_enabled, int dispatch_remaining)
Toggle event queue. If queueing is enabled, timetagged messages that are sent in advance of the curre...
lo_message_add_float
int lo_message_add_float(lo_message m, float a)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_bundle_set_timestamp
void lo_bundle_set_timestamp(lo_bundle b, lo_timetag t)
Get the timestamp associated with a bundle.
lo_server_new_with_proto
lo_server lo_server_new_with_proto(const char *port, int proto, lo_err_handler err_h)
Create a new server instance, specifying protocol.
lo_message_add_infinitum
int lo_message_add_infinitum(lo_message m)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_message_add_string
int lo_message_add_string(lo_message m, const char *a)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_server_get_port
int lo_server_get_port(lo_server s)
Return the port number that the server has bound to.
lo_server_add_method
lo_method lo_server_add_method(lo_server s, const char *path, const char *typespec, lo_method_handler h, const void *user_data)
Add an OSC method to the specifed server.
lo_message_get_argc
int lo_message_get_argc(lo_message m)
Return the message argument count.
lo_message_get_argv
lo_arg ** lo_message_get_argv(lo_message m)
Return the message arguments. Do not free the returned data.
lo_address_set_iface
int lo_address_set_iface(lo_address t, const char *iface, const char *ip)
Set the network interface to use for a given target address.
lo_server_next_event_delay
double lo_server_next_event_delay(lo_server s)
Return the time in seconds until the next scheduled event.
lo_server_recv_noblock
int lo_server_recv_noblock(lo_server s, int timeout)
Look for an OSC message waiting to be received.
lo_server_new
lo_server lo_server_new(const char *port, lo_err_handler err_h)
Create a new server instance.
lo_bundle_count
unsigned int lo_bundle_count(lo_bundle b)
Return the number of top-level elements in a bundle.
lo_message_add_int32
int lo_message_add_int32(lo_message m, int32_t a)
Append a data item and typechar of the specified type to a message.
lo_address_set_stream_slip
int lo_address_set_stream_slip(lo_address t, lo_slip_encoding encoding)
Set outgoing stream connections (e.g., TCP) to be transmitted using the SLIP packetizing protocol.
lo_server_new_multicast
lo_server lo_server_new_multicast(const char *group, const char *port, lo_err_handler err_h)
Create a new server instance, and join a UDP multicast group.
lo_bundle_get_type
lo_element_type lo_bundle_get_type(lo_bundle b, int index)
Gets the element type contained within a bundle.
lo_message_clone
lo_message lo_message_clone(lo_message m)
Create a new lo_message object by cloning an already existing one.
lo_bundle_free_recursive
void lo_bundle_free_recursive(lo_bundle b)
Frees the memory taken by a bundle object and its messages and nested bundles recursively.
lo_message_add_symbol
int lo_message_add_symbol(lo_message m, const char *a)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_address_get_iface
const char * lo_address_get_iface(lo_address t)
Get the name of the network interface assigned to an OSC address.
lo_message_free
void lo_message_free(lo_message m)
Free memory allocated by lo_message_new() and any subsequent lo_message_add_int32 lo_message_add*() c...
lo_message_add_varargs
int lo_message_add_varargs(lo_message m, const char *types, va_list ap)
Append a varargs list to a message.
lo_send_message_from
int lo_send_message_from(lo_address targ, lo_server serv, const char *path, lo_message msg)
Send a lo_message object to target targ from address of serv.
lo_address_set_tcp_nodelay
int lo_address_set_tcp_nodelay(lo_address t, int enable)
Set the TCP_NODELAY flag on outgoing TCP connections.
lo_message_add_true
int lo_message_add_true(lo_message m)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_server_dispatch_data
int lo_server_dispatch_data(lo_server s, void *data, size_t size)
Dispatch a raw block of memory containing an OSC message.
lo_bundle_length
size_t lo_bundle_length(lo_bundle b)
Return the length of a bundle in bytes.
lo_address_get_protocol
int lo_address_get_protocol(lo_address a)
Return the protocol of a lo_address object.
lo_message_add_midi
int lo_message_add_midi(lo_message m, uint8_t a[4])
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_bundle_get_bundle
lo_bundle lo_bundle_get_bundle(lo_bundle b, int index)
Gets a nested bundle contained within a bundle.
lo_message_add_char
int lo_message_add_char(lo_message m, char a)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_server_get_protocol
int lo_server_get_protocol(lo_server s)
Return the protocol that the server is using.
lo_send_bundle_from
int lo_send_bundle_from(lo_address targ, lo_server serv, lo_bundle b)
Send a lo_bundle object to address targ from address of serv.
lo_server_del_lo_method
int lo_server_del_lo_method(lo_server s, lo_method m)
Delete a specific OSC method from the specified server.
lo_message_add_nil
int lo_message_add_nil(lo_message m)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_message_add_blob
int lo_message_add_blob(lo_message m, lo_blob a)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_address_get_port
const char * lo_address_get_port(lo_address a)
Return the port/service name of a lo_address object.
lo_message_clear
void lo_message_clear(lo_message m)
Clear elements from a lo_message but do not free allocated memory.
lo_address_get_url
char * lo_address_get_url(lo_address a)
Return a URL representing an OSC address.
lo_send_bundle
int lo_send_bundle(lo_address targ, lo_bundle b)
Send a lo_bundle object to address targ.
lo_bundle_add_bundle
int lo_bundle_add_bundle(lo_bundle b, lo_bundle n)
Adds an OSC bundle to an existing bundle.
lo_server_free
void lo_server_free(lo_server s)
Free up memory used by the lo_server object.
lo_timetag_now
void lo_timetag_now(lo_timetag *t)
Return a timetag for the current time.
lo_message_add_double
int lo_message_add_double(lo_message m, double a)
Append a data item and typechar of the specified type to a message. See lo_message_add_int32() for de...
lo_server_new_multicast_iface
lo_server lo_server_new_multicast_iface(const char *group, const char *port, const char *iface, const char *ip, lo_err_handler err_h)
Create a new server instance, and join a UDP multicast group, optionally specifying which network int...
lo_server_get_socket_fd
int lo_server_get_socket_fd(lo_server s)
Return the file descriptor of the server socket.
lo_message_incref
void lo_message_incref(lo_message m)
Add one to a message's reference count.
lo_server_recv
int lo_server_recv(lo_server s)
Block, waiting for an OSC message to be received.
lo_bundle_get_timestamp
lo_timetag lo_bundle_get_timestamp(lo_bundle b)
Get the timestamp associated with a bundle.
lo_bundle_incref
void lo_bundle_incref(lo_bundle b)
Add one to a bundle's reference count.
lo_bundle_serialise
void * lo_bundle_serialise(lo_bundle b, void *to, size_t *size)
Serialise the bundle object to an area of memory and return a pointer to the serialised form.
lo_server_del_method
void lo_server_del_method(lo_server s, const char *path, const char *typespec)
Delete an OSC method from the specified server.
lo_message_pp
void lo_message_pp(lo_message m)
Pretty-print a lo_message object.
lo_bundle_pp
void lo_bundle_pp(lo_bundle b)
Pretty-print a lo_bundle object.
lo.h
lo::immediate
lo_timetag immediate()
Return the OSC timetag representing "immediately".
Definition lo_cpp.h:1123
lo::now
lo_timetag now()
Return the current time in lo_timetag format.
Definition lo_cpp.h:1120
lo::version
std::string version()
Return the library version as an std::string.
Definition lo_cpp.h:1113
lo_server_thread_stop
int lo_server_thread_stop(lo_server_thread st)
Stop the server thread.
lo_server_thread_new_multicast
lo_server_thread lo_server_thread_new_multicast(const char *group, const char *port, lo_err_handler err_h)
Create a new server thread to handle incoming OSC messages, and join a UDP multicast group.
lo_server_thread_start
int lo_server_thread_start(lo_server_thread st)
Start the server thread.
lo_server_thread_new_with_proto
lo_server_thread lo_server_thread_new_with_proto(const char *port, int proto, lo_err_handler err_h)
Create a new server thread to handle incoming OSC messages, specifying protocol.
lo_server_thread_set_callbacks
void lo_server_thread_set_callbacks(lo_server_thread st, lo_server_thread_init_callback init, lo_server_thread_cleanup_callback cleanup, void *user_data)
Set an init and/or a cleanup function to the specifed server thread.
lo_server_thread_get_server
lo_server lo_server_thread_get_server(lo_server_thread st)
Return the lo_server for a lo_server_thread.
lo_server_thread_new
lo_server_thread lo_server_thread_new(const char *port, lo_err_handler err_h)
Create a new server thread to handle incoming OSC messages.
lo_server_thread_new_multicast_iface
lo_server_thread lo_server_thread_new_multicast_iface(const char *group, const char *port, const char *iface, const char *ip, lo_err_handler err_h)
Create a new server thread instance, and join a UDP multicast group, optionally specifying which netw...
lo_server_thread_free
void lo_server_thread_free(lo_server_thread st)
Free memory taken by a server thread.
lo_server_thread_add_method
lo_method lo_server_thread_add_method(lo_server_thread st, const char *path, const char *typespec, lo_method_handler h, const void *user_data)
Add an OSC method to the specifed server thread.
lo_server
struct lo_server_ * lo_server
An object representing an instance of an OSC server.
Definition lo_types.h:85
lo_bundle_start_handler
int(* lo_bundle_start_handler)(lo_timetag time, void *user_data)
A callback function to receive notification of a bundle being dispatched by the server or server thre...
Definition lo_types.h:155
lo_address
struct lo_address_ * lo_address
A reference to an OSC service.
Definition lo_types.h:45
lo_message
struct lo_message_ * lo_message
A low-level object used to represent messages passed over OSC.
Definition lo_types.h:60
lo_method_handler
int(* lo_method_handler)(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data)
A callback function to receive notification of matching message arriving in the server or server thre...
Definition lo_types.h:134
lo_blob
struct lo_blob_ * lo_blob
A object to store an opaque binary data object.
Definition lo_types.h:52
lo_err_handler
void(* lo_err_handler)(int num, const char *msg, const char *where)
A callback function to receive notification of an error in a server or server thread.
Definition lo_types.h:105
lo_bundle_end_handler
int(* lo_bundle_end_handler)(void *user_data)
A callback function to receive notification of a bundle dispatch being completed by the server or ser...
Definition lo_types.h:166
lo_server_thread
struct lo_server_thread_ * lo_server_thread
An object representing a thread containing an OSC server.
Definition lo_types.h:92
lo_bundle
struct lo_bundle_ * lo_bundle
A low-level object used to represent bundles of messages passed over OSC.
Definition lo_types.h:69
lo_method
struct lo_method_ * lo_method
An object representing an method on a server.
Definition lo_types.h:77
lo::PathMsg
Class representing an OSC path (std::string) and lo::Message pair.
Definition lo_cpp.h:963
lo_timetag
A structure to store OSC TimeTag values.
Definition lo_osc_types.h:35
lo_arg
Union used to read values from incoming messages.
Definition lo_osc_types.h:104