xbmc
SMBWSDiscovery.h
1 /*
2  * Copyright (C) 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 #include "threads/SingleLock.h"
14 
15 #include "platform/posix/filesystem/SMBWSDiscoveryListener.h"
16 
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 class CFileItemList;
22 
23 namespace WSDiscovery
24 {
25 class CWSDiscoveryListenerUDP;
26 }
27 
28 namespace WSDiscovery
29 {
31 {
32  std::string action; // ToDo: Action probably isnt required to be stored
33  std::string msgid;
34  std::string types; // ToDo: Types may not be needed.
35  std::string address;
36  std::string xaddrs;
37  std::string xaddrs_host;
38  std::string computer;
39 
40  bool operator==(const wsd_req_info& item) const
41  {
42  return ((item.xaddrs == xaddrs) && (item.address == address));
43  }
44 };
45 
47 {
48 public:
50 
51  // IWSDiscovery interface methods
52  ~CWSDiscoveryPosix() override;
53  bool StartServices() override;
54  bool StopServices() override;
55  bool IsRunning() override;
56 
57  /*
58  * Get List of smb servers found by WSD
59  * out (CFileItemList&) List of fileitems populated with smb addresses
60  * return (bool) true if >0 WSD addresses found
61  */
62  bool GetServerList(CFileItemList& items);
63 
64  long long GetInstanceID() const { return wsd_instance_id; }
65 
66  /*
67  * Set List of WSD info request
68  * out (vector<wsd_req_info>) vector of WSD responses received
69  * return void
70  */
71  void SetItems(std::vector<WSDiscovery::wsd_req_info> entries);
72 
73  /*
74  * Lookup host name in collected ws-discovery data
75  * in (const std::string&) Host name
76  * out (std::string&) IP address if found
77  * return (bool) true if found
78  */
79  bool GetCached(const std::string& strHostName, std::string& strIpAddress);
80 
81  static bool IsInitialized() { return m_isInitialized; }
82 
83 private:
84  CCriticalSection m_critWSD;
85 
86  /*
87  * As per docs - Pg32 - http://specs.xmlsoap.org/ws/2005/04/discovery/ws-discovery.pdf
88  * MUST be incremented by >= 1 each time the service has gone down, lost state,
89  * and came back up again. SHOULD NOT be incremented otherwise. Means to set
90  * this value include, but are not limited to:
91  * • A counter that is incremented on each 'cold' boot
92  * • The boot time of the service, expressed as seconds elapsed since midnight
93  * January 1, 1970
94  *
95  * Our implementation will only set this on creation of the class
96  * We arent providing services to clients, so this should be ok.
97  */
98  long long wsd_instance_id;
99 
100  // WSD UDP daemon
101  std::unique_ptr<WSDiscovery::CWSDiscoveryListenerUDP> m_WSDListenerUDP;
102 
103  std::vector<WSDiscovery::wsd_req_info> m_vecWSDInfo;
104 
105  static std::atomic<bool> m_isInitialized;
106 };
107 } // namespace WSDiscovery
Definition: SMBWSDiscovery.h:46
Definition: IWSDiscovery.h:13
Represents a list of files.
Definition: FileItem.h:721
Definition: IWSDiscovery.h:15
Definition: SMBWSDiscovery.h:30