kodi
ZeroconfDarwin.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 <memory>
12 #include <vector>
13 
14 #include "network/Zeroconf.h"
15 #include "threads/CriticalSection.h"
16 
17 #include <CoreFoundation/CoreFoundation.h>
18 #if defined(TARGET_DARWIN_OSX)
19  #include <CoreServices/CoreServices.h>
20 #else
21  #include <CFNetwork/CFNetServices.h>
22 #endif
23 
24 class CZeroconfDarwin : public CZeroconf
25 {
26 public:
28  ~CZeroconfDarwin() override;
29 
30 protected:
31  //implement base CZeroConf interface
32  bool doPublishService(const std::string& fcr_identifier,
33  const std::string& fcr_type,
34  const std::string& fcr_name,
35  unsigned int f_port,
36  const std::vector<std::pair<std::string, std::string>>& txt) override;
37 
38  bool doForceReAnnounceService(const std::string& fcr_identifier) override;
39 
40  bool doRemoveService(const std::string& fcr_ident) override;
41 
42  void doStop() override;
43 
44 private:
45  static void registerCallback(CFNetServiceRef theService, CFStreamError* error, void* info);
46  void cancelRegistration(CFNetServiceRef theService);
47 
48  //CF runloop ref; we're using main-threads runloop
49  CFRunLoopRef m_runloop = nullptr;
50 
51  //lock + data (accessed from runloop(main thread) + the rest)
52  CCriticalSection m_data_guard;
53  typedef std::map<std::string, CFNetServiceRef> tServiceMap;
54  tServiceMap m_services;
55 };
Definition: ZeroconfDarwin.h:24
this class provides support for zeroconf while the different zeroconf implementations have asynchrono...
Definition: Zeroconf.h:28