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