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(ipaddr);
53  add(port);
54  }
55 
56  Gtk::TreeModelColumn<Glib::ustring> name; /**< The name of the service */
57  Gtk::TreeModelColumn<Glib::ustring> type; /**< The type of the service */
58  Gtk::TreeModelColumn<Glib::ustring> domain; /**< The domain of the service */
59  Gtk::TreeModelColumn<Glib::ustring> hostname; /**< The name of the host the service is running on */
60  Gtk::TreeModelColumn<Glib::ustring> ipaddr; /**< The IP address as string of the host the service is running on */
61  Gtk::TreeModelColumn<unsigned short> port; /**< The port the service is running on */
62  };
63 
65 
66  protected:
67  // service browser handler
68  void all_for_now();
69  void cache_exhausted();
70  void browse_failed( const char* name,
71  const char* type,
72  const char* domain );
73  void service_added( const char* name,
74  const char* type,
75  const char* domain,
76  const char* host_name,
77  const struct sockaddr* addr,
78  const socklen_t addr_size,
79  uint16_t port,
80  std::list<std::string>& txt,
81  int flags );
82  void service_removed( const char* name,
83  const char* type,
84  const char* domain );
85 
87  {
88  std::string name; /**< the name of the new service */
89  std::string type; /**< the type of the new service */
90  std::string domain; /**< the domain of the new service */
91  std::string hostname; /**< the hostname of the new 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  };
95 
97  {
98  std::string name; /**< the name of the service */
99  std::string type; /**< the type of the service */
100  std::string domain; /**< the domain of the service */
101  };
102 
105 
106  Glib::Dispatcher m_signal_service_added;
107  Glib::Dispatcher m_signal_service_removed;
108 
109  virtual void on_service_added();
110  virtual void on_service_removed();
111 
112  Glib::RefPtr<Gtk::ListStore> m_service_list;
114 
116 
117  private:
118  bool m_own_avahi_thread;
119 };
120 
121 }
122 
123 #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
void service_added(const char *name, const char *type, const char *domain, const char *host_name, 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.
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:59
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:91
Fawkes library namespace.
Detects services and manages information about detected services.
Definition: service_model.h:43
std::string type
the type of the service
Definition: service_model.h:99
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:57
fawkes::LockQueue< ServiceRemovedRecord > m_removed_services
Queue that holds the recently removed services.
Interface for class that process browse results.
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.
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:96
std::string type
the type of the new service
Definition: service_model.h:89
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:88
Gtk::TreeModelColumn< Glib::ustring > domain
The domain of the service.
Definition: service_model.h:58
Avahi main thread.
Definition: avahi_thread.h:55
Gtk::TreeModelColumn< unsigned short > port
The port the service is running on.
Definition: service_model.h:61
Queue with a lock.
Definition: lock_queue.h:43
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:86
Gtk::TreeModelColumn< Glib::ustring > name
The name of the service.
Definition: service_model.h:56
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:90
Glib::Dispatcher m_signal_service_added
This signal is emitted whenever a new service has been added.
Gtk::TreeModelColumn< Glib::ustring > ipaddr
The IP address as string of the host the service is running on.
Definition: service_model.h:60
std::string name
the name of the service
Definition: service_model.h:98
fawkes::LockQueue< ServiceAddedRecord > m_added_services
Queue that holds the newly added services.