24 #include <gui_utils/service_model.h>
25 #include <netcomm/dns-sd/avahi_thread.h>
27 #include <sys/types.h>
28 #include <sys/socket.h>
29 #include <arpa/inet.h>
86 ServiceModel::ServiceModel(
const char* service)
88 m_service_list = Gtk::ListStore::create(m_service_record);
91 m_avahi->watch_service(service,
this);
94 m_own_avahi_thread =
true;
96 m_signal_service_added.connect( sigc::mem_fun(*
this, &ServiceModel::on_service_added) );
97 m_signal_service_removed.connect( sigc::mem_fun(*
this, &ServiceModel::on_service_removed) );
106 m_service_list = Gtk::ListStore::create(m_service_record);
108 m_avahi = avahi_thread;
109 m_own_avahi_thread =
false;
113 ServiceModel::~ServiceModel()
115 if (m_own_avahi_thread)
126 Glib::RefPtr<Gtk::ListStore>&
127 ServiceModel::get_list_store()
129 return m_service_list;
136 ServiceModel::get_column_record()
138 return m_service_record;
142 ServiceModel::all_for_now()
147 ServiceModel::cache_exhausted()
152 ServiceModel::browse_failed(
const char* name,
159 ServiceModel::service_added(
const char* name,
162 const char* host_name,
163 const struct sockaddr* addr,
164 const socklen_t addr_size,
166 std::list<std::string>& txt,
170 char ipaddr[INET_ADDRSTRLEN];
171 struct sockaddr_in *saddr = (
struct sockaddr_in *)addr;
172 s.
name = string(name);
173 s.
type = string(type);
174 s.
domain = string(domain);
176 s.
ipaddr = inet_ntop(AF_INET, &(saddr->sin_addr), ipaddr,
sizeof(ipaddr));
179 m_added_services.push_locked(s);
181 m_signal_service_added();
185 ServiceModel::service_removed(
const char* name,
190 s.
name = string(name);
191 s.
type = string(type);
192 s.
domain = string(domain);
194 m_removed_services.push_locked(s);
196 m_signal_service_removed();
201 ServiceModel::on_service_added()
203 m_added_services.lock();
205 while ( !m_added_services.empty() )
209 Gtk::TreeModel::Row row = *m_service_list->append();
211 row[m_service_record.name] = s.
name;
212 row[m_service_record.type] = s.
type;
213 row[m_service_record.domain] = s.
domain;
214 row[m_service_record.hostname] = s.
hostname;
215 row[m_service_record.ipaddr] = s.
ipaddr;
216 row[m_service_record.port] = s.
port;
218 m_added_services.pop();
221 m_added_services.unlock();
226 ServiceModel::on_service_removed()
228 m_removed_services.lock();
230 while ( !m_removed_services.empty() )
235 iter = m_service_list->children().begin();
237 while ( iter != m_service_list->children().end() )
239 Gtk::TreeModel::Row row = *iter;
240 if ( (row[m_service_record.name] == s.
name) &&
241 (row[m_service_record.type] == s.
type) &&
242 (row[m_service_record.domain] == s.
domain) )
244 iter = m_service_list->erase(iter);
245 m_service_list->row_deleted( m_service_list->get_path(iter) );
251 m_removed_services.pop();
254 m_removed_services.unlock();
std::string ipaddr
the IP address of the new service
std::string hostname
the hostname of the new service
Fawkes library namespace.
Detects services and manages information about detected services.
std::string type
the type of the service
unsigned short port
the port the new service is running on
Data structure to hold information about a recently removed services.
std::string type
the type of the new service
std::string name
the name of the new service
void cancel()
Cancel a thread.
std::string domain
the domain of the service
Data structure to hold information about a newly added services.
std::string domain
the domain of the new service
std::string name
the name of the service