LinkConfiguration.h 6.92 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 18

#ifndef LINKCONFIGURATION_H
#define LINKCONFIGURATION_H

#include <QSettings>

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
    Q_OBJECT
22
    Q_ENUMS(LinkType)
Don Gagne's avatar
Don Gagne committed
23

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

29
    Q_PROPERTY(QString          name                READ name           WRITE setName           NOTIFY nameChanged)
30
    Q_PROPERTY(LinkInterface*   link                READ link           WRITE setLink           NOTIFY linkChanged)
31
    Q_PROPERTY(LinkType         linkType            READ type                                   CONSTANT)
32 33 34
    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)
35
    Q_PROPERTY(QString          settingsURL         READ settingsURL                            CONSTANT)
36 37
    Q_PROPERTY(bool             highLatency         READ isHighLatency  WRITE setHighLatency    NOTIFY highLatencyChanged)
    Q_PROPERTY(bool             highLatencyAllowed  READ isHighLatencyAllowed                   CONSTANT)
Don Gagne's avatar
Don Gagne committed
38 39 40

    // Property accessors

41
    QString         name(void) const { return _name; }
Don Gagne's avatar
Don Gagne committed
42 43 44 45 46
    LinkInterface*  link(void)  { return _link; }

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

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

dogmaphobic's avatar
dogmaphobic committed
67 68 69 70 71 72 73
    /*!
     *
     * Is this a dynamic configuration? (non persistent)
     * @return True if this is an automatically added configuration.
     */
    bool isDynamic() { return _dynamic; }

74 75 76 77 78 79 80
    /*!
     *
     * Is this an Auto Connect configuration?
     * @return True if this is an Auto Connect configuration (connects automatically at boot time).
     */
    bool isAutoConnect() { return _autoConnect; }

81 82 83 84 85 86 87
    /*!
     *
     * 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
88 89 90
    /*!
     * Set if this is this a dynamic configuration. (decided at runtime)
    */
91 92 93 94 95 96
    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
97

98 99 100 101 102
    /*!
     * Set if this is this an High Latency configuration.
    */
    void setHighLatency(bool hl = false) { _highLatency = hl; emit highLatencyChanged(); }

103 104
    /// Virtual Methods

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
     */
110
    virtual bool isAutoConnectAllowed() { return false; }
111

112 113 114 115 116 117 118
    /*!
     *
     * Is High Latency allowed for this type?
     * @return True if this type can be set as an High Latency configuration
     */
    virtual bool isHighLatencyAllowed() { return false; }

119 120 121 122 123 124
    /*!
     * @brief Connection type
     *
     * Pure virtual method returning one of the -TypeXxx types above.
     * @return The type of links these settings belong to.
     */
125
    virtual LinkType type() = 0;
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144

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

145 146 147 148 149 150 151
    /*!
     * @brief Settings URL
     *
     * Pure virtual method providing the URL for the (QML) settings dialog
     */
    virtual QString settingsURL() = 0;

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 184 185 186 187 188 189 190 191 192
    /*!
     * @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
193
signals:
194 195 196
    void nameChanged        (const QString& name);
    void dynamicChanged     ();
    void autoConnectChanged ();
197
    void linkChanged        (LinkInterface* link);
198
    void highLatencyChanged ();
Don Gagne's avatar
Don Gagne committed
199

200 201 202 203
protected:
    LinkInterface* _link; ///< Link currently using this configuration (if any)
private:
    QString _name;
204 205
    bool    _dynamic;       ///< A connection added automatically and not persistent (unless it's edited).
    bool    _autoConnect;   ///< This connection is started automatically at boot
206
    bool    _highLatency;
207 208
};

209 210
typedef QSharedPointer<LinkConfiguration> SharedLinkConfigurationPointer;

211
#endif // LINKCONFIGURATION_H