2 * This file is part of the libjaylink project.
4 * Copyright (C) 2014-2015 Marc Schink <jaylink-dev@marcschink.de>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef LIBJAYLINK_LIBJAYLINK_INTERNAL_H
21 #define LIBJAYLINK_LIBJAYLINK_INTERNAL_H
25 #include <sys/types.h>
28 #include "libjaylink.h"
33 * Internal libjaylink header file.
36 /** Macro to mark private libjaylink symbol. */
37 #if defined(_WIN32) || defined(__MSYS__) || defined(__CYGWIN__)
40 #define JAYLINK_PRIV __attribute__ ((visibility ("hidden")))
43 /** Calculate the minimum of two numeric values. */
44 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
46 struct jaylink_context
{
47 /** libusb context. */
48 struct libusb_context
*usb_ctx
;
50 * List of allocated device instances.
52 * Used to prevent multiple device instances for the same device.
55 /** Current log level. */
57 /** Log callback function. */
58 jaylink_log_callback log_callback
;
59 /** User data to be passed to the log callback function. */
60 void *log_callback_data
;
62 char log_domain
[JAYLINK_LOG_DOMAIN_MAX_LENGTH
+ 1];
65 struct jaylink_device
{
66 /** libjaylink context. */
67 struct jaylink_context
*ctx
;
68 /** Number of references held on this device instance. */
70 /** libusb device instance. */
71 struct libusb_device
*usb_dev
;
72 /** USB address of the device. */
75 * Serial number of the device.
77 * This number is for enumeration purpose only and can differ from the
78 * real serial number of the device.
80 uint32_t serial_number
;
81 /** Indicates whether the serial number is valid. */
82 int valid_serial_number
;
85 struct jaylink_device_handle
{
86 /** Device instance. */
87 struct jaylink_device
*dev
;
88 /** libusb device handle. */
89 struct libusb_device_handle
*usb_devh
;
90 /** USB interface number of the device. */
91 uint8_t interface_number
;
92 /** USB interface IN endpoint of the device. */
94 /** USB interface OUT endpoint of the device. */
97 * Buffer for write and read operations.
99 * Note that write and read operations are always processed
100 * consecutively and therefore the same buffer can be used for both.
105 /** Number of bytes left for the read operation. */
107 /** Number of bytes available in the buffer to be read. */
108 size_t bytes_available
;
109 /** Current read position in the buffer. */
112 * Number of bytes left to be written before the write operation will
117 * Current write position in the buffer.
119 * This is equivalent to the number of bytes in the buffer and used for
120 * write operations only.
130 typedef int (*list_compare_callback
)(const void *a
, const void *b
);
132 /*--- buffer.c --------------------------------------------------------------*/
134 JAYLINK_PRIV
void buffer_set_u16(uint8_t *buffer
, uint16_t value
,
136 JAYLINK_PRIV
uint16_t buffer_get_u16(const uint8_t *buffer
, size_t offset
);
137 JAYLINK_PRIV
void buffer_set_u32(uint8_t *buffer
, uint32_t value
,
139 JAYLINK_PRIV
uint32_t buffer_get_u32(const uint8_t *buffer
, size_t offset
);
141 /*--- device.c --------------------------------------------------------------*/
143 JAYLINK_PRIV
struct jaylink_device
*device_allocate(
144 struct jaylink_context
*ctx
);
146 /*--- discovery.c -----------------------------------------------------------*/
148 JAYLINK_PRIV ssize_t
discovery_get_device_list(struct jaylink_context
*ctx
,
149 struct jaylink_device
***list
);
151 /*--- list.c ----------------------------------------------------------------*/
153 JAYLINK_PRIV
struct list
*list_prepend(struct list
*list
, void *data
);
154 JAYLINK_PRIV
struct list
*list_remove(struct list
*list
, const void *data
);
155 JAYLINK_PRIV
struct list
*list_find_custom(struct list
*list
,
156 list_compare_callback cb
, const void *cb_data
);
157 JAYLINK_PRIV
void list_free(struct list
*list
);
159 /*--- log.c -----------------------------------------------------------------*/
161 JAYLINK_PRIV
int log_vprintf(const struct jaylink_context
*ctx
, int level
,
162 const char *format
, va_list args
, void *user_data
);
163 JAYLINK_PRIV
void log_err(const struct jaylink_context
*ctx
,
164 const char *format
, ...);
165 JAYLINK_PRIV
void log_warn(const struct jaylink_context
*ctx
,
166 const char *format
, ...);
167 JAYLINK_PRIV
void log_info(const struct jaylink_context
*ctx
,
168 const char *format
, ...);
169 JAYLINK_PRIV
void log_dbg(const struct jaylink_context
*ctx
,
170 const char *format
, ...);
172 /*--- transport.c -----------------------------------------------------------*/
174 JAYLINK_PRIV
int transport_open(struct jaylink_device_handle
*devh
);
175 JAYLINK_PRIV
int transport_close(struct jaylink_device_handle
*devh
);
176 JAYLINK_PRIV
int transport_start_write_read(struct jaylink_device_handle
*devh
,
177 size_t write_length
, size_t read_length
, int has_command
);
178 JAYLINK_PRIV
int transport_start_write(struct jaylink_device_handle
*devh
,
179 size_t length
, int has_command
);
180 JAYLINK_PRIV
int transport_start_read(struct jaylink_device_handle
*devh
,
182 JAYLINK_PRIV
int transport_write(struct jaylink_device_handle
*devh
,
183 const uint8_t *buffer
, size_t length
);
184 JAYLINK_PRIV
int transport_read(struct jaylink_device_handle
*devh
,
185 uint8_t *buffer
, size_t length
);
187 #endif /* LIBJAYLINK_LIBJAYLINK_INTERNAL_H */