/[libhid]/trunk/src/hid_presentation.c
ViewVC logotype

Contents of /trunk/src/hid_presentation.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 364 - (show annotations) (download)
Tue Dec 23 03:52:50 2008 UTC (4 years, 4 months ago) by clepple-guest
File MIME type: text/x-csrc
File size: 5620 byte(s)
Rename include/assert.h to hid_assert.h (Debian bug #476525).

Also other misc changes.
1 #define HID_INTERNAL
2
3 #include <hid.h>
4 #include <hid_helpers.h>
5
6 #include <debug.h>
7 #include <hid_assert.h>
8
9 hid_return hid_write_identification(FILE* const out,
10 HIDInterface const* const hidif)
11 {
12 if (!hid_is_opened(hidif)) {
13 ERROR("cannot write identification of unopened HIDinterface.");
14 return HID_RET_DEVICE_NOT_OPENED;
15 }
16
17 if (!out) {
18 ERROR("cannot write HIDinterface identification of USB device %s "
19 "to NULL output stream.", hidif->id);
20 return HID_RET_INVALID_PARAMETER;
21 }
22
23 int len;
24 unsigned short const BUFLEN = 256;
25 char buffer[BUFLEN];
26
27 fprintf(out, "device identification of HIDInterface %s:\n", hidif->id);
28 fprintf(out, " dev_handle: 0x%08lx\n", (unsigned long)hidif->dev_handle);
29 fprintf(out, " device: 0x%08lx\n", (unsigned long)hidif->device);
30 fprintf(out, " location: %s/%s\n",
31 hidif->device->bus->dirname, hidif->device->filename);
32
33 if (hidif->device->descriptor.iManufacturer) {
34 len = usb_get_string_simple(hidif->dev_handle,
35 hidif->device->descriptor.iManufacturer, buffer, BUFLEN);
36
37 if (len > 0)
38 fprintf(out, " manufacturer: %s\n", buffer);
39 else
40 fprintf(out, "(unable to fetch manufacturer string)\n");
41 }
42
43 if (hidif->device->descriptor.iProduct) {
44 len = usb_get_string_simple(hidif->dev_handle,
45 hidif->device->descriptor.iProduct, buffer, BUFLEN);
46
47 if (len > 0)
48 fprintf(out, " product: %s\n", buffer);
49 else
50 fprintf(out, "(unable to fetch product string)\n");
51 }
52
53 if (hidif->device->descriptor.iSerialNumber) {
54 len = usb_get_string_simple(hidif->dev_handle,
55 hidif->device->descriptor.iSerialNumber, buffer, BUFLEN);
56
57 if (len > 0)
58 fprintf(out, " serial number: %s\n", buffer);
59 else
60 fprintf(out, "(unable to fetch product string)\n");
61 }
62
63 return HID_RET_SUCCESS;
64 }
65
66 hid_return hid_dump_tree(FILE* const out, HIDInterface* const hidif)
67 {
68 if (!hid_is_opened(hidif)) {
69 ERROR("cannot dump tree of unopened HIDinterface.");
70 return HID_RET_DEVICE_NOT_OPENED;
71 }
72
73 if (!out) {
74 ERROR("cannot dump HIDinterface tree of USB device %s to NULL output stream.",
75 hidif->id);
76 return HID_RET_INVALID_PARAMETER;
77 }
78
79 hid_reset_parser(hidif);
80
81 TRACE("iterating the parse tree for USB device %s...", hidif->id);
82
83 unsigned int i = 0;
84
85 fprintf(out, "parse tree of HIDInterface %s:\n", hidif->id);
86
87 while (HIDParse(hidif->hid_parser, hidif->hid_data)) {
88 fprintf(out, " path: ");
89 for (i = 0; i < hidif->hid_data->Path.Size; ++i) {
90 fprintf(out, "0x%08x", (hidif->hid_data->Path.Node[i].UPage << 16)
91 | hidif->hid_data->Path.Node[i].Usage);
92 if ((signed)i < hidif->hid_data->Path.Size - 1) fputc('.', out);
93 }
94 fprintf(out, "; type: 0x%02x\n", hidif->hid_data->Type);
95 }
96
97 hid_reset_parser(hidif);
98
99 return HID_RET_SUCCESS;
100 }
101
102 const char *hid_strerror(hid_return ret)
103 {
104 switch(ret) {
105 case HID_RET_SUCCESS:
106 return "libhid: success";
107 case HID_RET_INVALID_PARAMETER:
108 return "libhid: invalid parameter";
109 case HID_RET_NOT_INITIALISED:
110 return "libhid: not initialized; call hid_init() first";
111 case HID_RET_ALREADY_INITIALISED:
112 return "libhid: hid_init() already called";
113 case HID_RET_FAIL_FIND_BUSSES:
114 return "libhid: failed to find any USB busses";
115 case HID_RET_FAIL_FIND_DEVICES:
116 return "libhid: failed to find any USB devices";
117 case HID_RET_FAIL_OPEN_DEVICE:
118 return "libhid: failed to open device";
119 case HID_RET_DEVICE_NOT_FOUND:
120 return "libhid: device not found";
121 case HID_RET_DEVICE_NOT_OPENED:
122 return "libhid: device not yet opened";
123 case HID_RET_DEVICE_ALREADY_OPENED:
124 return "libhid: device already opened";
125 case HID_RET_FAIL_CLOSE_DEVICE:
126 return "libhid: could not close device";
127 case HID_RET_FAIL_CLAIM_IFACE:
128 return "libhid: failed to claim interface; is another driver using it?";
129 case HID_RET_FAIL_DETACH_DRIVER:
130 return "libhid: failed to detach kernel driver";
131 case HID_RET_NOT_HID_DEVICE:
132 return "libhid: not recognized as a HID device";
133 case HID_RET_HID_DESC_SHORT:
134 return "libhid: HID interface descriptor too short";
135 case HID_RET_REPORT_DESC_SHORT:
136 return "libhid: HID report descriptor too short";
137 case HID_RET_REPORT_DESC_LONG:
138 return "libhid: HID report descriptor too long";
139 case HID_RET_FAIL_ALLOC:
140 return "libhid: failed to allocate memory";
141 case HID_RET_OUT_OF_SPACE:
142 return "libhid: no space left in buffer";
143 case HID_RET_FAIL_SET_REPORT:
144 return "libhid: failed to set report";
145 case HID_RET_FAIL_GET_REPORT:
146 return "libhid: failed to get report";
147 case HID_RET_FAIL_INT_READ:
148 return "libhid: interrupt read failed";
149 case HID_RET_NOT_FOUND:
150 return "libhid: not found";
151 case HID_RET_TIMEOUT:
152 return "libhid: timeout";
153 }
154 return "libhid: unknown error";
155 }
156
157 /* COPYRIGHT --
158 *
159 * This file is part of libhid, a user-space HID access library.
160 * libhid is (c) 2003-2005
161 * Martin F. Krafft <libhid@pobox.madduck.net>
162 * Charles Lepple <clepple@ghz.cc>
163 * Arnaud Quette <arnaud.quette@free.fr> && <arnaud.quette@mgeups.com>
164 * and distributed under the terms of the GNU General Public License.
165 * See the file ./COPYING in the source distribution for more information.
166 *
167 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
168 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
169 * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
170 */

Properties

Name Value
cvs2svn:cvs-rev 1.7
svn:eol-style native
svn:keywords author date id revision
svn:mime-type text/x-csrc

  ViewVC Help
Powered by ViewVC 1.1.5