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
25#include "battery_monitor_treeview.h"
26
27#include <netcomm/dns-sd/avahi_thread.h>
28
29using namespace std;
30using namespace fawkes;
31
32/** @class BatteryMonitor tools/battery_monitor/battery_monitor.h
33 * A battery monitor.
34 * @author Daniel Beck
35 */
36
37/** Constructor.
38 * @param builder builder to get widgets from
39 */
40BatteryMonitor::BatteryMonitor(Glib::RefPtr<Gtk::Builder> builder)
41{
42 builder->get_widget("wndMain", m_wnd_main);
43 m_trv_battery = NULL;
44 builder->get_widget_derived("trvBattery", m_trv_battery);
45 builder->get_widget("btnQuit", m_btn_quit);
46 m_btn_quit->signal_clicked().connect(sigc::mem_fun(*this, &BatteryMonitor::on_btn_quit_clicked));
47
48 m_avahi = new AvahiThread();
49 m_avahi->watch_service("_fawkes._tcp", this);
50 m_avahi->start();
51}
52
53/** Destructor */
55{
56 m_avahi->cancel();
57 m_avahi->join();
58 delete m_avahi;
59}
60
61/** Obtain the main window.
62 * @return the main window
63 */
64Gtk::Window &
66{
67 return *m_wnd_main;
68}
69
70void
72{
73}
74
75void
77{
78}
79
80void
81BatteryMonitor::browse_failed(const char *name, const char *type, const char *domain)
82{
83}
84
85void
87 const char * type,
88 const char * domain,
89 const char * host_name,
90 const char * interface,
91 const struct sockaddr * addr,
92 const socklen_t addr_size,
93 uint16_t port,
94 std::list<std::string> &txt,
95 int flags)
96{
97 string service(name);
98 m_services[service] = host_name;
99 m_trv_battery->add_host(host_name);
100}
101
102void
103BatteryMonitor::service_removed(const char *name, const char *type, const char *domain)
104{
105 std::map<string, string>::iterator i = m_services.find(string(name));
106 if (i != m_services.end()) {
107 m_trv_battery->rem_host((i->second).c_str());
108 }
109}
110
111void
112BatteryMonitor::on_btn_quit_clicked()
113{
114 m_wnd_main->hide();
115}
void rem_host(const char *host)
Remove given host.
void add_host(const char *host)
Add given host.
void cache_exhausted()
Cache exhausted.
void browse_failed(const char *name, const char *type, const char *domain)
Failed to browse for a given service.
void all_for_now()
All results have been retrieved.
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.
Gtk::Window & get_window() const
Obtain the main window.
BatteryMonitor(Glib::RefPtr< Gtk::Builder > builder)
Constructor.
~BatteryMonitor()
Destructor.
Avahi main thread.
Definition: avahi_thread.h:55
void watch_service(const char *service_type, ServiceBrowseHandler *h)
Add a result handler.
void start(bool wait=true)
Call this method to start the thread.
Definition: thread.cpp:499
void join()
Join the thread.
Definition: thread.cpp:597
void cancel()
Cancel a thread.
Definition: thread.cpp:646
Fawkes library namespace.