1// -*- C++;indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
2/*
3 * hub_strings.cpp
4 *
5 *  Test suite program for C++ bindings
6 */
7
8#include <iostream>
9#include <iomanip>
10#include <usbpp.h>
11#include <errno.h>
12
13using namespace std;
14
15int main(void)
16{
17	USB::Busses buslist;
18	USB::Device *device;
19	list<USB::Device *> hubList;
20	list<USB::Device *>::const_iterator iter;
21	string manufString, prodString, serialString1, serialString2;
22	int retval;
23
24	cout << "Class/SubClass/Protocol" << endl;
25
26	hubList = buslist.match(0x9);
27
28	for (iter = hubList.begin(); iter != hubList.end(); iter++) {
29		device = *iter;
30
31		cout << hex << setw(2) << setfill('0')
32			 << int(device->devClass()) << "      "
33			 << hex << setw(2) << setfill('0')
34			 << int(device->devSubClass()) << "      "
35			 << hex << setw(2) << setfill('0')
36			 << int(device->devProtocol()) << endl;
37		retval = device->string(manufString, 3);
38		if ( 0 < retval ) {
39			cout << "3: " << manufString << endl;
40		} else {
41			if (-EPIPE != retval) { // we ignore EPIPE, because some hubs don't have strings
42				cout << "fetching string 3 failed: " << usb_strerror() << endl;
43				return EXIT_FAILURE;
44			}
45		}
46		retval = device->string(prodString, 2);
47		if ( 0 < retval ) {
48			cout << "2: " << prodString << endl;
49		} else {
50			if (-EPIPE != retval) { // we ignore EPIPE, because some hubs don't have strings
51				cout << "fetching string 2 failed: " << usb_strerror() << endl;
52				return EXIT_FAILURE;
53			}
54		}
55
56		retval = device->string(serialString1, 1);
57		if ( 0 < retval ) {
58			cout << "1a: " << serialString1 << endl;
59		} else {
60			if (-EPIPE != retval) { // we ignore EPIPE, because some hubs don't have strings
61				cout << "fetching string 1a failed: " << usb_strerror() << endl;
62				return EXIT_FAILURE;
63			}
64		}
65
66		retval = device->string(serialString2, 1, 0x0409);
67		if ( 0 < retval ) {
68			cout << "1b: " << serialString2 << endl;
69			if (serialString2 != serialString1) {
70				cout << "String fetch with explicit language ID produced different result" << endl;
71			}
72		} else {
73			if (-EPIPE != retval) { // we ignore EPIPE, because some hubs don't have strings
74				cout << "fetching string 1b failed: " << usb_strerror() << endl;
75				return EXIT_FAILURE;
76			}
77		}
78
79		cout << endl;
80	}
81
82	return EXIT_SUCCESS;
83}
84