File indexing completed on 2024-04-14 14:30:35

0001 /*
0002     SPDX-FileCopyrightText: 2011 Ilia Kats <ilia-kats@gmx.net>
0003     SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza <lamarque@kde.org>
0004     SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef NETWORKMANAGERQT_ACTIVECONNECTION_H
0010 #define NETWORKMANAGERQT_ACTIVECONNECTION_H
0011 
0012 #include <QDBusObjectPath>
0013 #include <QObject>
0014 #include <QSharedPointer>
0015 
0016 #include "connection.h"
0017 #include "dhcp4config.h"
0018 #include "dhcp6config.h"
0019 #include "ipconfig.h"
0020 #include <networkmanagerqt/networkmanagerqt_export.h>
0021 
0022 namespace NetworkManager
0023 {
0024 class ActiveConnectionPrivate;
0025 
0026 /**
0027  * An active connection
0028  */
0029 class NETWORKMANAGERQT_EXPORT ActiveConnection : public QObject
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     typedef QSharedPointer<ActiveConnection> Ptr;
0035     typedef QList<Ptr> List;
0036     /**
0037      * Enum describing possible active connection states
0038      */
0039     enum State {
0040         Unknown = 0, /**< The active connection is in an unknown state */
0041         Activating, /**< The connection is activating */
0042         Activated, /**< The connection is activated */
0043         Deactivating, /**< The connection is being torn down and cleaned up */
0044         Deactivated, /**< The connection is no longer active */
0045     };
0046 
0047     enum Reason {
0048         UknownReason = 0, /**< The reason for the active connection state change is unknown */
0049         None, /**< No reason was given for the active connection state change */
0050         UserDisconnected, /**< The active connection changed state because the user disconnected it */
0051         DeviceDisconnected, /**< The active connection changed state because the device it was using was disconnected */
0052         ServiceStopped, /**< The service providing the VPN connection was stopped */
0053         IpConfigInvalid, /**< The IP config of the active connection was invalid */
0054         ConnectTimeout, /**< The connection attempt to the VPN service timed out */
0055         ServiceStartTimeout, /**< A timeout occurred while starting the service providing the VPN connection */
0056         ServiceStartFailed, /**< Starting the service providing the VPN connection failed */
0057         NoSecrets, /**< Necessary secrets for the connection were not provided */
0058         LoginFailed, /**< Authentication to the server failed */
0059         ConnectionRemoved, /**< The connection was deleted from settings */
0060         DependencyFailed, /**< Master connection of this connection failed to activate */
0061         DeviceRealizeFailed, /**< Could not create the software device link */
0062         DeviceRemoved, /**< The device this connection depended on disappeared */
0063     };
0064 
0065     /**
0066      * Creates a new ActiveConnection object.
0067      *
0068      * @param path the DBus path of the device
0069      */
0070     explicit ActiveConnection(const QString &path, QObject *parent = nullptr);
0071 
0072     /**
0073      * Destroys an ActiveConnection object.
0074      */
0075     ~ActiveConnection() override;
0076 
0077     /**
0078      * Returns true is this object holds a valid connection
0079      */
0080     bool isValid() const;
0081     /**
0082      * Return path of the connection object
0083      */
0084     QString path() const;
0085     /**
0086      * Returns a valid NetworkManager::Connection object
0087      */
0088     Connection::Ptr connection() const;
0089     /**
0090      * Whether this connection has the default IPv4 route
0091      */
0092     bool default4() const;
0093     /**
0094      * Whether this connection has the default IPv6 route
0095      */
0096     bool default6() const;
0097     /**
0098      * The Ip4Config object describing the configuration of the
0099      * connection. Only valid when the connection is in the
0100      * NM_ACTIVE_CONNECTION_STATE_ACTIVATED state
0101      */
0102     IpConfig ipV4Config() const;
0103     /**
0104      * The Ip6Config object describing the configuration of the
0105      * connection. Only valid when the connection is in the
0106      * NM_ACTIVE_CONNECTION_STATE_ACTIVATED state
0107      */
0108     IpConfig ipV6Config() const;
0109     /**
0110      * The Dhcp4Config object describing the DHCP options
0111      * returned by the DHCP server (assuming the connection used DHCP). Only
0112      * valid when the connection is in the NM_ACTIVE_CONNECTION_STATE_ACTIVATED
0113      * state
0114      */
0115     Dhcp4Config::Ptr dhcp4Config() const;
0116     /**
0117      * The Dhcp6Config object describing the DHCP options
0118      * returned by the DHCP server (assuming the connection used DHCP). Only
0119      * valid when the connection is in the NM_ACTIVE_CONNECTION_STATE_ACTIVATED
0120      * state
0121      */
0122     Dhcp6Config::Ptr dhcp6Config() const;
0123     /**
0124      * The Id of the connection
0125      */
0126     QString id() const;
0127     /**
0128      * The type of the connection
0129      */
0130     NetworkManager::ConnectionSettings::ConnectionType type() const;
0131     /**
0132      * Returns the uni of master device if the connection is a slave.
0133      */
0134     QString master() const;
0135     /**
0136      * The path of the specific object associated with the connection.
0137      */
0138     QString specificObject() const;
0139     /**
0140      * The current state of the connection
0141      */
0142     NetworkManager::ActiveConnection::State state() const;
0143     /**
0144      * Whether this is a VPN connection
0145      */
0146     bool vpn() const;
0147     /**
0148      * The UUID of the connection.
0149      */
0150     QString uuid() const;
0151     /**
0152      * List of devices UNIs which are part of this connection.
0153      */
0154     QStringList devices() const;
0155 
0156 Q_SIGNALS:
0157     /**
0158      * This signal is emitted when the connection path has changed
0159      */
0160     void connectionChanged(const NetworkManager::Connection::Ptr &connection);
0161     /**
0162      * The state of the default IPv4 route changed
0163      */
0164     void default4Changed(bool isDefault);
0165     /**
0166      * The state of the default IPv6 route changed
0167      */
0168     void default6Changed(bool isDefault);
0169     /**
0170      * Emitted when the DHCP configuration for IPv4 of this network has changed.
0171      */
0172     void dhcp4ConfigChanged();
0173     /**
0174      * Emitted when the DHCP configuration for IPv6 of this network has changed.
0175      */
0176     void dhcp6ConfigChanged();
0177     /**
0178      * Emitted when the IPv4 configuration of this network has changed.
0179      */
0180     void ipV4ConfigChanged();
0181     /**
0182      * Emitted when the IPv6 configuration of this network has changed.
0183      */
0184     void ipV6ConfigChanged();
0185     /**
0186      * The @p id changed
0187      */
0188     void idChanged(const QString &id);
0189     /**
0190      * The @p type changed
0191      */
0192     void typeChanged(NetworkManager::ConnectionSettings::ConnectionType type);
0193     /**
0194      * The master device changed.
0195      */
0196     void masterChanged(const QString &uni);
0197     /**
0198      * The @p path to the specific object changed
0199      */
0200     void specificObjectChanged(const QString &path);
0201     /**
0202      * The @p state changed
0203      */
0204     void stateChanged(NetworkManager::ActiveConnection::State state);
0205     /**
0206      * The @p state changed because of reason @p reason
0207      * (never emitted in runtime NM < 1.8.0)
0208      */
0209     void stateChangedReason(NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason);
0210     /**
0211      * The VPN property changed.
0212      */
0213     void vpnChanged(bool isVpn);
0214     /**
0215      * The @p uuid changed.
0216      */
0217     void uuidChanged(const QString &uuid);
0218     /**
0219      * The list of devices changed.
0220      */
0221     void devicesChanged();
0222 
0223 protected:
0224     NETWORKMANAGERQT_NO_EXPORT explicit ActiveConnection(ActiveConnectionPrivate &dd, QObject *parent = nullptr);
0225 
0226     ActiveConnectionPrivate *const d_ptr;
0227 
0228 private:
0229     Q_DECLARE_PRIVATE(ActiveConnection)
0230 };
0231 
0232 } // namespace NetworkManager
0233 #endif // NETWORKMANAGERQT_ACTIVECONNECTION_H