QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
LinkConfiguration.cc
Go to the documentation of this file.
1#include "LinkConfiguration.h"
3#ifndef QGC_NO_SERIAL_LINK
4#include "SerialLink.h"
5#endif
6#include "UDPLink.h"
7#include "TCPLink.h"
8#include "LogReplayLink.h"
9#include "BluetoothLink.h"
10#ifdef QT_DEBUG
11#include "MockLink.h"
12#endif
13
14QGC_LOGGING_CATEGORY(LinkConfigurationLog, "Comms.LinkConfiguration")
15
16LinkConfiguration::LinkConfiguration(const QString &name, QObject *parent)
17 : QObject(parent)
18 , _name(name)
19{
20 qCDebug(LinkConfigurationLog) << this;
21}
22
23LinkConfiguration::LinkConfiguration(const LinkConfiguration *copy, QObject *parent)
24 : QObject(parent)
25 , _link(copy->_link)
26 , _name(copy->name())
27 , _dynamic(copy->isDynamic())
28 , _autoConnect(copy->isAutoConnect())
29 , _highLatency(copy->isHighLatency())
30{
31 qCDebug(LinkConfigurationLog) << this;
32
33 Q_ASSERT(!_name.isEmpty());
34}
35
36LinkConfiguration::~LinkConfiguration()
37{
38 qCDebug(LinkConfigurationLog) << this;
39}
40
41void LinkConfiguration::copyFrom(const LinkConfiguration *source)
42{
43 Q_ASSERT(source);
44
45 setLink(source->_link.lock());
46 setName(source->name());
47 setDynamic(source->isDynamic());
48 setAutoConnect(source->isAutoConnect());
49 setHighLatency(source->isHighLatency());
50}
51
52LinkConfiguration *LinkConfiguration::createSettings(int type, const QString &name)
53{
54 LinkConfiguration *config = nullptr;
55
56 switch (static_cast<LinkType>(type)) {
57#ifndef QGC_NO_SERIAL_LINK
58 case TypeSerial:
59 config = new SerialConfiguration(name);
60 break;
61#endif
62 case TypeUdp:
63 config = new UDPConfiguration(name);
64 break;
65 case TypeTcp:
66 config = new TCPConfiguration(name);
67 break;
68 case TypeBluetooth:
69 config = new BluetoothConfiguration(name);
70 break;
71 case TypeLogReplay:
72 config = new LogReplayConfiguration(name);
73 break;
74#ifdef QT_DEBUG
75 case TypeMock:
76 config = new MockConfiguration(name);
77 break;
78#endif
79 case TypeLast:
80 default:
81 break;
82 }
83
84 return config;
85}
86
87LinkConfiguration *LinkConfiguration::duplicateSettings(const LinkConfiguration *source)
88{
89 LinkConfiguration *dupe = nullptr;
90
91 switch(source->type()) {
92#ifndef QGC_NO_SERIAL_LINK
93 case TypeSerial:
94 dupe = new SerialConfiguration(qobject_cast<const SerialConfiguration*>(source));
95 break;
96#endif
97 case TypeUdp:
98 dupe = new UDPConfiguration(qobject_cast<const UDPConfiguration*>(source));
99 break;
100 case TypeTcp:
101 dupe = new TCPConfiguration(qobject_cast<const TCPConfiguration*>(source));
102 break;
103 case TypeBluetooth:
104 dupe = new BluetoothConfiguration(qobject_cast<const BluetoothConfiguration*>(source));
105 break;
106 case TypeLogReplay:
107 dupe = new LogReplayConfiguration(qobject_cast<const LogReplayConfiguration*>(source));
108 break;
109#ifdef QT_DEBUG
110 case TypeMock:
111 dupe = new MockConfiguration(qobject_cast<const MockConfiguration*>(source));
112 break;
113#endif
114 case TypeLast:
115 default:
116 break;
117 }
118
119 return dupe;
120}
121
122void LinkConfiguration::setName(const QString &name)
123{
124 if (name != _name) {
125 _name = name;
126 emit nameChanged(name);
127 }
128}
129
130void LinkConfiguration::setLink(const SharedLinkInterfacePtr link)
131{
132 if (link.get() != this->link()) {
133 _link = link;
134 emit linkChanged();
135
136 if (link.get()) {
137 (void) connect(link.get(), &LinkInterface::disconnected, this, &LinkConfiguration::linkChanged, Qt::QueuedConnection);
138 }
139 }
140}
141
142void LinkConfiguration::setDynamic(bool dynamic)
143{
144 if (dynamic != _dynamic) {
145 _dynamic = dynamic;
146 emit dynamicChanged();
147 }
148}
149
150void LinkConfiguration::setAutoConnect(bool autoc)
151{
152 if (autoc != _autoConnect) {
153 _autoConnect = autoc;
154 emit autoConnectChanged();
155 }
156}
157
158void LinkConfiguration::setHighLatency(bool hl)
159{
160 if (hl != _highLatency) {
161 _highLatency = hl;
162 emit highLatencyChanged();
163 }
164}
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Interface holding link specific settings.
std::weak_ptr< LinkInterface > _link
Link currently using this configuration (if any)
void autoConnectChanged()
void highLatencyChanged()
void nameChanged(const QString &name)
void disconnected()