kodi
WSDiscoveryWin32.h
1 /*
2  * Copyright (C) 2005-2021 Team Kodi
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/IWSDiscovery.h"
12 #include "threads/CriticalSection.h"
13 
14 #include <wsdapi.h>
15 #pragma comment(lib, "wsdapi.lib")
16 
17 #include <vector>
18 
19 namespace WSDiscovery
20 {
21 class CClientNotificationSink : public IWSDiscoveryProviderNotify
22 {
23 public:
26 
27  static HRESULT Create(CClientNotificationSink** sink);
28 
29  HRESULT STDMETHODCALLTYPE Add(IWSDiscoveredService* service);
30  HRESULT STDMETHODCALLTYPE Remove(IWSDiscoveredService* service);
31  HRESULT STDMETHODCALLTYPE SearchFailed(HRESULT hr, LPCWSTR tag);
32  HRESULT STDMETHODCALLTYPE SearchComplete(LPCWSTR tag);
33  HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** object);
34  ULONG STDMETHODCALLTYPE AddRef();
35  ULONG STDMETHODCALLTYPE Release();
36 
37  bool ThereAreServers() { return m_serversIPs.size() > 0; }
38  std::vector<std::wstring> GetServersIPs() { return m_serversIPs; }
39 
40 private:
41  std::vector<std::wstring> m_serversIPs;
42  ULONG m_cRef;
43  CCriticalSection m_criticalSection;
44 };
45 
47 {
48 public:
49  CWSDiscoveryWindows() = default;
50  ~CWSDiscoveryWindows() override;
51 
52  bool StartServices() override;
53  bool StopServices() override;
54  bool IsRunning() override;
55 
56  bool ThereAreServers();
57  std::vector<std::wstring> GetServersIPs();
58 
59  static std::wstring ResolveHostName(const std::wstring& serverIP);
60 
61 private:
62  bool m_initialized = false;
63  IWSDiscoveryProvider* m_provider = nullptr;
64  CClientNotificationSink* m_sink = nullptr;
65 };
66 } // namespace WSDiscovery
Definition: IWSDiscovery.h:13
Definition: WSDiscoveryWin32.h:46
Definition: IWSDiscovery.h:15
Definition: WSDiscoveryWin32.h:21