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