XrdOucAppleBonjour.hh

Go to the documentation of this file.
00001 #ifndef __XRDOUCAPPLEBONJOUR_HH__
00002 #define __XRDOUCAPPLEBONJOUR_HH__
00003 
00004 #include <dns_sd.h>
00005 #include <list>
00006 #include "XrdOuc/XrdOucBonjour.hh"
00007 #include "XrdOuc/XrdOucString.hh"
00008 #include "XrdSys/XrdSysPthread.hh"
00009 
00010 /******************************************************************************/
00011 /*                      B o n j o u r   s e r v i c e s                       */
00012 /******************************************************************************/
00013 
00014 class XrdOucAppleBonjour : public XrdOucBonjour {
00015 private:
00016    // Singleton instance.
00017    static XrdOucAppleBonjour *_Instance;
00018 
00019    // Mutex to protect the construction of the instance.
00020    static XrdSysMutex SingletonMutex;
00021 
00022    // All the constructors are private in order to disable object creation,
00023    // copy or assignment.
00024    XrdOucAppleBonjour();
00025    virtual ~XrdOucAppleBonjour();
00026    XrdOucAppleBonjour(const XrdOucAppleBonjour &) { }
00027    XrdOucAppleBonjour &operator=(const XrdOucAppleBonjour &) {
00028       return *this;
00029    }
00030 
00031    // This a trick to ensure that the singleton object will be deleted when
00032    // the class is unloaded at program shutdown.
00033    friend class XrdOucAppleBonjourSingletonCleanup;
00034    class XrdOucAppleBonjourSingletonCleanup {
00035    public:
00036       ~XrdOucAppleBonjourSingletonCleanup();
00037    };
00038 
00039    class XrdOucAppleBonjourSearchNode {
00040    private:
00041       const char * ServiceName;
00042 
00043    public:
00044       XrdOucAppleBonjourSearchNode(const char * name) {
00045          ServiceName = name;
00046       }
00047       bool operator()(XrdOucBonjourNode * value);
00048    };
00049 
00050    // List of registered services we have. We mantain this since the service
00051    // ref is needed to keep alive in order to matain the registration. In
00052    // this moment a function to release registrations is not needed since
00053    // protocols live as much as the whole process.
00054    std::list<XrdOucBonjourRegisteredEntry *> ListOfRegistrations;
00055 
00056    // Callbacks for the DNS-SD C API
00057    static void RegisterReply(DNSServiceRef ref,
00058                              DNSServiceFlags flags,
00059                              DNSServiceErrorType error,
00060                              const char * name,
00061                              const char * regtype,
00062                              const char * domain,
00063                              void * context);
00064 
00065    static void BrowseReply(DNSServiceRef ref,
00066                            DNSServiceFlags flags,
00067                            uint32_t interfaceIndex,
00068                            DNSServiceErrorType error,
00069                            const char * name,
00070                            const char * regtype,
00071                            const char * domain,
00072                            void * context);
00073 
00074    static void ResolveReply(DNSServiceRef ref,
00075                             DNSServiceFlags flags,
00076                             uint32_t interfaceIndex,
00077                             DNSServiceErrorType error,
00078                             const char * fullname,
00079                             const char * hostname,
00080                             uint16_t port,
00081                             uint16_t txtLen,
00082                             const unsigned char * txtVal,
00083                             void * context);
00084 
00085    // Internal thread that updates the node list as updates come from the
00086    // dns responder.
00087    pthread_t BrowseEventLoopThreadInfo;
00088    static void * BrowseEventLoopThread(void * context);
00089 
00090 public:
00091    // Register a service on the mDNS local service. This funcion also
00092    // subscribes the sender for updates on the discoverage service.
00093    int RegisterService(XrdOucBonjourRecord &record,
00094                        unsigned short port = 0);
00095 
00096    // Subscribes a new client to receive updates about service discoveries.
00097    // This will detatch a new thread to process the updates, running (when
00098    // a new update arrives) the callback function in its own thread. This
00099    // function mush be thread-safe, and its responsability of the client
00100    // to ensure that.
00101    int SubscribeForUpdates(const char * servicetype,
00102                            XrdOucBonjourUpdateCallback callback,
00103                            void * context);
00104 
00105    // Resolves the name of a node. If you provides a pointer to a node
00106    // object, this function completes the current information about hostname
00107    // and port. It is important to use the resolution by-demand since the list
00108    // may not contain updated information due to the use of highly dynamical
00109    // DHCP and APIPA addresses.
00110    int ResolveNodeInformation(XrdOucBonjourResolutionEntry * nodeAndCallback);
00111 
00112    // Accessor to get the singleton instance.
00113    static XrdOucAppleBonjour &getInstance();
00114 };
00115 
00116 /******************************************************************************/
00117 /*                      A b s t r a c t   f a c t o r y                       */
00118 /******************************************************************************/
00119 
00120 class XrdOucAppleBonjourFactory : public XrdOucBonjourFactory {
00121    XrdOucBonjour &GetBonjourManager() {
00122       return XrdOucAppleBonjour::getInstance();
00123    }
00124 };
00125 
00126 #endif

Generated on Tue Jul 5 14:46:48 2011 for ROOT_528-00b_version by  doxygen 1.5.1