annotate win32-mingw/include/lo/lo.h @ 9:c0fb53affa76

Add liblo
author Chris Cannam
date Wed, 20 Mar 2013 15:25:02 +0000
parents
children
rev   line source
Chris@9 1 /*
Chris@9 2 * Copyright (C) 2004 Steve Harris
Chris@9 3 *
Chris@9 4 * This program is free software; you can redistribute it and/or
Chris@9 5 * modify it under the terms of the GNU Lesser General Public License
Chris@9 6 * as published by the Free Software Foundation; either version 2.1
Chris@9 7 * of the License, or (at your option) any later version.
Chris@9 8 *
Chris@9 9 * This program is distributed in the hope that it will be useful,
Chris@9 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@9 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@9 12 * GNU Lesser General Public License for more details.
Chris@9 13 *
Chris@9 14 * $Id$
Chris@9 15 */
Chris@9 16
Chris@9 17 #ifndef LO_H
Chris@9 18 #define LO_H
Chris@9 19
Chris@9 20 #ifdef __cplusplus
Chris@9 21 extern "C" {
Chris@9 22 #endif
Chris@9 23
Chris@9 24 /**
Chris@9 25 * \file lo.h The liblo main headerfile and high-level API functions.
Chris@9 26 */
Chris@9 27
Chris@9 28 #include "lo/lo_endian.h"
Chris@9 29 #include "lo/lo_types.h"
Chris@9 30 #include "lo/lo_osc_types.h"
Chris@9 31 #include "lo/lo_errors.h"
Chris@9 32 #include "lo/lo_lowlevel.h"
Chris@9 33
Chris@9 34 /**
Chris@9 35 * \defgroup liblo High-level OSC API
Chris@9 36 *
Chris@9 37 * Defines the high-level API functions necessary to implement OSC support.
Chris@9 38 * Should be adequate for most applications, but if you require lower level
Chris@9 39 * control you can use the functions defined in lo_lowlevel.h
Chris@9 40 * @{
Chris@9 41 */
Chris@9 42
Chris@9 43 /**
Chris@9 44 * \brief Declare an OSC destination, given IP address and port number.
Chris@9 45 * Same as lo_address_new_with_proto(), but using UDP.
Chris@9 46 *
Chris@9 47 * \param host An IP address or number, or NULL for the local machine.
Chris@9 48 * \param port a decimal port number or service name.
Chris@9 49 *
Chris@9 50 * The lo_address object may be used as the target of OSC messages.
Chris@9 51 *
Chris@9 52 * Note: if you wish to receive replies from the target of this address, you
Chris@9 53 * must first create a lo_server_thread or lo_server object which will receive
Chris@9 54 * the replies. The last lo_server(_thread) object creted will be the receiver.
Chris@9 55 */
Chris@9 56 lo_address lo_address_new(const char *host, const char *port);
Chris@9 57
Chris@9 58 /**
Chris@9 59 * \brief Declare an OSC destination, given IP address and port number,
Chris@9 60 * specifying protocol.
Chris@9 61 *
Chris@9 62 * \param proto The protocol to use, must be one of LO_UDP, LO_TCP or LO_UNIX.
Chris@9 63 * \param host An IP address or number, or NULL for the local machine.
Chris@9 64 * \param port a decimal port number or service name.
Chris@9 65 *
Chris@9 66 * The lo_address object may be used as the target of OSC messages.
Chris@9 67 *
Chris@9 68 * Note: if you wish to receive replies from the target of this address, you
Chris@9 69 * must first create a lo_server_thread or lo_server object which will receive
Chris@9 70 * the replies. The last lo_server(_thread) object creted will be the receiver.
Chris@9 71 */
Chris@9 72 lo_address lo_address_new_with_proto(int proto, const char *host, const char *port);
Chris@9 73
Chris@9 74 /**
Chris@9 75 * \brief Create a lo_address object from an OSC URL.
Chris@9 76 *
Chris@9 77 * example: \c "osc.udp://localhost:4444/my/path/"
Chris@9 78 */
Chris@9 79 lo_address lo_address_new_from_url(const char *url);
Chris@9 80
Chris@9 81 /**
Chris@9 82 * \brief Free the memory used by the lo_address object
Chris@9 83 */
Chris@9 84 void lo_address_free(lo_address t);
Chris@9 85
Chris@9 86 /**
Chris@9 87 * \brief Set the Time-to-Live value for a given target address.
Chris@9 88 *
Chris@9 89 * This is required for sending multicast UDP messages. A value of 1
Chris@9 90 * (the usual case) keeps the message within the subnet, while 255
Chris@9 91 * means a global, unrestricted scope.
Chris@9 92 *
Chris@9 93 * \param t An OSC address.
Chris@9 94 * \param ttl An integer specifying the scope of a multicast UDP message.
Chris@9 95 */
Chris@9 96 void lo_address_set_ttl(lo_address t, int ttl);
Chris@9 97
Chris@9 98 /**
Chris@9 99 * \brief Get the Time-to-Live value for a given target address.
Chris@9 100 *
Chris@9 101 * \param t An OSC address.
Chris@9 102 * \return An integer specifying the scope of a multicast UDP message.
Chris@9 103 */
Chris@9 104 int lo_address_get_ttl(lo_address t);
Chris@9 105
Chris@9 106 /**
Chris@9 107 * \brief Send a OSC formatted message to the address specified.
Chris@9 108 *
Chris@9 109 * \param targ The target OSC address
Chris@9 110 * \param path The OSC path the message will be delivered to
Chris@9 111 * \param type The types of the data items in the message, types are defined in
Chris@9 112 * lo_osc_types.h
Chris@9 113 * \param ... The data values to be transmitted. The types of the arguments
Chris@9 114 * passed here must agree with the types specified in the type parameter.
Chris@9 115 *
Chris@9 116 * example:
Chris@9 117 * \code
Chris@9 118 * lo_send(t, "/foo/bar", "ff", 0.1f, 23.0f);
Chris@9 119 * \endcode
Chris@9 120 *
Chris@9 121 * \return -1 on failure.
Chris@9 122 */
Chris@9 123 int lo_send(lo_address targ, const char *path, const char *type, ...);
Chris@9 124
Chris@9 125 /**
Chris@9 126 * \brief Send a OSC formatted message to the address specified,
Chris@9 127 * from the same socket as the specificied server.
Chris@9 128 *
Chris@9 129 * \param targ The target OSC address
Chris@9 130 * \param from The server to send message from (can be NULL to use new socket)
Chris@9 131 * \param ts The OSC timetag timestamp at which the message will be processed
Chris@9 132 * (can be LO_TT_IMMEDIATE if you don't want to attach a timetag)
Chris@9 133 * \param path The OSC path the message will be delivered to
Chris@9 134 * \param type The types of the data items in the message, types are defined in
Chris@9 135 * lo_osc_types.h
Chris@9 136 * \param ... The data values to be transmitted. The types of the arguments
Chris@9 137 * passed here must agree with the types specified in the type parameter.
Chris@9 138 *
Chris@9 139 * example:
Chris@9 140 * \code
Chris@9 141 * serv = lo_server_new(NULL, err);
Chris@9 142 * lo_server_add_method(serv, "/reply", "ss", reply_handler, NULL);
Chris@9 143 * lo_send_from(t, serv, LO_TT_IMMEDIATE, "/foo/bar", "ff", 0.1f, 23.0f);
Chris@9 144 * \endcode
Chris@9 145 *
Chris@9 146 * \return on success, the number of bytes sent, or -1 on failure.
Chris@9 147 */
Chris@9 148 int lo_send_from(lo_address targ, lo_server from, lo_timetag ts,
Chris@9 149 const char *path, const char *type, ...);
Chris@9 150
Chris@9 151 /**
Chris@9 152 * \brief Send a OSC formatted message to the address specified, scheduled to
Chris@9 153 * be dispatch at some time in the future.
Chris@9 154 *
Chris@9 155 * \param targ The target OSC address
Chris@9 156 * \param ts The OSC timetag timestamp at which the message will be processed
Chris@9 157 * \param path The OSC path the message will be delivered to
Chris@9 158 * \param type The types of the data items in the message, types are defined in
Chris@9 159 * lo_osc_types.h
Chris@9 160 * \param ... The data values to be transmitted. The types of the arguments
Chris@9 161 * passed here must agree with the types specified in the type parameter.
Chris@9 162 *
Chris@9 163 * example:
Chris@9 164 * \code
Chris@9 165 * lo_timetag now;<br>
Chris@9 166 * lo_timetag_now(&now);<br>
Chris@9 167 * lo_send_timestamped(t, now, "/foo/bar", "ff", 0.1f, 23.0f);
Chris@9 168 * \endcode
Chris@9 169 *
Chris@9 170 * \return on success, the number of bytes sent, or -1 on failure.
Chris@9 171 */
Chris@9 172 int lo_send_timestamped(lo_address targ, lo_timetag ts, const char *path,
Chris@9 173 const char *type, ...);
Chris@9 174
Chris@9 175 /**
Chris@9 176 * \brief Return the error number from the last failed lo_send() or
Chris@9 177 * lo_address_new() call
Chris@9 178 */
Chris@9 179 int lo_address_errno(lo_address a);
Chris@9 180
Chris@9 181 /**
Chris@9 182 * \brief Return the error string from the last failed lo_send() or
Chris@9 183 * lo_address_new() call
Chris@9 184 */
Chris@9 185 const char *lo_address_errstr(lo_address a);
Chris@9 186
Chris@9 187 /**
Chris@9 188 * \brief Create a new server thread to handle incoming OSC
Chris@9 189 * messages.
Chris@9 190 *
Chris@9 191 * Server threads take care of the message reception and dispatch by
Chris@9 192 * transparently creating a system thread to handle incoming messages.
Chris@9 193 * Use this if you do not want to handle the threading yourself.
Chris@9 194 *
Chris@9 195 * \param port If NULL is passed then an unused port will be chosen by the
Chris@9 196 * system, its number may be retrieved with lo_server_thread_get_port()
Chris@9 197 * so it can be passed to clients. Otherwise a decimal port number, service
Chris@9 198 * name or UNIX domain socket path may be passed.
Chris@9 199 * \param err_h A function that will be called in the event of an error being
Chris@9 200 * raised. The function prototype is defined in lo_types.h
Chris@9 201 */
Chris@9 202 lo_server_thread lo_server_thread_new(const char *port, lo_err_handler err_h);
Chris@9 203
Chris@9 204 /**
Chris@9 205 * \brief Create a new server thread to handle incoming OSC
Chris@9 206 * messages, and join a UDP multicast group.
Chris@9 207 *
Chris@9 208 * Server threads take care of the message reception and dispatch by
Chris@9 209 * transparently creating a system thread to handle incoming messages.
Chris@9 210 * Use this if you do not want to handle the threading yourself.
Chris@9 211 *
Chris@9 212 * \param group The multicast group to join. See documentation on IP
Chris@9 213 * multicast for the acceptable address range; e.g., http://tldp.org/HOWTO/Multicast-HOWTO-2.html
Chris@9 214 * \param port If NULL is passed then an unused port will be chosen by the
Chris@9 215 * system, its number may be retrieved with lo_server_thread_get_port()
Chris@9 216 * so it can be passed to clients. Otherwise a decimal port number, service
Chris@9 217 * name or UNIX domain socket path may be passed.
Chris@9 218 * \param err_h A function that will be called in the event of an error being
Chris@9 219 * raised. The function prototype is defined in lo_types.h
Chris@9 220 */
Chris@9 221 lo_server_thread lo_server_thread_new_multicast(const char *group, const char *port,
Chris@9 222 lo_err_handler err_h);
Chris@9 223
Chris@9 224 /**
Chris@9 225 * \brief Create a new server thread to handle incoming OSC
Chris@9 226 * messages, specifying protocol.
Chris@9 227 *
Chris@9 228 * Server threads take care of the message reception and dispatch by
Chris@9 229 * transparently creating a system thread to handle incoming messages.
Chris@9 230 * Use this if you do not want to handle the threading yourself.
Chris@9 231 *
Chris@9 232 * \param port If NULL is passed then an unused port will be chosen by the
Chris@9 233 * system, its number may be retrieved with lo_server_thread_get_port()
Chris@9 234 * so it can be passed to clients. Otherwise a decimal port number, service
Chris@9 235 * name or UNIX domain socket path may be passed.
Chris@9 236 * \param proto The protocol to use, should be one of LO_UDP, LO_TCP or LO_UNIX.
Chris@9 237 * \param err_h A function that will be called in the event of an error being
Chris@9 238 * raised. The function prototype is defined in lo_types.h
Chris@9 239 */
Chris@9 240 lo_server_thread lo_server_thread_new_with_proto(const char *port, int proto,
Chris@9 241 lo_err_handler err_h);
Chris@9 242
Chris@9 243 /**
Chris@9 244 * \brief Free memory taken by a server thread
Chris@9 245 *
Chris@9 246 * Frees the memory, and, if currently running will stop the associated thread.
Chris@9 247 */
Chris@9 248 void lo_server_thread_free(lo_server_thread st);
Chris@9 249
Chris@9 250 /**
Chris@9 251 * \brief Add an OSC method to the specifed server thread.
Chris@9 252 *
Chris@9 253 * \param st The server thread the method is to be added to.
Chris@9 254 * \param path The OSC path to register the method to. If NULL is passed the
Chris@9 255 * method will match all paths.
Chris@9 256 * \param typespec The typespec the method accepts. Incoming messages with
Chris@9 257 * similar typespecs (e.g. ones with numerical types in the same position) will
Chris@9 258 * be coerced to the typespec given here.
Chris@9 259 * \param h The method handler callback function that will be called it a
Chris@9 260 * matching message is received
Chris@9 261 * \param user_data A value that will be passed to the callback function, h,
Chris@9 262 * when its invoked matching from this method.
Chris@9 263 */
Chris@9 264 lo_method lo_server_thread_add_method(lo_server_thread st, const char *path,
Chris@9 265 const char *typespec, lo_method_handler h,
Chris@9 266 void *user_data);
Chris@9 267 /**
Chris@9 268 * \brief Delete an OSC method from the specifed server thread.
Chris@9 269 *
Chris@9 270 * \param st The server thread the method is to be removed from.
Chris@9 271 * \param path The OSC path of the method to delete. If NULL is passed the
Chris@9 272 * method will match the generic handler.
Chris@9 273 * \param typespec The typespec the method accepts.
Chris@9 274 */
Chris@9 275 void lo_server_thread_del_method(lo_server_thread st, const char *path,
Chris@9 276 const char *typespec);
Chris@9 277
Chris@9 278 /**
Chris@9 279 * \brief Start the server thread
Chris@9 280 *
Chris@9 281 * \param st the server thread to start.
Chris@9 282 * \return Less than 0 on failure, 0 on success.
Chris@9 283 */
Chris@9 284 int lo_server_thread_start(lo_server_thread st);
Chris@9 285
Chris@9 286 /**
Chris@9 287 * \brief Stop the server thread
Chris@9 288 *
Chris@9 289 * \param st the server thread to start.
Chris@9 290 * \return Less than 0 on failure, 0 on success.
Chris@9 291 */
Chris@9 292 int lo_server_thread_stop(lo_server_thread st);
Chris@9 293
Chris@9 294 /**
Chris@9 295 * \brief Return the port number that the server thread has bound to.
Chris@9 296 */
Chris@9 297 int lo_server_thread_get_port(lo_server_thread st);
Chris@9 298
Chris@9 299 /**
Chris@9 300 * \brief Return a URL describing the address of the server thread.
Chris@9 301 *
Chris@9 302 * Return value must be free()'d to reclaim memory.
Chris@9 303 */
Chris@9 304 char *lo_server_thread_get_url(lo_server_thread st);
Chris@9 305
Chris@9 306 /**
Chris@9 307 * \brief Return the lo_server for a lo_server_thread
Chris@9 308 *
Chris@9 309 * This function is useful for passing a thread's lo_server
Chris@9 310 * to lo_send_from().
Chris@9 311 */
Chris@9 312 lo_server lo_server_thread_get_server(lo_server_thread st);
Chris@9 313
Chris@9 314 /** \brief Return true if there are scheduled events (eg. from bundles) waiting
Chris@9 315 * to be dispatched by the thread */
Chris@9 316 int lo_server_thread_events_pending(lo_server_thread st);
Chris@9 317
Chris@9 318 /**
Chris@9 319 * \brief Create a new OSC blob type.
Chris@9 320 *
Chris@9 321 * \param size The amount of space to allocate in the blob structure.
Chris@9 322 * \param data The data that will be used to initialise the blob, should be
Chris@9 323 * size bytes long.
Chris@9 324 */
Chris@9 325 lo_blob lo_blob_new(int32_t size, const void *data);
Chris@9 326
Chris@9 327 /**
Chris@9 328 * \brief Free the memory taken by a blob
Chris@9 329 */
Chris@9 330 void lo_blob_free(lo_blob b);
Chris@9 331
Chris@9 332 /**
Chris@9 333 * \brief Return the amount of valid data in a lo_blob object.
Chris@9 334 *
Chris@9 335 * If you want to know the storage size, use lo_arg_size().
Chris@9 336 */
Chris@9 337 uint32_t lo_blob_datasize(lo_blob b);
Chris@9 338
Chris@9 339 /**
Chris@9 340 * \brief Return a pointer to the start of the blob data to allow contents to
Chris@9 341 * be changed.
Chris@9 342 */
Chris@9 343 void *lo_blob_dataptr(lo_blob b);
Chris@9 344
Chris@9 345 /** @} */
Chris@9 346
Chris@9 347 #include "lo/lo_macros.h"
Chris@9 348
Chris@9 349 #ifdef __cplusplus
Chris@9 350 }
Chris@9 351 #endif
Chris@9 352
Chris@9 353 #endif