00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _BONJOUR_DISCOVERY_H_
00018 #define _BONJOUR_DISCOVERY_H_
00019
00020 #ifndef DTN_CONFIG_STATE
00021 #error "MUST INCLUDE dtn-config.h before including this file"
00022 #endif
00023
00024 #ifdef OASYS_BONJOUR_ENABLED
00025
00026 #include <dns_sd.h>
00027 #include <vector>
00028
00029 #include <oasys/thread/Notifier.h>
00030 #include <oasys/thread/Thread.h>
00031 #include "Discovery.h"
00032
00033 namespace dtn {
00034
00039 class BonjourDiscovery : public Discovery, public oasys::Thread {
00040 public:
00042 BonjourDiscovery(const std::string& name);
00043 virtual ~BonjourDiscovery();
00044
00046 bool configure(int argc, const char* argv[]);
00047 void shutdown();
00049
00051 void run();
00052
00053 private:
00054 oasys::Notifier notifier_;
00055 bool shutdown_;
00056 typedef std::vector<DNSServiceRef> SvcVector;
00057 SvcVector svc_vec_;
00058
00059 int ttl_;
00060
00062 static void register_reply_callback(DNSServiceRef sdRef,
00063 DNSServiceFlags flags,
00064 DNSServiceErrorType errorCode,
00065 const char *name,
00066 const char *regtype,
00067 const char *domain,
00068 void *context)
00069 {
00070 ((BonjourDiscovery*)context)->
00071 handle_register_reply(sdRef, flags, errorCode, name,
00072 regtype, domain);
00073 }
00074
00076 void handle_register_reply(DNSServiceRef sdRef,
00077 DNSServiceFlags flags,
00078 DNSServiceErrorType errorCode,
00079 const char *name,
00080 const char *regtype,
00081 const char *domain);
00082
00084 static void browse_callback(DNSServiceRef sdRef,
00085 DNSServiceFlags flags,
00086 uint32_t interfaceIndex,
00087 DNSServiceErrorType errorCode,
00088 const char *serviceName,
00089 const char *regtype,
00090 const char *replyDomain,
00091 void *context)
00092 {
00093 ((BonjourDiscovery*)context)->
00094 handle_browse(sdRef, flags, interfaceIndex, errorCode,
00095 serviceName, regtype, replyDomain);
00096 }
00097
00099 void handle_browse(DNSServiceRef sdRef,
00100 DNSServiceFlags flags,
00101 uint32_t interfaceIndex,
00102 DNSServiceErrorType errorCode,
00103 const char *serviceName,
00104 const char *regtype,
00105 const char *replyDomain);
00106
00108 static void resolve_callback(DNSServiceRef sdRef,
00109 DNSServiceFlags flags,
00110 uint32_t interfaceIndex,
00111 DNSServiceErrorType errorCode,
00112 const char *fullname,
00113 const char *hosttarget,
00114 uint16_t port,
00115 uint16_t txtlen,
00116 const char* txtRecord,
00117 void *context)
00118 {
00119 ((BonjourDiscovery*)context)->
00120 handle_resolve(sdRef, flags, interfaceIndex, errorCode,
00121 fullname, hosttarget, port, txtlen, txtRecord);
00122 }
00123
00125 void handle_resolve(DNSServiceRef sdRef,
00126 DNSServiceFlags flags,
00127 uint32_t interfaceIndex,
00128 DNSServiceErrorType errorCode,
00129 const char *fullname,
00130 const char *hosttarget,
00131 uint16_t port,
00132 uint16_t txtlen,
00133 const char* txtRecord);
00134
00139 static const char* dns_service_strerror(DNSServiceErrorType err);
00140
00144 void remove_svc(DNSServiceRef sdRef);
00145 };
00146
00147 }
00148
00149 #endif
00150
00151 #endif