/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright 2013 - 2020, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. * This project including source code and documentation is protected by * copyright law, and remains the property of nymea GmbH. All rights, including * reproduction, publication, editing and translation, are reserved. The use of * this project is subject to the terms of a license agreement to be concluded * with nymea GmbH in accordance with the terms of use of nymea GmbH, available * under https://nymea.io/license * * GNU General Public License Usage * Alternatively, this project may be redistributed and/or modified under the * terms of the GNU General Public License as published by the Free Software * Foundation, GNU version 3. This project is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * * You should have received a copy of the GNU General Public License along with * this project. If not, see . * * For any further details and any questions please contact us under * contact@nymea.io or see our FAQ/Licensing Information on * https://nymea.io/license/faq * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #ifndef NETWORKMANAGER_H #define NETWORKMANAGER_H #include #include #include "jsonrpc/jsonhandler.h" class Engine; class NetworkDevices; class WiredNetworkDevices; class WirelessNetworkDevices; class NetworkManager : public JsonHandler { Q_OBJECT Q_PROPERTY(Engine *engine READ engine WRITE setEngine NOTIFY engineChanged) Q_PROPERTY(NetworkManagerState state READ state NOTIFY stateChanged) Q_PROPERTY(bool networkingEnabled READ networkingEnabled NOTIFY networkingEnabledChanged) Q_PROPERTY(bool wirelessNetworkingEnabled READ wirelessNetworkingEnabled NOTIFY wirelessNetworkingEnabledChanged) Q_PROPERTY(WiredNetworkDevices* wiredNetworkDevices READ wiredNetworkDevices CONSTANT) Q_PROPERTY(WirelessNetworkDevices* wirelessNetworkDevices READ wirelessNetworkDevices CONSTANT) public: enum NetworkManagerState { NetworkManagerStateUnknown = 0, NetworkManagerStateAsleep = 10, NetworkManagerStateDisconnected = 20, NetworkManagerStateDisconnecting = 30, NetworkManagerStateConnecting = 40, NetworkManagerStateConnectedLocal = 50, NetworkManagerStateConnectedSite = 60, NetworkManagerStateConnectedGlobal = 70 }; Q_ENUM(NetworkManagerState) explicit NetworkManager(QObject *parent = nullptr); ~NetworkManager(); void setEngine(Engine *engine); Engine *engine() const; QString nameSpace() const override; NetworkManagerState state() const; bool networkingEnabled() const; bool wirelessNetworkingEnabled() const; WiredNetworkDevices* wiredNetworkDevices() const; WirelessNetworkDevices* wirelessNetworkDevices() const; Q_INVOKABLE void enableNetworking(bool enable); Q_INVOKABLE void enableWirelessNetworking(bool enable); Q_INVOKABLE void refreshWifis(const QString &interface); Q_INVOKABLE void connectToWiFi(const QString &interface, const QString &ssid, const QString &passphrase); Q_INVOKABLE void disconnectInterface(const QString &interface); private slots: void init(); void getStatusReply(const QVariantMap ¶ms); void getDevicesReply(const QVariantMap ¶ms); void getAccessPointsReply(const QVariantMap ¶ms); void connectToWiFiReply(const QVariantMap ¶ms); void disconnectReply(const QVariantMap ¶ms); void enableNetworkingReply(const QVariantMap ¶ms); void notificationReceived(const QVariantMap ¶ms); signals: void engineChanged(); void stateChanged(); void networkingEnabledChanged(); void wirelessNetworkingEnabledChanged(); private: Engine *m_engine = nullptr; NetworkManagerState m_state = NetworkManagerStateUnknown; bool m_networkingEnabled = false; bool m_wirelessNetworkingEnabled = false; WiredNetworkDevices* m_wiredNetworkDevices = nullptr; WirelessNetworkDevices* m_wirelessNetworkDevices = nullptr; QHash m_apRequests; // requestId, interface }; #endif // NETWORKMANAGER_H