LinkConfiguration.cc 4.29 KB
Newer Older
1 2 3 4
/*=====================================================================

QGroundControl Open Source Ground Control Station

5
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

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

#include "LinkConfiguration.h"
dogmaphobic's avatar
dogmaphobic committed
31
#ifndef __ios__
32
#include "SerialLink.h"
dogmaphobic's avatar
dogmaphobic committed
33
#endif
34
#include "UDPLink.h"
35
#include "TCPLink.h"
dogmaphobic's avatar
dogmaphobic committed
36
#ifndef __mobile__
Don Gagne's avatar
Don Gagne committed
37
#include "LogReplayLink.h"
dogmaphobic's avatar
dogmaphobic committed
38
#endif
39

40
#ifdef QT_DEBUG
41
#include "MockLink.h"
42
#endif
43 44 45 46

#define LINK_SETTING_ROOT "LinkConfigurations"

LinkConfiguration::LinkConfiguration(const QString& name)
Don Gagne's avatar
Don Gagne committed
47 48
    : _link(NULL)
    , _name(name)
dogmaphobic's avatar
dogmaphobic committed
49
    , _dynamic(false)
50
    , _autoConnect(false)
51 52
{
    _name = name;
Don Gagne's avatar
Don Gagne committed
53 54 55
    if (_name.isEmpty()) {
        qWarning() << "Internal error";
    }
56 57 58 59
}

LinkConfiguration::LinkConfiguration(LinkConfiguration* copy)
{
Don Gagne's avatar
Don Gagne committed
60
    _link       = copy->link();
dogmaphobic's avatar
dogmaphobic committed
61 62
    _name       = copy->name();
    _dynamic    = copy->isDynamic();
63
    _autoConnect= copy->isAutoConnect();
64 65 66 67 68 69
    Q_ASSERT(!_name.isEmpty());
}

void LinkConfiguration::copyFrom(LinkConfiguration* source)
{
    Q_ASSERT(source != NULL);
Don Gagne's avatar
Don Gagne committed
70
    _link       = source->link();
dogmaphobic's avatar
dogmaphobic committed
71 72
    _name       = source->name();
    _dynamic    = source->isDynamic();
73
    _autoConnect= source->isAutoConnect();
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
}

/*!
  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
93
#ifndef __ios__
94 95 96
        case LinkConfiguration::TypeSerial:
            config = new SerialConfiguration(name);
            break;
dogmaphobic's avatar
dogmaphobic committed
97
#endif
98 99 100
        case LinkConfiguration::TypeUdp:
            config = new UDPConfiguration(name);
            break;
101 102 103
        case LinkConfiguration::TypeTcp:
            config = new TCPConfiguration(name);
            break;
dogmaphobic's avatar
dogmaphobic committed
104
#ifndef __mobile__
Don Gagne's avatar
Don Gagne committed
105 106 107
        case LinkConfiguration::TypeLogReplay:
            config = new LogReplayLinkConfiguration(name);
            break;
dogmaphobic's avatar
dogmaphobic committed
108
#endif
109
#ifdef QT_DEBUG
110 111 112
        case LinkConfiguration::TypeMock:
            config = new MockConfiguration(name);
            break;
113
#endif
114 115 116 117 118 119 120 121 122 123 124 125
    }
    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
126
#ifndef __ios__
127 128 129
        case TypeSerial:
            dupe = new SerialConfiguration(dynamic_cast<SerialConfiguration*>(source));
            break;
dogmaphobic's avatar
dogmaphobic committed
130
#endif
131 132 133
        case TypeUdp:
            dupe = new UDPConfiguration(dynamic_cast<UDPConfiguration*>(source));
            break;
134 135 136
        case TypeTcp:
            dupe = new TCPConfiguration(dynamic_cast<TCPConfiguration*>(source));
            break;
dogmaphobic's avatar
dogmaphobic committed
137
#ifndef __mobile__
Don Gagne's avatar
Don Gagne committed
138 139 140
        case TypeLogReplay:
            dupe = new LogReplayLinkConfiguration(dynamic_cast<LogReplayLinkConfiguration*>(source));
            break;
dogmaphobic's avatar
dogmaphobic committed
141
#endif
142
#ifdef QT_DEBUG
143 144 145
        case TypeMock:
            dupe = new MockConfiguration(dynamic_cast<MockConfiguration*>(source));
            break;
146
#endif
147 148 149
        case TypeLast:
        default:
            break;
150 151 152
    }
    return dupe;
}
Don Gagne's avatar
Don Gagne committed
153 154 155 156 157 158 159 160 161 162 163 164

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

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