LinkConfiguration.h 6.12 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10
#pragma once
11 12 13

#include <QSettings>

14 15
#include <memory>

16 17 18
class LinkInterface;

/// Interface holding link specific settings.
Don Gagne's avatar
Don Gagne committed
19
class LinkConfiguration : public QObject
20
{
Don Gagne's avatar
Don Gagne committed
21 22
    Q_OBJECT

23 24 25 26 27
public:
    LinkConfiguration(const QString& name);
    LinkConfiguration(LinkConfiguration* copy);
    virtual ~LinkConfiguration() {}

28
    Q_PROPERTY(QString          name                READ name           WRITE setName           NOTIFY nameChanged)
29
    Q_PROPERTY(LinkInterface*   link                READ link                                   NOTIFY linkChanged)
30
    Q_PROPERTY(LinkType         linkType            READ type                                   CONSTANT)
31 32
    Q_PROPERTY(bool             dynamic             READ isDynamic      WRITE setDynamic        NOTIFY dynamicChanged)
    Q_PROPERTY(bool             autoConnect         READ isAutoConnect  WRITE setAutoConnect    NOTIFY autoConnectChanged)
33
    Q_PROPERTY(QString          settingsURL         READ settingsURL                            CONSTANT)
34
    Q_PROPERTY(QString          settingsTitle       READ settingsTitle                          CONSTANT)
35
    Q_PROPERTY(bool             highLatency         READ isHighLatency  WRITE setHighLatency    NOTIFY highLatencyChanged)
Don Gagne's avatar
Don Gagne committed
36 37 38

    // Property accessors

39
    QString         name(void) const { return _name; }
40
    LinkInterface*  link(void)  { return _link.lock().get(); }
Don Gagne's avatar
Don Gagne committed
41 42

    void            setName(const QString name);
43
    void            setLink(std::shared_ptr<LinkInterface> link);
Don Gagne's avatar
Don Gagne committed
44

45
    ///  The link types supported by QGC
dogmaphobic's avatar
dogmaphobic committed
46
    ///  Any changes here MUST be reflected in LinkManager::linkTypeStrings()
47
    enum LinkType {
Gus Grubba's avatar
Gus Grubba committed
48
#ifndef NO_SERIAL_LINK
49
        TypeSerial,     ///< Serial Link
dogmaphobic's avatar
dogmaphobic committed
50
#endif
51
        TypeUdp,        ///< UDP Link
52
        TypeTcp,        ///< TCP Link
dogmaphobic's avatar
dogmaphobic committed
53
#ifdef QGC_ENABLE_BLUETOOTH
dogmaphobic's avatar
dogmaphobic committed
54 55
        TypeBluetooth,  ///< Bluetooth Link
#endif
dogmaphobic's avatar
dogmaphobic committed
56
#ifdef QT_DEBUG
57
        TypeMock,       ///< Mock Link for Unitesting
dogmaphobic's avatar
dogmaphobic committed
58
#endif
Don Gagne's avatar
Don Gagne committed
59
        TypeLogReplay,
60 61
        TypeLast        // Last type value (type >= TypeLast == invalid)
    };
62
    Q_ENUM(LinkType)
63

64 65
    bool isDynamic      () { return _dynamic; }     ///< Not persisted
    bool isAutoConnect  () { return _autoConnect; }
66

67 68 69 70 71 72 73
    /*!
     *
     * Is this a High Latency configuration?
     * @return True if this is an High Latency configuration (link with large delays).
     */
    bool isHighLatency() { return _highLatency; }

dogmaphobic's avatar
dogmaphobic committed
74 75 76
    /*!
     * Set if this is this a dynamic configuration. (decided at runtime)
    */
77 78 79 80 81 82
    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
83

84 85 86 87 88
    /*!
     * Set if this is this an High Latency configuration.
    */
    void setHighLatency(bool hl = false) { _highLatency = hl; emit highLatencyChanged(); }

89 90 91 92 93 94 95 96
    /// Virtual Methods

    /*!
     * @brief Connection type
     *
     * Pure virtual method returning one of the -TypeXxx types above.
     * @return The type of links these settings belong to.
     */
97
    virtual LinkType type() = 0;
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

    /*!
     * @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;

117 118 119 120 121
    /*!
     * @brief Settings URL
     *
     * Pure virtual method providing the URL for the (QML) settings dialog
     */
122 123 124 125 126 127 128 129
    virtual QString settingsURL     () = 0;

    /*!
     * @brief Settings Title
     *
     * Pure virtual method providing the Title for the (QML) settings dialog
     */
    virtual QString settingsTitle   () = 0;
130

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    /*!
     * @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
165
signals:
166 167 168
    void nameChanged        (const QString& name);
    void dynamicChanged     ();
    void autoConnectChanged ();
169
    void highLatencyChanged ();
170
    void linkChanged        ();
Don Gagne's avatar
Don Gagne committed
171

172
protected:
173 174
    std::weak_ptr<LinkInterface> _link; ///< Link currently using this configuration (if any)

175 176
private:
    QString _name;
177 178
    bool    _dynamic;       ///< A connection added automatically and not persistent (unless it's edited).
    bool    _autoConnect;   ///< This connection is started automatically at boot
179
    bool    _highLatency;
180 181
};

182 183
typedef std::shared_ptr<LinkConfiguration>  SharedLinkConfigurationPtr;
typedef std::weak_ptr<LinkConfiguration>    WeakLinkConfigurationPtr;
184