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 <netcomm/service_discovery/browse_handler.h>
28 #include <core/utils/lock_queue.h>
29 #include <gtkmm.h>
30 
31 namespace fawkes {
32 class AvahiThread;
33 
35 {
36  public:
37  ServiceModel(const char* service = "_fawkes._tcp");
38  ServiceModel(fawkes::AvahiThread* avahi_thread);
39  virtual ~ServiceModel();
40 
41  Glib::RefPtr<Gtk::ListStore>& get_list_store();
42 
43  class ServiceRecord : public Gtk::TreeModelColumnRecord
44  {
45  public:
47  {
48  add(name);
49  add(type);
50  add(domain);
51  add(hostname);
52  add(interface);
53  add(ipaddr);
54  add(port);
55  add(addrport);
56  add(sockaddr);
57  }
58 
59  Gtk::TreeModelColumn<Glib::ustring> name; /**< The name of the service */
60  Gtk::TreeModelColumn<Glib::ustring> type; /**< The type of the service */
61  Gtk::TreeModelColumn<Glib::ustring> domain; /**< The domain of the service */
62  Gtk::TreeModelColumn<Glib::ustring> hostname; /**< The name of the host the service is running on */
63  Gtk::TreeModelColumn<Glib::ustring> interface; /**< Name of network interface to reach service */
64  Gtk::TreeModelColumn<Glib::ustring> ipaddr; /**< The IP address as string of the host the service is running on */
65  Gtk::TreeModelColumn<unsigned short> port; /**< The port the service is running on */
66  Gtk::TreeModelColumn<Glib::ustring> addrport; /**< Address:port string */
67  Gtk::TreeModelColumn<struct sockaddr_storage> sockaddr; /**< sockaddr structure */
68  };
69 
71 
72  protected:
73  // service browser handler
74  void all_for_now();
75  void cache_exhausted();
76  void browse_failed( const char* name,
77  const char* type,
78  const char* domain );
79  void service_added( const char* name, const char* type,
80  const char* domain, const char* host_name, const char *interface,
81  const struct sockaddr* addr, const socklen_t addr_size,
82  uint16_t port, std::list<std::string>& txt, int flags );
83  void service_removed( const char* name, const char* type, const char* domain );
84 
86  {
87  std::string name; /**< the name of the new service */
88  std::string type; /**< the type of the new service */
89  std::string domain; /**< the domain of the new service */
90  std::string hostname; /**< the hostname of the new service */
91  std::string interface; /**< name of network interface to reach service */
92  std::string ipaddr; /**< the IP address of the new service */
93  unsigned short port; /**< the port the new service is running on */
94  std::string addrport; /**< address:port */
95  struct sockaddr_storage sockaddr; /**< sockaddr structure */
96  };
97 
99  {
100  std::string name; /**< the name of the service */
101  std::string type; /**< the type of the service */
102  std::string domain; /**< the domain of the service */
103  };
104 
107 
108  Glib::Dispatcher m_signal_service_added;
109  Glib::Dispatcher m_signal_service_removed;
110 
111  virtual void on_service_added();
112  virtual void on_service_removed();
113 
114  Glib::RefPtr<Gtk::ListStore> m_service_list;
116 
118 
119  private:
120  bool m_own_avahi_thread;
121 };
122 
123 }
124 
125 #endif /* __LIBS_GUI_UTILS_HOST_MODEL_H_ */
Abstract base class for widgets that allow to view the detected services of a certain type...
Definition: service_model.h:34
ServiceRecord & get_column_record()
Access the column record.
void all_for_now()
All results have been retrieved.
Glib::RefPtr< Gtk::ListStore > m_service_list
Storage object.
virtual ~ServiceModel()
Destructor.
std::string ipaddr
the IP address of the new service
Definition: service_model.h:92
Gtk::TreeModelColumn< Glib::ustring > hostname
The name of the host the service is running on.
Definition: service_model.h:62
void browse_failed(const char *name, const char *type, const char *domain)
Failed to browse for a given service.
std::string hostname
the hostname of the new service
Definition: service_model.h:90
Fawkes library namespace.
Detects services and manages information about detected services.
Definition: service_model.h:43
std::string type
the type of the service
Glib::RefPtr< Gtk::ListStore > & get_list_store()
Get a reference to the model.
Gtk::TreeModelColumn< Glib::ustring > type
The type of the service.
Definition: service_model.h:60
fawkes::LockQueue< ServiceRemovedRecord > m_removed_services
Queue that holds the recently removed services.
std::string interface
name of network interface to reach service
Definition: service_model.h:91
Interface for class that process browse results.
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.
Glib::Dispatcher m_signal_service_removed
This signal is emitted whenever a service is removed.
virtual void on_service_removed()
Signal handler for the service-removed signal.
Gtk::TreeModelColumn< struct sockaddr_storage > sockaddr
sockaddr structure
Definition: service_model.h:67
unsigned short port
the port the new service is running on
Definition: service_model.h:93
ServiceRecord m_service_record
Column record class.
Data structure to hold information about a recently removed services.
Definition: service_model.h:98
std::string type
the type of the new service
Definition: service_model.h:88
fawkes::AvahiThread * m_avahi
Avahi thread.
virtual void on_service_added()
Signal handler for the service-added signal.
std::string name
the name of the new service
Definition: service_model.h:87
Gtk::TreeModelColumn< Glib::ustring > domain
The domain of the service.
Definition: service_model.h:61
Avahi main thread.
Definition: avahi_thread.h:54
Gtk::TreeModelColumn< unsigned short > port
The port the service is running on.
Definition: service_model.h:65
Queue with a lock.
Definition: lock_queue.h:43
Gtk::TreeModelColumn< Glib::ustring > addrport
Address:port string.
Definition: service_model.h:66
std::string domain
the domain of the service
void cache_exhausted()
Cache exhausted.
ServiceModel(const char *service="_fawkes._tcp")
Constructor.
Data structure to hold information about a newly added services.
Definition: service_model.h:85
Gtk::TreeModelColumn< Glib::ustring > name
The name of the service.
Definition: service_model.h:59
void service_removed(const char *name, const char *type, const char *domain)
A service has been removed from the network.
std::string domain
the domain of the new service
Definition: service_model.h:89
Glib::Dispatcher m_signal_service_added
This signal is emitted whenever a new service has been added.
Gtk::TreeModelColumn< Glib::ustring > interface
Name of network interface to reach service.
Definition: service_model.h:63
Gtk::TreeModelColumn< Glib::ustring > ipaddr
The IP address as string of the host the service is running on.
Definition: service_model.h:64
std::string name
the name of the service
fawkes::LockQueue< ServiceAddedRecord > m_added_services
Queue that holds the newly added services.