From 65a34fc4e7c2980f3b6f071336bab35a2d26f2df Mon Sep 17 00:00:00 2001 From: Anton Fedchin Date: Tue, 3 Apr 2018 17:57:30 +0300 Subject: [win10] network: move implementation to platform folder --- cmake/treedata/windowsstore/subdirs.txt | 2 +- xbmc/network/Network.h | 2 +- xbmc/network/win10/CMakeLists.txt | 5 - xbmc/network/win10/NetworkWin10.cpp | 215 --------------------------- xbmc/network/win10/NetworkWin10.h | 96 ------------ xbmc/platform/win10/network/CMakeLists.txt | 5 + xbmc/platform/win10/network/NetworkWin10.cpp | 215 +++++++++++++++++++++++++++ xbmc/platform/win10/network/NetworkWin10.h | 96 ++++++++++++ 8 files changed, 318 insertions(+), 318 deletions(-) delete mode 100644 xbmc/network/win10/CMakeLists.txt delete mode 100644 xbmc/network/win10/NetworkWin10.cpp delete mode 100644 xbmc/network/win10/NetworkWin10.h create mode 100644 xbmc/platform/win10/network/CMakeLists.txt create mode 100644 xbmc/platform/win10/network/NetworkWin10.cpp create mode 100644 xbmc/platform/win10/network/NetworkWin10.h diff --git a/cmake/treedata/windowsstore/subdirs.txt b/cmake/treedata/windowsstore/subdirs.txt index 97d22730d5..d66845cb18 100644 --- a/cmake/treedata/windowsstore/subdirs.txt +++ b/cmake/treedata/windowsstore/subdirs.txt @@ -1,10 +1,10 @@ xbmc/platform/win10 platform/win10 xbmc/platform/win10/filesystem platform/win10/filesystem xbmc/platform/win10/storage platfrom/win10/storage +xbmc/platform/win10/network platform/win10/network xbmc/platform/win32/filesystem platform/win32/filesystem xbmc/input/touch input/touch xbmc/input/touch/generic input/touch/generic -xbmc/network/win10 network/win10 xbmc/network/mdns network/mdns xbmc/peripherals/bus/win10 peripherals/bus/win10 xbmc/powermanagement/win10 powermanagement/win10 diff --git a/xbmc/network/Network.h b/xbmc/network/Network.h index d1bab96f26..2a975c0030 100644 --- a/xbmc/network/Network.h +++ b/xbmc/network/Network.h @@ -159,7 +159,7 @@ public: #elif defined(HAS_WIN32_NETWORK) #include "windows/NetworkWin32.h" #elif defined(HAS_WIN10_NETWORK) -#include "win10/NetworkWin10.h" +#include "platform/win10/network/NetworkWin10.h" #endif //creates, binds and listens a tcp socket on the desired port. Set bindLocal to diff --git a/xbmc/network/win10/CMakeLists.txt b/xbmc/network/win10/CMakeLists.txt deleted file mode 100644 index 0fe16d6f77..0000000000 --- a/xbmc/network/win10/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -set(SOURCES NetworkWin10.cpp) - -set(HEADERS NetworkWin10.h) - -core_add_library(network_win10) diff --git a/xbmc/network/win10/NetworkWin10.cpp b/xbmc/network/win10/NetworkWin10.cpp deleted file mode 100644 index ab43eb2951..0000000000 --- a/xbmc/network/win10/NetworkWin10.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program 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 XBMC; see the file COPYING. If not, see - * . - * - */ - -#include -#include -#include "filesystem/SpecialProtocol.h" -#include -#include -#include "PlatformDefs.h" -#include "platform/win32/WIN32Util.h" -#include "NetworkWin10.h" -#include "utils/log.h" -#include "threads/SingleLock.h" -#include "utils/CharsetConverter.h" -#include "utils/StringUtils.h" -#include "utils/CharsetConverter.h" - -#pragma pack(push, 8) - -using namespace Windows::Networking; -using namespace Windows::Networking::Connectivity; - -CNetworkInterfaceWin10::CNetworkInterfaceWin10(CNetworkWin10* network, Windows::Networking::Connectivity::ConnectionProfile^ profile) -{ - m_network = network; - m_adapter = profile; - g_charsetConverter.wToUTF8(std::wstring(profile->ProfileName->Data()), m_adaptername, false); -} - -CNetworkInterfaceWin10::~CNetworkInterfaceWin10(void) -{ - m_adapter = nullptr; -} - -std::string& CNetworkInterfaceWin10::GetName(void) -{ - return m_adaptername; -} - -bool CNetworkInterfaceWin10::IsWireless() -{ - WlanConnectionProfileDetails^ wlanConnectionProfileDetails = m_adapter->WlanConnectionProfileDetails; - return wlanConnectionProfileDetails != nullptr; -} - -bool CNetworkInterfaceWin10::IsEnabled() -{ - return true; -} - -bool CNetworkInterfaceWin10::IsConnected() -{ - return m_adapter->GetNetworkConnectivityLevel() != NetworkConnectivityLevel::None; -} - -std::string CNetworkInterfaceWin10::GetMacAddress() -{ - return "Unknown"; -} - -bool CNetworkInterfaceWin10::GetHostMacAddress(unsigned long host, std::string& mac) -{ - mac = ""; - return false; -} - -void CNetworkInterfaceWin10::GetSettings(NetworkAssignment& assignment, std::string& ipAddress, std::string& networkMask, std::string& defaultGateway, std::string& essId, std::string& key, EncMode& encryptionMode) -{ -} - -void CNetworkInterfaceWin10::SetSettings(NetworkAssignment& assignment, std::string& ipAddress, std::string& networkMask, std::string& defaultGateway, std::string& essId, std::string& key, EncMode& encryptionMode) -{ -} - -std::vector CNetworkInterfaceWin10::GetAccessPoints(void) -{ - std::vector accessPoints; - return accessPoints; -} - -void CNetworkInterfaceWin10::GetMacAddressRaw(char rawMac[6]) -{ -} - -std::string CNetworkInterfaceWin10::GetCurrentIPAddress(void) -{ - Platform::String^ ipAddress = L"0.0.0.0"; - std::string result; - - if (m_adapter->NetworkAdapter != nullptr) - { - auto hostnames = NetworkInformation::GetHostNames(); - for (unsigned int i = 0; i < hostnames->Size; ++i) - { - auto hostname = hostnames->GetAt(i); - if (hostname->Type != HostNameType::Ipv4) - { - continue; - } - - if (hostname->IPInformation != nullptr && hostname->IPInformation->NetworkAdapter != nullptr) - { - if (hostname->IPInformation->NetworkAdapter->NetworkAdapterId == m_adapter->NetworkAdapter->NetworkAdapterId) - { - ipAddress = hostname->CanonicalName; - break; - } - } - } - } - - g_charsetConverter.wToUTF8(std::wstring(ipAddress->Data()), result, false); - - return result; -} - -std::string CNetworkInterfaceWin10::GetCurrentNetmask(void) -{ - return ""; -} - -std::string CNetworkInterfaceWin10::GetCurrentWirelessEssId(void) -{ - std::string result = ""; - if (!IsWireless()) - return result; - - auto ssid = m_adapter->WlanConnectionProfileDetails->GetConnectedSsid(); - g_charsetConverter.wToUTF8(std::wstring(ssid->Data()), result, false); - return result; -} - -std::string CNetworkInterfaceWin10::GetCurrentDefaultGateway(void) -{ - return ""; -} - -CNetworkWin10::CNetworkWin10(void) -{ - queryInterfaceList(); - NetworkInformation::NetworkStatusChanged += ref new NetworkStatusChangedEventHandler([this](Platform::Object^) { - CSingleLock lock(m_critSection); - queryInterfaceList(); - }); -} - -CNetworkWin10::~CNetworkWin10(void) -{ - CleanInterfaceList(); -} - -void CNetworkWin10::CleanInterfaceList() -{ - std::vector::iterator it = m_interfaces.begin(); - while(it != m_interfaces.end()) - { - CNetworkInterface* nInt = *it; - delete nInt; - it = m_interfaces.erase(it); - } -} - -std::vector& CNetworkWin10::GetInterfaceList(void) -{ - CSingleLock lock (m_critSection); - return m_interfaces; -} - -void CNetworkWin10::queryInterfaceList() -{ - CleanInterfaceList(); - - auto connectionProfiles = NetworkInformation::GetConnectionProfiles(); - std::for_each(begin(connectionProfiles), end(connectionProfiles), [this](ConnectionProfile^ connectionProfile) - { - if (connectionProfile != nullptr && connectionProfile->GetNetworkConnectivityLevel() != NetworkConnectivityLevel::None) - { - m_interfaces.push_back(new CNetworkInterfaceWin10(this, connectionProfile)); - } - }); -} - -std::vector CNetworkWin10::GetNameServers(void) -{ - return std::vector(); -} - -void CNetworkWin10::SetNameServers(const std::vector& nameServers) -{ - return; -} - -bool CNetworkWin10::PingHost(unsigned long host, unsigned int timeout_ms /* = 2000 */) -{ - return false; -} - -#pragma pack(pop) diff --git a/xbmc/network/win10/NetworkWin10.h b/xbmc/network/win10/NetworkWin10.h deleted file mode 100644 index 821c60c068..0000000000 --- a/xbmc/network/win10/NetworkWin10.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program 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 XBMC; see the file COPYING. If not, see - * . - * - */ -#ifndef NETWORK_WIN10_H_ -#define NETWORK_WIN10_H_ - -#include -#include -#include "network/Network.h" -#include "Iphlpapi.h" -#include "utils/stopwatch.h" -#include "threads/CriticalSection.h" - -class CNetworkWin10; - - -class CNetworkInterfaceWin10 : public CNetworkInterface -{ -public: - CNetworkInterfaceWin10(CNetworkWin10* network, Windows::Networking::Connectivity::ConnectionProfile^ profile); - ~CNetworkInterfaceWin10(void); - - virtual std::string& GetName(void); - - virtual bool IsEnabled(void); - virtual bool IsConnected(void); - virtual bool IsWireless(void); - - virtual std::string GetMacAddress(void); - virtual void GetMacAddressRaw(char rawMac[6]); - - virtual bool GetHostMacAddress(unsigned long host, std::string& mac); - - virtual std::string GetCurrentIPAddress(); - virtual std::string GetCurrentNetmask(); - virtual std::string GetCurrentDefaultGateway(void); - virtual std::string GetCurrentWirelessEssId(void); - - virtual void GetSettings(NetworkAssignment& assignment, std::string& ipAddress, std::string& networkMask, std::string& defaultGateway, std::string& essId, std::string& key, EncMode& encryptionMode); - virtual void SetSettings(NetworkAssignment& assignment, std::string& ipAddress, std::string& networkMask, std::string& defaultGateway, std::string& essId, std::string& key, EncMode& encryptionMode); - - // Returns the list of access points in the area - virtual std::vector GetAccessPoints(void); - -private: - void WriteSettings(FILE* fw, NetworkAssignment assignment, std::string& ipAddress, std::string& networkMask, std::string& defaultGateway, std::string& essId, std::string& key, EncMode& encryptionMode); - CNetworkWin10* m_network; - std::string m_adaptername; - Windows::Networking::Connectivity::ConnectionProfile^ m_adapter; -}; - - -class CNetworkWin10 : public CNetwork -{ -public: - CNetworkWin10(void); - virtual ~CNetworkWin10(void); - - // Return the list of interfaces - virtual std::vector& GetInterfaceList(void); - - // Ping remote host - virtual bool PingHost(unsigned long host, unsigned int timeout_ms = 2000); - - // Get/set the nameserver(s) - virtual std::vector GetNameServers(void); - virtual void SetNameServers(const std::vector& nameServers); - - friend class CNetworkInterfaceWin10; - -private: - int GetSocket() { return m_sock; } - void queryInterfaceList(); - void CleanInterfaceList(); - std::vector m_interfaces; - int m_sock; - CStopWatch m_netrefreshTimer; - CCriticalSection m_critSection; -}; -#endif diff --git a/xbmc/platform/win10/network/CMakeLists.txt b/xbmc/platform/win10/network/CMakeLists.txt new file mode 100644 index 0000000000..eb933c76e2 --- /dev/null +++ b/xbmc/platform/win10/network/CMakeLists.txt @@ -0,0 +1,5 @@ +set(SOURCES NetworkWin10.cpp) + +set(HEADERS NetworkWin10.h) + +core_add_library(platform_win10_network) diff --git a/xbmc/platform/win10/network/NetworkWin10.cpp b/xbmc/platform/win10/network/NetworkWin10.cpp new file mode 100644 index 0000000000..ab43eb2951 --- /dev/null +++ b/xbmc/platform/win10/network/NetworkWin10.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2005-2013 Team XBMC + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program 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 XBMC; see the file COPYING. If not, see + * . + * + */ + +#include +#include +#include "filesystem/SpecialProtocol.h" +#include +#include +#include "PlatformDefs.h" +#include "platform/win32/WIN32Util.h" +#include "NetworkWin10.h" +#include "utils/log.h" +#include "threads/SingleLock.h" +#include "utils/CharsetConverter.h" +#include "utils/StringUtils.h" +#include "utils/CharsetConverter.h" + +#pragma pack(push, 8) + +using namespace Windows::Networking; +using namespace Windows::Networking::Connectivity; + +CNetworkInterfaceWin10::CNetworkInterfaceWin10(CNetworkWin10* network, Windows::Networking::Connectivity::ConnectionProfile^ profile) +{ + m_network = network; + m_adapter = profile; + g_charsetConverter.wToUTF8(std::wstring(profile->ProfileName->Data()), m_adaptername, false); +} + +CNetworkInterfaceWin10::~CNetworkInterfaceWin10(void) +{ + m_adapter = nullptr; +} + +std::string& CNetworkInterfaceWin10::GetName(void) +{ + return m_adaptername; +} + +bool CNetworkInterfaceWin10::IsWireless() +{ + WlanConnectionProfileDetails^ wlanConnectionProfileDetails = m_adapter->WlanConnectionProfileDetails; + return wlanConnectionProfileDetails != nullptr; +} + +bool CNetworkInterfaceWin10::IsEnabled() +{ + return true; +} + +bool CNetworkInterfaceWin10::IsConnected() +{ + return m_adapter->GetNetworkConnectivityLevel() != NetworkConnectivityLevel::None; +} + +std::string CNetworkInterfaceWin10::GetMacAddress() +{ + return "Unknown"; +} + +bool CNetworkInterfaceWin10::GetHostMacAddress(unsigned long host, std::string& mac) +{ + mac = ""; + return false; +} + +void CNetworkInterfaceWin10::GetSettings(NetworkAssignment& assignment, std::string& ipAddress, std::string& networkMask, std::string& defaultGateway, std::string& essId, std::string& key, EncMode& encryptionMode) +{ +} + +void CNetworkInterfaceWin10::SetSettings(NetworkAssignment& assignment, std::string& ipAddress, std::string& networkMask, std::string& defaultGateway, std::string& essId, std::string& key, EncMode& encryptionMode) +{ +} + +std::vector CNetworkInterfaceWin10::GetAccessPoints(void) +{ + std::vector accessPoints; + return accessPoints; +} + +void CNetworkInterfaceWin10::GetMacAddressRaw(char rawMac[6]) +{ +} + +std::string CNetworkInterfaceWin10::GetCurrentIPAddress(void) +{ + Platform::String^ ipAddress = L"0.0.0.0"; + std::string result; + + if (m_adapter->NetworkAdapter != nullptr) + { + auto hostnames = NetworkInformation::GetHostNames(); + for (unsigned int i = 0; i < hostnames->Size; ++i) + { + auto hostname = hostnames->GetAt(i); + if (hostname->Type != HostNameType::Ipv4) + { + continue; + } + + if (hostname->IPInformation != nullptr && hostname->IPInformation->NetworkAdapter != nullptr) + { + if (hostname->IPInformation->NetworkAdapter->NetworkAdapterId == m_adapter->NetworkAdapter->NetworkAdapterId) + { + ipAddress = hostname->CanonicalName; + break; + } + } + } + } + + g_charsetConverter.wToUTF8(std::wstring(ipAddress->Data()), result, false); + + return result; +} + +std::string CNetworkInterfaceWin10::GetCurrentNetmask(void) +{ + return ""; +} + +std::string CNetworkInterfaceWin10::GetCurrentWirelessEssId(void) +{ + std::string result = ""; + if (!IsWireless()) + return result; + + auto ssid = m_adapter->WlanConnectionProfileDetails->GetConnectedSsid(); + g_charsetConverter.wToUTF8(std::wstring(ssid->Data()), result, false); + return result; +} + +std::string CNetworkInterfaceWin10::GetCurrentDefaultGateway(void) +{ + return ""; +} + +CNetworkWin10::CNetworkWin10(void) +{ + queryInterfaceList(); + NetworkInformation::NetworkStatusChanged += ref new NetworkStatusChangedEventHandler([this](Platform::Object^) { + CSingleLock lock(m_critSection); + queryInterfaceList(); + }); +} + +CNetworkWin10::~CNetworkWin10(void) +{ + CleanInterfaceList(); +} + +void CNetworkWin10::CleanInterfaceList() +{ + std::vector::iterator it = m_interfaces.begin(); + while(it != m_interfaces.end()) + { + CNetworkInterface* nInt = *it; + delete nInt; + it = m_interfaces.erase(it); + } +} + +std::vector& CNetworkWin10::GetInterfaceList(void) +{ + CSingleLock lock (m_critSection); + return m_interfaces; +} + +void CNetworkWin10::queryInterfaceList() +{ + CleanInterfaceList(); + + auto connectionProfiles = NetworkInformation::GetConnectionProfiles(); + std::for_each(begin(connectionProfiles), end(connectionProfiles), [this](ConnectionProfile^ connectionProfile) + { + if (connectionProfile != nullptr && connectionProfile->GetNetworkConnectivityLevel() != NetworkConnectivityLevel::None) + { + m_interfaces.push_back(new CNetworkInterfaceWin10(this, connectionProfile)); + } + }); +} + +std::vector CNetworkWin10::GetNameServers(void) +{ + return std::vector(); +} + +void CNetworkWin10::SetNameServers(const std::vector& nameServers) +{ + return; +} + +bool CNetworkWin10::PingHost(unsigned long host, unsigned int timeout_ms /* = 2000 */) +{ + return false; +} + +#pragma pack(pop) diff --git a/xbmc/platform/win10/network/NetworkWin10.h b/xbmc/platform/win10/network/NetworkWin10.h new file mode 100644 index 0000000000..821c60c068 --- /dev/null +++ b/xbmc/platform/win10/network/NetworkWin10.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2005-2013 Team XBMC + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program 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 XBMC; see the file COPYING. If not, see + * . + * + */ +#ifndef NETWORK_WIN10_H_ +#define NETWORK_WIN10_H_ + +#include +#include +#include "network/Network.h" +#include "Iphlpapi.h" +#include "utils/stopwatch.h" +#include "threads/CriticalSection.h" + +class CNetworkWin10; + + +class CNetworkInterfaceWin10 : public CNetworkInterface +{ +public: + CNetworkInterfaceWin10(CNetworkWin10* network, Windows::Networking::Connectivity::ConnectionProfile^ profile); + ~CNetworkInterfaceWin10(void); + + virtual std::string& GetName(void); + + virtual bool IsEnabled(void); + virtual bool IsConnected(void); + virtual bool IsWireless(void); + + virtual std::string GetMacAddress(void); + virtual void GetMacAddressRaw(char rawMac[6]); + + virtual bool GetHostMacAddress(unsigned long host, std::string& mac); + + virtual std::string GetCurrentIPAddress(); + virtual std::string GetCurrentNetmask(); + virtual std::string GetCurrentDefaultGateway(void); + virtual std::string GetCurrentWirelessEssId(void); + + virtual void GetSettings(NetworkAssignment& assignment, std::string& ipAddress, std::string& networkMask, std::string& defaultGateway, std::string& essId, std::string& key, EncMode& encryptionMode); + virtual void SetSettings(NetworkAssignment& assignment, std::string& ipAddress, std::string& networkMask, std::string& defaultGateway, std::string& essId, std::string& key, EncMode& encryptionMode); + + // Returns the list of access points in the area + virtual std::vector GetAccessPoints(void); + +private: + void WriteSettings(FILE* fw, NetworkAssignment assignment, std::string& ipAddress, std::string& networkMask, std::string& defaultGateway, std::string& essId, std::string& key, EncMode& encryptionMode); + CNetworkWin10* m_network; + std::string m_adaptername; + Windows::Networking::Connectivity::ConnectionProfile^ m_adapter; +}; + + +class CNetworkWin10 : public CNetwork +{ +public: + CNetworkWin10(void); + virtual ~CNetworkWin10(void); + + // Return the list of interfaces + virtual std::vector& GetInterfaceList(void); + + // Ping remote host + virtual bool PingHost(unsigned long host, unsigned int timeout_ms = 2000); + + // Get/set the nameserver(s) + virtual std::vector GetNameServers(void); + virtual void SetNameServers(const std::vector& nameServers); + + friend class CNetworkInterfaceWin10; + +private: + int GetSocket() { return m_sock; } + void queryInterfaceList(); + void CleanInterfaceList(); + std::vector m_interfaces; + int m_sock; + CStopWatch m_netrefreshTimer; + CCriticalSection m_critSection; +}; +#endif -- cgit v1.2.3