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();
Gtk::TreeModelColumn< float > relative_soc
The battery's relative state of charge.
Gtk::TreeModelColumn< float > absolute_soc
The battery's absolute state of charge.
Gtk::TreeModelColumn< Glib::ustring > short_name
A shorter hostname (w/o domain)
Gtk::TreeModelColumn< float > current
The battery's current.
Gtk::TreeModelColumn< Glib::ustring > fqdn
The FQDN.
Gtk::TreeModelColumn< float > voltage
The battery's voltage.
virtual ~BatteryMonitorTreeView()
Destructor.
std::map< std::string, fawkes::BlackBoard * > m_remote_bbs
Map with remote blackboards: hostname -> remote blackboard.
void rem_host(const char *host)
Remove given host.
std::map< std::string, fawkes::BatteryInterface * > m_battery_interfaces
Map containing the battery interfaces: hostname -> battery interface.
BatteryMonitorTreeView(BaseObjectType *cobject, const Glib::RefPtr< Gtk::Builder > &builder)
Constructor.
BatteryRecord m_battery_record
Column record object to acces the columns of the storage object.
std::map< std::string, fawkes::InterfaceDispatcher * > m_interface_dispatcher
Interface dispatcher for the battery interfaces.
void add_host(const char *host)
Add given host.
Glib::RefPtr< Gtk::ListStore > m_battery_list
Storage object.
BatteryInterface Fawkes BlackBoard Interface.
uint32_t voltage() const
Get voltage value.
float absolute_soc() const
Get absolute_soc value.
float relative_soc() const
Get relative_soc value.
uint32_t current() const
Get current value.
The BlackBoard abstract class.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
virtual void close(Interface *interface)=0
Close interface.
Base class for exceptions in Fawkes.
void print_trace() noexcept
Prints trace to stderr.
void append(const char *format,...) noexcept
Append messages to the message list.
Interface listener with dispatcher.
Base class for all Fawkes BlackBoard interfaces.
void read()
Read from BlackBoard into local copy.
bool has_writer() const
Check if there is a writer for the interface.
Fawkes library namespace.