forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoped_libusb_device_handle.h
41 lines (29 loc) · 1.16 KB
/
scoped_libusb_device_handle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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.
#ifndef SERVICES_DEVICE_USB_SCOPED_LIBUSB_DEVICE_HANDLE_H_
#define SERVICES_DEVICE_USB_SCOPED_LIBUSB_DEVICE_HANDLE_H_
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
struct libusb_device_handle;
namespace device {
class UsbContext;
// This class owns a reference to a libusb_device_handle as well as a reference
// to the libusb_context. The libusb_context must outlive any
// libusb_device_handle instances created from it.
class ScopedLibusbDeviceHandle {
public:
ScopedLibusbDeviceHandle(libusb_device_handle* handle,
scoped_refptr<UsbContext> context);
ScopedLibusbDeviceHandle(ScopedLibusbDeviceHandle&& other);
~ScopedLibusbDeviceHandle();
libusb_device_handle* get() const { return handle_; }
void Reset();
bool IsValid() const;
private:
libusb_device_handle* handle_;
scoped_refptr<UsbContext> context_;
DISALLOW_COPY_AND_ASSIGN(ScopedLibusbDeviceHandle);
};
} // namespace device
#endif // SERVICES_DEVICE_USB_SCOPED_LIBUSB_DEVICE_HANDLE_H_