annotate src/liblo-0.26/lo/lo_lowlevel.h @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents e13257ea84a4
children
rev   line source
Chris@4 1 /*
Chris@4 2 * Copyright (C) 2004 Steve Harris
Chris@4 3 *
Chris@4 4 * This program is free software; you can redistribute it and/or
Chris@4 5 * modify it under the terms of the GNU Lesser General Public License
Chris@4 6 * as published by the Free Software Foundation; either version 2.1
Chris@4 7 * of the License, or (at your option) any later version.
Chris@4 8 *
Chris@4 9 * This program is distributed in the hope that it will be useful,
Chris@4 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@4 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@4 12 * GNU Lesser General Public License for more details.
Chris@4 13 *
Chris@4 14 * $Id$
Chris@4 15 */
Chris@4 16
Chris@4 17 #ifndef LO_LOWLEVEL_H
Chris@4 18 #define LO_LOWLEVEL_H
Chris@4 19
Chris@4 20 #include "lo/lo_osc_types.h"
Chris@4 21
Chris@4 22 /**
Chris@4 23 * \file lo_lowlevel.h The liblo headerfile defining the low-level API
Chris@4 24 * functions.
Chris@4 25 */
Chris@4 26
Chris@4 27 #ifdef __cplusplus
Chris@4 28 extern "C" {
Chris@4 29 #endif
Chris@4 30
Chris@4 31 #include <stdarg.h>
Chris@4 32 #ifdef _MSC_VER
Chris@4 33 #define ssize_t SSIZE_T
Chris@4 34 #define uint32_t unsigned __int32
Chris@4 35 #else
Chris@4 36 #include <stdint.h>
Chris@4 37 #endif
Chris@4 38
Chris@4 39 #include "lo/lo_types.h"
Chris@4 40 #include "lo/lo_errors.h"
Chris@4 41
Chris@4 42 /**
Chris@4 43 * \defgroup liblolowlevel Low-level OSC API
Chris@4 44 *
Chris@4 45 * Use these functions if you require more precise control over OSC message
Chris@4 46 * contruction or handling that what is provided in the high-level functions
Chris@4 47 * described in liblo.
Chris@4 48 * @{
Chris@4 49 */
Chris@4 50
Chris@4 51 /**
Chris@4 52 * \brief Type used to represent numerical values in conversions between OSC
Chris@4 53 * types.
Chris@4 54 */
Chris@4 55 typedef long double lo_hires;
Chris@4 56
Chris@4 57
Chris@4 58
Chris@4 59
Chris@4 60 /**
Chris@4 61 * \brief Send a lo_message object to target targ
Chris@4 62 *
Chris@4 63 * This is slightly more efficient than lo_send() if you want to send a lot of
Chris@4 64 * similar messages. The messages are constructed with the lo_message_new() and
Chris@4 65 * \ref lo_message_add_int32 "lo_message_add*()" functions.
Chris@4 66 */
Chris@4 67 int lo_send_message(lo_address targ, const char *path, lo_message msg);
Chris@4 68
Chris@4 69 /**
Chris@4 70 * \brief Send a lo_message object to target targ from address of serv
Chris@4 71 *
Chris@4 72 * This is slightly more efficient than lo_send() if you want to send a lot of
Chris@4 73 * similar messages. The messages are constructed with the lo_message_new() and
Chris@4 74 * \ref lo_message_add_int32 "lo_message_add*()" functions.
Chris@4 75 *
Chris@4 76 * \param targ The address to send the message to
Chris@4 77 * \param serv The server socket to send the message from
Chris@4 78 * (can be NULL to use new socket)
Chris@4 79 * \param path The path to send the message to
Chris@4 80 * \param msg The bundle itself
Chris@4 81 */
Chris@4 82 int lo_send_message_from(lo_address targ, lo_server serv,
Chris@4 83 const char *path, lo_message msg);
Chris@4 84
Chris@4 85 /**
Chris@4 86 * \brief Send a lo_bundle object to address targ
Chris@4 87 *
Chris@4 88 * Bundles are constructed with the
Chris@4 89 * lo_bundle_new() and lo_bundle_add_message() functions.
Chris@4 90 */
Chris@4 91 int lo_send_bundle(lo_address targ, lo_bundle b);
Chris@4 92
Chris@4 93 /**
Chris@4 94 * \brief Send a lo_bundle object to address targ from address of serv
Chris@4 95 *
Chris@4 96 * Bundles are constructed with the
Chris@4 97 * lo_bundle_new() and lo_bundle_add_message() functions.
Chris@4 98 *
Chris@4 99 * \param targ The address to send the bundle to
Chris@4 100 * \param serv The server socket to send the bundle from
Chris@4 101 * (can be NULL to use new socket)
Chris@4 102 * \param b The bundle itself
Chris@4 103 */
Chris@4 104 int lo_send_bundle_from(lo_address targ, lo_server serv, lo_bundle b);
Chris@4 105
Chris@4 106 /**
Chris@4 107 * \brief Create a new lo_message object
Chris@4 108 */
Chris@4 109 lo_message lo_message_new();
Chris@4 110
Chris@4 111 /**
Chris@4 112 * \brief Free memory allocated by lo_message_new() and any subsequent
Chris@4 113 * \ref lo_message_add_int32 lo_message_add*() calls.
Chris@4 114 */
Chris@4 115 void lo_message_free(lo_message m);
Chris@4 116
Chris@4 117 /**
Chris@4 118 * \brief Append a number of arguments to a message.
Chris@4 119 *
Chris@4 120 * The data will be added in OSC byteorder (bigendian).
Chris@4 121 *
Chris@4 122 * \param m The message to be extended.
Chris@4 123 * \param types The types of the data items in the message, types are defined in
Chris@4 124 * lo_types_common.h
Chris@4 125 * \param ... The data values to be transmitted. The types of the arguments
Chris@4 126 * passed here must agree with the types specified in the type parameter.
Chris@4 127 *
Chris@4 128 * \return Less than 0 on failure, 0 on success.
Chris@4 129 */
Chris@4 130 int lo_message_add(lo_message m, const char *types, ...);
Chris@4 131
Chris@4 132 /** \internal \brief the real message_add function (don't call directly) */
Chris@4 133 int lo_message_add_internal(lo_message m, const char *file, const int line,
Chris@4 134 const char *types, ...);
Chris@4 135
Chris@4 136 /**
Chris@4 137 * \brief Append a varargs list to a message.
Chris@4 138 *
Chris@4 139 * The data will be added in OSC byteorder (bigendian).
Chris@4 140 * IMPORTANT: args list must be terminated with LO_ARGS_END, or this call will
Chris@4 141 * fail. This is used to do simple error checking on the sizes of parameters
Chris@4 142 * passed.
Chris@4 143 *
Chris@4 144 * \param m The message to be extended.
Chris@4 145 * \param types The types of the data items in the message, types are defined in
Chris@4 146 * lo_types_common.h
Chris@4 147 * \param ap The va_list created by a C function declared with an
Chris@4 148 * ellipsis (...) argument, and pre-initialised with
Chris@4 149 * "va_start(ap)". The types of the arguments passed here must agree
Chris@4 150 * with the types specified in the type parameter.
Chris@4 151 *
Chris@4 152 * \return Less than 0 on failure, 0 on success.
Chris@4 153 */
Chris@4 154 int lo_message_add_varargs(lo_message m, const char *types, va_list ap);
Chris@4 155
Chris@4 156 /** \internal \brief the real message_add_varargs function (don't call directly) */
Chris@4 157 int lo_message_add_varargs_internal(lo_message m, const char *types, va_list ap,
Chris@4 158 const char *file, const int line);
Chris@4 159
Chris@4 160 /**
Chris@4 161 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 162 *
Chris@4 163 * The data will be added in OSC byteorder (bigendian).
Chris@4 164 *
Chris@4 165 * \param m The message to be extended.
Chris@4 166 * \param a The data item.
Chris@4 167 *
Chris@4 168 * \return Less than 0 on failure, 0 on success.
Chris@4 169 */
Chris@4 170 int lo_message_add_int32(lo_message m, int32_t a);
Chris@4 171
Chris@4 172 /**
Chris@4 173 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 174 * See lo_message_add_int32() for details.
Chris@4 175 *
Chris@4 176 * \return Less than 0 on failure, 0 on success.
Chris@4 177 */
Chris@4 178 int lo_message_add_float(lo_message m, float a);
Chris@4 179
Chris@4 180 /**
Chris@4 181 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 182 * See lo_message_add_int32() for details.
Chris@4 183 *
Chris@4 184 * \return Less than 0 on failure, 0 on success.
Chris@4 185 */
Chris@4 186 int lo_message_add_string(lo_message m, const char *a);
Chris@4 187
Chris@4 188 /**
Chris@4 189 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 190 * See lo_message_add_int32() for details.
Chris@4 191 *
Chris@4 192 * \return Less than 0 on failure, 0 on success.
Chris@4 193 */
Chris@4 194 int lo_message_add_blob(lo_message m, lo_blob a);
Chris@4 195
Chris@4 196 /**
Chris@4 197 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 198 * See lo_message_add_int32() for details.
Chris@4 199 *
Chris@4 200 * \return Less than 0 on failure, 0 on success.
Chris@4 201 */
Chris@4 202 int lo_message_add_int64(lo_message m, int64_t a);
Chris@4 203
Chris@4 204 /**
Chris@4 205 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 206 * See lo_message_add_int32() for details.
Chris@4 207 *
Chris@4 208 * \return Less than 0 on failure, 0 on success.
Chris@4 209 */
Chris@4 210 int lo_message_add_timetag(lo_message m, lo_timetag a);
Chris@4 211
Chris@4 212 /**
Chris@4 213 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 214 * See lo_message_add_int32() for details.
Chris@4 215 *
Chris@4 216 * \return Less than 0 on failure, 0 on success.
Chris@4 217 */
Chris@4 218 int lo_message_add_double(lo_message m, double a);
Chris@4 219
Chris@4 220 /**
Chris@4 221 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 222 * See lo_message_add_int32() for details.
Chris@4 223 *
Chris@4 224 * \return Less than 0 on failure, 0 on success.
Chris@4 225 */
Chris@4 226 int lo_message_add_symbol(lo_message m, const char *a);
Chris@4 227
Chris@4 228 /**
Chris@4 229 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 230 * See lo_message_add_int32() for details.
Chris@4 231 *
Chris@4 232 * \return Less than 0 on failure, 0 on success.
Chris@4 233 */
Chris@4 234 int lo_message_add_char(lo_message m, char a);
Chris@4 235
Chris@4 236 /**
Chris@4 237 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 238 * See lo_message_add_int32() for details.
Chris@4 239 *
Chris@4 240 * \return Less than 0 on failure, 0 on success.
Chris@4 241 */
Chris@4 242 int lo_message_add_midi(lo_message m, uint8_t a[4]);
Chris@4 243
Chris@4 244 /**
Chris@4 245 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 246 * See lo_message_add_int32() for details.
Chris@4 247 *
Chris@4 248 * \return Less than 0 on failure, 0 on success.
Chris@4 249 */
Chris@4 250 int lo_message_add_true(lo_message m);
Chris@4 251
Chris@4 252 /**
Chris@4 253 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 254 * See lo_message_add_int32() for details.
Chris@4 255 *
Chris@4 256 * \return Less than 0 on failure, 0 on success.
Chris@4 257 */
Chris@4 258 int lo_message_add_false(lo_message m);
Chris@4 259
Chris@4 260 /**
Chris@4 261 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 262 * See lo_message_add_int32() for details.
Chris@4 263 *
Chris@4 264 * \return Less than 0 on failure, 0 on success.
Chris@4 265 */
Chris@4 266 int lo_message_add_nil(lo_message m);
Chris@4 267
Chris@4 268 /**
Chris@4 269 * \brief Append a data item and typechar of the specified type to a message.
Chris@4 270 * See lo_message_add_int32() for details.
Chris@4 271 *
Chris@4 272 * \return Less than 0 on failure, 0 on success.
Chris@4 273 */
Chris@4 274 int lo_message_add_infinitum(lo_message m);
Chris@4 275
Chris@4 276 /**
Chris@4 277 * \brief Returns the source (lo_address) of an incoming message.
Chris@4 278 *
Chris@4 279 * Returns NULL if the message is outgoing. Do not free the returned address.
Chris@4 280 */
Chris@4 281 lo_address lo_message_get_source(lo_message m);
Chris@4 282
Chris@4 283 /**
Chris@4 284 * \brief Returns the timestamp (lo_timetag *) of a bundled incoming message.
Chris@4 285 *
Chris@4 286 * Returns LO_TT_IMMEDIATE if the message is outgoing, or did not arrive
Chris@4 287 * contained in a bundle. Do not free the returned timetag.
Chris@4 288 */
Chris@4 289 lo_timetag lo_message_get_timestamp(lo_message m);
Chris@4 290
Chris@4 291 /**
Chris@4 292 * \brief Return the message type tag string.
Chris@4 293 *
Chris@4 294 * The result is valid until further data is added with lo_message_add*().
Chris@4 295 */
Chris@4 296 char *lo_message_get_types(lo_message m);
Chris@4 297
Chris@4 298 /**
Chris@4 299 * \brief Return the message argument count.
Chris@4 300 *
Chris@4 301 * The result is valid until further data is added with lo_message_add*().
Chris@4 302 */
Chris@4 303 int lo_message_get_argc(lo_message m);
Chris@4 304
Chris@4 305 /**
Chris@4 306 * \brief Return the message arguments. Do not free the returned data.
Chris@4 307 *
Chris@4 308 * The result is valid until further data is added with lo_message_add*().
Chris@4 309 */
Chris@4 310 lo_arg **lo_message_get_argv(lo_message m);
Chris@4 311
Chris@4 312 /**
Chris@4 313 * \brief Return the length of a message in bytes.
Chris@4 314 *
Chris@4 315 * \param m The message to be sized
Chris@4 316 * \param path The path the message will be sent to
Chris@4 317 */
Chris@4 318 size_t lo_message_length(lo_message m, const char *path);
Chris@4 319
Chris@4 320 /**
Chris@4 321 * \brief Serialise the lo_message object to an area of memory and return a
Chris@4 322 * pointer to the serialised form. Opposite of lo_message_deserialise().
Chris@4 323 *
Chris@4 324 * \param m The message to be serialised
Chris@4 325 * \param path The path the message will be sent to
Chris@4 326 * \param to The address to serialise to, memory will be allocated if to is
Chris@4 327 * NULL.
Chris@4 328 * \param size If this pointer is non-NULL the size of the memory area
Chris@4 329 * will be written here
Chris@4 330 *
Chris@4 331 * The returned form is suitable to be sent over a low level OSC transport,
Chris@4 332 * having the correct endianess and bit-packed structure.
Chris@4 333 */
Chris@4 334 void *lo_message_serialise(lo_message m, const char *path, void *to,
Chris@4 335 size_t *size);
Chris@4 336
Chris@4 337 /**
Chris@4 338 * \brief Deserialise a raw OSC message and return a new lo_message object.
Chris@4 339 * Opposite of lo_message_serialise().
Chris@4 340 *
Chris@4 341 * \param data Pointer to the raw OSC message data in network transmission form
Chris@4 342 * (network byte order where appropriate).
Chris@4 343 * \param size The size of data in bytes
Chris@4 344 * \param result If this pointer is non-NULL, the result or error code will
Chris@4 345 * be written here.
Chris@4 346 *
Chris@4 347 * Returns a new lo_message, or NULL if deserialisation fails.
Chris@4 348 * Use lo_message_free() to free the resulting object.
Chris@4 349 */
Chris@4 350 lo_message lo_message_deserialise(void *data, size_t size, int *result);
Chris@4 351
Chris@4 352 /**
Chris@4 353 * \brief Dispatch a raw block of memory containing an OSC message.
Chris@4 354 *
Chris@4 355 * This is useful when a raw block of memory is available that is
Chris@4 356 * structured as OSC, and you wish to use liblo to dispatch the
Chris@4 357 * message to a handler function as if it had been received over the
Chris@4 358 * network.
Chris@4 359 *
Chris@4 360 * \param s The lo_server to use for dispatching.
Chris@4 361 * \param data Pointer to the raw OSC message data in network transmission form
Chris@4 362 * (network byte order where appropriate).
Chris@4 363 * \param size The size of data in bytes
Chris@4 364 *
Chris@4 365 * Returns the number of bytes used if successful, or less than 0 otherwise.
Chris@4 366 */
Chris@4 367 int lo_server_dispatch_data(lo_server s, void *data, size_t size);
Chris@4 368
Chris@4 369 /**
Chris@4 370 * \brief Return the hostname of a lo_address object
Chris@4 371 *
Chris@4 372 * Returned value must not be modified or free'd. Value will be a dotted quad,
Chris@4 373 * colon'd IPV6 address, or resolvable name.
Chris@4 374 */
Chris@4 375 const char *lo_address_get_hostname(lo_address a);
Chris@4 376
Chris@4 377 /**
Chris@4 378 * \brief Return the port/service name of a lo_address object
Chris@4 379 *
Chris@4 380 * Returned value must not be modified or free'd. Value will be a service name
Chris@4 381 * or ASCII representation of the port number.
Chris@4 382 */
Chris@4 383 const char *lo_address_get_port(lo_address a);
Chris@4 384
Chris@4 385 /**
Chris@4 386 * \brief Return the protocol of a lo_address object
Chris@4 387 *
Chris@4 388 * Returned value will be one of LO_UDP, LO_TCP or LO_UNIX.
Chris@4 389 */
Chris@4 390 int lo_address_get_protocol(lo_address a);
Chris@4 391
Chris@4 392 /**
Chris@4 393 * \brief Return a URL representing an OSC address
Chris@4 394 *
Chris@4 395 * Returned value must be free'd.
Chris@4 396 */
Chris@4 397 char *lo_address_get_url(lo_address a);
Chris@4 398
Chris@4 399 /**
Chris@4 400 * \brief Set the Time-to-Live value for a given target address.
Chris@4 401 *
Chris@4 402 * This is required for sending multicast UDP messages. A value of 1
Chris@4 403 * (the usual case) keeps the message within the subnet, while 255
Chris@4 404 * means a global, unrestricted scope.
Chris@4 405 *
Chris@4 406 * \param t An OSC address.
Chris@4 407 * \param ttl An integer specifying the scope of a multicast UDP message.
Chris@4 408 */
Chris@4 409 void lo_address_set_ttl(lo_address t, int ttl);
Chris@4 410
Chris@4 411 /**
Chris@4 412 * \brief Get the Time-to-Live value for a given target address.
Chris@4 413 *
Chris@4 414 * \param t An OSC address.
Chris@4 415 * \return An integer specifying the scope of a multicast UDP message.
Chris@4 416 */
Chris@4 417 int lo_address_get_ttl(lo_address t);
Chris@4 418
Chris@4 419 /**
Chris@4 420 * \brief Create a new bundle object.
Chris@4 421 *
Chris@4 422 * OSC Bundles encapsulate one or more OSC messages and may include a timestamp
Chris@4 423 * indicating when the bundle should be dispatched.
Chris@4 424 *
Chris@4 425 * \param tt The timestamp when the bundle should be handled by the receiver.
Chris@4 426 * Pass LO_TT_IMMEDIATE if you want the receiving server to dispatch
Chris@4 427 * the bundle as soon as it receives it.
Chris@4 428 */
Chris@4 429 lo_bundle lo_bundle_new(lo_timetag tt);
Chris@4 430
Chris@4 431 /**
Chris@4 432 * \brief Adds an OSC message to an existing bundle.
Chris@4 433 *
Chris@4 434 * The message passed is appended to the list of messages in the bundle to be
Chris@4 435 * dispatched to 'path'.
Chris@4 436 *
Chris@4 437 * \return 0 if successful, less than 0 otherwise.
Chris@4 438 */
Chris@4 439 int lo_bundle_add_message(lo_bundle b, const char *path, lo_message m);
Chris@4 440
Chris@4 441 /**
Chris@4 442 * \brief Return the length of a bundle in bytes.
Chris@4 443 *
Chris@4 444 * Includes the marker and typetage length.
Chris@4 445 *
Chris@4 446 * \param b The bundle to be sized
Chris@4 447 */
Chris@4 448 size_t lo_bundle_length(lo_bundle b);
Chris@4 449
Chris@4 450 /**
Chris@4 451 * \brief Serialise the bundle object to an area of memory and return a
Chris@4 452 * pointer to the serialised form.
Chris@4 453 *
Chris@4 454 * \param b The bundle to be serialised
Chris@4 455 * \param to The address to serialise to, memory will be allocated if to is
Chris@4 456 * NULL.
Chris@4 457 * \param size If this pointer is non-NULL the size of the memory area
Chris@4 458 * will be written here
Chris@4 459 *
Chris@4 460 * The returned form is suitable to be sent over a low level OSC transport,
Chris@4 461 * having the correct endianess and bit-packed structure.
Chris@4 462 */
Chris@4 463 void *lo_bundle_serialise(lo_bundle b, void *to, size_t *size);
Chris@4 464
Chris@4 465 /**
Chris@4 466 * \brief Frees the memory taken by a bundle object.
Chris@4 467 *
Chris@4 468 * \param b The bundle to be freed.
Chris@4 469 */
Chris@4 470 void lo_bundle_free(lo_bundle b);
Chris@4 471
Chris@4 472 /**
Chris@4 473 * \brief Frees the memory taken by a bundle object and messages in the bundle.
Chris@4 474 *
Chris@4 475 * \param b The bundle, which may contain messages, to be freed.
Chris@4 476 */
Chris@4 477 void lo_bundle_free_messages(lo_bundle b);
Chris@4 478
Chris@4 479 /**
Chris@4 480 * \brief Return true if the type specified has a numerical value, such as
Chris@4 481 * LO_INT32, LO_FLOAT etc.
Chris@4 482 *
Chris@4 483 * \param a The type to be tested.
Chris@4 484 */
Chris@4 485 int lo_is_numerical_type(lo_type a);
Chris@4 486
Chris@4 487 /**
Chris@4 488 * \brief Return true if the type specified has a textual value, such as
Chris@4 489 * LO_STRING or LO_SYMBOL.
Chris@4 490 *
Chris@4 491 * \param a The type to be tested.
Chris@4 492 */
Chris@4 493 int lo_is_string_type(lo_type a);
Chris@4 494
Chris@4 495 /**
Chris@4 496 * \brief Attempt to convert one OSC type to another.
Chris@4 497 *
Chris@4 498 * Numerical types (eg LO_INT32, LO_FLOAT etc.) may be converted to other
Chris@4 499 * numerical types and string types (LO_STRING and LO_SYMBOL) may be converted
Chris@4 500 * to the other type. This is done automatically if a received message matches
Chris@4 501 * the path, but not the exact types, and is coercible (ie. all numerical
Chris@4 502 * types in numerical positions).
Chris@4 503 *
Chris@4 504 * On failure no translation occurs and false is returned.
Chris@4 505 *
Chris@4 506 * \param type_to The type of the destination variable.
Chris@4 507 * \param to A pointer to the destination variable.
Chris@4 508 * \param type_from The type of the source variable.
Chris@4 509 * \param from A pointer to the source variable.
Chris@4 510 */
Chris@4 511 int lo_coerce(lo_type type_to, lo_arg *to, lo_type type_from, lo_arg *from);
Chris@4 512
Chris@4 513 /**
Chris@4 514 * \brief Return the numerical value of the given argument with the
Chris@4 515 * maximum native system precision.
Chris@4 516 */
Chris@4 517 lo_hires lo_hires_val(lo_type type, lo_arg *p);
Chris@4 518
Chris@4 519 /**
Chris@4 520 * \brief Create a new server instance.
Chris@4 521 *
Chris@4 522 * Using lo_server_recv(), lo_servers block until they receive OSC
Chris@4 523 * messages. If you want non-blocking behaviour see
Chris@4 524 * lo_server_recv_noblock() or the \ref lo_server_thread_new
Chris@4 525 * "lo_server_thread_*" functions.
Chris@4 526 *
Chris@4 527 * \param port If NULL is passed then an unused UDP port will be chosen by the
Chris@4 528 * system, its number may be retrieved with lo_server_thread_get_port()
Chris@4 529 * so it can be passed to clients. Otherwise a decimal port number, service
Chris@4 530 * name or UNIX domain socket path may be passed.
Chris@4 531 * \param err_h An error callback function that will be called if there is an
Chris@4 532 * error in messge reception or server creation. Pass NULL if you do not want
Chris@4 533 * error handling.
Chris@4 534 */
Chris@4 535 lo_server lo_server_new(const char *port, lo_err_handler err_h);
Chris@4 536
Chris@4 537 /**
Chris@4 538 * \brief Create a new server instance, specifying protocol.
Chris@4 539 *
Chris@4 540 * Using lo_server_recv(), lo_servers block until they receive OSC
Chris@4 541 * messages. If you want non-blocking behaviour see
Chris@4 542 * lo_server_recv_noblock() or the \ref lo_server_thread_new
Chris@4 543 * "lo_server_thread_*" functions.
Chris@4 544 *
Chris@4 545 * \param port If using UDP then NULL may be passed to find an unused port.
Chris@4 546 * Otherwise a decimal port number orservice name or may be passed.
Chris@4 547 * If using UNIX domain sockets then a socket path should be passed here.
Chris@4 548 * \param proto The protocol to use, should be one of LO_UDP, LO_TCP or LO_UNIX.
Chris@4 549 * \param err_h An error callback function that will be called if there is an
Chris@4 550 * error in messge reception or server creation. Pass NULL if you do not want
Chris@4 551 * error handling.
Chris@4 552 */
Chris@4 553 lo_server lo_server_new_with_proto(const char *port, int proto,
Chris@4 554 lo_err_handler err_h);
Chris@4 555
Chris@4 556 /**
Chris@4 557 * \brief Create a new server instance, and join a UDP multicast group.
Chris@4 558 *
Chris@4 559 * \param group The multicast group to join. See documentation on IP
Chris@4 560 * multicast for the acceptable address range; e.g., http://tldp.org/HOWTO/Multicast-HOWTO-2.html
Chris@4 561 * \param port If using UDP then NULL may be passed to find an unused port.
Chris@4 562 * Otherwise a decimal port number or service name or may be passed.
Chris@4 563 * If using UNIX domain sockets then a socket path should be passed here.
Chris@4 564 * \param err_h An error callback function that will be called if there is an
Chris@4 565 * error in messge reception or server creation. Pass NULL if you do not want
Chris@4 566 * error handling.
Chris@4 567 */
Chris@4 568 lo_server lo_server_new_multicast(const char *group, const char *port,
Chris@4 569 lo_err_handler err_h);
Chris@4 570
Chris@4 571 /**
Chris@4 572 * \brief Free up memory used by the lo_server object
Chris@4 573 */
Chris@4 574 void lo_server_free(lo_server s);
Chris@4 575
Chris@4 576 /**
Chris@4 577 * \brief Wait for an OSC message to be received
Chris@4 578 *
Chris@4 579 * \param s The server to wait for connections on.
Chris@4 580 * \param timeout A timeout in milliseconds to wait for the incoming packet.
Chris@4 581 * a value of 0 will return immediately.
Chris@4 582 *
Chris@4 583 * The return value is 1 if there is a message waiting or 0 if
Chris@4 584 * there is no message. If there is a message waiting you can now
Chris@4 585 * call lo_server_recv() to receive that message.
Chris@4 586 */
Chris@4 587 int lo_server_wait(lo_server s, int timeout);
Chris@4 588
Chris@4 589 /**
Chris@4 590 * \brief Look for an OSC message waiting to be received
Chris@4 591 *
Chris@4 592 * \param s The server to wait for connections on.
Chris@4 593 * \param timeout A timeout in milliseconds to wait for the incoming packet.
Chris@4 594 * a value of 0 will return immediately.
Chris@4 595 *
Chris@4 596 * The return value is the number of bytes in the received message or 0 if
Chris@4 597 * there is no message. The message will be dispatched to a matching method
Chris@4 598 * if one is found.
Chris@4 599 */
Chris@4 600 int lo_server_recv_noblock(lo_server s, int timeout);
Chris@4 601
Chris@4 602 /**
Chris@4 603 * \brief Block, waiting for an OSC message to be received
Chris@4 604 *
Chris@4 605 * The return value is the number of bytes in the received message. The message
Chris@4 606 * will be dispatched to a matching method if one is found.
Chris@4 607 */
Chris@4 608 int lo_server_recv(lo_server s);
Chris@4 609
Chris@4 610 /**
Chris@4 611 * \brief Add an OSC method to the specifed server.
Chris@4 612 *
Chris@4 613 * \param s The server the method is to be added to.
Chris@4 614 * \param path The OSC path to register the method to. If NULL is passed the
Chris@4 615 * method will match all paths.
Chris@4 616 * \param typespec The typespec the method accepts. Incoming messages with
Chris@4 617 * similar typespecs (e.g. ones with numerical types in the same position) will
Chris@4 618 * be coerced to the typespec given here.
Chris@4 619 * \param h The method handler callback function that will be called if a
Chris@4 620 * matching message is received
Chris@4 621 * \param user_data A value that will be passed to the callback function, h,
Chris@4 622 * when its invoked matching from this method.
Chris@4 623 */
Chris@4 624 lo_method lo_server_add_method(lo_server s, const char *path,
Chris@4 625 const char *typespec, lo_method_handler h,
Chris@4 626 void *user_data);
Chris@4 627
Chris@4 628 /**
Chris@4 629 * \brief Delete an OSC method from the specifed server.
Chris@4 630 *
Chris@4 631 * \param s The server the method is to be removed from.
Chris@4 632 * \param path The OSC path of the method to delete. If NULL is passed the
Chris@4 633 * method will match the generic handler.
Chris@4 634 * \param typespec The typespec the method accepts.
Chris@4 635 */
Chris@4 636 void lo_server_del_method(lo_server s, const char *path,
Chris@4 637 const char *typespec);
Chris@4 638
Chris@4 639 /**
Chris@4 640 * \brief Return the file descriptor of the server socket.
Chris@4 641 *
Chris@4 642 * If the server protocol supports exposing the server's underlying
Chris@4 643 * receive mechanism for monitoring with select() or poll(), this function
Chris@4 644 * returns the file descriptor needed, otherwise, it returns -1.
Chris@4 645 *
Chris@4 646 * WARNING: when using this function beware that not all OSC packets that are
Chris@4 647 * received are dispatched immediately. lo_server_events_pending() and
Chris@4 648 * lo_server_next_event_delay() can be used to tell if there are pending
Chris@4 649 * events and how long before you should attempt to receive them.
Chris@4 650 */
Chris@4 651 int lo_server_get_socket_fd(lo_server s);
Chris@4 652
Chris@4 653 /**
Chris@4 654 * \brief Return the port number that the server has bound to.
Chris@4 655 *
Chris@4 656 * Useful when NULL is passed for the port number and you wish to know how to
Chris@4 657 * address the server.
Chris@4 658 */
Chris@4 659 int lo_server_get_port(lo_server s);
Chris@4 660
Chris@4 661 /**
Chris@4 662 * \brief Return the protocol that the server is using.
Chris@4 663 *
Chris@4 664 * Returned value will be one of LO_UDP, LO_TCP or LO_UNIX.
Chris@4 665 */
Chris@4 666 int lo_server_get_protocol(lo_server s);
Chris@4 667
Chris@4 668 /**
Chris@4 669 * \brief Return an OSC URL that can be used to contact the server.
Chris@4 670 *
Chris@4 671 * The return value should be free()'d when it is no longer needed.
Chris@4 672 */
Chris@4 673 char *lo_server_get_url(lo_server s);
Chris@4 674
Chris@4 675 /**
Chris@4 676 * \brief Return true if there are scheduled events (eg. from bundles)
Chris@4 677 * waiting to be dispatched by the server
Chris@4 678 */
Chris@4 679 int lo_server_events_pending(lo_server s);
Chris@4 680
Chris@4 681 /**
Chris@4 682 * \brief Return the time in seconds until the next scheduled event.
Chris@4 683 *
Chris@4 684 * If the delay is greater than 100 seconds then it will return 100.0.
Chris@4 685 */
Chris@4 686 double lo_server_next_event_delay(lo_server s);
Chris@4 687
Chris@4 688 /**
Chris@4 689 * \brief Return the protocol portion of an OSC URL, eg. udp, tcp.
Chris@4 690 *
Chris@4 691 * This library uses OSC URLs of the form: osc.prot://hostname:port/path if the
Chris@4 692 * prot part is missing, UDP is assumed.
Chris@4 693 *
Chris@4 694 * The return value should be free()'d when it is no longer needed.
Chris@4 695 */
Chris@4 696 char *lo_url_get_protocol(const char *url);
Chris@4 697
Chris@4 698 /**
Chris@4 699 * \brief Return the protocol ID of an OSC URL.
Chris@4 700 *
Chris@4 701 * This library uses OSC URLs of the form: osc.prot://hostname:port/path if the
Chris@4 702 * prot part is missing, UDP is assumed.
Chris@4 703 * Returned value will be one of LO_UDP, LO_TCP, LO_UNIX or -1.
Chris@4 704 *
Chris@4 705 * \return An integer specifying the protocol. Return -1 when the protocol is
Chris@4 706 * not supported by liblo.
Chris@4 707 *
Chris@4 708 */
Chris@4 709 int lo_url_get_protocol_id(const char *url);
Chris@4 710
Chris@4 711 /**
Chris@4 712 * \brief Return the hostname portion of an OSC URL.
Chris@4 713 *
Chris@4 714 * The return value should be free()'d when it is no longer needed.
Chris@4 715 */
Chris@4 716 char *lo_url_get_hostname(const char *url);
Chris@4 717
Chris@4 718 /**
Chris@4 719 * \brief Return the port portion of an OSC URL.
Chris@4 720 *
Chris@4 721 * The return value should be free()'d when it is no longer needed.
Chris@4 722 */
Chris@4 723 char *lo_url_get_port(const char *url);
Chris@4 724
Chris@4 725 /**
Chris@4 726 * \brief Return the path portion of an OSC URL.
Chris@4 727 *
Chris@4 728 * The return value should be free()'d when it is no longer needed.
Chris@4 729 */
Chris@4 730 char *lo_url_get_path(const char *url);
Chris@4 731
Chris@4 732 /* utility functions */
Chris@4 733
Chris@4 734 /**
Chris@4 735 * \brief A function to calculate the amount of OSC message space required by a
Chris@4 736 * C char *.
Chris@4 737 *
Chris@4 738 * Returns the storage size in bytes, which will always be a multiple of four.
Chris@4 739 */
Chris@4 740 int lo_strsize(const char *s);
Chris@4 741
Chris@4 742 /**
Chris@4 743 * \brief A function to calculate the amount of OSC message space required by a
Chris@4 744 * lo_blob object.
Chris@4 745 *
Chris@4 746 * Returns the storage size in bytes, which will always be a multiple of four.
Chris@4 747 */
Chris@4 748 uint32_t lo_blobsize(lo_blob b);
Chris@4 749
Chris@4 750 /**
Chris@4 751 * \brief Test a string against an OSC pattern glob
Chris@4 752 *
Chris@4 753 * \param str The string to test
Chris@4 754 * \param p The pattern to test against
Chris@4 755 */
Chris@4 756 int lo_pattern_match(const char *str, const char *p);
Chris@4 757
Chris@4 758 /** \internal \brief the real send function (don't call directly) */
Chris@4 759 int lo_send_internal(lo_address t, const char *file, const int line,
Chris@4 760 const char *path, const char *types, ...);
Chris@4 761 /** \internal \brief the real send_timestamped function (don't call directly) */
Chris@4 762 int lo_send_timestamped_internal(lo_address t, const char *file, const int line,
Chris@4 763 lo_timetag ts, const char *path, const char *types, ...);
Chris@4 764 /** \internal \brief the real lo_send_from() function (don't call directly) */
Chris@4 765 int lo_send_from_internal(lo_address targ, lo_server from, const char *file,
Chris@4 766 const int line, const lo_timetag ts,
Chris@4 767 const char *path, const char *types, ...);
Chris@4 768
Chris@4 769
Chris@4 770 /** \brief Find the time difference between two timetags
Chris@4 771 *
Chris@4 772 * Returns a - b in seconds.
Chris@4 773 */
Chris@4 774 double lo_timetag_diff(lo_timetag a, lo_timetag b);
Chris@4 775
Chris@4 776 /** \brief Return a timetag for the current time
Chris@4 777 *
Chris@4 778 * On exit the timetag pointed to by t is filled with the OSC
Chris@4 779 * representation of this instant in time.
Chris@4 780 */
Chris@4 781 void lo_timetag_now(lo_timetag *t);
Chris@4 782
Chris@4 783 /**
Chris@4 784 * \brief Return the storage size, in bytes, of the given argument.
Chris@4 785 */
Chris@4 786 size_t lo_arg_size(lo_type type, void *data);
Chris@4 787
Chris@4 788 /**
Chris@4 789 * \brief Given a raw OSC message, return the message path.
Chris@4 790 *
Chris@4 791 * \param data A pointer to the raw OSC message data.
Chris@4 792 * \param size The size of data in bytes (total buffer bytes).
Chris@4 793 *
Chris@4 794 * Returns the message path or NULL if an error occurs.
Chris@4 795 * Do not free() the returned pointer.
Chris@4 796 */
Chris@4 797 char *lo_get_path(void *data, ssize_t size);
Chris@4 798
Chris@4 799 /**
Chris@4 800 * \brief Convert the specified argument to host byte order where necessary.
Chris@4 801 *
Chris@4 802 * \param type The OSC type of the data item (eg. LO_FLOAT).
Chris@4 803 * \param data A pointer to the data item to be converted. It is changed
Chris@4 804 * in-place.
Chris@4 805 */
Chris@4 806 void lo_arg_host_endian(lo_type type, void *data);
Chris@4 807
Chris@4 808 /**
Chris@4 809 * \brief Convert the specified argument to network byte order where necessary.
Chris@4 810 *
Chris@4 811 * \param type The OSC type of the data item (eg. LO_FLOAT).
Chris@4 812 * \param data A pointer to the data item to be converted. It is changed
Chris@4 813 * in-place.
Chris@4 814 */
Chris@4 815 void lo_arg_network_endian(lo_type type, void *data);
Chris@4 816
Chris@4 817 /** @} */
Chris@4 818
Chris@4 819 /* prettyprinters */
Chris@4 820
Chris@4 821 /**
Chris@4 822 * \defgroup pp Prettyprinting functions
Chris@4 823 *
Chris@4 824 * These functions all print an ASCII representation of their argument to
Chris@4 825 * stdout. Useful for debugging.
Chris@4 826 * @{
Chris@4 827 */
Chris@4 828
Chris@4 829 /** \brief Pretty-print a lo_bundle object. */
Chris@4 830 void lo_bundle_pp(lo_bundle b);
Chris@4 831
Chris@4 832 /** \brief Pretty-print a lo_message object. */
Chris@4 833 void lo_message_pp(lo_message m);
Chris@4 834
Chris@4 835 /** \brief Pretty-print a set of typed arguments.
Chris@4 836 * \param type A type string in the form provided to lo_send().
Chris@4 837 * \param data An OSC data pointer, like that provided in the
Chris@4 838 * lo_method_handler.
Chris@4 839 */
Chris@4 840 void lo_arg_pp(lo_type type, void *data);
Chris@4 841
Chris@4 842 /** \brief Pretty-print a lo_server object. */
Chris@4 843 void lo_server_pp(lo_server s);
Chris@4 844
Chris@4 845 /** \brief Pretty-print a lo_method object. */
Chris@4 846 void lo_method_pp(lo_method m);
Chris@4 847
Chris@4 848 /** \brief Pretty-print a lo_method object, but prepend a given prefix
Chris@4 849 * to all field names. */
Chris@4 850 void lo_method_pp_prefix(lo_method m, const char *p);
Chris@4 851
Chris@4 852 /** \brief Pretty-print a lo_server_thread object. */
Chris@4 853 void lo_server_thread_pp(lo_server_thread st);
Chris@4 854 /** @} */
Chris@4 855
Chris@4 856 #ifdef __cplusplus
Chris@4 857 }
Chris@4 858 #endif
Chris@4 859
Chris@4 860 #endif