LinkConfiguration.cc 4.06 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"
dogmaphobic's avatar
dogmaphobic committed
18
#ifndef __ios__
19
#include "SerialLink.h"
dogmaphobic's avatar
dogmaphobic committed
20
#endif
21
#include "UDPLink.h"
22
#include "TCPLink.h"
dogmaphobic's avatar
dogmaphobic committed
23
#ifndef __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)
Don Gagne's avatar
Don Gagne committed
36 37
    : _link(NULL)
    , _name(name)
dogmaphobic's avatar
dogmaphobic committed
38
    , _dynamic(false)
39
    , _autoConnect(false)
40 41
{
    _name = name;
Don Gagne's avatar
Don Gagne committed
42 43 44
    if (_name.isEmpty()) {
        qWarning() << "Internal error";
    }
45 46 47 48
}

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

void LinkConfiguration::copyFrom(LinkConfiguration* source)
{
    Q_ASSERT(source != NULL);
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
}

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

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

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

void LinkConfiguration::setLink(LinkInterface* link)
{
    _link = link;
    emit linkChanged(link);
}