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 
32 namespace fawkes {
33 class AvahiThread;
34 
36 {
37 public:
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 
76 protected:
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 
127 private:
128  bool m_own_avahi_thread;
129 };
130 
131 } // namespace fawkes
132 
133 #endif /* LIBS_GUI_UTILS_HOST_MODEL_H__ */
fawkes::ServiceModel::~ServiceModel
virtual ~ServiceModel()
Destructor.
Definition: service_model.cpp:115
fawkes::ServiceModel::ServiceRecord::addrport
Gtk::TreeModelColumn< Glib::ustring > addrport
Address:port string.
Definition: service_model.h:70
fawkes::ServiceModel::ServiceRecord::type
Gtk::TreeModelColumn< Glib::ustring > type
The type of the service.
Definition: service_model.h:61
fawkes::ServiceModel::get_list_store
Glib::RefPtr< Gtk::ListStore > & get_list_store()
Get a reference to the model.
Definition: service_model.cpp:128
fawkes::ServiceModel::ServiceRecord
Detects services and manages information about detected services.
Definition: service_model.h:45
fawkes::ServiceModel::ServiceAddedRecord::name
std::string name
the name of the new service
Definition: service_model.h:95
fawkes::ServiceModel::m_added_services
fawkes::LockQueue< ServiceAddedRecord > m_added_services
Queue that holds the newly added services.
Definition: service_model.h:113
fawkes::ServiceModel::ServiceRecord::interface
Gtk::TreeModelColumn< Glib::ustring > interface
Name of network interface to reach service.
Definition: service_model.h:66
fawkes::ServiceModel::on_service_removed
virtual void on_service_removed()
Signal handler for the service-removed signal.
Definition: service_model.cpp:251
fawkes::ServiceModel::ServiceAddedRecord::domain
std::string domain
the domain of the new service
Definition: service_model.h:97
fawkes::ServiceModel::m_signal_service_removed
Glib::Dispatcher m_signal_service_removed
This signal is emitted whenever a service is removed.
Definition: service_model.h:117
fawkes::ServiceModel::ServiceAddedRecord::ipaddr
std::string ipaddr
the IP address of the new service
Definition: service_model.h:100
fawkes::ServiceModel::all_for_now
void all_for_now()
All results have been retrieved.
Definition: service_model.cpp:143
fawkes::ServiceModel::ServiceRemovedRecord
Data structure to hold information about a recently removed services.
Definition: service_model.h:107
fawkes::ServiceModel::ServiceAddedRecord::sockaddr
struct sockaddr_storage sockaddr
sockaddr structure
Definition: service_model.h:103
fawkes::ServiceModel::m_removed_services
fawkes::LockQueue< ServiceRemovedRecord > m_removed_services
Queue that holds the recently removed services.
Definition: service_model.h:114
fawkes::ServiceModel::ServiceRemovedRecord::type
std::string type
the type of the service
Definition: service_model.h:109
fawkes::ServiceModel::m_avahi
fawkes::AvahiThread * m_avahi
Avahi thread.
Definition: service_model.h:125
fawkes::ServiceModel::ServiceRecord::hostname
Gtk::TreeModelColumn< Glib::ustring > hostname
The name of the host the service is running on.
Definition: service_model.h:64
fawkes::ServiceModel::ServiceRecord::domain
Gtk::TreeModelColumn< Glib::ustring > domain
The domain of the service.
Definition: service_model.h:62
fawkes::ServiceModel
Abstract base class for widgets that allow to view the detected services of a certain type.
Definition: service_model.h:36
fawkes::AvahiThread
Avahi main thread.
Definition: avahi_thread.h:55
fawkes::ServiceModel::on_service_added
virtual void on_service_added()
Signal handler for the service-added signal.
Definition: service_model.cpp:224
fawkes::ServiceModel::ServiceRecord::sockaddr
Gtk::TreeModelColumn< struct sockaddr_storage > sockaddr
sockaddr structure
Definition: service_model.h:71
fawkes
Fawkes library namespace.
fawkes::ServiceModel::ServiceAddedRecord::interface
std::string interface
name of network interface to reach service
Definition: service_model.h:99
fawkes::ServiceModel::m_service_record
ServiceRecord m_service_record
Column record class.
Definition: service_model.h:123
fawkes::ServiceModel::service_added
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.
Definition: service_model.cpp:158
fawkes::ServiceModel::ServiceModel
ServiceModel(const char *service="_fawkes._tcp")
Constructor.
Definition: service_model.cpp:88
fawkes::ServiceModel::cache_exhausted
void cache_exhausted()
Cache exhausted.
Definition: service_model.cpp:148
fawkes::ServiceModel::ServiceRemovedRecord::name
std::string name
the name of the service
Definition: service_model.h:108
fawkes::ServiceModel::ServiceRecord::port
Gtk::TreeModelColumn< unsigned short > port
The port the service is running on.
Definition: service_model.h:69
fawkes::LockQueue
Queue with a lock.
Definition: lock_queue.h:45
fawkes::ServiceModel::m_signal_service_added
Glib::Dispatcher m_signal_service_added
This signal is emitted whenever a new service has been added.
Definition: service_model.h:116
fawkes::ServiceModel::ServiceAddedRecord::type
std::string type
the type of the new service
Definition: service_model.h:96
fawkes::ServiceModel::service_removed
void service_removed(const char *name, const char *type, const char *domain)
A service has been removed from the network.
Definition: service_model.cpp:210
fawkes::ServiceModel::ServiceAddedRecord::hostname
std::string hostname
the hostname of the new service
Definition: service_model.h:98
fawkes::ServiceModel::get_column_record
ServiceRecord & get_column_record()
Access the column record.
Definition: service_model.cpp:137
fawkes::ServiceModel::ServiceAddedRecord::port
unsigned short port
the port the new service is running on
Definition: service_model.h:101
fawkes::ServiceModel::ServiceAddedRecord::addrport
std::string addrport
address:port
Definition: service_model.h:102
fawkes::ServiceModel::browse_failed
void browse_failed(const char *name, const char *type, const char *domain)
Failed to browse for a given service.
Definition: service_model.cpp:153
fawkes::ServiceModel::ServiceRemovedRecord::domain
std::string domain
the domain of the service
Definition: service_model.h:110
fawkes::ServiceModel::ServiceAddedRecord
Data structure to hold information about a newly added services.
Definition: service_model.h:94
fawkes::ServiceModel::m_service_list
Glib::RefPtr< Gtk::ListStore > m_service_list
Storage object.
Definition: service_model.h:122
fawkes::ServiceModel::ServiceRecord::name
Gtk::TreeModelColumn< Glib::ustring > name
The name of the service.
Definition: service_model.h:60
fawkes::ServiceBrowseHandler
Interface for class that process browse results.
Definition: browse_handler.h:47
fawkes::ServiceModel::ServiceRecord::ipaddr
Gtk::TreeModelColumn< Glib::ustring > ipaddr
The IP address as string of the host the service is running on.
Definition: service_model.h:68