LinkConfiguration.cc 3.99 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10

#include "LinkConfiguration.h"
Gus Grubba's avatar
Gus Grubba committed
11
#ifndef NO_SERIAL_LINK
12
#include "SerialLink.h"
dogmaphobic's avatar
dogmaphobic committed
13
#endif
14
#include "UDPLink.h"
15
#include "TCPLink.h"
Don Gagne's avatar
Don Gagne committed
16
#include "LogReplayLink.h"
dogmaphobic's avatar
dogmaphobic committed
17
#ifdef QGC_ENABLE_BLUETOOTH
dogmaphobic's avatar
dogmaphobic committed
18 19
#include "BluetoothLink.h"
#endif
20
#ifdef QT_DEBUG
21
#include "MockLink.h"
22
#endif
23 24 25 26

#define LINK_SETTING_ROOT "LinkConfigurations"

LinkConfiguration::LinkConfiguration(const QString& name)
27 28 29 30
    : _name         (name)
    , _dynamic      (false)
    , _autoConnect  (false)
    , _highLatency  (false)
31 32
{
    _name = name;
Don Gagne's avatar
Don Gagne committed
33 34 35
    if (_name.isEmpty()) {
        qWarning() << "Internal error";
    }
36 37 38 39
}

LinkConfiguration::LinkConfiguration(LinkConfiguration* copy)
{
40
    _link       = copy->_link;
dogmaphobic's avatar
dogmaphobic committed
41 42
    _name       = copy->name();
    _dynamic    = copy->isDynamic();
43
    _autoConnect= copy->isAutoConnect();
44
    _highLatency= copy->isHighLatency();
45 46 47 48 49
    Q_ASSERT(!_name.isEmpty());
}

void LinkConfiguration::copyFrom(LinkConfiguration* source)
{
50 51
    Q_ASSERT(source != nullptr);
    _link       = source->_link;
dogmaphobic's avatar
dogmaphobic committed
52 53
    _name       = source->name();
    _dynamic    = source->isDynamic();
54
    _autoConnect= source->isAutoConnect();
55
    _highLatency= source->isHighLatency();
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
}

/*!
  Where the settings are saved
  @return The root path of the setting.
*/
const QString LinkConfiguration::settingsRoot()
{
    return QString(LINK_SETTING_ROOT);
}

/*!
  Configuration Factory
  @return A new instance of the given type
*/
LinkConfiguration* LinkConfiguration::createSettings(int type, const QString& name)
{
73
    LinkConfiguration* config = nullptr;
74
    switch(type) {
Gus Grubba's avatar
Gus Grubba committed
75
#ifndef NO_SERIAL_LINK
76 77 78
        case LinkConfiguration::TypeSerial:
            config = new SerialConfiguration(name);
            break;
dogmaphobic's avatar
dogmaphobic committed
79
#endif
80 81 82
        case LinkConfiguration::TypeUdp:
            config = new UDPConfiguration(name);
            break;
83 84 85
        case LinkConfiguration::TypeTcp:
            config = new TCPConfiguration(name);
            break;
dogmaphobic's avatar
dogmaphobic committed
86
#ifdef QGC_ENABLE_BLUETOOTH
dogmaphobic's avatar
dogmaphobic committed
87 88 89 90
    case LinkConfiguration::TypeBluetooth:
        config = new BluetoothConfiguration(name);
        break;
#endif
Don Gagne's avatar
Don Gagne committed
91 92 93
        case LinkConfiguration::TypeLogReplay:
            config = new LogReplayLinkConfiguration(name);
            break;
94
#ifdef QT_DEBUG
95 96 97
        case LinkConfiguration::TypeMock:
            config = new MockConfiguration(name);
            break;
98
#endif
99 100 101 102 103 104 105 106 107 108
    }
    return config;
}

/*!
  Duplicate link settings
  @return A new copy of the given settings instance
*/
LinkConfiguration* LinkConfiguration::duplicateSettings(LinkConfiguration* source)
{
109
    LinkConfiguration* dupe = nullptr;
110
    switch(source->type()) {
Gus Grubba's avatar
Gus Grubba committed
111
#ifndef NO_SERIAL_LINK
112
        case TypeSerial:
113
            dupe = new SerialConfiguration(qobject_cast<SerialConfiguration*>(source));
114
            break;
dogmaphobic's avatar
dogmaphobic committed
115
#endif
116
        case TypeUdp:
117
            dupe = new UDPConfiguration(qobject_cast<UDPConfiguration*>(source));
118
            break;
119
        case TypeTcp:
120
            dupe = new TCPConfiguration(qobject_cast<TCPConfiguration*>(source));
121
            break;
dogmaphobic's avatar
dogmaphobic committed
122 123
#ifdef QGC_ENABLE_BLUETOOTH
        case TypeBluetooth:
124
            dupe = new BluetoothConfiguration(qobject_cast<BluetoothConfiguration*>(source));
dogmaphobic's avatar
dogmaphobic committed
125
            break;
dogmaphobic's avatar
dogmaphobic committed
126
#endif
Don Gagne's avatar
Don Gagne committed
127
        case TypeLogReplay:
128
            dupe = new LogReplayLinkConfiguration(qobject_cast<LogReplayLinkConfiguration*>(source));
Don Gagne's avatar
Don Gagne committed
129
            break;
130
#ifdef QT_DEBUG
131
        case TypeMock:
132
            dupe = new MockConfiguration(qobject_cast<MockConfiguration*>(source));
133
            break;
134
#endif
135 136
        case TypeLast:
            break;
137 138 139
    }
    return dupe;
}
Don Gagne's avatar
Don Gagne committed
140 141 142 143 144 145 146

void LinkConfiguration::setName(const QString name)
{
    _name = name;
    emit nameChanged(name);
}

147
void LinkConfiguration::setLink(SharedLinkInterfacePtr link)
Don Gagne's avatar
Don Gagne committed
148
{
149 150
    _link = link;
    emit linkChanged();
Don Gagne's avatar
Don Gagne committed
151
}