blob: b3ac5e8eb08dec38a5c328d0d51d42f2f7a5bba1 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/usb/scoped_libusb_device_ref.h"
#include "device/usb/usb_context.h"
#include "third_party/libusb/src/libusb/libusb.h"
namespace device {
ScopedLibusbDeviceRef::ScopedLibusbDeviceRef(libusb_device* device,
scoped_refptr<UsbContext> context)
: device_(device), context_(std::move(context)) {}
ScopedLibusbDeviceRef::ScopedLibusbDeviceRef(ScopedLibusbDeviceRef&& other)
: device_(other.device_), context_(std::move(other.context_)) {
other.device_ = nullptr;
}
ScopedLibusbDeviceRef::~ScopedLibusbDeviceRef() {
Reset();
}
void ScopedLibusbDeviceRef::Reset() {
libusb_unref_device(device_);
device_ = nullptr;
context_.reset();
}
bool ScopedLibusbDeviceRef::IsValid() const {
return device_ != nullptr;
}
bool operator==(const ScopedLibusbDeviceRef& ref, libusb_device* device) {
return ref.get() == device;
}
} // namespace device