3 /// General Barry interface routines
7 Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
27 #ifdef USE_BARRY_SOCKETS
33 bool __data_dump_mode__
;
35 std::ostream
*LogStream
= &std::cout
;
36 pthread_mutex_t LogStreamMutex
;
42 /// Barry library initializer. Call this before anything else.
43 /// This takes care of initializing the lower level libusb.
45 /// This function is safe to be called multiple times. The
46 /// data_dump_mode and the log stream will be updated each time
47 /// it is called, but the USB library will not be re-initialized.
49 /// \param[in] data_dump_mode If set to true, the protocol conversation
50 /// will be sent to the logStream specified
51 /// in the second argument.
52 /// \param[in] LogStream Pointer to std::ostream object to use for
53 /// debug output and logging. Defaults to
56 void Init(bool data_dump_mode
, std::ostream
*logStream
)
58 static bool initialized
= false;
60 #ifdef USE_BARRY_SOCKETS
61 Usb::LibraryInterface::SetDataDump(data_dump_mode
);
64 // perform one-time initalization
66 #ifdef USE_BARRY_SOCKETS
67 // Should call Usb::Uninit at some point,
68 // but there isn't currently a deinit call.
69 int err
= Usb::LibraryInterface::Init();
71 eout("USB library failed to initialise with error: " << err
);
72 throw Error("Failed to initialise USB");
77 // only need to initialize this once
78 pthread_mutex_init(&LogStreamMutex
, NULL
);
84 __data_dump_mode__
= data_dump_mode
;
85 LogStream
= logStream
;
91 /// This API call lets the application enable / disable verbose debug
92 /// output on the fly.
94 /// \param[in] data_dump_mode If set to true, the protocol conversation
95 /// will be sent to the logStream specified
96 /// in the Barry::Init() call.
98 void Verbose(bool data_dump_mode
)
100 __data_dump_mode__
= data_dump_mode
;
102 #ifdef USE_BARRY_SOCKETS
103 Usb::LibraryInterface::SetDataDump(data_dump_mode
);
110 /// Returns true if data dump mode is enabled.
114 return __data_dump_mode__
;