annotate src/liblo-0.26/lo/lo.h @ 111:585a7be09763

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