kodi
ZeroconfMDNS.h
1 /*
2  * Copyright (C) 2005-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/Zeroconf.h"
12 #include "threads/CriticalSection.h"
13 #include "threads/Thread.h"
14 
15 #include <memory>
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
20 #include <dns_sd.h>
21 
22 class CZeroconfMDNS : public CZeroconf,public CThread
23 {
24 public:
25  CZeroconfMDNS();
26  ~CZeroconfMDNS();
27 
28 protected:
29 
30  //CThread interface
31  void Process();
32 
33  //implement base CZeroConf interface
34  bool doPublishService(const std::string& fcr_identifier,
35  const std::string& fcr_type,
36  const std::string& fcr_name,
37  unsigned int f_port,
38  const std::vector<std::pair<std::string, std::string> >& txt);
39 
40  bool doForceReAnnounceService(const std::string& fcr_identifier);
41  bool doRemoveService(const std::string& fcr_ident);
42 
43  virtual void doStop();
44 
45  bool IsZCdaemonRunning();
46 
47  void ProcessResults();
48 
49 private:
50 
51  static void DNSSD_API registerCallback(DNSServiceRef sdref,
52  const DNSServiceFlags flags,
53  DNSServiceErrorType errorCode,
54  const char *name,
55  const char *regtype,
56  const char *domain,
57  void *context);
58 
59 
60  //lock + data (accessed from runloop(main thread) + the rest)
61  CCriticalSection m_data_guard;
62  struct tServiceRef
63  {
64  DNSServiceRef serviceRef;
65  TXTRecordRef txtRecordRef;
66  int updateNumber;
67  };
68  typedef std::map<std::string, struct tServiceRef> tServiceMap;
69  tServiceMap m_services;
70  DNSServiceRef m_service;
71 };
bool IsZCdaemonRunning()
Definition: ZeroconfMDNS.cpp:61
Definition: Thread.h:44
Definition: ZeroconfMDNS.h:22
this class provides support for zeroconf while the different zeroconf implementations have asynchrono...
Definition: Zeroconf.h:28
bool doPublishService(const std::string &fcr_identifier, const std::string &fcr_type, const std::string &fcr_name, unsigned int f_port, const std::vector< std::pair< std::string, std::string > > &txt)
Definition: ZeroconfMDNS.cpp:80