dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
connectionmanager.h
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  *
28  * Additional note on redistribution: The copyright and license notices above
29  * must be maintained in each individual source file that is a derivative work
30  * of this source file; otherwise redistribution is prohibited.
31  */
32 
33 #ifndef CONNECTIONMANAGER_H
34 #define CONNECTIONMANAGER_H
35 
36 #include "QWidget"
37 #include "mainwindow.h"
38 #include "generalsettings.h"
39 #include "telemetrymonitorwidget.h"
40 #include <coreplugin/iconnection.h>
41 #include <QtCore/QVector>
42 #include <QtCore/QIODevice>
43 #include <QtCore/QLinkedList>
44 #include <QPushButton>
45 #include <QComboBox>
46 #include <QPointer>
47 #include <QMessageBox>
48 
49 #include "core_global.h"
50 #include <QTimer>
51 
52 QT_BEGIN_NAMESPACE
53 class QTabWidget;
54 QT_END_NAMESPACE
55 
56 namespace Core {
57 
58 class IConnection;
59 class IDevice;
60 
61 namespace Internal {
62  class MainWindow;
63 } // namespace Internal
64 
66 {
67 public:
69  : connection(c)
70  , device(d)
71  {
72  }
73 
75  : connection(NULL)
76  {
77  }
78 
79  QString getConName()
80  {
81  if (connection == NULL || device.isNull())
82  return "";
83  return connection->shortName() + ": " + device->getDisplayName();
84  }
85 
86  bool operator==(const DevListItem &rhs)
87  {
88  return connection == rhs.connection && device == rhs.device;
89  }
90 
91  bool operator!=(const DevListItem &rhs) { return !(this == &rhs); }
92 
94  QPointer<IDevice> device;
95 };
96 
97 class CORE_EXPORT ConnectionManager : public QWidget
98 {
99  Q_OBJECT
100 
101 public:
102  ConnectionManager(Internal::MainWindow *mainWindow, QTabWidget *modeStack);
103  virtual ~ConnectionManager();
104 
105  void init();
106 
107  QIODevice *getCurrentConnection() { return m_ioDev; }
108  DevListItem getCurrentDevice() { return m_connectionDevice; }
109  DevListItem findDevice(const QString &devName);
110 
111  QLinkedList<DevListItem> getAvailableDevices() { return m_devList; }
112 
113  bool isConnected() { return m_ioDev != nullptr; }
114 
115  bool connectDevice(DevListItem device);
116  bool disconnectDevice();
117  void suspendPolling();
118  void resumePolling();
119  TelemetryMonitorWidget *getTelemetryMonitorWidget() { return m_monitorWidget; }
120  bool getAutoconnect();
121 
122 protected:
123  void updateConnectionList(IConnection *connection);
124  void registerDevice(IConnection *conn, IDevice *device);
125  void updateConnectionDropdown();
126 
127 signals:
128  void deviceConnected(QIODevice *device);
129  void deviceAboutToDisconnect();
130  void deviceDisconnected();
131  void availableDevicesChanged(const QLinkedList<Core::DevListItem> devices);
132 
133 public slots:
134  void telemetryConnected();
135  void telemetryDisconnected();
136  void telemetryUpdated(double txRate, double rxRate);
137 
138 private slots:
139  void objectAdded(QObject *obj);
140  void aboutToRemoveObject(QObject *obj);
141 
142  void onConnectClicked();
143  void devChanged(IConnection *connection);
144 
145  void onConnectionDestroyed(QObject *obj);
146  void connectionsCallBack(); // used to call devChange after all the plugins are loaded
147  void reconnectSlot();
148  void reconnectCheckSlot();
149 
150 protected:
151  QComboBox *m_availableDevList;
152  QPushButton *m_connectBtn;
153  QLinkedList<DevListItem> m_devList;
155 
156  // tx/rx telemetry monitor
158 
159  // currently connected connection plugin
161 
162  // Last thing the user tried to connect to manually
164 
165  // currently connected QIODevice
166  QIODevice *m_ioDev;
167 
168 private:
169  bool connectDevice();
170  bool polling;
171  Internal::MainWindow *m_mainWindow;
172  QList<IConnection *> connectionBackup;
173  QTimer *reconnect;
174  QTimer *reconnectCheck;
175 
176  void connectDeviceFailed(DevListItem &device);
177 };
178 
179 } // namespace Core
180 
181 #endif // CONNECTIONMANAGER_H
QList< IConnection * > m_connectionsList
QIODevice * getCurrentConnection()
TelemetryMonitorWidget * getTelemetryMonitorWidget()
QLinkedList< DevListItem > m_devList
bool operator!=(const DevListItem &rhs)
QLinkedList< DevListItem > getAvailableDevices()
bool operator==(const DevListItem &rhs)
IPConnection * connection
IConnection * connection
QPointer< IDevice > device
DevListItem(IConnection *c, IDevice *d)
Definition: icore.h:39
TelemetryMonitorWidget * m_monitorWidget
virtual QString shortName()
Definition: iconnection.h:71