Debian Codegraph @

xpp/xtalk/xtalk-xusb.c

raw
1 /*
2 * Written by Oron Peled <[email protected]>
3 * Copyright (C) 2012, Xorcom
4 *
5 * All rights reserved.
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
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22
23 /*
24 * Convenience wrappers for xtalk_base over xusb
25 */
26 #include <assert.h>
27 #include <xtalk/debug.h>
28 #include <xtalk/xusb.h>
29 #include <autoconfig.h>
30 #include "xtalk_base.h"
31
32 static inline int close_func(void *priv)
33 {
34 struct xusb_iface *iface = (struct xusb_iface *)priv;
35 xusb_release(iface);
36 return 0;
37 }
38
39 static inline int send_func(void *priv, const char *data, size_t len, int timeout)
40 {
41 return xusb_send((struct xusb_iface *)priv, data, len, timeout);
42 }
43
44 static inline int recv_func(void *priv, char *data, size_t maxlen, int timeout)
45 {
46 return xusb_recv((struct xusb_iface *)priv, data, maxlen, timeout);
47 }
48
49
50 static struct xtalk_ops xtalk_ops = {
51 .send_func = send_func,
52 .recv_func = recv_func,
53 .close_func = close_func,
54 };
55
56 struct xtalk_base *xtalk_base_new_on_xusb(struct xusb_iface *xusb_iface)
57 {
58 struct xtalk_base *xtalk_base;
59 int packet_size;
60
61 assert(xusb_iface);
62 packet_size = xusb_packet_size(xusb_deviceof(xusb_iface));
63
64 xtalk_base = xtalk_base_new(&xtalk_ops, packet_size, xusb_iface);
65 if (!xtalk_base) {
66 ERR("Failed creating the xtalk device abstraction\n");
67 return NULL;
68 }
69 return xtalk_base;
70 }