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


/*!
    @file
       @brief Link specific configuration base class
       @author Gus Grubba <mavlink@grubba.com>
*/

#include "LinkConfiguration.h"
Gus Grubba's avatar
Gus Grubba committed
18
#ifndef NO_SERIAL_LINK
19
#include "SerialLink.h"
dogmaphobic's avatar
dogmaphobic committed
20
#endif
21
#include "UDPLink.h"
22
#include "TCPLink.h"
Don Gagne's avatar
Don Gagne committed
23
#include "LogReplayLink.h"
dogmaphobic's avatar
dogmaphobic committed
24
#ifdef QGC_ENABLE_BLUETOOTH
dogmaphobic's avatar
dogmaphobic committed
25 26
#include "BluetoothLink.h"
#endif
27
#ifdef QT_DEBUG
28
#include "MockLink.h"
29
#endif
30 31 32 33

#define LINK_SETTING_ROOT "LinkConfigurations"

LinkConfiguration::LinkConfiguration(const QString& name)
34
    : _link(nullptr)
Don Gagne's avatar
Don Gagne committed
35
    , _name(name)
dogmaphobic's avatar
dogmaphobic committed
36
    , _dynamic(false)
37
    , _autoConnect(false)
38
    , _highLatency(false)
39 40
{
    _name = name;
Don Gagne's avatar
Don Gagne committed
41 42 43
    if (_name.isEmpty()) {
        qWarning() << "Internal error";
    }
44 45 46 47
}

LinkConfiguration::LinkConfiguration(LinkConfiguration* copy)
{
Don Gagne's avatar
Don Gagne committed
48
    _link       = copy->link();
dogmaphobic's avatar
dogmaphobic committed
49 50
    _name       = copy->name();
    _dynamic    = copy->isDynamic();
51
    _autoConnect= copy->isAutoConnect();
52
    _highLatency= copy->isHighLatency();
53 54 55 56 57
    Q_ASSERT(!_name.isEmpty());
}

void LinkConfiguration::copyFrom(LinkConfiguration* source)
{
58
    Q_ASSERT(source != nullptr);
Don Gagne's avatar
Don Gagne committed
59
    _link       = source->link();
dogmaphobic's avatar
dogmaphobic committed
60 61
    _name       = source->name();
    _dynamic    = source->isDynamic();
62
    _autoConnect= source->isAutoConnect();
63
    _highLatency= source->isHighLatency();
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
}

/*!
  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)
{
81
    LinkConfiguration* config = nullptr;
82
    switch(type) {
Gus Grubba's avatar
Gus Grubba committed
83
#ifndef NO_SERIAL_LINK
84 85 86
        case LinkConfiguration::TypeSerial:
            config = new SerialConfiguration(name);
            break;
dogmaphobic's avatar
dogmaphobic committed
87
#endif
88 89 90
        case LinkConfiguration::TypeUdp:
            config = new UDPConfiguration(name);
            break;
91 92 93
        case LinkConfiguration::TypeTcp:
            config = new TCPConfiguration(name);
            break;
dogmaphobic's avatar
dogmaphobic committed
94
#ifdef QGC_ENABLE_BLUETOOTH
dogmaphobic's avatar
dogmaphobic committed
95 96 97 98
    case LinkConfiguration::TypeBluetooth:
        config = new BluetoothConfiguration(name);
        break;
#endif
Don Gagne's avatar
Don Gagne committed
99 100 101
        case LinkConfiguration::TypeLogReplay:
            config = new LogReplayLinkConfiguration(name);
            break;
102
#ifdef QT_DEBUG
103 104 105
        case LinkConfiguration::TypeMock:
            config = new MockConfiguration(name);
            break;
106
#endif
107 108 109 110 111 112 113 114 115 116
    }
    return config;
}

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

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

void LinkConfiguration::setLink(LinkInterface* link)
{
157 158 159 160
    if(_link != link) {
        _link = link;
        emit linkChanged(link);
    }
Don Gagne's avatar
Don Gagne committed
161
}