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;
96 std::map<string, BlackBoard *>::iterator rbit;
99 std::map<string, InterfaceDispatcher *>::iterator idit;
103 rbit->second->unregister_listener(idit->second);
104 rbit->second->close(biit->second);
110 std::map<string, InterfaceDispatcher *>::iterator i;
121 delete m_dlg_warning;
133 std::map<string, BlackBoard *>::iterator i =
m_remote_bbs.find(host);
142 e.
append(
"Could not open remote blackboard on host %s", h);
160 id->signal_data_changed().connect(
161 sigc::mem_fun(*
this, &BatteryMonitorTreeView::on_data_changed));
162 id->signal_writer_added().connect(
163 sigc::mem_fun(*
this, &BatteryMonitorTreeView::on_writer_added));
164 id->signal_writer_removed().connect(
165 sigc::mem_fun(*
this, &BatteryMonitorTreeView::on_writer_removed));
166 rbb->
register_listener(
id, BlackBoard::BBIL_FLAG_DATA | BlackBoard::BBIL_FLAG_WRITER);
168 e.
append(
"Opening battery interface on host %s failed", h);
173 m_below_threshold_counter[host] = 0;
187 std::map<string, BlackBoard *>::iterator rbbit =
m_remote_bbs.find(host);
204 rbb->
close(biit->second);
207 e.
append(
"Closing battery interface for host %s could not be closed", h);
213 delete rbbit->second;
217 m_below_threshold_counter.erase(host);
223 BatteryMonitorTreeView::update()
226 Gtk::TreeModel::Children::iterator rit =
m_battery_list->children().begin();
240 e.
append(
"read() failed");
251 Gtk::TreeModel::Row row;
255 char *fqdn = strdup((biit->first).c_str());
258 sh = strtok(fqdn, &delim);
272 string fqdn_str = string(fqdn);
274 unsigned int cnt = m_below_threshold_counter[fqdn_str];
275 m_below_threshold_counter[fqdn_str] = ++cnt;
277 m_below_threshold_counter[fqdn_str] = 0;
283 Glib::ustring secondary =
"The batteries on ";
284 bool below_threshold =
false;
286 for (std::map<string, unsigned int>::iterator i = m_below_threshold_counter.begin();
287 i != m_below_threshold_counter.end();
290 secondary +=
"<b>" + Glib::ustring((i->first).c_str()) +
"</b>" +
" ";
293 below_threshold =
true;
296 secondary +=
"need to be replaced.";
298 if (below_threshold) {
299 m_dlg_warning->set_secondary_text(secondary,
true);
300 m_dlg_warning->set_urgency_hint();
301 m_dlg_warning->run();
302 m_dlg_warning->hide();