annotate win32-mingw/include/lo/lo_lowlevel.h @ 94:d278df1123f9

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