scoped_libusb_device_handle.cc 997 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "services/device/usb/scoped_libusb_device_handle.h"
  5. #include "services/device/usb/usb_context.h"
  6. #include "third_party/libusb/src/libusb/libusb.h"
  7. namespace device {
  8. ScopedLibusbDeviceHandle::ScopedLibusbDeviceHandle(
  9. libusb_device_handle* handle,
  10. scoped_refptr<UsbContext> context)
  11. : handle_(handle), context_(std::move(context)) {}
  12. ScopedLibusbDeviceHandle::ScopedLibusbDeviceHandle(
  13. ScopedLibusbDeviceHandle&& other)
  14. : handle_(other.handle_), context_(std::move(other.context_)) {
  15. other.handle_ = nullptr;
  16. }
  17. ScopedLibusbDeviceHandle::~ScopedLibusbDeviceHandle() {
  18. Reset();
  19. }
  20. void ScopedLibusbDeviceHandle::Reset() {
  21. libusb_close(handle_);
  22. handle_ = nullptr;
  23. context_.reset();
  24. }
  25. bool ScopedLibusbDeviceHandle::IsValid() const {
  26. return handle_ != nullptr;
  27. }
  28. } // namespace device