battery_monitor.cpp

00001 
00002 /***************************************************************************
00003  *  battery_monitor.cpp - Fawkes Battery Monitor
00004  *
00005  *  Created: Mon Apr 06 17:11:55 2009
00006  *  Copyright  2009  Daniel Beck
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #include "battery_monitor.h"
00024 #include "battery_monitor_treeview.h"
00025 
00026 #include <netcomm/dns-sd/avahi_thread.h>
00027 
00028 using namespace std;
00029 using namespace fawkes;
00030 
00031 /** @class BatteryMonitor tools/battery_monitor/battery_monitor.h
00032  * A battery monitor.
00033  * @author Daniel Beck
00034  */
00035 
00036 /** Constructor.
00037  * @param ref_xml Glade XML object
00038  */
00039 BatteryMonitor::BatteryMonitor( Glib::RefPtr< Gnome::Glade::Xml > ref_xml )
00040 {
00041   ref_xml->get_widget("wndMain", m_wnd_main);
00042   m_trv_battery = NULL;
00043   ref_xml->get_widget_derived( "trvBattery", m_trv_battery );
00044   ref_xml->get_widget("btnQuit", m_btn_quit);
00045   m_btn_quit->signal_clicked().connect( sigc::mem_fun( *this, &BatteryMonitor::on_btn_quit_clicked ) );
00046 
00047   m_avahi = new AvahiThread();
00048   m_avahi->watch_service( "_fawkes._tcp", this );
00049   m_avahi->start();
00050 }
00051 
00052 /** Destructor */
00053 BatteryMonitor::~BatteryMonitor()
00054 {
00055   m_avahi->cancel();
00056   m_avahi->join();
00057   delete m_avahi;
00058 }
00059 
00060 /** Obtain the main window.
00061  * @return the main window
00062  */
00063 Gtk::Window&
00064 BatteryMonitor::get_window() const
00065 {
00066   return *m_wnd_main;
00067 }
00068 
00069 void
00070 BatteryMonitor::all_for_now()
00071 {
00072 }
00073 
00074 void
00075 BatteryMonitor::cache_exhausted()
00076 {
00077 }
00078 
00079 void
00080 BatteryMonitor::browse_failed( const char* name,
00081                                const char* type,
00082                                const char* domain )
00083 {
00084 }
00085 
00086 void
00087 BatteryMonitor::service_added( const char* name,
00088                                const char* type,
00089                                const char* domain,
00090                                const char* host_name,
00091                                const struct sockaddr* addr,
00092                                const socklen_t addr_size,
00093                                uint16_t port,
00094                                std::list<std::string>& txt,
00095                                int flags )
00096 {
00097   string host( host_name );
00098   string service( name );
00099   m_services[ service ] = host_name;
00100   m_trv_battery->add_host( host_name );
00101 }
00102 
00103 void
00104 BatteryMonitor::service_removed( const char* name,
00105                                  const char* type,
00106                                  const char* domain )
00107 {
00108   std::map< string, string >::iterator i =  m_services.find( string( name ) );
00109   if ( i != m_services.end() )
00110   { m_trv_battery->rem_host( (i->second).c_str() ); }
00111 }
00112 
00113 void
00114 BatteryMonitor::on_btn_quit_clicked()
00115 {
00116   m_wnd_main->hide();
00117 }

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1