From 11f7766ab4f92ee8ad3a9ddb3d014ae730972d22 Mon Sep 17 00:00:00 2001 From: edouard Date: Sun, 20 Mar 2011 15:55:02 +0000 Subject: [PATCH] Raw HID plugin: improve initialization in case another plugin wants to use the USBMonitor. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@3049 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../src/plugins/rawhid/rawhidplugin.cpp | 17 ++++++++++------- .../src/plugins/rawhid/rawhidplugin.h | 4 +++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.cpp b/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.cpp index 85f76f243..5b9131820 100644 --- a/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.cpp +++ b/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.cpp @@ -40,14 +40,15 @@ // ********************************************************************** RawHIDConnection::RawHIDConnection() - : m_usbMonitor(this) { //added by andrew RawHidHandle = NULL; enablePolling = true; - connect(&m_usbMonitor, SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(onDeviceConnected())); - connect(&m_usbMonitor, SIGNAL(deviceRemoved(USBPortInfo)), this, SLOT(onDeviceDisconnected())); + m_usbMonitor = USBMonitor::instance(); + + connect(m_usbMonitor, SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(onDeviceConnected())); + connect(m_usbMonitor, SIGNAL(deviceRemoved(USBPortInfo)), this, SLOT(onDeviceDisconnected())); } @@ -56,9 +57,6 @@ RawHIDConnection::~RawHIDConnection() if (RawHidHandle) if (RawHidHandle->isOpen()) RawHidHandle->close(); - - m_usbMonitor.quit(); - m_usbMonitor.wait(500); } /** @@ -85,7 +83,7 @@ QStringList RawHIDConnection::availableDevices() { QStringList devices; - QList portsList = m_usbMonitor.availableDevices(USBMonitor::idVendor_OpenPilot, -1, -1,USBMonitor::Running); + QList portsList = m_usbMonitor->availableDevices(USBMonitor::idVendor_OpenPilot, -1, -1,USBMonitor::Running); // We currently list devices by their serial number foreach(USBPortInfo prt, portsList) { devices.append(prt.serialNumber); @@ -155,6 +153,8 @@ RawHIDPlugin::RawHIDPlugin() RawHIDPlugin::~RawHIDPlugin() { + m_usbMonitor->quit(); + m_usbMonitor->wait(500); } @@ -172,6 +172,9 @@ bool RawHIDPlugin::initialize(const QStringList & arguments, QString * errorStri Q_UNUSED(arguments); Q_UNUSED(errorString); + // We have to create the USB Monitor here: + m_usbMonitor = new USBMonitor(this); + return true; } diff --git a/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.h b/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.h index dea3f1668..8e1f7b244 100644 --- a/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.h +++ b/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.h @@ -76,7 +76,7 @@ private: protected: QMutex m_enumMutex; - USBMonitor m_usbMonitor; + USBMonitor* m_usbMonitor; bool m_deviceOpened; }; @@ -93,6 +93,8 @@ public: virtual void extensionsInitialized(); private: RawHIDConnection *hidConnection; + USBMonitor* m_usbMonitor; + }; #endif // RAWHIDPLUGIN_H