00001 #ifndef __XRDOUCAvahiBONJOUR_HH__
00002 #define __XRDOUCAvahiBONJOUR_HH__
00003
00004 #include <avahi-client/client.h>
00005 #include <avahi-client/lookup.h>
00006 #include <avahi-client/publish.h>
00007 #include <avahi-common/alternative.h>
00008 #include <avahi-common/simple-watch.h>
00009 #include <avahi-common/malloc.h>
00010 #include <avahi-common/error.h>
00011 #include <avahi-common/timeval.h>
00012
00013 #include <list>
00014 #include "XrdOuc/XrdOucBonjour.hh"
00015 #include "XrdOuc/XrdOucString.hh"
00016 #include "XrdSys/XrdSysPthread.hh"
00017
00018
00019
00020
00021
00022 class XrdOucAvahiBonjour : public XrdOucBonjour {
00023 private:
00024
00025 static XrdOucAvahiBonjour *_Instance;
00026
00027
00028 static XrdSysMutex SingletonMutex;
00029
00030
00031
00032 XrdOucAvahiBonjour();
00033 virtual ~XrdOucAvahiBonjour();
00034 XrdOucAvahiBonjour(const XrdOucAvahiBonjour &) { }
00035 XrdOucAvahiBonjour &operator=(const XrdOucAvahiBonjour &) {
00036 return *this;
00037 }
00038
00039
00040
00041 friend class XrdOucAvahiBonjourSingletonCleanup;
00042 class XrdOucAvahiBonjourSingletonCleanup {
00043 public:
00044 ~XrdOucAvahiBonjourSingletonCleanup();
00045 };
00046
00047 class XrdOucAvahiBonjourSearchNode {
00048 private:
00049 const char * ServiceName;
00050
00051 public:
00052 XrdOucAvahiBonjourSearchNode(const char * name) {
00053 ServiceName = name;
00054 }
00055 bool operator()(XrdOucBonjourNode * value);
00056 };
00057
00058
00059
00060
00061
00062 std::list<XrdOucBonjourRegisteredEntry *> ListOfRegistrations;
00063
00064
00065
00066 pthread_t BrowseEventLoopThreadInfo;
00067 static void * BrowseEventLoopThread(void * context);
00068
00069
00070 AvahiSimplePoll * poller;
00071
00072
00073
00074 static void RegisterReply(AvahiClient *c,
00075 AvahiClientState state,
00076 void * userdata);
00077
00078 static void RegisterEntries(XrdOucBonjourRegisteredEntry * entry);
00079
00080 static void EntryGroupReply(AvahiEntryGroup *g,
00081 AvahiEntryGroupState state,
00082 void *userdata);
00083
00084 static void ClientReply(AvahiClient *c,
00085 AvahiClientState state,
00086 void * userdata);
00087
00088 static void BrowseReply(AvahiServiceBrowser *b,
00089 AvahiIfIndex interface,
00090 AvahiProtocol protocol,
00091 AvahiBrowserEvent event,
00092 const char *name,
00093 const char *type,
00094 const char *domain,
00095 AvahiLookupResultFlags flags,
00096 void* userdata);
00097
00098 static void ResolveReply(AvahiServiceResolver *r,
00099 AvahiIfIndex interface,
00100 AvahiProtocol protocol,
00101 AvahiResolverEvent event,
00102 const char *name,
00103 const char *type,
00104 const char *domain,
00105 const char *host_name,
00106 const AvahiAddress *address,
00107 uint16_t port,
00108 AvahiStringList *txt,
00109 AvahiLookupResultFlags flags,
00110 void* userdata);
00111
00112 public:
00113
00114
00115 int RegisterService(XrdOucBonjourRecord &record,
00116 unsigned short port = 0);
00117
00118
00119
00120
00121
00122
00123 int SubscribeForUpdates(const char * servicetype,
00124 XrdOucBonjourUpdateCallback callback,
00125 void * context);
00126
00127
00128
00129
00130
00131
00132 int ResolveNodeInformation(XrdOucBonjourResolutionEntry * nodeAndCallback);
00133
00134
00135 static XrdOucAvahiBonjour &getInstance();
00136 };
00137
00138
00139
00140
00141
00142 class XrdOucAvahiBonjourFactory : public XrdOucBonjourFactory {
00143 XrdOucBonjour &GetBonjourManager() {
00144 return XrdOucAvahiBonjour::getInstance();
00145 }
00146 };
00147
00148 #endif