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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* AsyncPluginImpl.h
* The asynchronous libusb implementation.
* Copyright (C) 2014 Simon Newton
*/
#ifndef PLUGINS_USBDMX_ASYNCPLUGINIMPL_H_
#define PLUGINS_USBDMX_ASYNCPLUGINIMPL_H_
#include <libusb.h>
#if HAVE_CONFIG_H
#include <config.h>
#endif // HAVE_CONFIG_H
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "libs/usb/Types.h"
#include "libs/usb/HotplugAgent.h"
#include "ola/base/Macro.h"
#include "ola/thread/Future.h"
#include "olad/Preferences.h"
#include "plugins/usbdmx/PluginImplInterface.h"
#include "plugins/usbdmx/SyncronizedWidgetObserver.h"
#include "plugins/usbdmx/WidgetFactory.h"
namespace ola {
namespace usb {
class LibUsbThread;
class AsyncronousLibUsbAdaptor;
} // namespace usb
class Device;
namespace plugin {
namespace usbdmx {
/**
* @brief The asynchronous libusb implementation.
*/
class AsyncPluginImpl: public PluginImplInterface, public WidgetObserver {
public:
/**
* @brief Create a new AsyncPluginImpl.
* @param plugin_adaptor The PluginAdaptor to use, ownership is not
* transferred.
* @param plugin The parent Plugin object which is used when creating
* devices.
* @param debug_level the debug level to use for libusb.
* @param preferences The Preferences container used by the plugin
*/
AsyncPluginImpl(PluginAdaptor *plugin_adaptor,
Plugin *plugin,
unsigned int debug_level,
Preferences *preferences);
~AsyncPluginImpl();
bool Start();
bool Stop();
// These are all run in the main SelectServer thread.
bool NewWidget(class AnymauDMX *widget);
bool NewWidget(class DMXCProjectsNodleU1 *widget);
bool NewWidget(class EurolitePro *widget);
bool NewWidget(ola::usb::JaRuleWidget *widget);
bool NewWidget(class ScanlimeFadecandy *widget);
bool NewWidget(class Sunlite *widget);
bool NewWidget(class VellemanK8062 *widget);
private:
typedef std::vector<class WidgetFactory*> WidgetFactories;
typedef std::map<ola::usb::USBDeviceID, class DeviceState*> USBDeviceMap;
PluginAdaptor* const m_plugin_adaptor;
Plugin* const m_plugin;
const unsigned int m_debug_level;
std::auto_ptr<ola::usb::HotplugAgent> m_agent;
Preferences* const m_preferences;
SyncronizedWidgetObserver m_widget_observer;
ola::usb::AsyncronousLibUsbAdaptor *m_usb_adaptor; // not owned
WidgetFactories m_widget_factories;
USBDeviceMap m_device_map;
void DeviceEvent(ola::usb::HotplugAgent::EventType event,
struct libusb_device *device);
void SetupUSBDevice(libusb_device *device);
template <typename Widget>
bool StartAndRegisterDevice(Widget *widget, Device *device);
void ShutdownDevice(Device *device, ola::thread::Future<void> *f);
DISALLOW_COPY_AND_ASSIGN(AsyncPluginImpl);
};
} // namespace usbdmx
} // namespace plugin
} // namespace ola
#endif // PLUGINS_USBDMX_ASYNCPLUGINIMPL_H_
|