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);
90 details (AvahiIfIndex i, AvahiProtocol p) : interface (i), protocol (p) {}
92 details (AvahiIfIndex i, AvahiProtocol p, Glib::ustring a, AvahiLookupResultFlags f) : interface (i), protocol (p), address (a), flags (f) {}
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));
Base class for classes which want reference counting through Glib::RefPtr.
Definition: refbase.hh:27
Class for browsing other hosts.
Definition: avahi.hh:75
Serve and browse the local network using avahi.
Definition: avahi.hh:40
AvahiLookupResultFlags flags
Some flags about the result. Usually not useful; see the avahi documentation for possible values and ...
Definition: avahi.hh:88
AvahiProtocol protocol
Protocol. This is always tcp, because other protocols are never browsed by this class.
Definition: avahi.hh:84
static Glib::RefPtr< avahi > create(Glib::ustring const &name=Glib::ustring())
Create an avahi object for serving and/or browsing.
Definition: avahi.hh:54
details()
Create a details object. The application has no use for this.
Definition: avahi.hh:94
details(AvahiIfIndex i, AvahiProtocol p)
Create a details object. The application has no use for this.
Definition: avahi.hh:90
details(AvahiIfIndex i, AvahiProtocol p, Glib::ustring a, AvahiLookupResultFlags f)
Create a details object. The application has no use for this.
Definition: avahi.hh:92
~avahi()
Unpublish all ports and free all structures associated with the object.
AvahiIfIndex interface
Network interface.
Definition: avahi.hh:82
Glib::RefPtr< browser > create_browser(Glib::ustring const &protocol)
Create a browser and populate it with a list of available hosts for the requested protocol...
Definition: avahi.hh:140
Glib::ustring address
Hostname or ip address of the server.
Definition: avahi.hh:86
Details about a discovered service. These are internally created and may be examined by the applicati...
Definition: avahi.hh:79
void publish(Glib::ustring const &protocol, int port)
Publish a service on a port.