Fawkes API Fawkes Development Version
service_model.h
1
2/***************************************************************************
3 * service_model.h - Manages list of discovered services of given type
4 *
5 * Created: Mon Sep 29 16:26:04 2008
6 * Copyright 2008 Daniel Beck
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#ifndef _LIBS_GUI_UTILS_SERVICE_MODEL_H_
25#define _LIBS_GUI_UTILS_SERVICE_MODEL_H_
26
27#include <core/utils/lock_queue.h>
28#include <netcomm/service_discovery/browse_handler.h>
29
30#include <gtkmm.h>
31
32namespace fawkes {
33class AvahiThread;
34
36{
37public:
38 ServiceModel(const char *service = "_fawkes._tcp");
39 ServiceModel(fawkes::AvahiThread *avahi_thread);
40 virtual ~ServiceModel();
41
42 Glib::RefPtr<Gtk::ListStore> &get_list_store();
43
44 class ServiceRecord : public Gtk::TreeModelColumnRecord
45 {
46 public:
48 {
49 add(name);
50 add(type);
51 add(domain);
52 add(hostname);
53 add(interface);
54 add(ipaddr);
55 add(port);
56 add(addrport);
57 add(sockaddr);
58 }
59
60 Gtk::TreeModelColumn<Glib::ustring> name; /**< The name of the service */
61 Gtk::TreeModelColumn<Glib::ustring> type; /**< The type of the service */
62 Gtk::TreeModelColumn<Glib::ustring> domain; /**< The domain of the service */
63 Gtk::TreeModelColumn<Glib::ustring>
64 hostname; /**< The name of the host the service is running on */
65 Gtk::TreeModelColumn<Glib::ustring>
66 interface; /**< Name of network interface to reach service */
67 Gtk::TreeModelColumn<Glib::ustring>
68 ipaddr; /**< The IP address as string of the host the service is running on */
69 Gtk::TreeModelColumn<unsigned short> port; /**< The port the service is running on */
70 Gtk::TreeModelColumn<Glib::ustring> addrport; /**< Address:port string */
71 Gtk::TreeModelColumn<struct sockaddr_storage> sockaddr; /**< sockaddr structure */
72 };
73
75
76protected:
77 // service browser handler
78 void all_for_now();
79 void cache_exhausted();
80 void browse_failed(const char *name, const char *type, const char *domain);
81 void service_added(const char * name,
82 const char * type,
83 const char * domain,
84 const char * host_name,
85 const char * interface,
86 const struct sockaddr * addr,
87 const socklen_t addr_size,
88 uint16_t port,
89 std::list<std::string> &txt,
90 int flags);
91 void service_removed(const char *name, const char *type, const char *domain);
92
94 {
95 std::string name; /**< the name of the new service */
96 std::string type; /**< the type of the new service */
97 std::string domain; /**< the domain of the new service */
98 std::string hostname; /**< the hostname of the new service */
99 std::string interface; /**< name of network interface to reach service */
100 std::string ipaddr; /**< the IP address of the new service */
101 unsigned short port; /**< the port the new service is running on */
102 std::string addrport; /**< address:port */
103 struct sockaddr_storage sockaddr; /**< sockaddr structure */
104 };
105
107 {
108 std::string name; /**< the name of the service */
109 std::string type; /**< the type of the service */
110 std::string domain; /**< the domain of the service */
111 };
112
115
116 Glib::Dispatcher m_signal_service_added;
117 Glib::Dispatcher m_signal_service_removed;
118
119 virtual void on_service_added();
120 virtual void on_service_removed();
121
122 Glib::RefPtr<Gtk::ListStore> m_service_list;
124
126
127private:
128 bool m_own_avahi_thread;
129};
130
131} // namespace fawkes
132
133#endif /* LIBS_GUI_UTILS_HOST_MODEL_H__ */
Avahi main thread.
Definition: avahi_thread.h:55
Queue with a lock.
Definition: lock_queue.h:45
Interface for class that process browse results.
Detects services and manages information about detected services.
Definition: service_model.h:45
Gtk::TreeModelColumn< Glib::ustring > domain
The domain of the service.
Definition: service_model.h:62
Gtk::TreeModelColumn< unsigned short > port
The port the service is running on.
Definition: service_model.h:69
Gtk::TreeModelColumn< Glib::ustring > type
The type of the service.
Definition: service_model.h:61
Gtk::TreeModelColumn< Glib::ustring > addrport
Address:port string.
Definition: service_model.h:70
Gtk::TreeModelColumn< Glib::ustring > name
The name of the service.
Definition: service_model.h:60
Gtk::TreeModelColumn< Glib::ustring > hostname
The name of the host the service is running on.
Definition: service_model.h:64
Gtk::TreeModelColumn< struct sockaddr_storage > sockaddr
sockaddr structure
Definition: service_model.h:71
Gtk::TreeModelColumn< Glib::ustring > ipaddr
The IP address as string of the host the service is running on.
Definition: service_model.h:68
Gtk::TreeModelColumn< Glib::ustring > interface
Name of network interface to reach service.
Definition: service_model.h:66
Abstract base class for widgets that allow to view the detected services of a certain type.
Definition: service_model.h:36
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.
Fawkes library namespace.
Data structure to hold information about a newly added services.
Definition: service_model.h:94
std::string name
the name of the new service
Definition: service_model.h:95
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
Definition: service_model.h:98
std::string domain
the domain of the new service
Definition: service_model.h:97
std::string interface
name of network interface to reach service
Definition: service_model.h:99
std::string type
the type of the new service
Definition: service_model.h:96
std::string ipaddr
the IP address of the new service
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