2011-02-26 04:19:24 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file connectionmanager.h
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup CorePlugin Core Plugin
|
|
|
|
* @{
|
|
|
|
* @brief The Core GCS plugin
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* 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 3 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 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.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONNECTIONMANAGER_H
|
|
|
|
#define CONNECTIONMANAGER_H
|
|
|
|
|
2011-05-31 16:29:53 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "generalsettings.h"
|
2012-09-08 21:04:59 +02:00
|
|
|
#include <coreplugin/iconnection.h>
|
2013-06-09 17:28:28 +02:00
|
|
|
#include <QWidget>
|
2011-02-26 04:19:24 +01:00
|
|
|
#include <QtCore/QVector>
|
|
|
|
#include <QtCore/QIODevice>
|
|
|
|
#include <QtCore/QLinkedList>
|
2013-09-15 23:06:25 +02:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QComboBox>
|
2011-02-26 04:19:24 +01:00
|
|
|
|
|
|
|
#include "core_global.h"
|
2012-08-17 00:30:31 +02:00
|
|
|
#include <QTimer>
|
2011-02-26 04:19:24 +01:00
|
|
|
|
|
|
|
namespace Core {
|
2013-05-19 16:37:30 +02:00
|
|
|
class IConnection;
|
2011-02-26 04:19:24 +01:00
|
|
|
|
|
|
|
namespace Internal {
|
2013-05-19 16:37:30 +02:00
|
|
|
class MainWindow;
|
2011-02-26 04:19:24 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
class DevListItem {
|
2012-09-08 22:14:06 +02:00
|
|
|
public:
|
2012-09-08 22:59:54 +02:00
|
|
|
DevListItem(IConnection *c, IConnection::device d) :
|
2013-05-19 16:37:30 +02:00
|
|
|
connection(c), device(d) {}
|
2012-09-08 22:59:54 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
DevListItem() : connection(NULL) {}
|
2012-09-08 22:14:06 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
QString getConName()
|
|
|
|
{
|
|
|
|
if (connection == NULL) {
|
2012-09-08 22:14:06 +02:00
|
|
|
return "";
|
2013-05-19 16:37:30 +02:00
|
|
|
}
|
2012-09-08 22:14:06 +02:00
|
|
|
return connection->shortName() + ": " + device.displayName;
|
|
|
|
}
|
2012-09-08 22:45:08 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
bool operator==(const DevListItem &rhs)
|
|
|
|
{
|
2012-09-08 22:45:08 +02:00
|
|
|
return connection == rhs.connection && device == rhs.device;
|
|
|
|
}
|
2012-09-08 22:59:54 +02:00
|
|
|
|
2011-02-26 04:19:24 +01:00
|
|
|
IConnection *connection;
|
2012-09-08 22:59:54 +02:00
|
|
|
IConnection::device device;
|
2011-02-26 04:19:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
class CORE_EXPORT ConnectionManager : public QWidget {
|
2011-02-26 04:19:24 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2013-04-28 19:41:15 +02:00
|
|
|
ConnectionManager(Internal::MainWindow *mainWindow);
|
2011-02-26 04:19:24 +01:00
|
|
|
virtual ~ConnectionManager();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
QIODevice *getCurrentConnection()
|
|
|
|
{
|
|
|
|
return m_ioDev;
|
|
|
|
}
|
|
|
|
DevListItem getCurrentDevice()
|
|
|
|
{
|
|
|
|
return m_connectionDevice;
|
|
|
|
}
|
2012-09-13 22:11:37 +02:00
|
|
|
DevListItem findDevice(const QString &devName);
|
2012-07-17 01:24:22 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
QLinkedList<DevListItem> getAvailableDevices()
|
|
|
|
{
|
|
|
|
return m_devList;
|
|
|
|
}
|
2012-07-17 01:24:22 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
bool isConnected()
|
|
|
|
{
|
|
|
|
return m_ioDev != 0;
|
|
|
|
}
|
2012-07-17 01:24:22 +02:00
|
|
|
|
2013-04-28 19:41:15 +02:00
|
|
|
void addWidget(QWidget *widget);
|
|
|
|
|
2012-09-13 22:11:37 +02:00
|
|
|
bool connectDevice(DevListItem device);
|
2011-02-26 04:19:24 +01:00
|
|
|
bool disconnectDevice();
|
|
|
|
void suspendPolling();
|
|
|
|
void resumePolling();
|
|
|
|
|
|
|
|
protected:
|
2012-09-08 19:53:00 +02:00
|
|
|
void updateConnectionList(IConnection *connection);
|
2012-09-08 21:04:59 +02:00
|
|
|
void registerDevice(IConnection *conn, IConnection::device device);
|
2012-09-08 22:14:06 +02:00
|
|
|
void updateConnectionDropdown();
|
2011-02-26 04:19:24 +01:00
|
|
|
|
|
|
|
signals:
|
2012-09-13 22:11:37 +02:00
|
|
|
void deviceConnected(QIODevice *device);
|
2011-03-25 11:59:24 +01:00
|
|
|
void deviceAboutToDisconnect();
|
2012-09-16 15:14:47 +02:00
|
|
|
void deviceDisconnected();
|
2012-09-13 22:11:37 +02:00
|
|
|
void availableDevicesChanged(const QLinkedList<Core::DevListItem> devices);
|
2011-02-26 04:19:24 +01:00
|
|
|
|
2012-08-03 01:11:18 +02:00
|
|
|
public slots:
|
2012-08-14 21:35:53 +02:00
|
|
|
void telemetryConnected();
|
|
|
|
void telemetryDisconnected();
|
2012-08-03 01:11:18 +02:00
|
|
|
|
2011-02-26 04:19:24 +01:00
|
|
|
private slots:
|
|
|
|
void objectAdded(QObject *obj);
|
|
|
|
void aboutToRemoveObject(QObject *obj);
|
|
|
|
|
2012-07-30 13:58:36 +02:00
|
|
|
void onConnectClicked();
|
2013-03-12 22:36:35 +01:00
|
|
|
void onDeviceSelectionChanged(int index);
|
2011-02-26 04:19:24 +01:00
|
|
|
void devChanged(IConnection *connection);
|
|
|
|
|
2012-09-12 12:09:30 +02:00
|
|
|
void onConnectionDestroyed(QObject *obj);
|
2013-05-19 16:37:30 +02:00
|
|
|
void connectionsCallBack(); // used to call devChange after all the plugins are loaded
|
2012-08-14 21:35:53 +02:00
|
|
|
void reconnectSlot();
|
|
|
|
void reconnectCheckSlot();
|
|
|
|
|
2011-02-26 04:19:24 +01:00
|
|
|
protected:
|
|
|
|
QComboBox *m_availableDevList;
|
|
|
|
QPushButton *m_connectBtn;
|
2012-09-08 22:45:08 +02:00
|
|
|
QLinkedList<DevListItem> m_devList;
|
2013-05-19 16:37:30 +02:00
|
|
|
QList<IConnection *> m_connectionsList;
|
2011-02-26 04:19:24 +01:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
// currently connected connection plugin
|
2012-09-08 22:45:08 +02:00
|
|
|
DevListItem m_connectionDevice;
|
2011-02-26 04:19:24 +01:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
// currently connected QIODevice
|
2011-02-26 04:19:24 +01:00
|
|
|
QIODevice *m_ioDev;
|
2011-03-04 21:42:47 +01:00
|
|
|
|
|
|
|
private:
|
2013-05-19 16:37:30 +02:00
|
|
|
bool connectDevice();
|
2012-09-09 02:06:03 +02:00
|
|
|
bool polling;
|
2012-07-17 01:24:22 +02:00
|
|
|
Internal::MainWindow *m_mainWindow;
|
|
|
|
QList <IConnection *> connectionBackup;
|
2012-08-14 21:35:53 +02:00
|
|
|
QTimer *reconnect;
|
|
|
|
QTimer *reconnectCheck;
|
2011-02-26 04:19:24 +01:00
|
|
|
};
|
2013-05-19 16:37:30 +02:00
|
|
|
} // namespace Core
|
2011-02-26 04:19:24 +01:00
|
|
|
|
|
|
|
#endif // CONNECTIONMANAGER_H
|