00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __LIBS_GUI_UTILS_SERVICE_MODEL_H_
00025 #define __LIBS_GUI_UTILS_SERVICE_MODEL_H_
00026
00027 #include <netcomm/service_discovery/browse_handler.h>
00028 #include <core/utils/lock_queue.h>
00029 #include <gtkmm.h>
00030
00031 namespace fawkes {
00032 class AvahiThread;
00033
00034 class ServiceModel : public fawkes::ServiceBrowseHandler
00035 {
00036 public:
00037 ServiceModel(const char* service = "_fawkes._tcp");
00038 ServiceModel(fawkes::AvahiThread* avahi_thread);
00039 virtual ~ServiceModel();
00040
00041 Glib::RefPtr<Gtk::ListStore>& get_list_store();
00042
00043 class ServiceRecord : public Gtk::TreeModelColumnRecord
00044 {
00045 public:
00046 ServiceRecord()
00047 {
00048 add(name);
00049 add(type);
00050 add(domain);
00051 add(hostname);
00052 add(ipaddr);
00053 add(port);
00054 }
00055
00056 Gtk::TreeModelColumn<Glib::ustring> name;
00057 Gtk::TreeModelColumn<Glib::ustring> type;
00058 Gtk::TreeModelColumn<Glib::ustring> domain;
00059 Gtk::TreeModelColumn<Glib::ustring> hostname;
00060 Gtk::TreeModelColumn<Glib::ustring> ipaddr;
00061 Gtk::TreeModelColumn<unsigned short> port;
00062 };
00063
00064 ServiceRecord& get_column_record();
00065
00066 protected:
00067
00068 void all_for_now();
00069 void cache_exhausted();
00070 void browse_failed( const char* name,
00071 const char* type,
00072 const char* domain );
00073 void service_added( const char* name,
00074 const char* type,
00075 const char* domain,
00076 const char* host_name,
00077 const struct sockaddr* addr,
00078 const socklen_t addr_size,
00079 uint16_t port,
00080 std::list<std::string>& txt,
00081 int flags );
00082 void service_removed( const char* name,
00083 const char* type,
00084 const char* domain );
00085
00086 struct ServiceAddedRecord
00087 {
00088 std::string name;
00089 std::string type;
00090 std::string domain;
00091 std::string hostname;
00092 std::string ipaddr;
00093 unsigned short port;
00094 };
00095
00096 struct ServiceRemovedRecord
00097 {
00098 std::string name;
00099 std::string type;
00100 std::string domain;
00101 };
00102
00103 fawkes::LockQueue<ServiceAddedRecord> m_added_services;
00104 fawkes::LockQueue<ServiceRemovedRecord> m_removed_services;
00105
00106 Glib::Dispatcher m_signal_service_added;
00107 Glib::Dispatcher m_signal_service_removed;
00108
00109 virtual void on_service_added();
00110 virtual void on_service_removed();
00111
00112 Glib::RefPtr<Gtk::ListStore> m_service_list;
00113 ServiceRecord m_service_record;
00114
00115 fawkes::AvahiThread* m_avahi;
00116
00117 private:
00118 bool m_own_avahi_thread;
00119 };
00120
00121 }
00122
00123 #endif