LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / coreplugin / connectionmanager.h
blobb19cc7c5dcb65a386c0de34ec1e2e52a7e1d7130
1 /**
2 ******************************************************************************
4 * @file connectionmanager.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup CorePlugin Core Plugin
10 * @{
11 * @brief The Core GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef CONNECTIONMANAGER_H
30 #define CONNECTIONMANAGER_H
32 #include "mainwindow.h"
33 #include "generalsettings.h"
34 #include <coreplugin/iconnection.h>
35 #include <QWidget>
36 #include <QtCore/QVector>
37 #include <QtCore/QIODevice>
38 #include <QtCore/QLinkedList>
39 #include <QPushButton>
40 #include <QComboBox>
42 #include "core_global.h"
43 #include <QTimer>
45 namespace Core {
46 class IConnection;
48 namespace Internal {
49 class MainWindow;
50 } // namespace Internal
52 class DevListItem {
53 public:
54 DevListItem(IConnection *c, IConnection::device d) :
55 connection(c), device(d) {}
57 DevListItem() : connection(NULL) {}
59 QString getConName()
61 if (connection == NULL) {
62 return "";
64 return connection->shortName() + ": " + device.displayName;
67 bool operator==(const DevListItem &rhs)
69 return connection == rhs.connection && device == rhs.device;
72 IConnection *connection;
73 IConnection::device device;
77 class CORE_EXPORT ConnectionManager : public QWidget {
78 Q_OBJECT
80 public:
81 ConnectionManager(Internal::MainWindow *mainWindow);
82 virtual ~ConnectionManager();
84 void init();
86 DevListItem getCurrentDevice()
88 return m_connectionDevice;
90 DevListItem findDevice(const QString &devName);
92 QLinkedList<DevListItem> getAvailableDevices()
94 return m_devList;
97 bool isConnected()
99 return m_ioDev != 0;
102 void addWidget(QWidget *widget);
104 bool connectDevice(DevListItem device);
105 bool disconnectDevice();
106 void suspendPolling();
107 void resumePolling();
109 protected:
110 void updateConnectionList(IConnection *connection);
111 void registerDevice(IConnection *conn, IConnection::device device);
112 void updateConnectionDropdown();
114 signals:
115 void deviceConnected(QIODevice *device);
116 void deviceAboutToDisconnect();
117 void deviceDisconnected();
118 void availableDevicesChanged(const QLinkedList<Core::DevListItem> devices);
120 public slots:
121 void telemetryConnected();
122 void telemetryDisconnected();
124 private slots:
125 void objectAdded(QObject *obj);
126 void aboutToRemoveObject(QObject *obj);
128 void onConnectClicked();
129 void onDeviceSelectionChanged(int index);
130 void devChanged(IConnection *connection);
132 void onConnectionDestroyed(QObject *obj);
133 void connectionsCallBack(); // used to call devChange after all the plugins are loaded
134 void reconnectSlot();
135 void reconnectCheckSlot();
137 protected:
138 QComboBox *m_availableDevList;
139 QPushButton *m_connectBtn;
140 QLinkedList<DevListItem> m_devList;
141 QList<IConnection *> m_connectionsList;
143 // currently connected connection plugin
144 DevListItem m_connectionDevice;
146 // currently connected QIODevice
147 QIODevice *m_ioDev;
149 private:
150 bool connectDevice();
151 bool polling;
152 Internal::MainWindow *m_mainWindow;
153 QList <IConnection *> connectionBackup;
154 QTimer *reconnect;
155 QTimer *reconnectCheck;
157 } // namespace Core
159 #endif // CONNECTIONMANAGER_H