Open Lighting Architecture  0.9.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BonjourDiscoveryAgent.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * BonjourDiscoveryAgent.h
17  * The Bonjour implementation of DiscoveryAgentInterface.
18  * Copyright (C) 2013 Simon Newton
19  */
20 
21 #ifndef OLAD_BONJOURDISCOVERYAGENT_H_
22 #define OLAD_BONJOURDISCOVERYAGENT_H_
23 
24 #include <dns_sd.h>
25 
26 #include <ola/base/Macro.h>
27 #include <ola/io/Descriptor.h>
28 #include <ola/io/SelectServer.h>
29 #include <memory>
30 #include <string>
31 #include <vector>
32 
33 #include "olad/DiscoveryAgent.h"
34 
35 namespace ola {
36 namespace thread {
37 class CallbackThread;
38 }
39 
45  public:
48 
49  bool Init();
50 
51  void RegisterService(const std::string &service_name,
52  const std::string &type,
53  uint16_t port,
54  const RegisterOptions &options);
55 
56  private:
57  struct RegisterArgs : public RegisterOptions {
58  std::string service_name;
59  std::string type;
60  uint16_t port;
61 
62  RegisterArgs(const std::string &service_name,
63  const std::string &type,
64  uint16_t port,
65  const RegisterOptions &options);
66  };
67 
68  struct ServiceRef {
69  // DNSServiceRef is just a pointer.
70  DNSServiceRef service_ref;
71  class DNSSDDescriptor *descriptor;
72  };
73 
74  typedef std::vector<ServiceRef> ServiceRefs;
75 
77  std::auto_ptr<thread::CallbackThread> m_thread;
78  ServiceRefs m_refs;
79 
80  void InternalRegisterService(RegisterArgs *args);
81  std::string BuildTxtRecord(const RegisterOptions::TxtData &txt_data);
82  void RunThread();
84 };
85 } // namespace ola
86 #endif // OLAD_BONJOURDISCOVERYAGENT_H_