got all of glibusb compiling (and the tests work)
diff --git a/aos/build/aos_all.gyp b/aos/build/aos_all.gyp
index ba30a35..95aaaa5 100644
--- a/aos/build/aos_all.gyp
+++ b/aos/build/aos_all.gyp
@@ -22,6 +22,7 @@
'../common/util/util.gyp:trapezoid_profile_test',
'../common/sensors/sensors.gyp:sensor_receiver_test',
'../common/glibusb/glibusb.gyp:gbuffer_test',
+ '../common/glibusb/glibusb.gyp:glibusb_test',
'Common',
# TODO(brians): move this to Common
'<(AOS)/common/sensors/sensors.gyp:sensors_test',
diff --git a/aos/common/glibusb/CMakeLists.txt b/aos/common/glibusb/CMakeLists.txt
deleted file mode 100644
index 11151fe..0000000
--- a/aos/common/glibusb/CMakeLists.txt
+++ /dev/null
@@ -1,93 +0,0 @@
-cmake_minimum_required(VERSION 2.8)
-project(glibusb)
-
-enable_testing()
-
-find_package(Boost REQUIRED COMPONENTS thread date_time) # need >= 1.48
-find_package(PkgConfig REQUIRED)
-#pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
-pkg_check_modules(GFLAGS REQUIRED libgflags)
-pkg_check_modules(GLOG REQUIRED libglog)
-
-add_definitions("-std=c++11 -Wall -Wextra")
-
-set(GTEST_INCLUDEDIR "/usr/src/gtest")
-set(GTEST_SRCS
- /usr/src/gtest/src/gtest_main.cc
- /usr/src/gtest/src/gtest-all.cc
-)
-
-
-include_directories(
- ${Boost_INCLUDE_DIRS}
- /usr/include/libusb-1.0
- ${GFLAGS_INCLUDE_DIRS}
- ${GLOG_INCLUDE_DIRS}
- ${GTEST_INCLUDEDIR}
-)
-
-link_directories(
- ${Boost_LIBRARY_DIRS}
- ${GFLAGS_LIBRARY_DIRS}
- ${GLOG_LIBRARY_DIRS}
-)
-
-set(LIBRARIES
- ${Boost_LIBRARIES}
- usb-1.0
- ${GFLAGS_LIBRARIES}
- ${GLOG_LIBRARIES}
- pthread
-)
-
-set(HEADERS
- gbuffer.h
- ghexdump.h
- glibusb_device_internal.h
- glibusb_endpoint.h
- glibusb_endpoint_internal.h
- glibusb.h
- glibusb_internal.h
- glibusb_transfer.h
-)
-
-#
-add_library(glibusb
- gbuffer.cc
- glibusb.cc
- glibusb_device.cc
- glibusb_endpoint.cc
- glibusb_internal.cc
- glibusb_transfer.cc
- ghexdump.cc
-)
-target_link_libraries(glibusb ${LIBRARIES})
-
-#
-add_executable(gbuffer_test
- testing/gbuffer_test.cc
- ${GTEST_SRCS}
-)
-target_link_libraries(gbuffer_test glibusb ${LIBRARIES})
-add_test(gbuffer_test gbuffer_test)
-
-#
-add_executable(glibusb_test
- testing/glibusb_test.cc
- ${GTEST_SRCS}
-)
-target_link_libraries(glibusb_test glibusb ${LIBRARIES})
-add_test(glibusb_test glibusb_test)
-
-install(TARGETS glibusb
- LIBRARY DESTINATION lib COMPONENT Runtime
- ARCHIVE DESTINATION lib COMPONENT Runtime
-)
-install(FILES ${HEADERS}
- DESTINATION /usr/include/glibusb
- COMPONENT Development)
-
-set(CPACK_GENERATOR DEB)
-set(CPACK_PACKAGE_VERSION "1.0.14")
-set(CPACK_PACKAGE_CONTACT "charliehotel@google.com")
-include(CPack)
diff --git a/aos/common/glibusb/gbuffer_test.cc b/aos/common/glibusb/gbuffer_test.cc
index c0d8bbf..0b085a8 100644
--- a/aos/common/glibusb/gbuffer_test.cc
+++ b/aos/common/glibusb/gbuffer_test.cc
@@ -9,8 +9,8 @@
#include <stdint.h>
#include <limits>
+#include <memory>
-#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
#include "aos/common/queue_testutils.h"
@@ -171,7 +171,7 @@
// Tests slicing an empty buffer.
TEST_F(BufferTest, EmptyBufferSlice) {
Buffer buffer;
- boost::scoped_ptr<Buffer> slice(buffer.MakeSlice(0, 0));
+ ::std::unique_ptr<Buffer> slice(buffer.MakeSlice(0, 0));
EXPECT_EQ(0u, slice->Length());
}
@@ -229,7 +229,7 @@
buffer.reset(new Buffer(kDeadBeef, sizeof(kDeadBeef)));
}
- boost::scoped_ptr<Buffer> buffer;
+ ::std::unique_ptr<Buffer> buffer;
};
typedef ConstructedFromDataBufferTest ConstructedFromDataBufferDeathTest;
@@ -302,7 +302,7 @@
// Tests that Get{S,U}{8,16,32,64} work on zero.
TEST_F(BufferTest, GetZero) {
- boost::scoped_ptr<Buffer> buffer(new Buffer());
+ ::std::unique_ptr<Buffer> buffer(new Buffer());
for (int i = 0; i < 8; ++i) {
buffer->Append(uint8_t(0));
}
@@ -334,7 +334,7 @@
// Tests that GetU{8,16,32,64} work.
TEST_F(BufferTest, GetUXX) {
- boost::scoped_ptr<Buffer> buffer(new Buffer());
+ ::std::unique_ptr<Buffer> buffer(new Buffer());
buffer->Append(uint8_t(0x88));
buffer->Append(uint8_t(0x77));
buffer->Append(uint8_t(0x66));
@@ -359,7 +359,7 @@
// Tests that GetS{8,16,32,64} work for positive values.
TEST_F(BufferTest, GetSXXPositive) {
- boost::scoped_ptr<Buffer> buffer(new Buffer());
+ ::std::unique_ptr<Buffer> buffer(new Buffer());
buffer->Append(uint8_t(0x08));
buffer->Append(uint8_t(0x07));
buffer->Append(uint8_t(0x06));
@@ -384,7 +384,7 @@
// Tests that GetS{8,16,32,64} work for negative values.
TEST_F(BufferTest, GetSXXNegative) {
- boost::scoped_ptr<Buffer> buffer(new Buffer());
+ ::std::unique_ptr<Buffer> buffer(new Buffer());
buffer->Append(uint8_t(0xF8));
buffer->Append(uint8_t(0xF7));
buffer->Append(uint8_t(0x06));
@@ -483,13 +483,13 @@
// Tests emtpy slicing.
TEST_F(ConstructedFromDataBufferTest, ConstructedFromDataSlice) {
- boost::scoped_ptr<Buffer> slice(buffer->MakeSlice(0, 0));
+ ::std::unique_ptr<Buffer> slice(buffer->MakeSlice(0, 0));
EXPECT_EQ(0u, slice->Length());
}
// Tests slicing.
TEST_F(ConstructedFromDataBufferTest, ConstructedFromDataSlice2) {
- boost::scoped_ptr<Buffer> slice(buffer->MakeSlice(0, 2));
+ ::std::unique_ptr<Buffer> slice(buffer->MakeSlice(0, 2));
EXPECT_EQ(2u, slice->Length());
uint16_t u16;
slice->Get(0, &u16);
diff --git a/aos/common/glibusb/glibusb.cc b/aos/common/glibusb/glibusb.cc
index 576e35c..5dd0075 100644
--- a/aos/common/glibusb/glibusb.cc
+++ b/aos/common/glibusb/glibusb.cc
@@ -1,14 +1,17 @@
// Copyright 2012 Google Inc. All Rights Reserved.
+//
+// Modified by FRC Team 971.
#include "glibusb.h"
+#include <inttypes.h>
#include <cstdio>
#include <sstream>
#include <iomanip>
#include <string>
-#include <glog/logging.h>
-#include <libusb.h>
+#include <libusb-1.0/libusb.h>
+#include "aos/common/logging/logging.h"
#include "glibusb_device_internal.h"
namespace glibusb {
@@ -102,8 +105,8 @@
*devices != NULL; ++devices) {
struct libusb_device_descriptor descriptor;
CHECK_GE(libusb_get_device_descriptor(*devices, &descriptor), 0);
- VLOG(2) << "idVendor = 0x" << std::hex << descriptor.idVendor
- << " idProduct = 0x" << std::hex << descriptor.idProduct;
+ LOG(DEBUG, "idVendor = 0x%" PRIx16 " idProduct = 0x%" PRIx16 "\n",
+ descriptor.idVendor, descriptor.idProduct);
DeviceLocationAndId dev_location_id;
dev_location_id.location.bus_number = libusb_get_bus_number(*devices);
dev_location_id.location.device_address =
@@ -142,11 +145,13 @@
struct libusb_device_descriptor descriptor;
CHECK_GE(libusb_get_device_descriptor(*devices, &descriptor), 0);
- VLOG(2) << "idVendor = 0x" << std::hex << descriptor.idVendor
- << " idProduct = 0x" << std::hex << descriptor.idProduct;
+ LOG(DEBUG, "idVendor = 0x%" PRIx16 " idProduct = 0x%" PRIx16 "\n",
+ descriptor.idVendor, descriptor.idProduct);
if (descriptor.idVendor == dev_location_id.id.vendor_id &&
descriptor.idProduct == dev_location_id.id.product_id) {
- CHECK(matching_device == NULL) << ": found multiple matching devices";
+ if (matching_device != NULL) {
+ LOG(FATAL, "found multiple matching devices\n");
+ }
matching_device = *devices;
}
}
@@ -154,27 +159,27 @@
int bus_number = static_cast<int>(dev_location_id.location.bus_number);
int device_address =
static_cast<int>(dev_location_id.location.device_address);
- CHECK(matching_device != NULL)
- << ": no matching device found for "
- << "vid=" << std::hex << dev_location_id.id.vendor_id << ", "
- << "pid=" << std::hex << dev_location_id.id.product_id << ", "
- << "bus_number=" << std::dec << bus_number << ", "
- << "device_address=" << std::dec << device_address;
+ if (matching_device == NULL) {
+ LOG(FATAL, "no matching device found for vid=%" PRIx16 ", pid=%" PRIx16
+ ", bus_number=%d, device_address=%d\n",
+ dev_location_id.id.vendor_id, dev_location_id.id.product_id,
+ bus_number, device_address);
+ }
} else {
const int vendor_id = dev_location_id.id.vendor_id;
const int product_id = dev_location_id.id.product_id;
- CHECK(matching_device != NULL) << ": no matching device found for "
- << "vid=" << std::hex << vendor_id << ", "
- << "pid=" << std::hex << product_id;
+ if (matching_device == NULL) {
+ LOG(FATAL, "no matching device found for vid=%d, pid=%d\n",
+ vendor_id, product_id);
+ }
}
struct libusb_device_handle *handle = NULL;
if (matching_device != NULL) {
int return_value = libusb_open(matching_device, &handle);
if (return_value < 0) {
- // TODO(charliehotel): this must not be FATAL.
- LOG(FATAL) << "Failed to open device: "
- << libusb_error_name(return_value);
+ LOG(FATAL, "Failed to open device: %s\n",
+ libusb_error_name(return_value));
}
CHECK_NOTNULL(handle); // should never happen
}
@@ -232,7 +237,7 @@
const std::string &target_vendor_product_id,
std::vector<VendorProductId> *target_ids) {
CHECK_NE(target_vendor_product_id, "");
- CHECK_EQ(target_vendor_product_id.size(), 9);
+ CHECK_EQ(target_vendor_product_id.size(), 9u);
CHECK_EQ(target_vendor_product_id[4], ':');
uint32_t vendor_id;
CHECK(safe_strtou32_hex(
@@ -248,7 +253,7 @@
/*static*/ void Libusb::ParseDeviceLocationString(
const std::string &target_device_location, DeviceLocation *location) {
- CHECK_EQ(target_device_location.size(), 7);
+ CHECK_EQ(target_device_location.size(), 7u);
CHECK_EQ(target_device_location[3], ':');
uint32_t parsed_bus_number;
CHECK(safe_strtou32(
diff --git a/aos/common/glibusb/glibusb.gyp b/aos/common/glibusb/glibusb.gyp
index 0b44d46..7b1c334 100644
--- a/aos/common/glibusb/glibusb.gyp
+++ b/aos/common/glibusb/glibusb.gyp
@@ -23,5 +23,41 @@
'<(AOS)/common/common.gyp:queue_testutils',
],
},
+ {
+ 'target_name': 'glibusb',
+ 'type': 'static_library',
+ 'sources': [
+ # These all have circularish dependencies so it's not really possible to
+ # split them out.
+ 'glibusb.cc',
+ 'glibusb_device.cc',
+ 'glibusb_internal.cc',
+ 'glibusb_transfer.cc',
+ 'glibusb_endpoint.cc',
+ ],
+ 'dependencies': [
+ 'gbuffer',
+ '<(AOS)/build/aos.gyp:logging',
+ '<(EXTERNALS):libusb',
+ '<(AOS)/common/common.gyp:mutex',
+ '<(AOS)/common/common.gyp:condition',
+ ],
+ 'export_dependent_settings': [
+ '<(EXTERNALS):libusb',
+ '<(AOS)/common/common.gyp:mutex',
+ '<(AOS)/common/common.gyp:condition',
+ ],
+ },
+ {
+ 'target_name': 'glibusb_test',
+ 'type': 'executable',
+ 'sources': [
+ 'glibusb_test.cc',
+ ],
+ 'dependencies': [
+ 'glibusb',
+ '<(EXTERNALS):gtest',
+ ],
+ },
],
}
diff --git a/aos/common/glibusb/glibusb_device.cc b/aos/common/glibusb/glibusb_device.cc
index 9fc8df3..4b2c922 100644
--- a/aos/common/glibusb/glibusb_device.cc
+++ b/aos/common/glibusb/glibusb_device.cc
@@ -1,11 +1,12 @@
// Copyright 2012 Google Inc. All Rights Reserved.
+//
+// Modified by FRC Team 971.
#include <stddef.h>
-#include <glog/logging.h>
-#include <boost/function.hpp>
-#include <boost/scoped_ptr.hpp>
-#include <libusb.h>
+#include <inttypes.h>
+#include <libusb-1.0/libusb.h>
+#include "aos/common/logging/logging.h"
#include "glibusb.h"
#include "glibusb_device_internal.h"
#include "glibusb_endpoint.h"
@@ -31,81 +32,85 @@
libusb_context_(CHECK_NOTNULL(context)),
device_handle_(CHECK_NOTNULL(handle)) {
int r = libusb_claim_interface(device_handle_, 0);
- // TODO(charliehotel): this must not be FATAL.
- CHECK_GE(r, 0) << ": libusb_claim_interface failed, r=" << std::dec << r;
+ if (r < 0) {
+ // TODO(charliehotel): this must not be FATAL.
+ LOG(FATAL, "libusb_claim_interface failed with %d: %s\n",
+ r, libusb_error_name(r));
+ }
struct libusb_device *dev = libusb_get_device(device_handle_);
- // TODO(charliehotel): this must not be FATAL.
- CHECK(dev != NULL) << ": libusb_get_device failed";
+ if (dev == NULL) {
+ // TODO(charliehotel): this must not be FATAL.
+ LOG(FATAL, "libusb_get_device failed\n");
+ }
struct libusb_device_descriptor desc;
r = libusb_get_device_descriptor(dev, &desc);
- // TODO(charliehotel): this must not be FATAL.
- CHECK_GE(r, 0) << ": libusb_get_device_descriptor failed";
+ if (r < 0) {
+ // TODO(charliehotel): this must not be FATAL.
+ LOG(FATAL, "libusb_get_device_descriptor failed with %d: %s\n",
+ r, libusb_error_name(r));
+ }
- VLOG(2) << "vid=0x" << std::hex << desc.idVendor
- << ", pid=0x" << desc.idProduct;
- VLOG(2) << " # of configurations = "
- << static_cast<int>(desc.bNumConfigurations);
+ LOG(DEBUG, "vid=0x%" PRIx16 ", pid=0x%" PRIx16 ", # of configurations = %d\n",
+ desc.idVendor, desc.idProduct, static_cast<int>(desc.bNumConfigurations));
struct libusb_config_descriptor *config;
r = libusb_get_active_config_descriptor(dev, &config);
- // TODO(charliehotel): this must not be FATAL.
- CHECK_GE(r, 0) << ": libusb_get_active_config_descriptor failed";
+ if (r < 0) {
+ // TODO(charliehotel): this must not be FATAL.
+ LOG(FATAL, "libusb_get_active_config_descriptor failed with %d: %s\n",
+ r, libusb_error_name(r));
+ }
// TODO(charliehotel): this must not be FATAL.
CHECK_NOTNULL(config);
if (config->bNumInterfaces != 1) {
- VLOG(2) << "config->bNumInterfaces="
- << static_cast<int>(config->bNumInterfaces)
- << ", expected ony one";
+ LOG(DEBUG, "config->bNumInterfaces=%d, expected only one\n",
+ static_cast<int>(config->bNumInterfaces));
}
- if (VLOG_IS_ON(2)) {
+ // TODO(brians): Make this enableable through the logging stuff.
+ if (false) {
for (int i = 0; i < config->bNumInterfaces; ++i) {
const struct libusb_interface *interface = config->interface + i;
const struct libusb_interface_descriptor *setting = interface->altsetting;
- VLOG(2) << "bInterfaceNumber="
- << static_cast<int>(setting->bInterfaceNumber);
- VLOG(2) << "bAlternateSetting="
- << static_cast<int>(setting->bAlternateSetting);
- VLOG(2) << "bNumEndpoints="
- << static_cast<int>(setting->bNumEndpoints);
+ LOG(DEBUG, "bInterfaceNumber=%d bAlternateSetting=%d bNumEndpoints=%d\n",
+ static_cast<int>(setting->bInterfaceNumber),
+ static_cast<int>(setting->bAlternateSetting),
+ static_cast<int>(setting->bNumEndpoints));
for (int j = 0; j < setting->bNumEndpoints; ++j) {
const struct libusb_endpoint_descriptor *endpoint =
setting->endpoint + j;
switch (endpoint->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
- VLOG(2) << "control";
+ LOG(DEBUG, "control\n");
break;
case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
- VLOG(2) << "iso";
+ LOG(DEBUG, "iso\n");
break;
case LIBUSB_TRANSFER_TYPE_BULK:
- VLOG(2) << "bulk";
+ LOG(DEBUG, "bulk\n");
break;
case LIBUSB_TRANSFER_TYPE_INTERRUPT:
- VLOG(2) << "interrupt";
+ LOG(DEBUG, "interrupt\n");
break;
default:
- LOG(FATAL) << "unknown transfer type";
+ LOG(FATAL, "unknown transfer type\n");
}
if ((endpoint->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) ==
LIBUSB_ENDPOINT_IN) {
- VLOG(2) << " ep: 0x"
- << std::hex << static_cast<int>(endpoint->bEndpointAddress)
- << " (in)";
+ LOG(DEBUG, " ep: 0x%x (in)\n",
+ static_cast<int>(endpoint->bEndpointAddress));
} else {
- VLOG(2) << " ep: 0x"
- << std::hex << static_cast<int>(endpoint->bEndpointAddress)
- << " (out)";
+ LOG(DEBUG, " ep: 0x%x (out)\n",
+ static_cast<int>(endpoint->bEndpointAddress));
}
- VLOG(2) << " packet size="
- << std::dec << static_cast<int>(endpoint->wMaxPacketSize);
- VLOG(2) << " interval="
- << std::dec << static_cast<int>(endpoint->bInterval);
+ LOG(DEBUG, " packet size=%d interval=%d\n",
+ static_cast<int>(endpoint->wMaxPacketSize),
+ static_cast<int>(endpoint->bInterval));
}
}
}
@@ -130,8 +135,11 @@
struct libusb_config_descriptor *config;
libusb_device *dev = libusb_get_device(device_handle_);
const int r = libusb_get_active_config_descriptor(dev, &config);
- // TODO(charliehotel): this must not be FATAL.
- CHECK_GE(r, 0) << ": libusb_get_active_config_descriptor failed";
+ if (r < 0) {
+ // TODO(charliehotel): this must not be FATAL.
+ LOG(FATAL, "libusb_get_active_config_descriptor failed with %d: %s\n",
+ r, libusb_error_name(r));
+ }
// TODO(charliehotel): this must not be FATAL.
CHECK_NOTNULL(config);
const struct libusb_interface *interface = config->interface;
@@ -184,16 +192,18 @@
} // namespace
UsbInEndpoint *PhysicalUsbDevice::DoInEndpoint(int number) {
- CHECK_EQ(number & LIBUSB_ENDPOINT_ADDRESS_MASK, number)
- << ": Endpoint out of range.";
+ if ((number & LIBUSB_ENDPOINT_ADDRESS_MASK) != number) {
+ LOG(FATAL, "Endpoint %d out of range.\n", number);
+ }
DescriptorHasAddressAndDirection matcher(number, UsbEndpoint::kIn);
return MatchEndpoint<PhysicalUsbInEndpoint>(matcher);
}
UsbOutEndpoint *PhysicalUsbDevice::DoOutEndpoint(int number) {
- CHECK_EQ(number & LIBUSB_ENDPOINT_ADDRESS_MASK, number)
- << ": Endpoint out of range.";
+ if ((number & LIBUSB_ENDPOINT_ADDRESS_MASK) != number) {
+ LOG(FATAL, "Endpoint %d out of range.\n", number);
+ }
DescriptorHasAddressAndDirection matcher(number, UsbEndpoint::kOut);
return MatchEndpoint<PhysicalUsbOutEndpoint>(matcher);
diff --git a/aos/common/glibusb/glibusb_device_internal.h b/aos/common/glibusb/glibusb_device_internal.h
index 4f2ad7f..ca6073d 100644
--- a/aos/common/glibusb/glibusb_device_internal.h
+++ b/aos/common/glibusb/glibusb_device_internal.h
@@ -1,5 +1,7 @@
// Copyright 2012 Google Inc. All Rights Reserved.
//
+// Modified by FRC Team 971.
+//
// Wrapper for libusb's device that implements the UsbDevice interface.
#ifndef _GLIBUSB_GLIBUSB_DEVICE_INTERNAL_H_
@@ -7,7 +9,7 @@
#include <stdint.h>
#include <utility>
-#include <boost/function.hpp>
+#include <functional>
#include "glibusb.h"
#include "glibusb_endpoint.h"
@@ -26,12 +28,12 @@
PhysicalUsbDevice(struct libusb_context *context,
struct libusb_device_handle *handle);
- typedef boost::function<bool(const struct libusb_endpoint_descriptor *)>
+ typedef ::std::function<bool(const struct libusb_endpoint_descriptor *)>
EndpointMatcher;
// Iterates through all the endpoint descriptors for this device
- // and allocates and allocates a UsbEndpointType for the first
- // endpoint for which the matcher returns true.
+ // and allocates and returns a UsbEndpointType for the first
+ // endpoint for which the matcher returns true or NULL.
template <class UsbEndpointType>
UsbEndpointType *MatchEndpoint(EndpointMatcher matcher);
diff --git a/aos/common/glibusb/glibusb_endpoint.cc b/aos/common/glibusb/glibusb_endpoint.cc
index 30c8bd7..1bfd583 100644
--- a/aos/common/glibusb/glibusb_endpoint.cc
+++ b/aos/common/glibusb/glibusb_endpoint.cc
@@ -1,12 +1,14 @@
// Copyright 2012 Google Inc. All Rights Reserved.
+//
+// Modified by FRC Team 971.
#include "glibusb_endpoint.h"
#include <stddef.h>
-#include <glog/logging.h>
-#include <boost/scoped_ptr.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
+#include <inttypes.h>
+#include <memory>
+#include "aos/common/logging/logging.h"
#include "gbuffer.h"
#include "glibusb_endpoint_internal.h"
#include "glibusb_internal.h"
@@ -31,34 +33,25 @@
} // namespace
Notification::Notification(bool prenotify)
- : notified_(prenotify) {}
+ : notified_changed_(&mutex_), notified_(prenotify) {}
bool Notification::HasBeenNotified() const {
- boost::lock_guard<boost::mutex> lock(mutex_);
+ ::aos::MutexLocker lock(&mutex_);
return notified_;
}
void Notification::WaitForNotification() const {
- boost::unique_lock<boost::mutex> lock(mutex_);
- notified_changed_.wait(
- lock,
- boost::bind(&Notification::HasBeenNotifiedUnlocked, this));
-}
-
-bool Notification::WaitForNotificationWithTimeout(int64_t milliseconds) const {
- boost::unique_lock<boost::mutex> lock(mutex_);
- auto timeout = boost::posix_time::milliseconds(milliseconds);
- notified_changed_.timed_wait(
- lock, timeout,
- boost::bind(&Notification::HasBeenNotifiedUnlocked, this));
- return notified_;
+ ::aos::MutexLocker lock(&mutex_);
+ while (HasBeenNotifiedUnlocked()) notified_changed_.Wait();
}
void Notification::Notify() {
- boost::lock_guard<boost::mutex> lock(mutex_);
- CHECK(!notified_) << ": already notified";
+ ::aos::MutexLocker lock(&mutex_);
+ if (notified_) {
+ LOG(FATAL, "already notified\n");
+ }
notified_ = true;
- notified_changed_.notify_all();
+ notified_changed_.Broadcast();
}
bool Notification::HasBeenNotifiedUnlocked() const {
@@ -74,11 +67,15 @@
: direction_(direction),
transfer_(transfer),
endpoint_address_and_direction_(endpoint_address | direction) {
- CHECK_EQ(endpoint_address_and_direction_ & 0x80, direction)
- << ": Direction in address doesn't match specified direction.";
- CHECK_EQ(endpoint_address_and_direction_ & 0x8f,
- endpoint_address_and_direction_)
- << ": Invalid endpoint address.";
+ if ((endpoint_address_and_direction_ & 0x80) != direction) {
+ LOG(FATAL, "Direction in address %x doesn't match direction %x.\n",
+ endpoint_address_and_direction_, direction);
+ }
+ if ((endpoint_address_and_direction_ & 0x8f) !=
+ endpoint_address_and_direction_) {
+ LOG(FATAL, "Invalid endpoint address %x.\n",
+ endpoint_address_and_direction_);
+ }
}
////////////////////////////////////////////////////////////////////////
@@ -142,8 +139,9 @@
DescriptorToAddress(descriptor)),
libusb_context_(CHECK_NOTNULL(context)),
handle_(CHECK_NOTNULL(handle)) {
- VLOG(1) << "0x" << std::hex << static_cast<int>(endpoint_address_and_direction())
- << ", max_packet_size " << std::dec << descriptor->wMaxPacketSize;
+ LOG(DEBUG, "0x%x, max_packet_size=%" PRId16 "\n",
+ static_cast<int>(endpoint_address_and_direction()),
+ descriptor->wMaxPacketSize);
CHECK_EQ(DescriptorToDirection(descriptor), UsbEndpoint::kIn);
}
@@ -175,7 +173,7 @@
case UsbEndpoint::kIsochronous:
return LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
default:
- LOG(FATAL) << "transfer_type " << transfer_type << " is bogus";
+ LOG(FATAL, "transfer_type %d is bogus", transfer_type);
}
}
@@ -195,7 +193,7 @@
case UsbEndpoint::kIsochronous:
return kTransferTypeNameIsochronous;
default:
- LOG(FATAL) << "transfer_type " << transfer_type << " is bogus";
+ LOG(FATAL, "transfer_type %d is bogus", transfer_type);
}
}
} // namespace
@@ -207,11 +205,11 @@
CHECK_GE(timeout_milliseconds, 0);
CHECK_NOTNULL(out);
- VLOG(2) << "read on 0x" << std::hex << endpoint_address_and_direction()
- << ", size 0x" << std::hex << length
- << ", timeout " << std::dec << timeout_milliseconds << " [ms]";
+ // TODO(brians): Conditionally enable this.
+ LOG(DEBUG, "read on 0x%x, size 0x%x, timeout %" PRId32 " [ms]\n",
+ endpoint_address_and_direction(), length, timeout_milliseconds);
- boost::scoped_ptr<Buffer> whole_buffer(new Buffer());
+ ::std::unique_ptr<Buffer> whole_buffer(new Buffer());
whole_buffer->Resize(length);
void *p = whole_buffer->GetBufferPointer(length);
int transferred;
@@ -231,31 +229,29 @@
size_t size_transferred = static_cast<size_t>(transferred);
whole_buffer->Resize(size_transferred);
- VLOG(2)
- << "read on 0x"
- << std::hex << static_cast<int>(endpoint_address_and_direction())
- << ", size_transferred=0x" << std::hex << size_transferred;
+ // TODO(brians): Conditionally enable this.
+ LOG(DEBUG, "read on 0x%x, size_transferred=%zx\n",
+ endpoint_address_and_direction(), size_transferred);
out->Copy(*whole_buffer);
return kSuccess;
}
case LIBUSB_ERROR_TIMEOUT:
- VLOG(2) << "libusb_" << TransferTypeName(transfer())
- << "_transfer timeout";
+ LOG(DEBUG, "libusb_%s_transfer timeout\n",
+ TransferTypeName(transfer()));
return kTimeout;
case LIBUSB_ERROR_IO:
- VLOG(1) << "Device i/o error.";
+ LOG(DEBUG, "device I/O error\n");
return kFail;
case LIBUSB_ERROR_NO_DEVICE:
- VLOG(1) << "Device disconnected.";
+ LOG(DEBUG, "device disconnected\n");
return kNoDevice;
case LIBUSB_ERROR_OTHER:
- LOG(INFO) << "libusb_" << TransferTypeName(transfer())
- << "_transfer failed with r=" << std::dec << r;
+ LOG(INFO, "libusb_%s_transfer other error\n", TransferTypeName(transfer()));
return kUnknown;
default:
// Most of these are more esoteric.
- LOG(INFO) << "libusb_" << TransferTypeName(transfer())
- << "_transfer failed with r=" << std::dec << r;
+ LOG(INFO, "libusb_%s_transfer failed with %d: %s\n",
+ TransferTypeName(transfer()), r, libusb_error_name(r));
return kFail;
}
}
@@ -270,8 +266,9 @@
DescriptorToAddress(descriptor)),
libusb_context_(CHECK_NOTNULL(context)),
handle_(CHECK_NOTNULL(handle)) {
- VLOG(1) << "0x" << std::hex << static_cast<int>(endpoint_address_and_direction())
- << ", max_packet_size " << std::dec << descriptor->wMaxPacketSize;
+ LOG(DEBUG, "0x%x, max_packet_size=%" PRId16 "\n",
+ static_cast<int>(endpoint_address_and_direction()),
+ descriptor->wMaxPacketSize);
CHECK_EQ(DescriptorToDirection(descriptor), UsbEndpoint::kOut);
}
@@ -296,9 +293,8 @@
CHECK_NOTNULL(handle_);
CHECK_EQ(direction(), kOut);
- VLOG(2) << "writing on 0x" << std::hex << endpoint_address_and_direction()
- << ", length=" << std::dec << buffer.Length()
- << ", timeout " << std::dec << timeout_milliseconds << " [ms]";
+ LOG(DEBUG, "writing on 0x%x, length=%zd, timeout %d [ms]\n",
+ endpoint_address_and_direction(), buffer.Length(), timeout_milliseconds);
size_t length = buffer.Length();
const unsigned char *p =
@@ -308,29 +304,30 @@
int transferred;
int r;
+ // TODO(brians): Conditionally enable this.
+ LOG(DEBUG, "libusb_%s_transfer, length=%d\n",
+ TransferTypeName(transfer()), length);
switch (transfer()) {
case kBulk:
- VLOG(2) << "libusb_bulk_transfer, length=" << std::dec << length;
r = libusb_bulk_transfer(handle_, endpoint_address_and_direction(),
const_cast<unsigned char *>(p),
length, &transferred,
timeout);
- VLOG(2) << "libusb_bulk_transfer, r=" << std::dec << r
- << ", transferred=" << std::dec << transferred;
break;
case kInterrupt:
- VLOG(2) << "libusb_interrupt_transfer, length="
- << std::dec << length;
r = libusb_interrupt_transfer(handle_, endpoint_address_and_direction(),
const_cast<unsigned char *>(p),
length, &transferred,
timeout);
- VLOG(2) << "libusb_interrupt_transfer, r=" << std::dec << r
- << ", transferred=" << std::dec << transferred;
break;
+ case kControl:
+ case kIsochronous:
default:
- LOG(FATAL) << "bogus transfer() value";
+ LOG(FATAL, "bogus transfer() value\n");
}
+ // TODO(brians): Conditionally enable this.
+ LOG(DEBUG, "libusb_%s_transfer, r=%d (%s), transferred=%d\n",
+ TransferTypeName(transfer()), r, libusb_error_name(r), transferred);
size_t size_transferred;
@@ -340,21 +337,21 @@
CHECK_EQ(size_transferred, length);
return kSuccess;
case LIBUSB_ERROR_TIMEOUT:
- VLOG(2) << "libusb_" << TransferTypeName(transfer()) << "_transfer timeout";
+ LOG(DEBUG, "libusb_%s_transfer timeout\n",
+ TransferTypeName(transfer()));
return kTimeout;
case LIBUSB_ERROR_IO:
- VLOG(1) << "Device i/o error.";
+ LOG(DEBUG, "device I/O error\n");
return kFail;
case LIBUSB_ERROR_NO_DEVICE:
- VLOG(1) << "Device disconnected.";
+ LOG(DEBUG, "device disconnected\n");
return kNoDevice;
case LIBUSB_ERROR_OTHER:
- LOG(INFO) << "libusb_" << TransferTypeName(transfer())
- << "_transfer failed with r=" << std::dec << r;
+ LOG(INFO, "libusb_%s_transfer other error\n", TransferTypeName(transfer()));
return kUnknown;
default:
- VLOG(1) << "libusb_" << TransferTypeName(transfer())
- << "_transfer failed, r=" << std::dec << r;
+ LOG(INFO, "libusb_%s_transfer failed with %d: %s\n",
+ TransferTypeName(transfer()), r, libusb_error_name(r));
return kFail;
}
}
diff --git a/aos/common/glibusb/glibusb_endpoint.h b/aos/common/glibusb/glibusb_endpoint.h
index 6b1b1a7..19f770e 100644
--- a/aos/common/glibusb/glibusb_endpoint.h
+++ b/aos/common/glibusb/glibusb_endpoint.h
@@ -1,5 +1,7 @@
// Copyright 2012 Google Inc. All Rights Reserved.
//
+// Modified by FRC Team 971.
+//
// Usb Endpoint Interfaces.
#ifndef _GLIBUSB_GLIBUSB_ENDPOINT_H_
@@ -8,11 +10,10 @@
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
-#include <libusb.h>
-#include <boost/bind.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/condition.hpp>
+#include <libusb-1.0/libusb.h>
+#include "aos/common/mutex.h"
+#include "aos/common/condition.h"
#include "gbuffer.h"
#ifndef MAX_ISO_BUFFER_LENGTH
@@ -37,14 +38,13 @@
explicit Notification(bool prenotify = false);
bool HasBeenNotified() const;
void WaitForNotification() const;
- bool WaitForNotificationWithTimeout(int64_t milliseconds) const;
void Notify();
private:
bool HasBeenNotifiedUnlocked() const;
- mutable boost::mutex mutex_;
- mutable boost::condition notified_changed_;
+ mutable ::aos::Mutex mutex_;
+ mutable ::aos::Condition notified_changed_;
bool notified_;
Notification(const Notification &) = delete;
diff --git a/aos/common/glibusb/glibusb_endpoint_internal.h b/aos/common/glibusb/glibusb_endpoint_internal.h
index f19899e..271ec14 100644
--- a/aos/common/glibusb/glibusb_endpoint_internal.h
+++ b/aos/common/glibusb/glibusb_endpoint_internal.h
@@ -1,5 +1,7 @@
// Copyright 2012 Google Inc. All Rights Reserved.
//
+// Modified by FRC Team 971.
+//
// Wrapper for libusb's endpoints.
#ifndef _GLIBUSB_GLIBUSB_ENDPOINT_INTERNAL_H_
@@ -7,7 +9,7 @@
#include <stddef.h>
#include <stdint.h>
-#include <libusb.h>
+#include <libusb-1.0/libusb.h>
#include "glibusb_endpoint.h"
diff --git a/aos/common/glibusb/glibusb_internal.cc b/aos/common/glibusb/glibusb_internal.cc
index f55dc2e..3990e6a 100644
--- a/aos/common/glibusb/glibusb_internal.cc
+++ b/aos/common/glibusb/glibusb_internal.cc
@@ -1,10 +1,12 @@
// Copyright 2012 Google Inc. All Rights Reserved.
+//
+// Modified by FRC Team 971.
#include "glibusb_internal.h"
-#include <libusb.h>
+#include <libusb-1.0/libusb.h>
-#include "glog/logging.h"
+#include "aos/common/logging/logging.h"
#include "glibusb_endpoint.h"
namespace glibusb {
@@ -42,7 +44,7 @@
return UsbEndpoint::kInterrupt;
break;
default:
- LOG(FATAL) << "bogus transfer type";
+ LOG(FATAL, "bogus transfer type\n");
}
}
diff --git a/aos/common/glibusb/glibusb_transfer.cc b/aos/common/glibusb/glibusb_transfer.cc
index a700cf2..ec4cd2c 100644
--- a/aos/common/glibusb/glibusb_transfer.cc
+++ b/aos/common/glibusb/glibusb_transfer.cc
@@ -1,5 +1,7 @@
// Copyright 2012 Google Inc. All Rights Reserved.
//
+// Modified by FRC Team 971.
+//
// Alternative libusb call to do transfers that quits when
// a notification is notified.
//
@@ -12,34 +14,11 @@
#include <stdint.h>
#include <stdio.h>
#include <sys/time.h>
-#include <gflags/gflags.h>
-#include <glog/logging.h>
-#include <libusb.h>
+#include <libusb-1.0/libusb.h>
+#include "aos/common/logging/logging.h"
#include "glibusb_endpoint.h"
-
-DEFINE_int32(notification_poll,
- 60,
- "Time in seconds to wait between checking the quit notification "
- "when waiting for USB messages.");
-
-namespace {
-
-static bool GEQZero(const char* flagname, int32_t value) {
- if (value < 0) {
- printf("Invalid value for --%s: %d\n", flagname, value);
- return false;
- }
- return true;
-}
-
-static const bool notification_poll_dummy = google::RegisterFlagValidator(
- &FLAGS_notification_poll, &GEQZero);
-
-} // namespace
-
-
namespace glibusb {
namespace {
@@ -47,7 +26,7 @@
void bulk_transfer_cb(struct libusb_transfer *transfer) {
int *completed = static_cast<int*>(transfer->user_data);
*completed = 1;
- VLOG(3) << "actual_length=" << transfer->actual_length;
+ LOG(DEBUG, "actual_length=%d\n", transfer->actual_length);
/* caller interprets results and frees transfer */
}
} // namespace
@@ -81,7 +60,7 @@
tv.tv_usec = 0;
r = libusb_handle_events_timeout_completed(context, &tv, &completed);
if (quit != NULL && quit->HasBeenNotified()) {
- LOG(WARNING) << "Caught quit notification. Canceling transfer.";
+ LOG(WARNING, "Caught quit notification. Canceling transfer.\n");
r = LIBUSB_ERROR_TIMEOUT;
}
if (r < 0) {
@@ -91,7 +70,7 @@
libusb_cancel_transfer(transfer);
while (!completed) {
struct timeval cancel_tv;
- cancel_tv.tv_sec = (quit == NULL ? FLAGS_notification_poll : 60);
+ cancel_tv.tv_sec = 60;
cancel_tv.tv_usec = 0;
if (libusb_handle_events_timeout_completed(context, &cancel_tv,
&completed) < 0) {
@@ -125,7 +104,8 @@
r = LIBUSB_ERROR_IO;
break;
default:
- LOG(WARNING) << "unrecognised status code " << transfer->status;
+ LOG(WARNING, "unrecognised status code %d\n",
+ static_cast<int>(transfer->status));
r = LIBUSB_ERROR_OTHER;
}