kodi
NetworkAndroid.h
1 /*
2  * Copyright (C) 2016 Christian Browet
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "network/Network.h"
12 #include "threads/CriticalSection.h"
13 
14 #include "platform/android/activity/JNIXBMCConnectivityManagerNetworkCallback.h"
15 
16 #include <androidjni/LinkProperties.h>
17 #include <androidjni/Network.h>
18 #include <androidjni/NetworkInterface.h>
19 
21 {
22 public:
23  CNetworkInterfaceAndroid(const CJNINetwork& network,
24  const CJNILinkProperties& lp,
25  const CJNINetworkInterface& intf);
26  std::vector<std::string> GetNameServers();
27 
28  // CNetworkInterface interface
29 public:
30  bool IsEnabled() const override;
31  bool IsConnected() const override;
32  std::string GetMacAddress() const override;
33  void GetMacAddressRaw(char rawMac[6]) const override;
34  bool GetHostMacAddress(unsigned long host_ip, std::string& mac) const override;
35  std::string GetCurrentIPAddress() const override;
36  std::string GetCurrentNetmask() const override;
37  std::string GetCurrentDefaultGateway() const override;
38 
39  std::string GetHostName();
40 
41 protected:
42  std::string m_name;
43  CJNINetwork m_network;
44  CJNILinkProperties m_lp;
45  CJNINetworkInterface m_intf;
46 };
47 
49 {
50  friend class CXBMCApp;
51 
52 public:
54  ~CNetworkAndroid() override;
55 
56  // CNetwork interface
57 public:
58  bool GetHostName(std::string& hostname) override;
59  std::vector<CNetworkInterface*>& GetInterfaceList() override;
60  CNetworkInterface* GetFirstConnectedInterface() override;
61  std::vector<std::string> GetNameServers() override;
62 
63  // Ping remote host
64  using CNetworkBase::PingHost;
65  bool PingHost(unsigned long remote_ip, unsigned int timeout_ms = 2000) override;
66 
67 protected:
68  void RetrieveInterfaces();
69  std::vector<CNetworkInterface*> m_interfaces;
70  std::vector<CNetworkInterface*> m_oldInterfaces;
71  CCriticalSection m_refreshMutex;
72 
73  std::unique_ptr<CNetworkInterface> m_defaultInterface;
74 
75 public:
76  void onAvailable(const CJNINetwork network) override;
77  void onLost(const CJNINetwork network) override;
78 };
Definition: NetworkAndroid.h:20
Definition: Network.h:18
Definition: JNIXBMCConnectivityManagerNetworkCallback.h:17
Definition: Network.h:40
Definition: XBMCApp.h:83
Definition: NetworkAndroid.h:48