Ocean
Loading...
Searching...
No Matches
system/usb/Manager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_SYSTEM_USB_MANAGER_H
9#define META_OCEAN_SYSTEM_USB_MANAGER_H
10
14
16#include "ocean/base/Thread.h"
17
18namespace Ocean
19{
20
21namespace System
22{
23
24namespace USB
25{
26
27/**
28 * This class implements a manager for USB devices.
29 * The manager holds an own context and can be used to enumerate all USB devices (on platforms allowing to discover devices).
30 * @ingroup systemusb
31 */
32class OCEAN_SYSTEM_USB_EXPORT Manager :
33 public Singleton<Manager>,
34 protected Thread
35{
36 friend class Singleton<Manager>;
37
38 public:
39
40 /**
41 * Enumerates all available USB devices.
42 * @param devices Resulting list of available USB devices
43 * @param deviceClass Optional USB class a device must have (can be an interface class) to be enumerated, -1 to enumerate all devices
44 * @return True, if succeeded
45 */
46 bool enumerateDevices(SharedDevices& devices, const int deviceClass = -1);
47
48 /**
49 * Finds a device by its name.
50 * @param deviceName The name of the USB device to find, must be valid
51 * @return The found device, nullptr if no such device exists
52 */
53 SharedDevice findDevice(const std::string& deviceName);
54
55 /**
56 * Returns the context of this manager.
57 * @return The manager's context
58 */
59 inline SharedContext context() const;
60
61 /**
62 * Explicitly releases the manager.
63 */
64 void release();
65
66 protected:
67
68 /**
69 * Creates a new manager with an own context.
70 */
72
73 /**
74 * Destructs the manager and releases connected resources.
75 */
76 ~Manager() override;
77
78 /**
79 * The manager's thread function.
80 */
81 void threadRun() override;
82
83 /**
84 * Libusb log callback function.
85 * @param context The libusb context sending the log
86 * @param level The log level
87 * @param message The log message
88 */
89 static void LIBUSB_CALL libLogCallback(libusb_context* context, enum libusb_log_level level, const char* message);
90
91 protected:
92
93 /// The manager's context.
95
96 /// The manager's lock.
98};
99
101{
102 return context_;
103}
104
105}
106
107}
108
109}
110
111#endif // META_OCEAN_SYSTEM_USB_MANAGER_H
This class implements a recursive lock object.
Definition Lock.h:31
This template class is the base class for all singleton objects.
Definition Singleton.h:71
This class implements a manager for USB devices.
Definition system/usb/Manager.h:35
SharedContext context() const
Returns the context of this manager.
Definition system/usb/Manager.h:100
Manager()
Creates a new manager with an own context.
void release()
Explicitly releases the manager.
Lock lock_
The manager's lock.
Definition system/usb/Manager.h:97
static void LIBUSB_CALL libLogCallback(libusb_context *context, enum libusb_log_level level, const char *message)
Libusb log callback function.
~Manager() override
Destructs the manager and releases connected resources.
bool enumerateDevices(SharedDevices &devices, const int deviceClass=-1)
Enumerates all available USB devices.
SharedContext context_
The manager's context.
Definition system/usb/Manager.h:94
void threadRun() override
The manager's thread function.
SharedDevice findDevice(const std::string &deviceName)
Finds a device by its name.
This class implements a thread.
Definition Thread.h:115
std::shared_ptr< Device > SharedDevice
Definition of a shared pointer holding a device.
Definition system/usb/Device.h:34
std::vector< SharedDevice > SharedDevices
Definition of a vector holding SharedDevice objects.
Definition system/usb/Device.h:41
std::shared_ptr< Context > SharedContext
Definition of a shared pointer holding a context.
Definition system/usb/Context.h:32
The namespace covering the entire Ocean framework.
Definition Accessor.h:15