25#include <gui_utils/service_model.h>
26#include <netcomm/dns-sd/avahi_thread.h>
27#include <sys/socket.h>
29#include <utils/misc/string_conversions.h>
88ServiceModel::ServiceModel(
const char *service)
96 m_own_avahi_thread =
true;
111 m_own_avahi_thread =
false;
117 if (m_own_avahi_thread) {
127Glib::RefPtr<Gtk::ListStore> &
161 const char * host_name,
162 const char * interface,
163 const struct sockaddr * addr,
164 const socklen_t addr_size,
166 std::list<std::string> &txt,
170 if (addr->sa_family == AF_INET) {
171 char ipaddr[INET_ADDRSTRLEN];
172 struct sockaddr_in *saddr = (
struct sockaddr_in *)addr;
173 if (inet_ntop(AF_INET, &(saddr->sin_addr), ipaddr,
sizeof(ipaddr)) != NULL) {
178 s.
addrport = std::string(
"Failed to convert IPv4: ") + strerror(errno);
180 }
else if (addr->sa_family == AF_INET6) {
181 char ipaddr[INET6_ADDRSTRLEN];
182 struct sockaddr_in6 *saddr = (
struct sockaddr_in6 *)addr;
183 if (inet_ntop(AF_INET6, &(saddr->sin6_addr), ipaddr,
sizeof(ipaddr)) != NULL) {
189 s.
addrport = std::string(
"Failed to convert IPv6: ") + strerror(errno);
193 s.
addrport =
"Unknown address family";
202 memcpy(&s.
sockaddr, addr, addr_size);
213 s.
name = string(name);
214 s.
type = string(type);
215 s.
domain = string(domain);
262 Gtk::TreeModel::Row row = *iter;
void watch_service(const char *service_type, ServiceBrowseHandler *h)
Add a result handler.
Detects services and manages information about detected services.
Gtk::TreeModelColumn< Glib::ustring > domain
The domain of the service.
Gtk::TreeModelColumn< unsigned short > port
The port the service is running on.
Gtk::TreeModelColumn< Glib::ustring > type
The type of the service.
Gtk::TreeModelColumn< Glib::ustring > addrport
Address:port string.
Gtk::TreeModelColumn< Glib::ustring > name
The name of the service.
Gtk::TreeModelColumn< Glib::ustring > hostname
The name of the host the service is running on.
Gtk::TreeModelColumn< struct sockaddr_storage > sockaddr
sockaddr structure
Gtk::TreeModelColumn< Glib::ustring > ipaddr
The IP address as string of the host the service is running on.
Gtk::TreeModelColumn< Glib::ustring > interface
Name of network interface to reach service.
fawkes::AvahiThread * m_avahi
Avahi thread.
ServiceRecord & get_column_record()
Access the column record.
void service_added(const char *name, const char *type, const char *domain, const char *host_name, const char *interface, const struct sockaddr *addr, const socklen_t addr_size, uint16_t port, std::list< std::string > &txt, int flags)
A service has been announced on the network.
void browse_failed(const char *name, const char *type, const char *domain)
Failed to browse for a given service.
fawkes::LockQueue< ServiceAddedRecord > m_added_services
Queue that holds the newly added services.
virtual void on_service_added()
Signal handler for the service-added signal.
virtual void on_service_removed()
Signal handler for the service-removed signal.
fawkes::LockQueue< ServiceRemovedRecord > m_removed_services
Queue that holds the recently removed services.
Glib::Dispatcher m_signal_service_added
This signal is emitted whenever a new service has been added.
void all_for_now()
All results have been retrieved.
ServiceModel(const char *service="_fawkes._tcp")
Constructor.
Glib::RefPtr< Gtk::ListStore > & get_list_store()
Get a reference to the model.
void cache_exhausted()
Cache exhausted.
Glib::RefPtr< Gtk::ListStore > m_service_list
Storage object.
Glib::Dispatcher m_signal_service_removed
This signal is emitted whenever a service is removed.
void service_removed(const char *name, const char *type, const char *domain)
A service has been removed from the network.
ServiceRecord m_service_record
Column record class.
virtual ~ServiceModel()
Destructor.
static std::string to_string(unsigned int i)
Convert unsigned int value to a string.
void start(bool wait=true)
Call this method to start the thread.
void join()
Join the thread.
void cancel()
Cancel a thread.
Fawkes library namespace.
Data structure to hold information about a newly added services.
std::string name
the name of the new service
unsigned short port
the port the new service is running on
struct sockaddr_storage sockaddr
sockaddr structure
std::string hostname
the hostname of the new service
std::string domain
the domain of the new service
std::string interface
name of network interface to reach service
std::string type
the type of the new service
std::string ipaddr
the IP address of the new service
std::string addrport
address:port
Data structure to hold information about a recently removed services.
std::string type
the type of the service
std::string domain
the domain of the service
std::string name
the name of the service