24 #include "battery_monitor_treeview.h" 26 #include <blackboard/remote.h> 27 #include <gui_utils/interface_dispatcher.h> 28 #include <interfaces/BatteryInterface.h> 71 const Glib::RefPtr<Gtk::Builder> &builder)
72 : Gtk::TreeView( cobject )
83 builder->get_widget(
"dlgWarning", m_dlg_warning);
84 m_dlg_warning->hide();
86 m_trigger_update.connect(sigc::mem_fun(*
this, &BatteryMonitorTreeView::update));
88 m_relative_soc_threshold = 20.0;
94 std::map< string, BatteryInterface* >::iterator biit;
99 std::map< string, BlackBoard* >::iterator rbit;
102 std::map< string, InterfaceDispatcher* >::iterator idit;
107 rbit->second->unregister_listener( idit->second );
108 rbit->second->close( biit->second );
114 std::map< string, InterfaceDispatcher* >::iterator i;
123 for ( std::map< string, BlackBoard* >::iterator i =
m_remote_bbs.begin();
130 delete m_dlg_warning;
142 std::map< string, BlackBoard* >::iterator i =
m_remote_bbs.find( host );
154 e.
append(
"Could not open remote blackboard on host %s", h );
174 id->signal_data_changed().connect( sigc::mem_fun( *
this,
175 &BatteryMonitorTreeView::on_data_changed ) );
176 id->signal_writer_added().connect( sigc::mem_fun( *
this,
177 &BatteryMonitorTreeView::on_writer_added ) );
178 id->signal_writer_removed().connect( sigc::mem_fun( *
this,
179 &BatteryMonitorTreeView::on_writer_removed ) );
180 rbb->
register_listener(
id, BlackBoard::BBIL_FLAG_DATA | BlackBoard::BBIL_FLAG_WRITER );
184 e.
append(
"Opening battery interface on host %s failed", h );
189 m_below_threshold_counter[ host ] = 0;
203 std::map< string, BlackBoard* >::iterator rbbit =
m_remote_bbs.find( host );
219 rbb->
close( biit->second );
224 e.
append(
"Closing battery interface for host %s could not be closed", h );
230 delete rbbit->second;
234 m_below_threshold_counter.erase( host );
240 BatteryMonitorTreeView::update()
243 Gtk::TreeModel::Children::iterator rit =
m_battery_list->children().begin();
262 e.
append(
"read() failed" );
271 Gtk::TreeModel::Row row;
275 char* fqdn = strdup( (biit->first).c_str() );
278 sh = strtok( fqdn, &delim );
291 string fqdn_str = string( fqdn );
294 unsigned int cnt = m_below_threshold_counter[ fqdn_str ];
295 m_below_threshold_counter[ fqdn_str ] = ++cnt;
298 { m_below_threshold_counter[ fqdn_str ] = 0; }
303 Glib::ustring secondary =
"The batteries on ";
304 bool below_threshold =
false;
306 for ( std::map< string, unsigned int >::iterator i = m_below_threshold_counter.begin();
307 i != m_below_threshold_counter.end();
312 secondary +=
"<b>" + Glib::ustring( (i->first).c_str() ) +
"</b>" +
" ";
315 below_threshold =
true;
318 secondary +=
"need to be replaced.";
320 if ( below_threshold )
322 m_dlg_warning->set_secondary_text( secondary,
true );
323 m_dlg_warning->set_urgency_hint();
324 m_dlg_warning->run();
325 m_dlg_warning->hide();
float relative_soc() const
Get relative_soc value.
std::map< std::string, fawkes::InterfaceDispatcher *> m_interface_dispatcher
Interface dispatcher for the battery interfaces.
uint32_t voltage() const
Get voltage value.
void rem_host(const char *host)
Remove given host.
Fawkes library namespace.
BatteryInterface Fawkes BlackBoard Interface.
float absolute_soc() const
Get absolute_soc value.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
Base class for all Fawkes BlackBoard interfaces.
Gtk::TreeModelColumn< Glib::ustring > short_name
A shorter hostname (w/o domain)
uint32_t current() const
Get current value.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
Base class for exceptions in Fawkes.
BatteryMonitorTreeView(BaseObjectType *cobject, const Glib::RefPtr< Gtk::Builder > &builder)
Constructor.
void read()
Read from BlackBoard into local copy.
Gtk::TreeModelColumn< Glib::ustring > fqdn
The FQDN.
Gtk::TreeModelColumn< float > relative_soc
The battery's relative state of charge.
bool has_writer() const
Check if there is a writer for the interface.
BatteryRecord m_battery_record
Column record object to acces the columns of the storage object.
Gtk::TreeModelColumn< float > voltage
The battery's voltage.
void print_trace()
Prints trace to stderr.
Gtk::TreeModelColumn< float > current
The battery's current.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
std::map< std::string, fawkes::BatteryInterface *> m_battery_interfaces
Map containing the battery interfaces: hostname -> battery interface.
virtual ~BatteryMonitorTreeView()
Destructor.
The BlackBoard abstract class.
void add_host(const char *host)
Add given host.
Gtk::TreeModelColumn< float > absolute_soc
The battery's absolute state of charge.
Interface listener with dispatcher.
void append(const char *format,...)
Append messages to the message list.
Glib::RefPtr< Gtk::ListStore > m_battery_list
Storage object.
std::map< std::string, fawkes::BlackBoard *> m_remote_bbs
Map with remote blackboards: hostname -> remote blackboard.
virtual void close(Interface *interface)=0
Close interface.