LCOV - code coverage report
Current view: top level - xenolith/platform/linux - XLPlatformLinuxDbus.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 11 27.3 %
Date: 2024-05-12 00:16:13 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef XENOLITH_PLATFORM_LINUX_XLPLATFORMLINUXDBUS_H_
      24             : #define XENOLITH_PLATFORM_LINUX_XLPLATFORMLINUXDBUS_H_
      25             : 
      26             : #include "SPCore.h"
      27             : #include "XLCommon.h"
      28             : 
      29             : #if LINUX
      30             : 
      31             : namespace STAPPLER_VERSIONIZED stappler::xenolith::platform {
      32             : 
      33             : enum NMState {
      34             :         NM_STATE_UNKNOWN = 0, // networking state is unknown
      35             :         NM_STATE_ASLEEP = 10, // networking is not enabled
      36             :         NM_STATE_DISCONNECTED = 20, // there is no active network connection
      37             :         NM_STATE_DISCONNECTING = 30, // network connections are being cleaned up
      38             :         NM_STATE_CONNECTING = 40, // a network connection is being started
      39             :         NM_STATE_CONNECTED_LOCAL = 50, // there is only local IPv4 and/or IPv6 connectivity
      40             :         NM_STATE_CONNECTED_SITE = 60, // there is only site-wide IPv4 and/or IPv6 connectivity
      41             :         NM_STATE_CONNECTED_GLOBAL = 70, // there is global IPv4 and/or IPv6 Internet connectivity
      42             : };
      43             : 
      44             : enum NMConnectivityState {
      45             :         NM_CONNECTIVITY_UNKNOWN = 1, // Network connectivity is unknown.
      46             :         NM_CONNECTIVITY_NONE = 2, // The host is not connected to any network.
      47             :         NM_CONNECTIVITY_PORTAL = 3, // The host is behind a captive portal and cannot reach the full Internet.
      48             :         NM_CONNECTIVITY_LIMITED = 4, // The host is connected to a network, but does not appear to be able to reach the full Internet.
      49             :         NM_CONNECTIVITY_FULL = 5, // The host is connected to a network, and appears to be able to reach the full Internet.
      50             : };
      51             : 
      52             : enum NMMetered {
      53             :         NM_METERED_UNKNOWN = 0, // The metered status is unknown
      54             :         NM_METERED_YES = 1, // Metered, the value was statically set
      55             :         NM_METERED_NO = 2, // Not metered, the value was statically set
      56             :         NM_METERED_GUESS_YES = 3, // Metered, the value was guessed
      57             :         NM_METERED_GUESS_NO = 4, // Not metered, the value was guessed
      58             : };
      59             : 
      60             : struct DBusInterface;
      61             : 
      62             : struct InterfaceThemeInfo {
      63             :         static constexpr auto DefaultCursorTheme = "Yaru";
      64             :         static constexpr uint16_t DefaultCursorSize = 24;
      65             : 
      66             :         String cursorTheme = DefaultCursorTheme;
      67             :         uint16_t cursorSize = DefaultCursorSize;
      68             : 
      69             :         bool operator==(const InterfaceThemeInfo &) const = default;
      70             :         bool operator!=(const InterfaceThemeInfo &) const = default;
      71             : };
      72             : 
      73             : struct NetworkState {
      74          25 :         bool networkingEnabled = false;
      75           0 :         bool wirelessEnabled = false;
      76           0 :         bool wwanEnabled = false;
      77           0 :         bool wimaxEnabled = false;
      78           0 :         NMMetered metered = NMMetered::NM_METERED_UNKNOWN;
      79           0 :         NMState state = NMState::NM_STATE_UNKNOWN;
      80           0 :         NMConnectivityState connectivity = NMConnectivityState::NM_CONNECTIVITY_UNKNOWN;
      81           0 :         String primaryConnectionType;
      82           0 :         Vector<uint32_t> capabilities;
      83             : 
      84          25 :         bool operator==(const NetworkState &) const = default;
      85          25 :         bool operator!=(const NetworkState &) const = default;
      86             : 
      87             :         String description() const;
      88             : };
      89             : 
      90             : class DBusLibrary {
      91             : public:
      92             :         static DBusLibrary get();
      93             : 
      94             :         bool isAvailable() const;
      95             : 
      96             :         InterfaceThemeInfo getCurrentInterfaceTheme() const;
      97             : 
      98             :         void addNetworkConnectionCallback(void *key, Function<void(const NetworkState &)> &&);
      99             :         void removeNetworkConnectionCallback(void *key);
     100             : 
     101             : protected:
     102             :         DBusLibrary(DBusInterface *);
     103             : 
     104             :         DBusInterface *_connection = nullptr;
     105             : };
     106             : 
     107             : }
     108             : 
     109             : #endif
     110             : 
     111             : #endif /* XENOLITH_PLATFORM_LINUX_XLPLATFORMLINUXDBUS_H_ */

Generated by: LCOV version 1.14