File indexing completed on 2024-04-28 07:49:03

0001 /*
0002     SPDX-FileCopyrightText: 2014 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "device.h"
0008 #include "activeconnection.h"
0009 
0010 #include <QDBusConnection>
0011 #include <QDBusMetaType>
0012 
0013 Device::Device(QObject *parent)
0014     : QObject(parent)
0015     , m_activeConnection(QDBusObjectPath("/"))
0016     , m_autoconnect(true)
0017     , m_capabilities(0)
0018     , m_deviceType(0)
0019     , m_dhcp4Config(QDBusObjectPath("/"))
0020     , m_dhcp6Config(QDBusObjectPath("/"))
0021     , m_firmwareMissing(false)
0022     , m_interfaceFlags(NM_DEVICE_INTERFACE_FLAG_NONE)
0023     , m_ip4Address(0)
0024     , m_ip4Config(QDBusObjectPath("/"))
0025     , m_ip6Config(QDBusObjectPath("/"))
0026     , m_managed(true)
0027     , m_mtu(0)
0028     , m_state(30)
0029 {
0030     qDBusRegisterMetaType<DeviceDBusStateReason>();
0031 }
0032 
0033 Device::~Device()
0034 {
0035 }
0036 
0037 QDBusObjectPath Device::activeConnection() const
0038 {
0039     return m_activeConnection;
0040 }
0041 
0042 bool Device::autoconnect() const
0043 {
0044     return m_autoconnect;
0045 }
0046 
0047 void Device::setAutoconnect(bool autoconnect)
0048 {
0049     m_autoconnect = autoconnect;
0050 }
0051 
0052 QList<QDBusObjectPath> Device::availableConnections() const
0053 {
0054     return m_availableConnections;
0055 }
0056 
0057 uint Device::capabilities() const
0058 {
0059     return m_capabilities;
0060 }
0061 
0062 QString Device::deviceInterface() const
0063 {
0064     if (m_deviceType == NetworkManager::Device::Ethernet) {
0065         return QLatin1String("org.kde.fakenetwork.Device.Wired");
0066     } else if (m_deviceType == NetworkManager::Device::Wifi) {
0067         return QLatin1String("org.kde.fakenetwork.Device.Wireless");
0068     }
0069 
0070     return QLatin1String("org.kde.fakenetwork.Device.Wired");
0071 }
0072 
0073 QString Device::devicePath() const
0074 {
0075     return m_devicePath;
0076 }
0077 
0078 void Device::setDevicePath(const QString &devicePath)
0079 {
0080     m_devicePath = devicePath;
0081 }
0082 
0083 uint Device::deviceType() const
0084 {
0085     return m_deviceType;
0086 }
0087 
0088 QDBusObjectPath Device::dhcp4Config() const
0089 {
0090     return m_dhcp4Config;
0091 }
0092 
0093 QDBusObjectPath Device::dhcp6Config() const
0094 {
0095     return m_dhcp6Config;
0096 }
0097 
0098 QString Device::driver() const
0099 {
0100     return m_driver;
0101 }
0102 
0103 QString Device::driverVersion() const
0104 {
0105     return m_driverVersion;
0106 }
0107 
0108 bool Device::firmwareMissing() const
0109 {
0110     return m_firmwareMissing;
0111 }
0112 
0113 QString Device::firmwareVersion() const
0114 {
0115     return m_firmwareVersion;
0116 }
0117 
0118 QString Device::interface() const
0119 {
0120     return m_interface;
0121 }
0122 
0123 int Device::ip4Address() const
0124 {
0125     return m_ip4Address;
0126 }
0127 
0128 QDBusObjectPath Device::ip4Config() const
0129 {
0130     return m_ip4Config;
0131 }
0132 
0133 QDBusObjectPath Device::ip6Config() const
0134 {
0135     return m_ip6Config;
0136 }
0137 
0138 QString Device::ipInterface() const
0139 {
0140     return m_ipInterface;
0141 }
0142 
0143 uint Device::interfaceFlags() const
0144 {
0145     return m_interfaceFlags;
0146 }
0147 
0148 bool Device::managed() const
0149 {
0150     return m_managed;
0151 }
0152 
0153 uint Device::mtu() const
0154 {
0155     return m_mtu;
0156 }
0157 
0158 uint Device::state() const
0159 {
0160     return m_state;
0161 }
0162 
0163 DeviceDBusStateReason Device::stateReason() const
0164 {
0165     return m_stateReason;
0166 }
0167 
0168 QString Device::udi() const
0169 {
0170     return m_udi;
0171 }
0172 
0173 void Device::addAvailableConnection(const QDBusObjectPath &availableConnection)
0174 {
0175     m_availableConnections << availableConnection;
0176 }
0177 
0178 void Device::removeAvailableConnection(const QDBusObjectPath &availableConnection)
0179 {
0180     m_availableConnections.removeAll(availableConnection);
0181 }
0182 
0183 void Device::setActiveConnection(const QString &activeConnection)
0184 {
0185     m_activeConnection = QDBusObjectPath(activeConnection);
0186 }
0187 
0188 void Device::setCapabilities(uint capabilities)
0189 {
0190     m_capabilities = capabilities;
0191 }
0192 
0193 void Device::setDeviceType(uint deviceType)
0194 {
0195     m_deviceType = deviceType;
0196 }
0197 
0198 void Device::setDhcp4Config(const QString &config)
0199 {
0200     m_dhcp4Config = QDBusObjectPath(config);
0201 }
0202 
0203 void Device::setDhcp6Config(const QString &config)
0204 {
0205     m_dhcp6Config = QDBusObjectPath(config);
0206 }
0207 
0208 void Device::setDriver(const QString &driver)
0209 {
0210     m_driver = driver;
0211 }
0212 
0213 void Device::setDriverVersion(const QString &driverVersion)
0214 {
0215     m_driverVersion = driverVersion;
0216 }
0217 
0218 void Device::setFirmwareMissing(bool firmwareMissing)
0219 {
0220     m_firmwareMissing = firmwareMissing;
0221 }
0222 
0223 void Device::setFirmwareVersion(const QString &firmwareVersion)
0224 {
0225     m_firmwareVersion = firmwareVersion;
0226 }
0227 
0228 void Device::setInterface(const QString &interface)
0229 {
0230     m_interface = interface;
0231 }
0232 
0233 void Device::setInterfaceFlags(uint interfaceFlags)
0234 {
0235     m_interfaceFlags = interfaceFlags;
0236 }
0237 
0238 void Device::setIp4Config(const QString &config)
0239 {
0240     m_ip4Config = QDBusObjectPath(config);
0241 }
0242 
0243 void Device::setIp6Config(const QString &config)
0244 {
0245     m_ip6Config = QDBusObjectPath(config);
0246 }
0247 
0248 void Device::setIpv4Address(int address)
0249 {
0250     m_ip4Address = address;
0251 }
0252 
0253 void Device::setIpInterface(const QString &interface)
0254 {
0255     m_ipInterface = interface;
0256 }
0257 
0258 void Device::setManaged(bool managed)
0259 {
0260     m_managed = managed;
0261 }
0262 
0263 void Device::setMtu(uint mtu)
0264 {
0265     m_mtu = mtu;
0266 }
0267 
0268 void Device::setState(uint state)
0269 {
0270     uint previousState = m_state;
0271     m_state = state;
0272     m_stateReason.state = state;
0273 
0274     QDBusMessage message = QDBusMessage::createSignal(m_devicePath, QLatin1String("org.kde.fakenetwork.Device"), QLatin1String("StateChanged"));
0275     message << previousState << state << m_stateReason.reason;
0276     QDBusConnection::sessionBus().send(message);
0277 }
0278 
0279 void Device::setStateReason(const DeviceDBusStateReason &reason)
0280 {
0281     m_stateReason = reason;
0282 }
0283 
0284 void Device::setUdi(const QString &udi)
0285 {
0286     m_udi = udi;
0287 }
0288 
0289 void Device::Disconnect()
0290 {
0291     // TODO
0292 }
0293 
0294 #include "moc_device.cpp"