Open Lighting Architecture: libs/usb/HotplugAgent.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
HotplugAgent.h
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 * HotplugAgent.h
17 * Handles auto-detection of USB devices.
18 * Copyright (C) 2015 Simon Newton
19 */
20
21#ifndef LIBS_USB_HOTPLUGAGENT_H_
22#define LIBS_USB_HOTPLUGAGENT_H_
23
24#include <libusb.h>
25#include <ola/Callback.h>
26#include <ola/thread/PeriodicThread.h>
27
28#include <map>
29#include <memory>
30
31#include "libs/usb/LibUsbAdaptor.h"
32#include "libs/usb/LibUsbThread.h"
33#include "libs/usb/Types.h"
34
35namespace ola {
36namespace usb {
37
45 class HotplugAgent {
46 public:
47 enum EventType {
48 DEVICE_ADDED,
49 DEVICE_REMOVED,
50 };
51
60 typedef ola::Callback2<void, EventType, struct libusb_device*>
61 NotificationCallback;
62
69 HotplugAgent(NotificationCallback* notification_cb,
70 int debug_level);
71
77 ~HotplugAgent();
78
86 AsyncronousLibUsbAdaptor *GetUSBAdaptor() const;
87
92 bool Init();
93
99 bool Start();
100
106 void HaltNotifications();
107
115 bool Stop();
116
117 #ifdef HAVE_LIBUSB_HOTPLUG_API
128 void HotPlugEvent(struct libusb_device *dev,
129 libusb_hotplug_event event);
130 #endif // HAVE_LIBUSB_HOTPLUG_API
131
132 private:
133 typedef std::map<USBDeviceID, struct libusb_device*> DeviceMap;
134
135 std::auto_ptr<NotificationCallback> const m_notification_cb;
136 const int m_debug_level;
137 bool m_use_hotplug;
138 libusb_context *m_context;
139 std::auto_ptr<ola::usb::LibUsbThread> m_usb_thread;
140 std::auto_ptr<ola::usb::AsyncronousLibUsbAdaptor> m_usb_adaptor;
141 std::auto_ptr<ola::thread::PeriodicThread> m_scanner_thread;
142
143 ola::thread::Mutex m_mutex;
144 bool m_suppress_hotplug_events; // GUARDED_BY(m_mutex);
145
146 // In hotplug mode, this is guarded by m_mutex while
147 // m_suppress_hotplug_events is false.
148 // In non-hotplug mode, this is only accessed from the scanner thread, unless
149 // the thread is no longer running in which case it's accessed from the main
150 // thread during cleanup
151 DeviceMap m_devices;
152
153 bool HotplugSupported();
154 bool ScanUSBDevices();
155
156 HotplugAgent(const HotplugAgent &) = delete;
157 const HotplugAgent &operator=(const HotplugAgent &) = delete;
158};
159} // namespace usb
160} // namespace ola
161#endif // LIBS_USB_HOTPLUGAGENT_H_
Callback.h
ola::Callback2
A 2 argument callback which can be called multiple times.
Definition Callback.h:1895
ola::plugin::usbdmx::HotplugAgent::HotplugAgent
HotplugAgent(NotificationCallback *notification_cb, int debug_level)
Create a new HotplugAgent.
Definition HotplugAgent.cpp:60
ola::thread::Mutex
Definition Mutex.h:41
ola::usb::AsyncronousLibUsbAdaptor
A LibUsbAdaptor for use with Asyncronous widgets.
Definition LibUsbAdaptor.h:564
ola::usb::HotplugAgent::Stop
bool Stop()
Stop the HotplugAgent.
Definition HotplugAgent.cpp:144
ola::usb::HotplugAgent::Start
bool Start()
Start the hotplug agent.
Definition HotplugAgent.cpp:110
ola::usb::HotplugAgent::HotplugAgent
HotplugAgent(NotificationCallback *notification_cb, int debug_level)
Create a new HotplugAgent.
Definition HotplugAgent.cpp:60
ola::usb::HotplugAgent::HaltNotifications
void HaltNotifications()
Prevent any further notifications from occurring.
Definition HotplugAgent.cpp:129
ola::usb::HotplugAgent::EventType
EventType
Definition HotplugAgent.h:47
ola::usb::HotplugAgent::DEVICE_REMOVED
@ DEVICE_REMOVED
The device ws removed.
Definition HotplugAgent.h:49
ola::usb::HotplugAgent::DEVICE_ADDED
@ DEVICE_ADDED
The device was added.
Definition HotplugAgent.h:48
ola::usb::HotplugAgent::~HotplugAgent
~HotplugAgent()
Destructor.
Definition HotplugAgent.cpp:69
ola::usb::HotplugAgent::GetUSBAdaptor
AsyncronousLibUsbAdaptor * GetUSBAdaptor() const
Get the AsyncronousLibUsbAdaptor to use.
Definition HotplugAgent.cpp:75
ola::usb::HotplugAgent::Init
bool Init()
Initialize the hotplug agent.
Definition HotplugAgent.cpp:79
ola::usb::HotplugAgent::NotificationCallback
ola::Callback2< void, EventType, struct libusb_device * > NotificationCallback
Called when a USB device has been added or removed.
Definition HotplugAgent.h:61
ola::usb
USB Device drivers.
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44