18 #ifndef SHEVEK_AVAHI_HH
19 #define SHEVEK_AVAHI_HH
26 #include <avahi-client/client.h>
27 #include <avahi-client/lookup.h>
28 #include <avahi-client/publish.h>
29 #include <avahi-common/alternative.h>
30 #include <avahi-common/error.h>
31 #include <avahi-common/simple-watch.h>
32 #include <avahi-glib/glib-watch.h>
46 void publish (Glib::ustring
const &protocol,
int port);
52 inline Glib::RefPtr <browser>
create_browser (Glib::ustring
const &protocol);
54 static Glib::RefPtr <avahi>
create (Glib::ustring
const &name = Glib::ustring ()) {
return Glib::RefPtr <avahi> (
new avahi (name)); }
58 avahi (Glib::ustring
const &name,
bool allow_restart =
true,
bool blocking_poller =
false);
59 std::map <Glib::ustring, int> m_ports;
62 AvahiPoll
const *m_poll_api;
63 AvahiGLibPoll *m_glib_poll;
64 AvahiEntryGroup *m_group;
65 AvahiClient *m_client;
66 AvahiSimplePoll *m_poller;
67 void create_services (AvahiClient *client);
68 void create_client ();
69 void name_change (AvahiClient *client);
70 static void group_callback (AvahiEntryGroup *g, AvahiEntryGroupState state,
void *userdata);
71 static void callback (AvahiClient *client, AvahiClientState state,
void *userdata);
96 bool operator< (
details const &that)
const {
return interface == that.interface ? protocol < that.protocol : interface < that.interface; }
99 typedef std::set <details> details_list;
108 owner (Glib::ustring const &h, int p) : host (h), port (p) {}
110 owner () : port (-1) {}
112 bool operator< (owner const &that) const { return host == that.host ? port < that.port : host < that.host; }
114 details_list details;
117 typedef std::map <Glib::ustring, owner> list;
119 list const &get_list () { return m_list; }
121 sigc::signal1 <void, Glib::ustring const &> signal_changed () { return m_changed; }
125 static Glib::RefPtr <browser> create (Glib::ustring const &protocol) { return Glib::RefPtr <browser> (new browser (avahi::create (), protocol)); }
127 static list get_list_block (Glib::ustring const &protocol, Glib::ustring const &name = Glib::ustring ());
129 Glib::RefPtr <avahi> m_parent;
131 AvahiServiceBrowser *m_sb;
132 sigc::signal1 <void, Glib::ustring const &> m_changed;
133 Glib::ustring m_filter;
135 browser (Glib::RefPtr <avahi> parent, Glib::ustring const &protocol);
136 static void resolve_callback (AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, char const *name, char const *type, char const *domain, char const *host_name, AvahiAddress const *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void * userdata);
137 static void browse_callback (AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char const *name, char const *type, char const *domain, AvahiLookupResultFlags flags, void *userdata);
140 Glib::RefPtr <avahi::browser> avahi::create_browser (Glib::ustring const &protocol)
142 return Glib::RefPtr <browser> (new browser (refptr_this <avahi> (), protocol));