File indexing completed on 2024-03-24 04:02:57

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