Fawkes API  Fawkes Development Version
battery_monitor.cpp
1 
2 /***************************************************************************
3  * battery_monitor.cpp - Fawkes Battery Monitor
4  *
5  * Created: Mon Apr 06 17:11:55 2009
6  * Copyright 2009 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.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "battery_monitor.h"
24 #include "battery_monitor_treeview.h"
25 
26 #include <netcomm/dns-sd/avahi_thread.h>
27 
28 using namespace std;
29 using namespace fawkes;
30 
31 /** @class BatteryMonitor tools/battery_monitor/battery_monitor.h
32  * A battery monitor.
33  * @author Daniel Beck
34  */
35 
36 /** Constructor.
37  * @param builder builder to get widgets from
38  */
39 BatteryMonitor::BatteryMonitor(Glib::RefPtr<Gtk::Builder> builder)
40 {
41  builder->get_widget("wndMain", m_wnd_main);
42  m_trv_battery = NULL;
43  builder->get_widget_derived( "trvBattery", m_trv_battery );
44  builder->get_widget("btnQuit", m_btn_quit);
45  m_btn_quit->signal_clicked().connect( sigc::mem_fun( *this, &BatteryMonitor::on_btn_quit_clicked ) );
46 
47  m_avahi = new AvahiThread();
48  m_avahi->watch_service( "_fawkes._tcp", this );
49  m_avahi->start();
50 }
51 
52 /** Destructor */
54 {
55  m_avahi->cancel();
56  m_avahi->join();
57  delete m_avahi;
58 }
59 
60 /** Obtain the main window.
61  * @return the main window
62  */
63 Gtk::Window&
65 {
66  return *m_wnd_main;
67 }
68 
69 void
71 {
72 }
73 
74 void
76 {
77 }
78 
79 void
81  const char* type,
82  const char* domain )
83 {
84 }
85 
86 void
88  const char* type,
89  const char* domain,
90  const char* host_name,
91  const char* interface,
92  const struct sockaddr* addr,
93  const socklen_t addr_size,
94  uint16_t port,
95  std::list<std::string>& txt,
96  int flags )
97 {
98  string host( host_name );
99  string service( name );
100  m_services[ service ] = host_name;
101  m_trv_battery->add_host( host_name );
102 }
103 
104 void
106  const char* type,
107  const char* domain )
108 {
109  std::map< string, string >::iterator i = m_services.find( string( name ) );
110  if ( i != m_services.end() )
111  { m_trv_battery->rem_host( (i->second).c_str() ); }
112 }
113 
114 void
115 BatteryMonitor::on_btn_quit_clicked()
116 {
117  m_wnd_main->hide();
118 }
Fawkes library namespace.
Gtk::Window & get_window() const
Obtain the main window.
STL namespace.
~BatteryMonitor()
Destructor.
void service_removed(const char *name, const char *type, const char *domain)
A service has been removed from the network.
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 all_for_now()
All results have been retrieved.
void browse_failed(const char *name, const char *type, const char *domain)
Failed to browse for a given service.
BatteryMonitor(Glib::RefPtr< Gtk::Builder > builder)
Constructor.
void cache_exhausted()
Cache exhausted.
Avahi main thread.
Definition: avahi_thread.h:54