annotate osx/include/lo/lo_lowlevel.h @ 83:ae30d91d2ffe

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