kodi
ZeroconfBrowserMDNS.h
1 /*
2  * Copyright (C) 2012-2018 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/ZeroconfBrowser.h"
12 #include "threads/CriticalSection.h"
13 #include "threads/Thread.h"
14 
15 #include <map>
16 #include <memory>
17 #include <utility>
18 #include <vector>
19 
20 #include <dns_sd.h>
21 
22 //platform specific implementation of zeroconfbrowser interface using native os x APIs
24 {
25 public:
28 
29 private:
32  virtual bool doAddServiceType(const std::string& fcr_service_type);
33  virtual bool doRemoveServiceType(const std::string& fcr_service_type);
34 
35  virtual std::vector<CZeroconfBrowser::ZeroconfService> doGetFoundServices();
36  virtual bool doResolveService(CZeroconfBrowser::ZeroconfService& fr_service, double f_timeout);
38 
40  static void DNSSD_API BrowserCallback(DNSServiceRef browser,
41  DNSServiceFlags flags,
42  uint32_t interfaceIndex,
43  DNSServiceErrorType errorCode,
44  const char *serviceName,
45  const char *regtype,
46  const char *replyDomain,
47  void *context);
49  static void DNSSD_API GetAddrInfoCallback(DNSServiceRef sdRef,
50  DNSServiceFlags flags,
51  uint32_t interfaceIndex,
52  DNSServiceErrorType errorCode,
53  const char *hostname,
54  const struct sockaddr *address,
55  uint32_t ttl,
56  void *context
57  );
58 
60  static void DNSSD_API ResolveCallback(DNSServiceRef sdRef,
61  DNSServiceFlags flags,
62  uint32_t interfaceIndex,
63  DNSServiceErrorType errorCode,
64  const char *fullname,
65  const char *hosttarget,
66  uint16_t port, /* In network byte order */
67  uint16_t txtLen,
68  const unsigned char *txtRecord,
69  void *context
70  );
71 
73  void addDiscoveredService(DNSServiceRef browser, CZeroconfBrowser::ZeroconfService const& fcr_service);
75  void removeDiscoveredService(DNSServiceRef browser, CZeroconfBrowser::ZeroconfService const& fcr_service);
76  // win32: process replies from the bonjour daemon
77  void ProcessResults();
78 
79  //shared variables (with guard)
80  CCriticalSection m_data_guard;
81  // tBrowserMap maps service types the corresponding browser
82  typedef std::map<std::string, DNSServiceRef> tBrowserMap;
83  tBrowserMap m_service_browsers;
84  //tDiscoveredServicesMap maps browsers to their discovered services + a ref-count for each service
85  //ref-count is needed, because a service might pop up more than once, if there's more than one network-iface
86  typedef std::map<DNSServiceRef, std::vector<std::pair<ZeroconfService, unsigned int> > > tDiscoveredServicesMap;
87  tDiscoveredServicesMap m_discovered_services;
88  DNSServiceRef m_browser;
89  CZeroconfBrowser::ZeroconfService m_resolving_service;
90  CEvent m_resolved_event;
91  CEvent m_addrinfo_event;
92 };
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: ZeroconfBrowserMDNS.h:23
Definition: ZeroconfBrowser.h:27
this class provides support for zeroconf browsing
Definition: ZeroconfBrowser.h:24