| 1 | /* |
| 2 | * Copyright (C) 2014 Steve Harris et al. (see AUTHORS) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public License |
| 6 | * as published by the Free Software Foundation; either version 2.1 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Lesser General Public License for more details. |
| 13 | * |
| 14 | * $Id$ |
| 15 | */ |
| 16 | |
| 17 | #ifndef LO_H |
| 18 | #define LO_H |
| 19 | |
| 20 | #ifdef __cplusplus |
| 21 | extern "C" { |
| 22 | #endif |
| 23 | |
| 24 | /** |
| 25 | * \file lo.h The liblo main headerfile and high-level API functions. |
| 26 | */ |
| 27 | |
| 28 | #include "lo_endian.h" |
| 29 | #include "lo_types.h" |
| 30 | #include "lo_osc_types.h" |
| 31 | #include "lo_errors.h" |
| 32 | #include "lo_lowlevel.h" |
| 33 | |
| 34 | /** |
| 35 | * \defgroup liblo High-level OSC API |
| 36 | * |
| 37 | * Defines the high-level API functions necessary to implement OSC support. |
| 38 | * Should be adequate for most applications, but if you require lower level |
| 39 | * control you can use the functions defined in lo_lowlevel.h |
| 40 | * @{ |
| 41 | */ |
| 42 | |
| 43 | /** |
| 44 | * \brief Declare an OSC destination, given IP address and port number. |
| 45 | * Same as lo_address_new_with_proto(), but using UDP. |
| 46 | * |
| 47 | * \param host An IP address or number, or NULL for the local machine. |
| 48 | * \param port a decimal port number or service name. |
| 49 | * |
| 50 | * The lo_address object may be used as the target of OSC messages. |
| 51 | * |
| 52 | * Note: if you wish to receive replies from the target of this |
| 53 | * address, you must either supply a lo_server by using lo_send_from() |
| 54 | * or lo_send_message_from() to send your message, otherwise the last |
| 55 | * lo_server or lo_server_thread that was created will be used as the |
| 56 | * reply socket. The remote receiver may get the reply address by |
| 57 | * calling lo_message_get_source() in the message handler. See |
| 58 | * example_tcp_echo_server.c for an example of how to establish |
| 59 | * bidirectional communication. |
| 60 | */ |
| 61 | lo_address lo_address_new(const char *host, const char *port); |
| 62 | |
| 63 | /** |
| 64 | * \brief Declare an OSC destination, given IP address and port number, |
| 65 | * specifying protocol. |
| 66 | * |
| 67 | * \param proto The protocol to use, must be one of LO_UDP, LO_TCP or LO_UNIX. |
| 68 | * \param host An IP address or number, or NULL for the local machine. |
| 69 | * \param port a decimal port number or service name. |
| 70 | * |
| 71 | * The lo_address object may be used as the target of OSC messages. |
| 72 | * |
| 73 | * Note: if you wish to receive replies from the target of this |
| 74 | * address, you must first create a lo_server_thread or lo_server |
| 75 | * object which will receive the replies. The last lo_server(_thread) |
| 76 | * object created will be the receiver. |
| 77 | */ |
| 78 | lo_address lo_address_new_with_proto(int proto, const char *host, const char *port); |
| 79 | |
| 80 | /** |
| 81 | * \brief Create a lo_address object from an OSC URL. |
| 82 | * |
| 83 | * example: \c "osc.udp://localhost:4444/my/path/" |
| 84 | */ |
| 85 | lo_address lo_address_new_from_url(const char *url); |
| 86 | |
| 87 | /** |
| 88 | * \brief Free the memory used by the lo_address object |
| 89 | */ |
| 90 | void lo_address_free(lo_address t); |
| 91 | |
| 92 | /** |
| 93 | * \brief Set the Time-to-Live value for a given target address. |
| 94 | * |
| 95 | * This is required for sending multicast UDP messages. A value of 1 |
| 96 | * (the usual case) keeps the message within the subnet, while 255 |
| 97 | * means a global, unrestricted scope. |
| 98 | * |
| 99 | * \param t An OSC address. |
| 100 | * \param ttl An integer specifying the scope of a multicast UDP message. |
| 101 | */ |
| 102 | void lo_address_set_ttl(lo_address t, int ttl); |
| 103 | |
| 104 | /** |
| 105 | * \brief Get the Time-to-Live value for a given target address. |
| 106 | * |
| 107 | * \param t An OSC address. |
| 108 | * \return An integer specifying the scope of a multicast UDP message. |
| 109 | */ |
| 110 | int lo_address_get_ttl(lo_address t); |
| 111 | |
| 112 | /** |
| 113 | * \brief Send a OSC formatted message to the address specified. |
| 114 | * |
| 115 | * \param targ The target OSC address |
| 116 | * \param path The OSC path the message will be delivered to |
| 117 | * \param type The types of the data items in the message, types are defined in |
| 118 | * lo_osc_types.h |
| 119 | * \param ... The data values to be transmitted. The types of the arguments |
| 120 | * passed here must agree with the types specified in the type parameter. |
| 121 | * |
| 122 | * example: |
| 123 | * \code |
| 124 | * lo_send(t, "/foo/bar", "ff", 0.1f, 23.0f); |
| 125 | * \endcode |
| 126 | * |
| 127 | * \return -1 on failure. |
| 128 | */ |
| 129 | int lo_send(lo_address targ, const char *path, const char *type, ...); |
| 130 | |
| 131 | /** |
| 132 | * \brief Send a OSC formatted message to the address specified, |
| 133 | * from the same socket as the specified server. |
| 134 | * |
| 135 | * If a liblo server is receiving this message, it can reply by |
| 136 | * getting the server's address by calling lo_message_get_source() in |
| 137 | * the message handler, passing the \ref lo_message provided as an |
| 138 | * argument to the \ref lo_method_handler. By this mechanism |
| 139 | * bidirectional communication can be established by setting up a \ref |
| 140 | * lo_server or \ref lo_server_thread on both sides. |
| 141 | * |
| 142 | * \param targ The target OSC address |
| 143 | * \param from The server to send message from (can be NULL to use new socket) |
| 144 | * \param ts The OSC timetag timestamp at which the message will be processed |
| 145 | * (can be LO_TT_IMMEDIATE if you don't want to attach a timetag) |
| 146 | * \param path The OSC path the message will be delivered to |
| 147 | * \param type The types of the data items in the message, types are defined in |
| 148 | * lo_osc_types.h |
| 149 | * \param ... The data values to be transmitted. The types of the arguments |
| 150 | * passed here must agree with the types specified in the type parameter. |
| 151 | * |
| 152 | * example: |
| 153 | * \code |
| 154 | * serv = lo_server_new(NULL, err); |
| 155 | * lo_server_add_method(serv, "/reply", "ss", reply_handler, NULL); |
| 156 | * lo_send_from(t, serv, LO_TT_IMMEDIATE, "/foo/bar", "ff", 0.1f, 23.0f); |
| 157 | * \endcode |
| 158 | * |
| 159 | * See \ref example_tcp_echo_server.c for an example of how to use |
| 160 | * lo_message_get_source() as described. |
| 161 | * |
| 162 | * \return on success, the number of bytes sent, or -1 on failure. |
| 163 | */ |
| 164 | int lo_send_from(lo_address targ, lo_server from, lo_timetag ts, |
| 165 | const char *path, const char *type, ...); |
| 166 | |
| 167 | /** |
| 168 | * \brief Send a OSC formatted message to the address specified, scheduled to |
| 169 | * be dispatch at some time in the future. |
| 170 | * |
| 171 | * \param targ The target OSC address |
| 172 | * \param ts The OSC timetag timestamp at which the message will be processed |
| 173 | * \param path The OSC path the message will be delivered to |
| 174 | * \param type The types of the data items in the message, types are defined in |
| 175 | * lo_osc_types.h |
| 176 | * \param ... The data values to be transmitted. The types of the arguments |
| 177 | * passed here must agree with the types specified in the type parameter. |
| 178 | * |
| 179 | * example: |
| 180 | * \code |
| 181 | * lo_timetag now;<br> |
| 182 | * lo_timetag_now(&now);<br> |
| 183 | * lo_send_timestamped(t, now, "/foo/bar", "ff", 0.1f, 23.0f); |
| 184 | * \endcode |
| 185 | * |
| 186 | * \return on success, the number of bytes sent, or -1 on failure. |
| 187 | */ |
| 188 | int lo_send_timestamped(lo_address targ, lo_timetag ts, const char *path, |
| 189 | const char *type, ...); |
| 190 | |
| 191 | /** |
| 192 | * \brief Return the error number from the last failed lo_send() or |
| 193 | * lo_address_new() call |
| 194 | */ |
| 195 | int lo_address_errno(lo_address a); |
| 196 | |
| 197 | /** |
| 198 | * \brief Return the error string from the last failed lo_send() or |
| 199 | * lo_address_new() call |
| 200 | */ |
| 201 | const char *lo_address_errstr(lo_address a); |
| 202 | |
| 203 | /** |
| 204 | * \brief Create a new OSC blob type. |
| 205 | * |
| 206 | * \param size The amount of space to allocate in the blob structure. |
| 207 | * \param data The data that will be used to initialise the blob, should be |
| 208 | * size bytes long. |
| 209 | */ |
| 210 | lo_blob lo_blob_new(int32_t size, const void *data); |
| 211 | |
| 212 | /** |
| 213 | * \brief Free the memory taken by a blob |
| 214 | */ |
| 215 | void lo_blob_free(lo_blob b); |
| 216 | |
| 217 | /** |
| 218 | * \brief Return the amount of valid data in a lo_blob object. |
| 219 | * |
| 220 | * If you want to know the storage size, use lo_arg_size(). |
| 221 | */ |
| 222 | uint32_t lo_blob_datasize(lo_blob b); |
| 223 | |
| 224 | /** |
| 225 | * \brief Return a pointer to the start of the blob data to allow contents to |
| 226 | * be changed. |
| 227 | * |
| 228 | * If the size is 0, this will return a NULL-pointer. |
| 229 | */ |
| 230 | void *lo_blob_dataptr(lo_blob b); |
| 231 | |
| 232 | /** |
| 233 | * \brief Get information on the version of liblo current in use. |
| 234 | * |
| 235 | * All parameters are optional and can be given the value of 0 if that |
| 236 | * information is not desired. For example, to get just the version |
| 237 | * as a string, call lo_version(str, size, 0, 0, 0, 0, 0, 0, 0); |
| 238 | * |
| 239 | * The "lt" fields, called the ABI version, corresponds to libtool's |
| 240 | * versioning system for binary interface compatibility, and is not |
| 241 | * related to the library version number. This information is usually |
| 242 | * encoded in the filename of the shared library. |
| 243 | * |
| 244 | * Typically the string returned in 'verstr' should correspond with |
| 245 | * $major.$minor$extra, e.g., "0.28rc". If no 'extra' information is |
| 246 | * present, e.g., "0.28", extra will given the null string. |
| 247 | * |
| 248 | * \param verstr A buffer to receive a string describing the |
| 249 | * library version. |
| 250 | * \param verstr_size Size of the buffer pointed to by string. |
| 251 | * \param major Location to receive the library major version. |
| 252 | * \param minor Location to receive the library minor version. |
| 253 | * \param extra Location to receive the library version extra string. |
| 254 | * \param extra_size Size of the buffer pointed to by extra. |
| 255 | * \param lt_major Location to receive the ABI major version. |
| 256 | * \param lt_minor Location to receive the ABI minor version. |
| 257 | * \param lt_bug Location to receive the ABI 'bugfix' version. |
| 258 | */ |
| 259 | void lo_version(char *verstr, int verstr_size, |
| 260 | int *major, int *minor, char *extra, int extra_size, |
| 261 | int *lt_major, int *lt_minor, int *lt_bug); |
| 262 | |
| 263 | /** @} */ |
| 264 | |
| 265 | #include "lo_macros.h" |
| 266 | |
| 267 | #ifdef __cplusplus |
| 268 | } |
| 269 | #endif |
| 270 | |
| 271 | #endif |