annotate src/liblo-0.26/lo/lo_lowlevel.h @ 169:223a55898ab9 tip default

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