Debian Codegraph @

src/internal.h

raw symbols SCIP
1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id$ */
3
4 /* libticables2 - link cable library, a part of the TiLP project
5 * Copyright (C) 2015 Benjamin Moody
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef __TICABLES_INTERNAL__
23 #define __TICABLES_INTERNAL__
24
25 #define VALIDATE_NONNULL(ptr) \
26 do \
27 { \
28 if (ptr == NULL) \
29 { \
30 ticables_critical("%s: " #ptr " is NULL", __FUNCTION__); \
31 return ERR_ILLEGAL_ARG; \
32 } \
33 } while(0);
34 #define VALIDATE_HANDLE(handle) \
35 do \
36 { \
37 if (!ticables_validate_handle(handle)) \
38 { \
39 ticables_critical("%s: " #handle " is invalid", __FUNCTION__); \
40 return ERR_ILLEGAL_ARG; \
41 } \
42 } while(0);
43 #define VALIDATE_CABLEFNCTS(cable) \
44 do \
45 { \
46 if (!ticables_validate_cablefncts(cable)) \
47 { \
48 ticables_critical("%s: " # cable " is invalid", __FUNCTION__); \
49 return ERR_ILLEGAL_ARG; \
50 } \
51 } while(0);
52
53 #define RETURN_IF_HANDLE_OPEN(handle) \
54 do \
55 { \
56 if (handle->open) \
57 { \
58 return ERR_BUSY; \
59 } \
60 } while(0);
61 #define RETURN_IF_HANDLE_NOT_OPEN(handle) \
62 do \
63 { \
64 if (!handle->open) \
65 { \
66 return ERR_NOT_OPEN; \
67 } \
68 } while(0);
69 #define RETURN_IF_HANDLE_BUSY(handle) \
70 do \
71 { \
72 if (handle->busy) \
73 { \
74 return ERR_BUSY; \
75 } \
76 } while(0);
77
78 static inline int ticables_validate_handle(CableHandle * handle)
79 {
80 return handle != NULL;
81 }
82
83 static inline int ticables_validate_cablefncts(const CableFncts * cable)
84 {
85 return cable != NULL;
86 }
87
88 static inline void ticables_event_fill_header(CableHandle * handle, CableEventData * event, CableEventType type, int retval, CableFnctsIdx operation)
89 {
90 event->version = 1;
91 event->type = type;
92 event->retval = retval;
93 event->open = handle->open;
94 event->operation = operation;
95 }
96
97 static inline void ticables_event_fill_data(CableEventData * event, uint8_t * data, uint32_t len)
98 {
99 event->data.data.data = data;
100 event->data.data.len = len;
101 }
102
103 static inline int ticables_event_send_simple_generic(CableHandle * handle, CableEventType type, int retval, CableFnctsIdx operation)
104 {
105 int ret = retval;
106
107 if (handle->event_hook)
108 {
109 CableEventData event;
110 ticables_event_fill_header(handle, &event, type, retval, operation);
111 memset((void *)&event.data, 0, sizeof(event.data));
112 handle->event_count++;
113 ret = handle->event_hook(handle, handle->event_count, &event, handle->user_pointer);
114 }
115
116 return ret;
117 }
118
119 static inline int ticables_event_send_simple(CableHandle * handle, CableEventType type, int retval)
120 {
121 return ticables_event_send_simple_generic(handle, type, retval, CABLE_FNCT_LAST);
122 }
123
124 static inline int ticables_event_send(CableHandle * handle, CableEventData * event)
125 {
126 int ret = event->retval;
127
128 if (handle->event_hook)
129 {
130 handle->event_count++;
131 ret = handle->event_hook(handle, handle->event_count, event, handle->user_pointer);
132 }
133
134 return ret;
135 }
136
137 typedef struct {
138 uint16_t vid;
139 uint16_t pid;
140 uint16_t version;
141 char product_str[65];
142 void *dev;
143 } USBCableInfo;
144
145 int usb_probe_device_info(const USBCableInfo **list, int *count);
146 void translate_usb_device_info(CableDeviceInfo *info, const USBCableInfo *usbinfo);
147
148 int dbus_decomp(const char *filename, int resync);
149 int dusb_decomp(const char *filename);
150 int nsp_decomp(const char *filename);
151
152 // link_nul.c
153 int noop_prepare(CableHandle *h);
154 int noop_probe(CableHandle *h);
155 int noop_open(CableHandle *h);
156 int noop_close(CableHandle *h);
157 int noop_reset(CableHandle *h);
158 int noop_put(CableHandle *h, uint8_t *data, uint32_t len);
159 int noop_get(CableHandle *h, uint8_t *data, uint32_t len);
160 int noop_check(CableHandle *h, int *status);
161 int noop_set_red_wire(CableHandle *h, int b);
162 int noop_set_white_wire(CableHandle *h, int b);
163 int noop_get_red_wire(CableHandle *h);
164 int noop_get_white_wire(CableHandle *h);
165 int noop_set_device(CableHandle *h, const char * device);
166
167 #endif