LinkConfiguration.cc 4.23 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"
Gus Grubba's avatar
Gus Grubba committed
23
#if !defined(__mobile__)
Don Gagne's avatar
Don Gagne committed
24
#include "LogReplayLink.h"
dogmaphobic's avatar
dogmaphobic committed
25
#endif
dogmaphobic's avatar
dogmaphobic committed
26
#ifdef QGC_ENABLE_BLUETOOTH
dogmaphobic's avatar
dogmaphobic committed
27 28
#include "BluetoothLink.h"
#endif
29
#ifdef QT_DEBUG
30
#include "MockLink.h"
31
#endif
32 33 34 35

#define LINK_SETTING_ROOT "LinkConfigurations"

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

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

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

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

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

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

void LinkConfiguration::setLink(LinkInterface* link)
{
163 164 165 166
    if(_link != link) {
        _link = link;
        emit linkChanged(link);
    }
Don Gagne's avatar
Don Gagne committed
167
}