LinkConfiguration.h 6.58 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 31 32

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/>.

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

#ifndef LINKCONFIGURATION_H
#define LINKCONFIGURATION_H

#include <QSettings>

class LinkInterface;

/// Interface holding link specific settings.

Don Gagne's avatar
Don Gagne committed
33
class LinkConfiguration : public QObject
34
{
Don Gagne's avatar
Don Gagne committed
35
    Q_OBJECT
36
    Q_ENUMS(LinkType)
Don Gagne's avatar
Don Gagne committed
37

38 39 40 41 42
public:
    LinkConfiguration(const QString& name);
    LinkConfiguration(LinkConfiguration* copy);
    virtual ~LinkConfiguration() {}

43 44
    Q_PROPERTY(QString          name                READ name           WRITE setName           NOTIFY nameChanged)
    Q_PROPERTY(LinkInterface*   link                READ link           WRITE setLink           NOTIFY linkChanged)
45
    Q_PROPERTY(LinkType         linkType            READ type                                   CONSTANT)
46 47 48
    Q_PROPERTY(bool             dynamic             READ isDynamic      WRITE setDynamic        NOTIFY dynamicChanged)
    Q_PROPERTY(bool             autoConnect         READ isAutoConnect  WRITE setAutoConnect    NOTIFY autoConnectChanged)
    Q_PROPERTY(bool             autoConnectAllowed  READ isAutoConnectAllowed                   CONSTANT)
49
    Q_PROPERTY(QString          settingsURL         READ settingsURL                            CONSTANT)
Don Gagne's avatar
Don Gagne committed
50 51 52 53 54 55 56 57 58

    // Property accessors

    const QString   name(void)  { return _name; }
    LinkInterface*  link(void)  { return _link; }

    void            setName(const QString name);
    void            setLink(LinkInterface* link);

59
    ///  The link types supported by QGC
60
    enum LinkType {
dogmaphobic's avatar
dogmaphobic committed
61
#ifndef __ios__
62
        TypeSerial,     ///< Serial Link
dogmaphobic's avatar
dogmaphobic committed
63
#endif
64
        TypeUdp,        ///< UDP Link
65
        TypeTcp,        ///< TCP Link
66
#if 0
Don Gagne's avatar
Don Gagne committed
67
        // TODO Below is not yet implemented
68 69 70
        TypeForwarding, ///< Forwarding Link
        TypeXbee,       ///< XBee Proprietary Link
        TypeOpal,       ///< Opal-RT Link
71 72
#endif
        TypeMock,       ///< Mock Link for Unitesting
Don Gagne's avatar
Don Gagne committed
73
        TypeLogReplay,
74 75 76
        TypeLast        // Last type value (type >= TypeLast == invalid)
    };

dogmaphobic's avatar
dogmaphobic committed
77 78 79 80 81 82 83
    /*!
     *
     * Is this a dynamic configuration? (non persistent)
     * @return True if this is an automatically added configuration.
     */
    bool isDynamic() { return _dynamic; }

84 85 86 87 88 89 90
    /*!
     *
     * Is this an Auto Connect configuration?
     * @return True if this is an Auto Connect configuration (connects automatically at boot time).
     */
    bool isAutoConnect() { return _autoConnect; }

dogmaphobic's avatar
dogmaphobic committed
91 92 93
    /*!
     * Set if this is this a dynamic configuration. (decided at runtime)
    */
94 95 96 97 98 99
    void setDynamic(bool dynamic = true) { _dynamic = dynamic; emit dynamicChanged(); }

    /*!
     * Set if this is this an Auto Connect configuration.
    */
    void setAutoConnect(bool autoc = true) { _autoConnect = autoc; emit autoConnectChanged(); }
dogmaphobic's avatar
dogmaphobic committed
100

101 102
    /// Virtual Methods

103 104 105 106 107 108 109
    /*!
     *
     * Is Auto Connect allowed for this type?
     * @return True if this type can be set as an Auto Connect configuration
     */
    virtual bool isAutoConnectAllowed() { return true; }

110 111 112 113 114 115
    /*!
     * @brief Connection type
     *
     * Pure virtual method returning one of the -TypeXxx types above.
     * @return The type of links these settings belong to.
     */
116
    virtual LinkType type() = 0;
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

    /*!
     * @brief Load settings
     *
     * Pure virtual method telling the instance to load its configuration.
     * @param[in] settings The QSettings instance to use
     * @param[in] root The root path of the setting.
     */
    virtual void loadSettings(QSettings& settings, const QString& root) = 0;

    /*!
     * @brief Save settings
     *
     * Pure virtual method telling the instance to save its configuration.
     * @param[in] settings The QSettings instance to use
     * @param[in] root The root path of the setting.
     */
    virtual void saveSettings(QSettings& settings, const QString& root) = 0;

136 137 138 139 140 141 142
    /*!
     * @brief Settings URL
     *
     * Pure virtual method providing the URL for the (QML) settings dialog
     */
    virtual QString settingsURL() = 0;

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    /*!
     * @brief Update settings
     *
     * After editing the settings, use this method to tell the connected link (if any) to reload its configuration.
     */
    virtual void updateSettings() {}

    /*!
     * @brief Copy instance data
     *
     * When manipulating data, you create a copy of the configuration using the copy constructor,
     * edit it and then transfer its content to the original using this method.
     * @param[in] source The source instance (the edited copy)
     */
    virtual void copyFrom(LinkConfiguration* source);

    /// Helper static methods

    /*!
     * @brief Root path for QSettings
     *
     * @return The root path of the settings.
     */
    static const QString settingsRoot();

    /*!
     * @brief Create new link configuration instance
     *
     * Configuration Factory. Creates an appropriate configuration instance based on the given type.
     * @return A new instance of the given type
     */
    static LinkConfiguration* createSettings(int type, const QString& name);

    /*!
     * @brief Duplicate configuration instance
     *
     * Helper method to create a new instance copy for editing.
     * @return A new copy of the given settings instance
     */
    static LinkConfiguration* duplicateSettings(LinkConfiguration *source);

Don Gagne's avatar
Don Gagne committed
184
signals:
185 186 187 188
    void nameChanged        (const QString& name);
    void linkChanged        (LinkInterface* link);
    void dynamicChanged     ();
    void autoConnectChanged ();
Don Gagne's avatar
Don Gagne committed
189

190 191 192 193
protected:
    LinkInterface* _link; ///< Link currently using this configuration (if any)
private:
    QString _name;
194 195
    bool    _dynamic;       ///< A connection added automatically and not persistent (unless it's edited).
    bool    _autoConnect;   ///< This connection is started automatically at boot
196 197 198
};

#endif // LINKCONFIGURATION_H