Chris@4: /* Chris@4: * Copyright (C) 2004 Steve Harris Chris@4: * Chris@4: * This program is free software; you can redistribute it and/or Chris@4: * modify it under the terms of the GNU Lesser General Public License Chris@4: * as published by the Free Software Foundation; either version 2.1 Chris@4: * of the License, or (at your option) any later version. Chris@4: * Chris@4: * This program is distributed in the hope that it will be useful, Chris@4: * but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@4: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@4: * GNU Lesser General Public License for more details. Chris@4: * Chris@4: * $Id$ Chris@4: */ Chris@4: Chris@4: #ifndef LO_LOWLEVEL_H Chris@4: #define LO_LOWLEVEL_H Chris@4: Chris@4: #include "lo/lo_osc_types.h" Chris@4: Chris@4: /** Chris@4: * \file lo_lowlevel.h The liblo headerfile defining the low-level API Chris@4: * functions. Chris@4: */ Chris@4: Chris@4: #ifdef __cplusplus Chris@4: extern "C" { Chris@4: #endif Chris@4: Chris@4: #include Chris@4: #ifdef _MSC_VER Chris@4: #define ssize_t SSIZE_T Chris@4: #define uint32_t unsigned __int32 Chris@4: #else Chris@4: #include Chris@4: #endif Chris@4: Chris@4: #include "lo/lo_types.h" Chris@4: #include "lo/lo_errors.h" Chris@4: Chris@4: /** Chris@4: * \defgroup liblolowlevel Low-level OSC API Chris@4: * Chris@4: * Use these functions if you require more precise control over OSC message Chris@4: * contruction or handling that what is provided in the high-level functions Chris@4: * described in liblo. Chris@4: * @{ Chris@4: */ Chris@4: Chris@4: /** Chris@4: * \brief Type used to represent numerical values in conversions between OSC Chris@4: * types. Chris@4: */ Chris@4: typedef long double lo_hires; Chris@4: Chris@4: Chris@4: Chris@4: Chris@4: /** Chris@4: * \brief Send a lo_message object to target targ Chris@4: * Chris@4: * This is slightly more efficient than lo_send() if you want to send a lot of Chris@4: * similar messages. The messages are constructed with the lo_message_new() and Chris@4: * \ref lo_message_add_int32 "lo_message_add*()" functions. Chris@4: */ Chris@4: int lo_send_message(lo_address targ, const char *path, lo_message msg); Chris@4: Chris@4: /** Chris@4: * \brief Send a lo_message object to target targ from address of serv Chris@4: * Chris@4: * This is slightly more efficient than lo_send() if you want to send a lot of Chris@4: * similar messages. The messages are constructed with the lo_message_new() and Chris@4: * \ref lo_message_add_int32 "lo_message_add*()" functions. Chris@4: * Chris@4: * \param targ The address to send the message to Chris@4: * \param serv The server socket to send the message from Chris@4: * (can be NULL to use new socket) Chris@4: * \param path The path to send the message to Chris@4: * \param msg The bundle itself Chris@4: */ Chris@4: int lo_send_message_from(lo_address targ, lo_server serv, Chris@4: const char *path, lo_message msg); Chris@4: Chris@4: /** Chris@4: * \brief Send a lo_bundle object to address targ Chris@4: * Chris@4: * Bundles are constructed with the Chris@4: * lo_bundle_new() and lo_bundle_add_message() functions. Chris@4: */ Chris@4: int lo_send_bundle(lo_address targ, lo_bundle b); Chris@4: Chris@4: /** Chris@4: * \brief Send a lo_bundle object to address targ from address of serv Chris@4: * Chris@4: * Bundles are constructed with the Chris@4: * lo_bundle_new() and lo_bundle_add_message() functions. Chris@4: * Chris@4: * \param targ The address to send the bundle to Chris@4: * \param serv The server socket to send the bundle from Chris@4: * (can be NULL to use new socket) Chris@4: * \param b The bundle itself Chris@4: */ Chris@4: int lo_send_bundle_from(lo_address targ, lo_server serv, lo_bundle b); Chris@4: Chris@4: /** Chris@4: * \brief Create a new lo_message object Chris@4: */ Chris@4: lo_message lo_message_new(); Chris@4: Chris@4: /** Chris@4: * \brief Free memory allocated by lo_message_new() and any subsequent Chris@4: * \ref lo_message_add_int32 lo_message_add*() calls. Chris@4: */ Chris@4: void lo_message_free(lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Append a number of arguments to a message. Chris@4: * Chris@4: * The data will be added in OSC byteorder (bigendian). Chris@4: * Chris@4: * \param m The message to be extended. Chris@4: * \param types The types of the data items in the message, types are defined in Chris@4: * lo_types_common.h Chris@4: * \param ... The data values to be transmitted. The types of the arguments Chris@4: * passed here must agree with the types specified in the type parameter. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add(lo_message m, const char *types, ...); Chris@4: Chris@4: /** \internal \brief the real message_add function (don't call directly) */ Chris@4: int lo_message_add_internal(lo_message m, const char *file, const int line, Chris@4: const char *types, ...); Chris@4: Chris@4: /** Chris@4: * \brief Append a varargs list to a message. Chris@4: * Chris@4: * The data will be added in OSC byteorder (bigendian). Chris@4: * IMPORTANT: args list must be terminated with LO_ARGS_END, or this call will Chris@4: * fail. This is used to do simple error checking on the sizes of parameters Chris@4: * passed. Chris@4: * Chris@4: * \param m The message to be extended. Chris@4: * \param types The types of the data items in the message, types are defined in Chris@4: * lo_types_common.h Chris@4: * \param ap The va_list created by a C function declared with an Chris@4: * ellipsis (...) argument, and pre-initialised with Chris@4: * "va_start(ap)". The types of the arguments passed here must agree Chris@4: * with the types specified in the type parameter. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_varargs(lo_message m, const char *types, va_list ap); Chris@4: Chris@4: /** \internal \brief the real message_add_varargs function (don't call directly) */ Chris@4: int lo_message_add_varargs_internal(lo_message m, const char *types, va_list ap, Chris@4: const char *file, const int line); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * Chris@4: * The data will be added in OSC byteorder (bigendian). Chris@4: * Chris@4: * \param m The message to be extended. Chris@4: * \param a The data item. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_int32(lo_message m, int32_t a); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_float(lo_message m, float a); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_string(lo_message m, const char *a); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_blob(lo_message m, lo_blob a); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_int64(lo_message m, int64_t a); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_timetag(lo_message m, lo_timetag a); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_double(lo_message m, double a); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_symbol(lo_message m, const char *a); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_char(lo_message m, char a); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_midi(lo_message m, uint8_t a[4]); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_true(lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_false(lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_nil(lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Append a data item and typechar of the specified type to a message. Chris@4: * See lo_message_add_int32() for details. Chris@4: * Chris@4: * \return Less than 0 on failure, 0 on success. Chris@4: */ Chris@4: int lo_message_add_infinitum(lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Returns the source (lo_address) of an incoming message. Chris@4: * Chris@4: * Returns NULL if the message is outgoing. Do not free the returned address. Chris@4: */ Chris@4: lo_address lo_message_get_source(lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Returns the timestamp (lo_timetag *) of a bundled incoming message. Chris@4: * Chris@4: * Returns LO_TT_IMMEDIATE if the message is outgoing, or did not arrive Chris@4: * contained in a bundle. Do not free the returned timetag. Chris@4: */ Chris@4: lo_timetag lo_message_get_timestamp(lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Return the message type tag string. Chris@4: * Chris@4: * The result is valid until further data is added with lo_message_add*(). Chris@4: */ Chris@4: char *lo_message_get_types(lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Return the message argument count. Chris@4: * Chris@4: * The result is valid until further data is added with lo_message_add*(). Chris@4: */ Chris@4: int lo_message_get_argc(lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Return the message arguments. Do not free the returned data. Chris@4: * Chris@4: * The result is valid until further data is added with lo_message_add*(). Chris@4: */ Chris@4: lo_arg **lo_message_get_argv(lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Return the length of a message in bytes. Chris@4: * Chris@4: * \param m The message to be sized Chris@4: * \param path The path the message will be sent to Chris@4: */ Chris@4: size_t lo_message_length(lo_message m, const char *path); Chris@4: Chris@4: /** Chris@4: * \brief Serialise the lo_message object to an area of memory and return a Chris@4: * pointer to the serialised form. Opposite of lo_message_deserialise(). Chris@4: * Chris@4: * \param m The message to be serialised Chris@4: * \param path The path the message will be sent to Chris@4: * \param to The address to serialise to, memory will be allocated if to is Chris@4: * NULL. Chris@4: * \param size If this pointer is non-NULL the size of the memory area Chris@4: * will be written here Chris@4: * Chris@4: * The returned form is suitable to be sent over a low level OSC transport, Chris@4: * having the correct endianess and bit-packed structure. Chris@4: */ Chris@4: void *lo_message_serialise(lo_message m, const char *path, void *to, Chris@4: size_t *size); Chris@4: Chris@4: /** Chris@4: * \brief Deserialise a raw OSC message and return a new lo_message object. Chris@4: * Opposite of lo_message_serialise(). Chris@4: * Chris@4: * \param data Pointer to the raw OSC message data in network transmission form Chris@4: * (network byte order where appropriate). Chris@4: * \param size The size of data in bytes Chris@4: * \param result If this pointer is non-NULL, the result or error code will Chris@4: * be written here. Chris@4: * Chris@4: * Returns a new lo_message, or NULL if deserialisation fails. Chris@4: * Use lo_message_free() to free the resulting object. Chris@4: */ Chris@4: lo_message lo_message_deserialise(void *data, size_t size, int *result); Chris@4: Chris@4: /** Chris@4: * \brief Dispatch a raw block of memory containing an OSC message. Chris@4: * Chris@4: * This is useful when a raw block of memory is available that is Chris@4: * structured as OSC, and you wish to use liblo to dispatch the Chris@4: * message to a handler function as if it had been received over the Chris@4: * network. Chris@4: * Chris@4: * \param s The lo_server to use for dispatching. Chris@4: * \param data Pointer to the raw OSC message data in network transmission form Chris@4: * (network byte order where appropriate). Chris@4: * \param size The size of data in bytes Chris@4: * Chris@4: * Returns the number of bytes used if successful, or less than 0 otherwise. Chris@4: */ Chris@4: int lo_server_dispatch_data(lo_server s, void *data, size_t size); Chris@4: Chris@4: /** Chris@4: * \brief Return the hostname of a lo_address object Chris@4: * Chris@4: * Returned value must not be modified or free'd. Value will be a dotted quad, Chris@4: * colon'd IPV6 address, or resolvable name. Chris@4: */ Chris@4: const char *lo_address_get_hostname(lo_address a); Chris@4: Chris@4: /** Chris@4: * \brief Return the port/service name of a lo_address object Chris@4: * Chris@4: * Returned value must not be modified or free'd. Value will be a service name Chris@4: * or ASCII representation of the port number. Chris@4: */ Chris@4: const char *lo_address_get_port(lo_address a); Chris@4: Chris@4: /** Chris@4: * \brief Return the protocol of a lo_address object Chris@4: * Chris@4: * Returned value will be one of LO_UDP, LO_TCP or LO_UNIX. Chris@4: */ Chris@4: int lo_address_get_protocol(lo_address a); Chris@4: Chris@4: /** Chris@4: * \brief Return a URL representing an OSC address Chris@4: * Chris@4: * Returned value must be free'd. Chris@4: */ Chris@4: char *lo_address_get_url(lo_address a); Chris@4: Chris@4: /** Chris@4: * \brief Set the Time-to-Live value for a given target address. Chris@4: * Chris@4: * This is required for sending multicast UDP messages. A value of 1 Chris@4: * (the usual case) keeps the message within the subnet, while 255 Chris@4: * means a global, unrestricted scope. Chris@4: * Chris@4: * \param t An OSC address. Chris@4: * \param ttl An integer specifying the scope of a multicast UDP message. Chris@4: */ Chris@4: void lo_address_set_ttl(lo_address t, int ttl); Chris@4: Chris@4: /** Chris@4: * \brief Get the Time-to-Live value for a given target address. Chris@4: * Chris@4: * \param t An OSC address. Chris@4: * \return An integer specifying the scope of a multicast UDP message. Chris@4: */ Chris@4: int lo_address_get_ttl(lo_address t); Chris@4: Chris@4: /** Chris@4: * \brief Create a new bundle object. Chris@4: * Chris@4: * OSC Bundles encapsulate one or more OSC messages and may include a timestamp Chris@4: * indicating when the bundle should be dispatched. Chris@4: * Chris@4: * \param tt The timestamp when the bundle should be handled by the receiver. Chris@4: * Pass LO_TT_IMMEDIATE if you want the receiving server to dispatch Chris@4: * the bundle as soon as it receives it. Chris@4: */ Chris@4: lo_bundle lo_bundle_new(lo_timetag tt); Chris@4: Chris@4: /** Chris@4: * \brief Adds an OSC message to an existing bundle. Chris@4: * Chris@4: * The message passed is appended to the list of messages in the bundle to be Chris@4: * dispatched to 'path'. Chris@4: * Chris@4: * \return 0 if successful, less than 0 otherwise. Chris@4: */ Chris@4: int lo_bundle_add_message(lo_bundle b, const char *path, lo_message m); Chris@4: Chris@4: /** Chris@4: * \brief Return the length of a bundle in bytes. Chris@4: * Chris@4: * Includes the marker and typetage length. Chris@4: * Chris@4: * \param b The bundle to be sized Chris@4: */ Chris@4: size_t lo_bundle_length(lo_bundle b); Chris@4: Chris@4: /** Chris@4: * \brief Serialise the bundle object to an area of memory and return a Chris@4: * pointer to the serialised form. Chris@4: * Chris@4: * \param b The bundle to be serialised Chris@4: * \param to The address to serialise to, memory will be allocated if to is Chris@4: * NULL. Chris@4: * \param size If this pointer is non-NULL the size of the memory area Chris@4: * will be written here Chris@4: * Chris@4: * The returned form is suitable to be sent over a low level OSC transport, Chris@4: * having the correct endianess and bit-packed structure. Chris@4: */ Chris@4: void *lo_bundle_serialise(lo_bundle b, void *to, size_t *size); Chris@4: Chris@4: /** Chris@4: * \brief Frees the memory taken by a bundle object. Chris@4: * Chris@4: * \param b The bundle to be freed. Chris@4: */ Chris@4: void lo_bundle_free(lo_bundle b); Chris@4: Chris@4: /** Chris@4: * \brief Frees the memory taken by a bundle object and messages in the bundle. Chris@4: * Chris@4: * \param b The bundle, which may contain messages, to be freed. Chris@4: */ Chris@4: void lo_bundle_free_messages(lo_bundle b); Chris@4: Chris@4: /** Chris@4: * \brief Return true if the type specified has a numerical value, such as Chris@4: * LO_INT32, LO_FLOAT etc. Chris@4: * Chris@4: * \param a The type to be tested. Chris@4: */ Chris@4: int lo_is_numerical_type(lo_type a); Chris@4: Chris@4: /** Chris@4: * \brief Return true if the type specified has a textual value, such as Chris@4: * LO_STRING or LO_SYMBOL. Chris@4: * Chris@4: * \param a The type to be tested. Chris@4: */ Chris@4: int lo_is_string_type(lo_type a); Chris@4: Chris@4: /** Chris@4: * \brief Attempt to convert one OSC type to another. Chris@4: * Chris@4: * Numerical types (eg LO_INT32, LO_FLOAT etc.) may be converted to other Chris@4: * numerical types and string types (LO_STRING and LO_SYMBOL) may be converted Chris@4: * to the other type. This is done automatically if a received message matches Chris@4: * the path, but not the exact types, and is coercible (ie. all numerical Chris@4: * types in numerical positions). Chris@4: * Chris@4: * On failure no translation occurs and false is returned. Chris@4: * Chris@4: * \param type_to The type of the destination variable. Chris@4: * \param to A pointer to the destination variable. Chris@4: * \param type_from The type of the source variable. Chris@4: * \param from A pointer to the source variable. Chris@4: */ Chris@4: int lo_coerce(lo_type type_to, lo_arg *to, lo_type type_from, lo_arg *from); Chris@4: Chris@4: /** Chris@4: * \brief Return the numerical value of the given argument with the Chris@4: * maximum native system precision. Chris@4: */ Chris@4: lo_hires lo_hires_val(lo_type type, lo_arg *p); Chris@4: Chris@4: /** Chris@4: * \brief Create a new server instance. Chris@4: * Chris@4: * Using lo_server_recv(), lo_servers block until they receive OSC Chris@4: * messages. If you want non-blocking behaviour see Chris@4: * lo_server_recv_noblock() or the \ref lo_server_thread_new Chris@4: * "lo_server_thread_*" functions. Chris@4: * Chris@4: * \param port If NULL is passed then an unused UDP port will be chosen by the Chris@4: * system, its number may be retrieved with lo_server_thread_get_port() Chris@4: * so it can be passed to clients. Otherwise a decimal port number, service Chris@4: * name or UNIX domain socket path may be passed. Chris@4: * \param err_h An error callback function that will be called if there is an Chris@4: * error in messge reception or server creation. Pass NULL if you do not want Chris@4: * error handling. Chris@4: */ Chris@4: lo_server lo_server_new(const char *port, lo_err_handler err_h); Chris@4: Chris@4: /** Chris@4: * \brief Create a new server instance, specifying protocol. Chris@4: * Chris@4: * Using lo_server_recv(), lo_servers block until they receive OSC Chris@4: * messages. If you want non-blocking behaviour see Chris@4: * lo_server_recv_noblock() or the \ref lo_server_thread_new Chris@4: * "lo_server_thread_*" functions. Chris@4: * Chris@4: * \param port If using UDP then NULL may be passed to find an unused port. Chris@4: * Otherwise a decimal port number orservice name or may be passed. Chris@4: * If using UNIX domain sockets then a socket path should be passed here. Chris@4: * \param proto The protocol to use, should be one of LO_UDP, LO_TCP or LO_UNIX. Chris@4: * \param err_h An error callback function that will be called if there is an Chris@4: * error in messge reception or server creation. Pass NULL if you do not want Chris@4: * error handling. Chris@4: */ Chris@4: lo_server lo_server_new_with_proto(const char *port, int proto, Chris@4: lo_err_handler err_h); Chris@4: Chris@4: /** Chris@4: * \brief Create a new server instance, and join a UDP multicast group. Chris@4: * Chris@4: * \param group The multicast group to join. See documentation on IP Chris@4: * multicast for the acceptable address range; e.g., http://tldp.org/HOWTO/Multicast-HOWTO-2.html Chris@4: * \param port If using UDP then NULL may be passed to find an unused port. Chris@4: * Otherwise a decimal port number or service name or may be passed. Chris@4: * If using UNIX domain sockets then a socket path should be passed here. Chris@4: * \param err_h An error callback function that will be called if there is an Chris@4: * error in messge reception or server creation. Pass NULL if you do not want Chris@4: * error handling. Chris@4: */ Chris@4: lo_server lo_server_new_multicast(const char *group, const char *port, Chris@4: lo_err_handler err_h); Chris@4: Chris@4: /** Chris@4: * \brief Free up memory used by the lo_server object Chris@4: */ Chris@4: void lo_server_free(lo_server s); Chris@4: Chris@4: /** Chris@4: * \brief Wait for an OSC message to be received Chris@4: * Chris@4: * \param s The server to wait for connections on. Chris@4: * \param timeout A timeout in milliseconds to wait for the incoming packet. Chris@4: * a value of 0 will return immediately. Chris@4: * Chris@4: * The return value is 1 if there is a message waiting or 0 if Chris@4: * there is no message. If there is a message waiting you can now Chris@4: * call lo_server_recv() to receive that message. Chris@4: */ Chris@4: int lo_server_wait(lo_server s, int timeout); Chris@4: Chris@4: /** Chris@4: * \brief Look for an OSC message waiting to be received Chris@4: * Chris@4: * \param s The server to wait for connections on. Chris@4: * \param timeout A timeout in milliseconds to wait for the incoming packet. Chris@4: * a value of 0 will return immediately. Chris@4: * Chris@4: * The return value is the number of bytes in the received message or 0 if Chris@4: * there is no message. The message will be dispatched to a matching method Chris@4: * if one is found. Chris@4: */ Chris@4: int lo_server_recv_noblock(lo_server s, int timeout); Chris@4: Chris@4: /** Chris@4: * \brief Block, waiting for an OSC message to be received Chris@4: * Chris@4: * The return value is the number of bytes in the received message. The message Chris@4: * will be dispatched to a matching method if one is found. Chris@4: */ Chris@4: int lo_server_recv(lo_server s); Chris@4: Chris@4: /** Chris@4: * \brief Add an OSC method to the specifed server. Chris@4: * Chris@4: * \param s The server the method is to be added to. Chris@4: * \param path The OSC path to register the method to. If NULL is passed the Chris@4: * method will match all paths. Chris@4: * \param typespec The typespec the method accepts. Incoming messages with Chris@4: * similar typespecs (e.g. ones with numerical types in the same position) will Chris@4: * be coerced to the typespec given here. Chris@4: * \param h The method handler callback function that will be called if a Chris@4: * matching message is received Chris@4: * \param user_data A value that will be passed to the callback function, h, Chris@4: * when its invoked matching from this method. Chris@4: */ Chris@4: lo_method lo_server_add_method(lo_server s, const char *path, Chris@4: const char *typespec, lo_method_handler h, Chris@4: void *user_data); Chris@4: Chris@4: /** Chris@4: * \brief Delete an OSC method from the specifed server. Chris@4: * Chris@4: * \param s The server the method is to be removed from. Chris@4: * \param path The OSC path of the method to delete. If NULL is passed the Chris@4: * method will match the generic handler. Chris@4: * \param typespec The typespec the method accepts. Chris@4: */ Chris@4: void lo_server_del_method(lo_server s, const char *path, Chris@4: const char *typespec); Chris@4: Chris@4: /** Chris@4: * \brief Return the file descriptor of the server socket. Chris@4: * Chris@4: * If the server protocol supports exposing the server's underlying Chris@4: * receive mechanism for monitoring with select() or poll(), this function Chris@4: * returns the file descriptor needed, otherwise, it returns -1. Chris@4: * Chris@4: * WARNING: when using this function beware that not all OSC packets that are Chris@4: * received are dispatched immediately. lo_server_events_pending() and Chris@4: * lo_server_next_event_delay() can be used to tell if there are pending Chris@4: * events and how long before you should attempt to receive them. Chris@4: */ Chris@4: int lo_server_get_socket_fd(lo_server s); Chris@4: Chris@4: /** Chris@4: * \brief Return the port number that the server has bound to. Chris@4: * Chris@4: * Useful when NULL is passed for the port number and you wish to know how to Chris@4: * address the server. Chris@4: */ Chris@4: int lo_server_get_port(lo_server s); Chris@4: Chris@4: /** Chris@4: * \brief Return the protocol that the server is using. Chris@4: * Chris@4: * Returned value will be one of LO_UDP, LO_TCP or LO_UNIX. Chris@4: */ Chris@4: int lo_server_get_protocol(lo_server s); Chris@4: Chris@4: /** Chris@4: * \brief Return an OSC URL that can be used to contact the server. Chris@4: * Chris@4: * The return value should be free()'d when it is no longer needed. Chris@4: */ Chris@4: char *lo_server_get_url(lo_server s); Chris@4: Chris@4: /** Chris@4: * \brief Return true if there are scheduled events (eg. from bundles) Chris@4: * waiting to be dispatched by the server Chris@4: */ Chris@4: int lo_server_events_pending(lo_server s); Chris@4: Chris@4: /** Chris@4: * \brief Return the time in seconds until the next scheduled event. Chris@4: * Chris@4: * If the delay is greater than 100 seconds then it will return 100.0. Chris@4: */ Chris@4: double lo_server_next_event_delay(lo_server s); Chris@4: Chris@4: /** Chris@4: * \brief Return the protocol portion of an OSC URL, eg. udp, tcp. Chris@4: * Chris@4: * This library uses OSC URLs of the form: osc.prot://hostname:port/path if the Chris@4: * prot part is missing, UDP is assumed. Chris@4: * Chris@4: * The return value should be free()'d when it is no longer needed. Chris@4: */ Chris@4: char *lo_url_get_protocol(const char *url); Chris@4: Chris@4: /** Chris@4: * \brief Return the protocol ID of an OSC URL. Chris@4: * Chris@4: * This library uses OSC URLs of the form: osc.prot://hostname:port/path if the Chris@4: * prot part is missing, UDP is assumed. Chris@4: * Returned value will be one of LO_UDP, LO_TCP, LO_UNIX or -1. Chris@4: * Chris@4: * \return An integer specifying the protocol. Return -1 when the protocol is Chris@4: * not supported by liblo. Chris@4: * Chris@4: */ Chris@4: int lo_url_get_protocol_id(const char *url); Chris@4: Chris@4: /** Chris@4: * \brief Return the hostname portion of an OSC URL. Chris@4: * Chris@4: * The return value should be free()'d when it is no longer needed. Chris@4: */ Chris@4: char *lo_url_get_hostname(const char *url); Chris@4: Chris@4: /** Chris@4: * \brief Return the port portion of an OSC URL. Chris@4: * Chris@4: * The return value should be free()'d when it is no longer needed. Chris@4: */ Chris@4: char *lo_url_get_port(const char *url); Chris@4: Chris@4: /** Chris@4: * \brief Return the path portion of an OSC URL. Chris@4: * Chris@4: * The return value should be free()'d when it is no longer needed. Chris@4: */ Chris@4: char *lo_url_get_path(const char *url); Chris@4: Chris@4: /* utility functions */ Chris@4: Chris@4: /** Chris@4: * \brief A function to calculate the amount of OSC message space required by a Chris@4: * C char *. Chris@4: * Chris@4: * Returns the storage size in bytes, which will always be a multiple of four. Chris@4: */ Chris@4: int lo_strsize(const char *s); Chris@4: Chris@4: /** Chris@4: * \brief A function to calculate the amount of OSC message space required by a Chris@4: * lo_blob object. Chris@4: * Chris@4: * Returns the storage size in bytes, which will always be a multiple of four. Chris@4: */ Chris@4: uint32_t lo_blobsize(lo_blob b); Chris@4: Chris@4: /** Chris@4: * \brief Test a string against an OSC pattern glob Chris@4: * Chris@4: * \param str The string to test Chris@4: * \param p The pattern to test against Chris@4: */ Chris@4: int lo_pattern_match(const char *str, const char *p); Chris@4: Chris@4: /** \internal \brief the real send function (don't call directly) */ Chris@4: int lo_send_internal(lo_address t, const char *file, const int line, Chris@4: const char *path, const char *types, ...); Chris@4: /** \internal \brief the real send_timestamped function (don't call directly) */ Chris@4: int lo_send_timestamped_internal(lo_address t, const char *file, const int line, Chris@4: lo_timetag ts, const char *path, const char *types, ...); Chris@4: /** \internal \brief the real lo_send_from() function (don't call directly) */ Chris@4: int lo_send_from_internal(lo_address targ, lo_server from, const char *file, Chris@4: const int line, const lo_timetag ts, Chris@4: const char *path, const char *types, ...); Chris@4: Chris@4: Chris@4: /** \brief Find the time difference between two timetags Chris@4: * Chris@4: * Returns a - b in seconds. Chris@4: */ Chris@4: double lo_timetag_diff(lo_timetag a, lo_timetag b); Chris@4: Chris@4: /** \brief Return a timetag for the current time Chris@4: * Chris@4: * On exit the timetag pointed to by t is filled with the OSC Chris@4: * representation of this instant in time. Chris@4: */ Chris@4: void lo_timetag_now(lo_timetag *t); Chris@4: Chris@4: /** Chris@4: * \brief Return the storage size, in bytes, of the given argument. Chris@4: */ Chris@4: size_t lo_arg_size(lo_type type, void *data); Chris@4: Chris@4: /** Chris@4: * \brief Given a raw OSC message, return the message path. Chris@4: * Chris@4: * \param data A pointer to the raw OSC message data. Chris@4: * \param size The size of data in bytes (total buffer bytes). Chris@4: * Chris@4: * Returns the message path or NULL if an error occurs. Chris@4: * Do not free() the returned pointer. Chris@4: */ Chris@4: char *lo_get_path(void *data, ssize_t size); Chris@4: Chris@4: /** Chris@4: * \brief Convert the specified argument to host byte order where necessary. Chris@4: * Chris@4: * \param type The OSC type of the data item (eg. LO_FLOAT). Chris@4: * \param data A pointer to the data item to be converted. It is changed Chris@4: * in-place. Chris@4: */ Chris@4: void lo_arg_host_endian(lo_type type, void *data); Chris@4: Chris@4: /** Chris@4: * \brief Convert the specified argument to network byte order where necessary. Chris@4: * Chris@4: * \param type The OSC type of the data item (eg. LO_FLOAT). Chris@4: * \param data A pointer to the data item to be converted. It is changed Chris@4: * in-place. Chris@4: */ Chris@4: void lo_arg_network_endian(lo_type type, void *data); Chris@4: Chris@4: /** @} */ Chris@4: Chris@4: /* prettyprinters */ Chris@4: Chris@4: /** Chris@4: * \defgroup pp Prettyprinting functions Chris@4: * Chris@4: * These functions all print an ASCII representation of their argument to Chris@4: * stdout. Useful for debugging. Chris@4: * @{ Chris@4: */ Chris@4: Chris@4: /** \brief Pretty-print a lo_bundle object. */ Chris@4: void lo_bundle_pp(lo_bundle b); Chris@4: Chris@4: /** \brief Pretty-print a lo_message object. */ Chris@4: void lo_message_pp(lo_message m); Chris@4: Chris@4: /** \brief Pretty-print a set of typed arguments. Chris@4: * \param type A type string in the form provided to lo_send(). Chris@4: * \param data An OSC data pointer, like that provided in the Chris@4: * lo_method_handler. Chris@4: */ Chris@4: void lo_arg_pp(lo_type type, void *data); Chris@4: Chris@4: /** \brief Pretty-print a lo_server object. */ Chris@4: void lo_server_pp(lo_server s); Chris@4: Chris@4: /** \brief Pretty-print a lo_method object. */ Chris@4: void lo_method_pp(lo_method m); Chris@4: Chris@4: /** \brief Pretty-print a lo_method object, but prepend a given prefix Chris@4: * to all field names. */ Chris@4: void lo_method_pp_prefix(lo_method m, const char *p); Chris@4: Chris@4: /** \brief Pretty-print a lo_server_thread object. */ Chris@4: void lo_server_thread_pp(lo_server_thread st); Chris@4: /** @} */ Chris@4: Chris@4: #ifdef __cplusplus Chris@4: } Chris@4: #endif Chris@4: Chris@4: #endif