[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / network / Zeroconf.h
blobbed66c936b61291c701e2537f14d9b11e4d832fb
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "utils/Job.h"
13 #include <map>
14 #include <string>
15 #include <utility>
16 #include <vector>
18 class CCriticalSection;
19 /// this class provides support for zeroconf
20 /// while the different zeroconf implementations have asynchronous APIs
21 /// this class hides it and provides only few ways to interact
22 /// with the services. If more control is needed, feel
23 /// free to add it. The main purpose currently is to provide an easy
24 /// way to publish services in the different StartXXX/StopXXX methods
25 /// in CApplication
26 //! @todo Make me safe for use in static initialization. CritSec is a static member :/
27 //! use e.g. loki's singleton implementation to make do it properly
28 class CZeroconf
30 public:
32 //tries to publish this service via zeroconf
33 //fcr_identifier can be used to stop or reannounce this service later
34 //fcr_type is the zeroconf service type to publish (e.g. _http._tcp for webserver)
35 //fcr_name is the name of the service to publish. The hostname is currently automatically appended
36 // and used for name collisions. e.g. XBMC would get published as fcr_name@Martn or, after collision fcr_name@Martn-2
37 //f_port port of the service to publish
38 // returns false if fcr_identifier was already present
39 bool PublishService(const std::string& fcr_identifier,
40 const std::string& fcr_type,
41 const std::string& fcr_name,
42 unsigned int f_port,
43 std::vector<std::pair<std::string, std::string> > txt /*= std::vector<std::pair<std::string, std::string> >()*/);
45 //tries to rebroadcast that service on the network without removing/readding
46 //this can be achieved by changing a fake txt record. Implementations should
47 //implement it by doing so.
49 //fcr_identifier - the identifier of the already published service which should be reannounced
50 // returns true on successful reannonuce - false if this service isn't published yet
51 bool ForceReAnnounceService(const std::string& fcr_identifier);
53 ///removes the specified service
54 ///returns false if fcr_identifier does not exist
55 bool RemoveService(const std::string& fcr_identifier);
57 ///returns true if fcr_identifier exists
58 bool HasService(const std::string& fcr_identifier) const;
60 //starts publishing
61 //services that were added with PublishService(...) while Zeroconf wasn't
62 //started, get published now.
63 bool Start();
65 // unpublishes all services (but keeps them stored in this class)
66 // a call to Start() will republish them
67 void Stop();
69 // class methods
70 // access to singleton; singleton gets created on call if not existent
71 // if zeroconf is disabled (!HAS_ZEROCONF), this will return a dummy implementation that
72 // just does nothings, otherwise the platform specific one
73 static CZeroconf* GetInstance();
74 // release the singleton; (save to call multiple times)
75 static void ReleaseInstance();
76 // returns false if ReleaseInstance() was called before
77 static bool IsInstantiated() { return smp_instance != 0; }
78 // win32: process results from the bonjour daemon
79 virtual void ProcessResults() {}
80 // returns if the service is started and services are announced
81 bool IsStarted() { return m_started; }
83 protected:
84 //methods to implement for concrete implementations
85 //publishs this service
86 virtual bool doPublishService(const std::string& fcr_identifier,
87 const std::string& fcr_type,
88 const std::string& fcr_name,
89 unsigned int f_port,
90 const std::vector<std::pair<std::string, std::string> >& txt) = 0;
92 //methods to implement for concrete implementations
93 //update this service
94 virtual bool doForceReAnnounceService(const std::string& fcr_identifier) = 0;
96 //removes the service if published
97 virtual bool doRemoveService(const std::string& fcr_ident) = 0;
99 //removes all services (short hand for "for i in m_service_map doRemoveService(i)")
100 virtual void doStop() = 0;
102 // return true if the zeroconf daemon is running
103 virtual bool IsZCdaemonRunning() { return true; }
105 protected:
106 //singleton: we don't want to get instantiated nor copied or deleted from outside
107 CZeroconf();
108 CZeroconf(const CZeroconf&);
109 virtual ~CZeroconf();
111 private:
112 struct PublishInfo{
113 std::string type;
114 std::string name;
115 unsigned int port;
116 std::vector<std::pair<std::string, std::string> > txt;
119 //protects data
120 CCriticalSection* mp_crit_sec;
121 typedef std::map<std::string, PublishInfo> tServiceMap;
122 tServiceMap m_service_map;
123 bool m_started = false;
125 static CZeroconf* smp_instance;
127 class CPublish : public CJob
129 public:
130 CPublish(const std::string& fcr_identifier, const PublishInfo& pubinfo);
131 explicit CPublish(const tServiceMap& servmap);
133 bool DoWork() override;
135 private:
136 tServiceMap m_servmap;