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