annotate src/liblo-0.26/lo/lo.h @ 57:e56993504470

Fixes and updates for 32-bit Windows build
author Chris Cannam
date Mon, 09 Jan 2017 11:53:06 +0000
parents e13257ea84a4
children
rev   line source
Chris@4 1 /*
Chris@4 2 * Copyright (C) 2004 Steve Harris
Chris@4 3 *
Chris@4 4 * This program is free software; you can redistribute it and/or
Chris@4 5 * modify it under the terms of the GNU Lesser General Public License
Chris@4 6 * as published by the Free Software Foundation; either version 2.1
Chris@4 7 * of the License, or (at your option) any later version.
Chris@4 8 *
Chris@4 9 * This program is distributed in the hope that it will be useful,
Chris@4 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@4 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@4 12 * GNU Lesser General Public License for more details.
Chris@4 13 *
Chris@4 14 * $Id$
Chris@4 15 */
Chris@4 16
Chris@4 17 #ifndef LO_H
Chris@4 18 #define LO_H
Chris@4 19
Chris@4 20 #ifdef __cplusplus
Chris@4 21 extern "C" {
Chris@4 22 #endif
Chris@4 23
Chris@4 24 /**
Chris@4 25 * \file lo.h The liblo main headerfile and high-level API functions.
Chris@4 26 */
Chris@4 27
Chris@4 28 #include "lo/lo_endian.h"
Chris@4 29 #include "lo/lo_types.h"
Chris@4 30 #include "lo/lo_osc_types.h"
Chris@4 31 #include "lo/lo_errors.h"
Chris@4 32 #include "lo/lo_lowlevel.h"
Chris@4 33
Chris@4 34 /**
Chris@4 35 * \defgroup liblo High-level OSC API
Chris@4 36 *
Chris@4 37 * Defines the high-level API functions necessary to implement OSC support.
Chris@4 38 * Should be adequate for most applications, but if you require lower level
Chris@4 39 * control you can use the functions defined in lo_lowlevel.h
Chris@4 40 * @{
Chris@4 41 */
Chris@4 42
Chris@4 43 /**
Chris@4 44 * \brief Declare an OSC destination, given IP address and port number.
Chris@4 45 * Same as lo_address_new_with_proto(), but using UDP.
Chris@4 46 *
Chris@4 47 * \param host An IP address or number, or NULL for the local machine.
Chris@4 48 * \param port a decimal port number or service name.
Chris@4 49 *
Chris@4 50 * The lo_address object may be used as the target of OSC messages.
Chris@4 51 *
Chris@4 52 * Note: if you wish to receive replies from the target of this address, you
Chris@4 53 * must first create a lo_server_thread or lo_server object which will receive
Chris@4 54 * the replies. The last lo_server(_thread) object creted will be the receiver.
Chris@4 55 */
Chris@4 56 lo_address lo_address_new(const char *host, const char *port);
Chris@4 57
Chris@4 58 /**
Chris@4 59 * \brief Declare an OSC destination, given IP address and port number,
Chris@4 60 * specifying protocol.
Chris@4 61 *
Chris@4 62 * \param proto The protocol to use, must be one of LO_UDP, LO_TCP or LO_UNIX.
Chris@4 63 * \param host An IP address or number, or NULL for the local machine.
Chris@4 64 * \param port a decimal port number or service name.
Chris@4 65 *
Chris@4 66 * The lo_address object may be used as the target of OSC messages.
Chris@4 67 *
Chris@4 68 * Note: if you wish to receive replies from the target of this address, you
Chris@4 69 * must first create a lo_server_thread or lo_server object which will receive
Chris@4 70 * the replies. The last lo_server(_thread) object creted will be the receiver.
Chris@4 71 */
Chris@4 72 lo_address lo_address_new_with_proto(int proto, const char *host, const char *port);
Chris@4 73
Chris@4 74 /**
Chris@4 75 * \brief Create a lo_address object from an OSC URL.
Chris@4 76 *
Chris@4 77 * example: \c "osc.udp://localhost:4444/my/path/"
Chris@4 78 */
Chris@4 79 lo_address lo_address_new_from_url(const char *url);
Chris@4 80
Chris@4 81 /**
Chris@4 82 * \brief Free the memory used by the lo_address object
Chris@4 83 */
Chris@4 84 void lo_address_free(lo_address t);
Chris@4 85
Chris@4 86 /**
Chris@4 87 * \brief Set the Time-to-Live value for a given target address.
Chris@4 88 *
Chris@4 89 * This is required for sending multicast UDP messages. A value of 1
Chris@4 90 * (the usual case) keeps the message within the subnet, while 255
Chris@4 91 * means a global, unrestricted scope.
Chris@4 92 *
Chris@4 93 * \param t An OSC address.
Chris@4 94 * \param ttl An integer specifying the scope of a multicast UDP message.
Chris@4 95 */
Chris@4 96 void lo_address_set_ttl(lo_address t, int ttl);
Chris@4 97
Chris@4 98 /**
Chris@4 99 * \brief Get the Time-to-Live value for a given target address.
Chris@4 100 *
Chris@4 101 * \param t An OSC address.
Chris@4 102 * \return An integer specifying the scope of a multicast UDP message.
Chris@4 103 */
Chris@4 104 int lo_address_get_ttl(lo_address t);
Chris@4 105
Chris@4 106 /**
Chris@4 107 * \brief Send a OSC formatted message to the address specified.
Chris@4 108 *
Chris@4 109 * \param targ The target OSC address
Chris@4 110 * \param path The OSC path the message will be delivered to
Chris@4 111 * \param type The types of the data items in the message, types are defined in
Chris@4 112 * lo_osc_types.h
Chris@4 113 * \param ... The data values to be transmitted. The types of the arguments
Chris@4 114 * passed here must agree with the types specified in the type parameter.
Chris@4 115 *
Chris@4 116 * example:
Chris@4 117 * \code
Chris@4 118 * lo_send(t, "/foo/bar", "ff", 0.1f, 23.0f);
Chris@4 119 * \endcode
Chris@4 120 *
Chris@4 121 * \return -1 on failure.
Chris@4 122 */
Chris@4 123 int lo_send(lo_address targ, const char *path, const char *type, ...);
Chris@4 124
Chris@4 125 /**
Chris@4 126 * \brief Send a OSC formatted message to the address specified,
Chris@4 127 * from the same socket as the specificied server.
Chris@4 128 *
Chris@4 129 * \param targ The target OSC address
Chris@4 130 * \param from The server to send message from (can be NULL to use new socket)
Chris@4 131 * \param ts The OSC timetag timestamp at which the message will be processed
Chris@4 132 * (can be LO_TT_IMMEDIATE if you don't want to attach a timetag)
Chris@4 133 * \param path The OSC path the message will be delivered to
Chris@4 134 * \param type The types of the data items in the message, types are defined in
Chris@4 135 * lo_osc_types.h
Chris@4 136 * \param ... The data values to be transmitted. The types of the arguments
Chris@4 137 * passed here must agree with the types specified in the type parameter.
Chris@4 138 *
Chris@4 139 * example:
Chris@4 140 * \code
Chris@4 141 * serv = lo_server_new(NULL, err);
Chris@4 142 * lo_server_add_method(serv, "/reply", "ss", reply_handler, NULL);
Chris@4 143 * lo_send_from(t, serv, LO_TT_IMMEDIATE, "/foo/bar", "ff", 0.1f, 23.0f);
Chris@4 144 * \endcode
Chris@4 145 *
Chris@4 146 * \return on success, the number of bytes sent, or -1 on failure.
Chris@4 147 */
Chris@4 148 int lo_send_from(lo_address targ, lo_server from, lo_timetag ts,
Chris@4 149 const char *path, const char *type, ...);
Chris@4 150
Chris@4 151 /**
Chris@4 152 * \brief Send a OSC formatted message to the address specified, scheduled to
Chris@4 153 * be dispatch at some time in the future.
Chris@4 154 *
Chris@4 155 * \param targ The target OSC address
Chris@4 156 * \param ts The OSC timetag timestamp at which the message will be processed
Chris@4 157 * \param path The OSC path the message will be delivered to
Chris@4 158 * \param type The types of the data items in the message, types are defined in
Chris@4 159 * lo_osc_types.h
Chris@4 160 * \param ... The data values to be transmitted. The types of the arguments
Chris@4 161 * passed here must agree with the types specified in the type parameter.
Chris@4 162 *
Chris@4 163 * example:
Chris@4 164 * \code
Chris@4 165 * lo_timetag now;<br>
Chris@4 166 * lo_timetag_now(&now);<br>
Chris@4 167 * lo_send_timestamped(t, now, "/foo/bar", "ff", 0.1f, 23.0f);
Chris@4 168 * \endcode
Chris@4 169 *
Chris@4 170 * \return on success, the number of bytes sent, or -1 on failure.
Chris@4 171 */
Chris@4 172 int lo_send_timestamped(lo_address targ, lo_timetag ts, const char *path,
Chris@4 173 const char *type, ...);
Chris@4 174
Chris@4 175 /**
Chris@4 176 * \brief Return the error number from the last failed lo_send() or
Chris@4 177 * lo_address_new() call
Chris@4 178 */
Chris@4 179 int lo_address_errno(lo_address a);
Chris@4 180
Chris@4 181 /**
Chris@4 182 * \brief Return the error string from the last failed lo_send() or
Chris@4 183 * lo_address_new() call
Chris@4 184 */
Chris@4 185 const char *lo_address_errstr(lo_address a);
Chris@4 186
Chris@4 187 /**
Chris@4 188 * \brief Create a new server thread to handle incoming OSC
Chris@4 189 * messages.
Chris@4 190 *
Chris@4 191 * Server threads take care of the message reception and dispatch by
Chris@4 192 * transparently creating a system thread to handle incoming messages.
Chris@4 193 * Use this if you do not want to handle the threading yourself.
Chris@4 194 *
Chris@4 195 * \param port If NULL is passed then an unused port will be chosen by the
Chris@4 196 * system, its number may be retrieved with lo_server_thread_get_port()
Chris@4 197 * so it can be passed to clients. Otherwise a decimal port number, service
Chris@4 198 * name or UNIX domain socket path may be passed.
Chris@4 199 * \param err_h A function that will be called in the event of an error being
Chris@4 200 * raised. The function prototype is defined in lo_types.h
Chris@4 201 */
Chris@4 202 lo_server_thread lo_server_thread_new(const char *port, lo_err_handler err_h);
Chris@4 203
Chris@4 204 /**
Chris@4 205 * \brief Create a new server thread to handle incoming OSC
Chris@4 206 * messages, and join a UDP multicast group.
Chris@4 207 *
Chris@4 208 * Server threads take care of the message reception and dispatch by
Chris@4 209 * transparently creating a system thread to handle incoming messages.
Chris@4 210 * Use this if you do not want to handle the threading yourself.
Chris@4 211 *
Chris@4 212 * \param group The multicast group to join. See documentation on IP
Chris@4 213 * multicast for the acceptable address range; e.g., http://tldp.org/HOWTO/Multicast-HOWTO-2.html
Chris@4 214 * \param port If NULL is passed then an unused port will be chosen by the
Chris@4 215 * system, its number may be retrieved with lo_server_thread_get_port()
Chris@4 216 * so it can be passed to clients. Otherwise a decimal port number, service
Chris@4 217 * name or UNIX domain socket path may be passed.
Chris@4 218 * \param err_h A function that will be called in the event of an error being
Chris@4 219 * raised. The function prototype is defined in lo_types.h
Chris@4 220 */
Chris@4 221 lo_server_thread lo_server_thread_new_multicast(const char *group, const char *port,
Chris@4 222 lo_err_handler err_h);
Chris@4 223
Chris@4 224 /**
Chris@4 225 * \brief Create a new server thread to handle incoming OSC
Chris@4 226 * messages, specifying protocol.
Chris@4 227 *
Chris@4 228 * Server threads take care of the message reception and dispatch by
Chris@4 229 * transparently creating a system thread to handle incoming messages.
Chris@4 230 * Use this if you do not want to handle the threading yourself.
Chris@4 231 *
Chris@4 232 * \param port If NULL is passed then an unused port will be chosen by the
Chris@4 233 * system, its number may be retrieved with lo_server_thread_get_port()
Chris@4 234 * so it can be passed to clients. Otherwise a decimal port number, service
Chris@4 235 * name or UNIX domain socket path may be passed.
Chris@4 236 * \param proto The protocol to use, should be one of LO_UDP, LO_TCP or LO_UNIX.
Chris@4 237 * \param err_h A function that will be called in the event of an error being
Chris@4 238 * raised. The function prototype is defined in lo_types.h
Chris@4 239 */
Chris@4 240 lo_server_thread lo_server_thread_new_with_proto(const char *port, int proto,
Chris@4 241 lo_err_handler err_h);
Chris@4 242
Chris@4 243 /**
Chris@4 244 * \brief Free memory taken by a server thread
Chris@4 245 *
Chris@4 246 * Frees the memory, and, if currently running will stop the associated thread.
Chris@4 247 */
Chris@4 248 void lo_server_thread_free(lo_server_thread st);
Chris@4 249
Chris@4 250 /**
Chris@4 251 * \brief Add an OSC method to the specifed server thread.
Chris@4 252 *
Chris@4 253 * \param st The server thread the method is to be added to.
Chris@4 254 * \param path The OSC path to register the method to. If NULL is passed the
Chris@4 255 * method will match all paths.
Chris@4 256 * \param typespec The typespec the method accepts. Incoming messages with
Chris@4 257 * similar typespecs (e.g. ones with numerical types in the same position) will
Chris@4 258 * be coerced to the typespec given here.
Chris@4 259 * \param h The method handler callback function that will be called it a
Chris@4 260 * matching message is received
Chris@4 261 * \param user_data A value that will be passed to the callback function, h,
Chris@4 262 * when its invoked matching from this method.
Chris@4 263 */
Chris@4 264 lo_method lo_server_thread_add_method(lo_server_thread st, const char *path,
Chris@4 265 const char *typespec, lo_method_handler h,
Chris@4 266 void *user_data);
Chris@4 267 /**
Chris@4 268 * \brief Delete an OSC method from the specifed server thread.
Chris@4 269 *
Chris@4 270 * \param st The server thread the method is to be removed from.
Chris@4 271 * \param path The OSC path of the method to delete. If NULL is passed the
Chris@4 272 * method will match the generic handler.
Chris@4 273 * \param typespec The typespec the method accepts.
Chris@4 274 */
Chris@4 275 void lo_server_thread_del_method(lo_server_thread st, const char *path,
Chris@4 276 const char *typespec);
Chris@4 277
Chris@4 278 /**
Chris@4 279 * \brief Start the server thread
Chris@4 280 *
Chris@4 281 * \param st the server thread to start.
Chris@4 282 * \return Less than 0 on failure, 0 on success.
Chris@4 283 */
Chris@4 284 int lo_server_thread_start(lo_server_thread st);
Chris@4 285
Chris@4 286 /**
Chris@4 287 * \brief Stop the server thread
Chris@4 288 *
Chris@4 289 * \param st the server thread to start.
Chris@4 290 * \return Less than 0 on failure, 0 on success.
Chris@4 291 */
Chris@4 292 int lo_server_thread_stop(lo_server_thread st);
Chris@4 293
Chris@4 294 /**
Chris@4 295 * \brief Return the port number that the server thread has bound to.
Chris@4 296 */
Chris@4 297 int lo_server_thread_get_port(lo_server_thread st);
Chris@4 298
Chris@4 299 /**
Chris@4 300 * \brief Return a URL describing the address of the server thread.
Chris@4 301 *
Chris@4 302 * Return value must be free()'d to reclaim memory.
Chris@4 303 */
Chris@4 304 char *lo_server_thread_get_url(lo_server_thread st);
Chris@4 305
Chris@4 306 /**
Chris@4 307 * \brief Return the lo_server for a lo_server_thread
Chris@4 308 *
Chris@4 309 * This function is useful for passing a thread's lo_server
Chris@4 310 * to lo_send_from().
Chris@4 311 */
Chris@4 312 lo_server lo_server_thread_get_server(lo_server_thread st);
Chris@4 313
Chris@4 314 /** \brief Return true if there are scheduled events (eg. from bundles) waiting
Chris@4 315 * to be dispatched by the thread */
Chris@4 316 int lo_server_thread_events_pending(lo_server_thread st);
Chris@4 317
Chris@4 318 /**
Chris@4 319 * \brief Create a new OSC blob type.
Chris@4 320 *
Chris@4 321 * \param size The amount of space to allocate in the blob structure.
Chris@4 322 * \param data The data that will be used to initialise the blob, should be
Chris@4 323 * size bytes long.
Chris@4 324 */
Chris@4 325 lo_blob lo_blob_new(int32_t size, const void *data);
Chris@4 326
Chris@4 327 /**
Chris@4 328 * \brief Free the memory taken by a blob
Chris@4 329 */
Chris@4 330 void lo_blob_free(lo_blob b);
Chris@4 331
Chris@4 332 /**
Chris@4 333 * \brief Return the amount of valid data in a lo_blob object.
Chris@4 334 *
Chris@4 335 * If you want to know the storage size, use lo_arg_size().
Chris@4 336 */
Chris@4 337 uint32_t lo_blob_datasize(lo_blob b);
Chris@4 338
Chris@4 339 /**
Chris@4 340 * \brief Return a pointer to the start of the blob data to allow contents to
Chris@4 341 * be changed.
Chris@4 342 */
Chris@4 343 void *lo_blob_dataptr(lo_blob b);
Chris@4 344
Chris@4 345 /** @} */
Chris@4 346
Chris@4 347 #include "lo/lo_macros.h"
Chris@4 348
Chris@4 349 #ifdef __cplusplus
Chris@4 350 }
Chris@4 351 #endif
Chris@4 352
Chris@4 353 #endif