[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 19/29: Implement proper debug logging function when needed

noreply at xfce.org noreply at xfce.org
Mon Dec 18 12:45:50 CET 2017


This is an automated email from the git hooks/post-receive script.

o   m   e   g   a   p   h   i   l       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-hardware-monitor-plugin.

commit c2e9777a8e5265f06ed3423c3bfc669661fe91af
Author: OmegaPhil <OmegaPhil at startmail.com>
Date:   Sat Dec 9 14:06:52 2017 +0000

    Implement proper debug logging function when needed
---
 src/choose-monitor-window.cpp |  46 ++++++++------
 src/choose-monitor-window.hpp |   4 +-
 src/monitor-impls.cpp         | 142 +++++++++++++++++++++++++++++-------------
 src/monitor-impls.hpp         |  25 ++++----
 src/monitor.hpp               |  16 +++--
 src/plugin.cpp                |  35 ++++++++++-
 src/plugin.hpp                |   8 +++
 src/preferences-window.cpp    |   2 +-
 8 files changed, 195 insertions(+), 83 deletions(-)

diff --git a/src/choose-monitor-window.cpp b/src/choose-monitor-window.cpp
index 57f9f52..42b7e4e 100644
--- a/src/choose-monitor-window.cpp
+++ b/src/choose-monitor-window.cpp
@@ -28,15 +28,15 @@
 #include "choose-monitor-window.hpp"
 #include "gui-helpers.hpp"
 #include "monitor-impls.hpp"
+#include "plugin.hpp"
 #include "ucompose.hpp"
 
 
 // Static intialisation
 ChooseMonitorWindow::NetworkInterfacesNamesCols ChooseMonitorWindow::nc;
 
-ChooseMonitorWindow::ChooseMonitorWindow(XfcePanelPlugin* xfce_plugin,
-                                         Gtk::Window &parent)
-  : xfce_plugin(xfce_plugin)
+ChooseMonitorWindow::ChooseMonitorWindow(Plugin& plugin, Gtk::Window &parent)
+  : plugin_priv(plugin)
 {
   // Now we are forced to use top-level widgets this is much more over the top...
   std::vector<Glib::ustring> objects(22);
@@ -414,7 +414,7 @@ ChooseMonitorWindow::ChooseMonitorWindow(XfcePanelPlugin* xfce_plugin,
       (*iter)[nc.interface_type] = NetworkLoadMonitor::
           interface_type_to_string(interface_type, false);
       (*iter)[nc.interface_name] = NetworkLoadMonitor::
-          get_interface_name(interface_type, xfce_plugin);
+          get_interface_name(interface_type, plugin_priv.xfce_plugin);
   }
 
   // Setup network direction combobox
@@ -539,7 +539,7 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
 {
   // Set up monitor
   // Search for settings file
-  gchar* file = xfce_panel_plugin_lookup_rc_file(xfce_plugin);
+  gchar* file = xfce_panel_plugin_lookup_rc_file(plugin_priv.xfce_plugin);
   if (file)
   {
     // Loading settings
@@ -666,6 +666,12 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
         bool fixed_max = xfce_rc_read_bool_entry(settings_ro, "fixed_max", false);
         disk_stats_fixed_max_checkbutton->set_active(fixed_max);
         disk_stats_max_spinbutton->set_value(max);
+
+        // Debug code
+        /*plugin_priv.debug_log(
+              String::ucompose("XFCE4 Hardware Monitor Plugin: "
+                             "ChooseMonitorWindow::run, disk stats monitor max "
+                             "value: %1", max));*/
       }
       else if (type == "swap_usage")
       {
@@ -789,6 +795,10 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
         bool fixed_max = xfce_rc_read_bool_entry(settings_ro, "fixed_max", false);
         network_load_fixed_max_checkbutton->set_active(fixed_max);
         network_load_max_spinbutton->set_value(max);
+
+        // Debug code
+        /*std::cerr << "XFCE4 Hardware Monitor Plugin: ChooseMonitorWindow::run, "
+                     "network load monitor max value: " << max << "\n";*/
       }
       else if (type == "temperature")
       {
@@ -936,28 +946,28 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
                 int(cpu_usage_refresh_delay_spinbutton->get_value() * 1000),
                 cpu_usage_incl_low_checkbutton->get_active(),
                 cpu_usage_incl_iowait_checkbutton->get_active(),
-                cpu_tag->get_text());
+                cpu_tag->get_text(), plugin_priv);
         else
           mon = new CpuUsageMonitor(
                 cpu_usage_fixed_max_checkbutton->get_active(),
                 int(cpu_usage_refresh_delay_spinbutton->get_value() * 1000),
                 cpu_usage_incl_low_checkbutton->get_active(),
                 cpu_usage_incl_iowait_checkbutton->get_active(),
-                cpu_tag->get_text());
+                cpu_tag->get_text(), plugin_priv);
       }
       else if (memory_usage_radiobutton->get_active())
       {
         mon = new MemoryUsageMonitor(
               int(memory_refresh_delay_spinbutton->get_value() * 1000),
               memory_fixed_max_checkbutton->get_active(),
-              memory_usage_tag->get_text());
+              memory_usage_tag->get_text(), plugin_priv);
       }
       else if (swap_usage_radiobutton->get_active())
       {
         mon = new SwapUsageMonitor(
               int(swap_refresh_delay_spinbutton->get_value() * 1000),
               swap_fixed_max_checkbutton->get_active(),
-              swap_usage_tag->get_text());
+              swap_usage_tag->get_text(), plugin_priv);
       }
       else if (load_average_radiobutton->get_active())
       {
@@ -965,7 +975,7 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
               int(load_average_refresh_delay_spinbutton->get_value() * 1000),
               load_average_fixed_max_checkbutton->get_active(),
               load_average_max_spinbutton->get_value(),
-              load_average_tag->get_text());
+              load_average_tag->get_text(), plugin_priv);
       }
       else if (disk_usage_radiobutton->get_active())
       {
@@ -999,7 +1009,7 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
         mon = new DiskUsageMonitor(mount_dir, show_free,
                   int(disk_usage_refresh_delay_spinbutton->get_value() * 1000),
                                    disk_usage_fixed_max_checkbutton->get_active(),
-                                   disk_usage_tag->get_text());
+                                   disk_usage_tag->get_text(), plugin_priv);
       }
       else if (disk_stats_radiobutton->get_active())
       {
@@ -1042,7 +1052,7 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
                   int(disk_stats_refresh_delay_spinbutton->get_value() * 1000),
                                    disk_stats_fixed_max_checkbutton->get_active(),
                                    disk_stats_max_spinbutton->get_value(),
-                                   disk_stats_tag->get_text());
+                                   disk_stats_tag->get_text(), plugin_priv);
       }
       else if (network_load_radiobutton->get_active())
       {
@@ -1088,7 +1098,7 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
                 int(network_load_refresh_delay_spinbutton->get_value() * 1000),
                                network_load_fixed_max_checkbutton->get_active(),
                                      network_load_max_spinbutton->get_value(),
-                                     network_load_tag->get_text(), xfce_plugin);
+                                     network_load_tag->get_text(), plugin_priv);
       }
       else if (temperature_radiobutton->get_active())
       {
@@ -1096,7 +1106,7 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
                  int(temperature_refresh_delay_spinbutton->get_value() * 1000),
                                 temperature_fixed_max_checkbutton->get_active(),
                                      temperature_max_spinbutton->get_value(),
-                                     temperature_tag->get_text());
+                                     temperature_tag->get_text(), plugin_priv);
       }
       else if (fan_speed_radiobutton->get_active())
       {
@@ -1104,7 +1114,7 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
                    int(fan_speed_refresh_delay_spinbutton->get_value() * 1000),
                                   fan_fixed_max_checkbutton->get_active(),
                                   fan_max_spinbutton->get_value(),
-                                  fan_speed_tag->get_text());
+                                  fan_speed_tag->get_text(), plugin_priv);
       }
       else if (generic_radiobutton->get_active())
       {
@@ -1242,7 +1252,7 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
                      int(generic_refresh_delay_spinbutton->get_value() * 1000),
                                  generic_fixed_max_checkbutton->get_active(),
                                  generic_max_spinbutton->get_value(),
-                                 generic_tag->get_text());
+                                 generic_tag->get_text(), plugin_priv);
       }
 
       return mon;
@@ -1371,7 +1381,7 @@ void ChooseMonitorWindow::on_network_interface_name_edited(
 
   // Setting and saving the real value
   NetworkLoadMonitor::set_interface_name(inter_type, new_text);
-  gchar* file = xfce_panel_plugin_save_location(xfce_plugin, true);
+  gchar* file = xfce_panel_plugin_save_location(plugin_priv.xfce_plugin, true);
   if (file)
   {
     XfceRc* settings_w = xfce_rc_simple_open(file, false);
@@ -1414,7 +1424,7 @@ void ChooseMonitorWindow::on_network_interfaces_restore_defaults_button_clicked(
   }
 
   // Updating storage vector and saving
-  gchar* file = xfce_panel_plugin_save_location(xfce_plugin, true);
+  gchar* file = xfce_panel_plugin_save_location(plugin_priv.xfce_plugin, true);
   if (file)
   {
     XfceRc* settings_w = xfce_rc_simple_open(file, false);
diff --git a/src/choose-monitor-window.hpp b/src/choose-monitor-window.hpp
index 2f0ab97..73f106f 100644
--- a/src/choose-monitor-window.hpp
+++ b/src/choose-monitor-window.hpp
@@ -52,7 +52,7 @@ public:
 
   /* xfce_plugin is required here as the user can edit NetworkLoadMonitor
    * interface names through a settings dialog, and this needs special saving */
-  ChooseMonitorWindow(XfcePanelPlugin* xfce_plugin, Gtk::Window &parent);
+  ChooseMonitorWindow(Plugin& plugin, Gtk::Window &parent);
   ~ChooseMonitorWindow();
 
   // given a monitor directory (may be ""), return a new monitor or 0
@@ -129,7 +129,7 @@ private:
                    *generic_change_in_value_negative_radiobutton,
                    *generic_change_in_value_both_radiobutton;
 
-  XfcePanelPlugin* xfce_plugin;
+  Plugin& plugin_priv;
 
   // For disk statistics device name combobox
   class DiskStatsDeviceNameCols: public Gtk::TreeModel::ColumnRecord
diff --git a/src/monitor-impls.cpp b/src/monitor-impls.cpp
index 49c6a9a..237204d 100644
--- a/src/monitor-impls.cpp
+++ b/src/monitor-impls.cpp
@@ -41,6 +41,7 @@
 #include <sys/time.h>  // For high-precision timing for network load and disk
                        // read/write speed
 
+#include "plugin.hpp"
 #include "monitor-impls.hpp"
 #include "ucompose.hpp"
 #include "i18n.hpp"
@@ -56,7 +57,7 @@ double const max_decay = 0.999;
 //
 
 std::list<Monitor *>
-load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
+load_monitors(XfceRc *settings_ro, Plugin& plugin)
 {
   std::list<Monitor *> monitors;
 
@@ -87,7 +88,20 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
        * unstringify the double */
       double max;
       std::stringstream s(xfce_rc_read_entry(settings_ro, "max", "0"));
-      s >> max;
+
+      // Debug code
+      /*plugin.debug_log(
+            String::ucompose("XFCE4 Hardware Monitor Plugin: "
+                           "ChooseMonitorWindow::run, disk stats monitor max "
+                           "value: %1", max));*/
+
+      if (!(s >> max))
+      {
+        /*plugin.debug_log("XFCE4 Hardware Monitor Plugin: Max loading from"
+                               " stringstream failed!");*/
+        std::cerr << "XFCE4 Hardware Monitor Plugin: Max loading for monitor "
+                  << settings_monitors[i] << " from stringstream failed!\n";
+      }
 
       bool fixed_max = xfce_rc_read_bool_entry(settings_ro, "fixed_max", false);
 
@@ -110,13 +124,13 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
         {
           monitors.push_back(new CpuUsageMonitor(fixed_max, incl_low_prio,
                                                  incl_iowait, update_interval,
-                                                 tag));
+                                                 tag, plugin));
         }
         else
         {
           monitors.push_back(new CpuUsageMonitor(cpu_no, fixed_max,
                                                  incl_low_prio, incl_iowait,
-                                                 update_interval, tag));
+                                                 update_interval, tag, plugin));
         }
       }
       else if (type == "memory_usage")
@@ -126,7 +140,7 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
           update_interval = MemoryUsageMonitor::update_interval_default;
 
         monitors.push_back(new MemoryUsageMonitor(update_interval, fixed_max,
-                                                  tag));
+                                                  tag, plugin));
       }
       else if (type == "swap_usage")
       {
@@ -134,7 +148,8 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
         if (update_interval == -1)
           update_interval = SwapUsageMonitor::update_interval_default;
 
-        monitors.push_back(new SwapUsageMonitor(update_interval, fixed_max, tag));
+        monitors.push_back(new SwapUsageMonitor(update_interval, fixed_max,
+                                                tag, plugin));
       }
       else if (type == "load_average")
       {
@@ -143,7 +158,7 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
           update_interval = LoadAverageMonitor::update_interval_default;
 
         monitors.push_back(new LoadAverageMonitor(update_interval, fixed_max,
-                                                  max, tag));
+                                                  max, tag, plugin));
       }
       else if (type == "disk_usage")
       {
@@ -161,7 +176,8 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
 
         // Creating disk usage monitor
         monitors.push_back(new DiskUsageMonitor(mount_dir, show_free,
-                                                update_interval, fixed_max, tag));
+                                                update_interval, fixed_max,
+                                                tag, plugin));
       }
       else if (type == "disk_statistics")
       {
@@ -180,7 +196,14 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
         // Creating disk statistics monitor
         monitors.push_back(new DiskStatsMonitor(device_name, stat,
                                                 update_interval, fixed_max, max,
-                                                tag));
+                                                tag, plugin));
+
+        // Debug code
+        /*
+        plugin.debug_log(
+              String::ucompose("XFCE4 Hardware Monitor Plugin: "
+                             "Disk stats monitor max value on load: %1", max));
+        */
       }
       else if (type == "network_load")
       {
@@ -212,7 +235,7 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
             inter_type = NetworkLoadMonitor::wireless_first;
 
           // Search for a writeable settings file, create one if it doesnt exist
-          gchar* file = xfce_panel_plugin_save_location(panel_plugin, true);
+          gchar* file = xfce_panel_plugin_save_location(plugin.xfce_plugin, true);
           if (file)
           {
             XfceRc* settings_w = xfce_rc_simple_open(file, false);
@@ -270,7 +293,14 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
         // Creating network load monitor
         monitors.push_back(new NetworkLoadMonitor(inter_type, inter_direction,
                                                   update_interval, fixed_max,
-                                                  max, tag, panel_plugin));
+                                                  max, tag, plugin));
+
+        // Debug code
+        /*
+        plugin.debug_log(
+              String::ucompose("XFCE4 Hardware Monitor Plugin: "
+                             "Network load monitor max value on load: %1", max));
+        */
       }
       else if (type == "temperature")
       {
@@ -285,7 +315,7 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
         // Creating temperature monitor
         monitors.push_back(new TemperatureMonitor(temperature_no,
                                                   update_interval, fixed_max,
-                                                  max, tag));
+                                                  max, tag, plugin));
       }
       else if (type == "fan_speed")
       {
@@ -298,7 +328,7 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
 
         // Creating fan monitor
         monitors.push_back(new FanSpeedMonitor(fan_no, update_interval,
-                                               fixed_max, max, tag));
+                                               fixed_max, max, tag, plugin));
       }
 
       else if (type == "generic")
@@ -345,7 +375,7 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
                                               data_source_name_long,
                                               data_source_name_short, units_long,
                                               units_short, update_interval,
-                                              fixed_max, max, tag));
+                                              fixed_max, max, tag, plugin));
       }
 
       // Saving the monitor's settings root
@@ -358,7 +388,7 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
 
   // Always start with a CpuUsageMonitor
   if (monitors.empty())
-    monitors.push_back(new CpuUsageMonitor(true, false, false, 1000, ""));
+    monitors.push_back(new CpuUsageMonitor(true, false, false, 1000, "", plugin));
 
   return monitors;
 }
@@ -508,18 +538,20 @@ int const CpuUsageMonitor::update_interval_default = 1000;
 
 CpuUsageMonitor::CpuUsageMonitor(bool fixed_max, bool incl_low_prio,
                                  bool incl_iowait, int interval,
-                                 const Glib::ustring &tag_string)
-  : Monitor(tag_string, interval), cpu_no(all_cpus), fixed_max_priv(fixed_max),
-    incl_low_prio_priv(incl_low_prio), incl_iowait_priv(incl_iowait),
-    total_time(0), nice_time(0), idle_time(0), iowait_time(0)
+                                 const Glib::ustring &tag_string, Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), cpu_no(all_cpus),
+    fixed_max_priv(fixed_max), incl_low_prio_priv(incl_low_prio),
+    incl_iowait_priv(incl_iowait), total_time(0), nice_time(0), idle_time(0),
+    iowait_time(0)
 {}
 
 CpuUsageMonitor::CpuUsageMonitor(int cpu, bool fixed_max, bool incl_low_prio,
                                  bool incl_iowait, int interval,
-                                 const Glib::ustring &tag_string)
-  : Monitor(tag_string, interval), cpu_no(cpu), fixed_max_priv(fixed_max),
-    incl_low_prio_priv(incl_low_prio), incl_iowait_priv(incl_iowait),
-    total_time(0), nice_time(0), idle_time(0), iowait_time(0)
+                                 const Glib::ustring &tag_string, Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), cpu_no(cpu),
+    fixed_max_priv(fixed_max), incl_low_prio_priv(incl_low_prio),
+    incl_iowait_priv(incl_iowait), total_time(0), nice_time(0), idle_time(0),
+    iowait_time(0)
 {
   if (cpu_no < 0 || cpu_no >= max_no_cpus)
     cpu_no = all_cpus;
@@ -646,8 +678,10 @@ int CpuUsageMonitor::update_interval()
 int const SwapUsageMonitor::update_interval_default = 10 * 1000;
 
 SwapUsageMonitor::SwapUsageMonitor(int interval, bool fixed_max,
-                                   const Glib::ustring &tag_string)
-  : Monitor(tag_string, interval), max_value(0), fixed_max_priv(fixed_max)
+                                   const Glib::ustring &tag_string,
+                                   Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), max_value(0),
+    fixed_max_priv(fixed_max)
 {
 }
 
@@ -732,8 +766,10 @@ int SwapUsageMonitor::update_interval()
 int const LoadAverageMonitor::update_interval_default = 30 * 1000;
 
 LoadAverageMonitor::LoadAverageMonitor(int interval, bool fixed_max, double max,
-                                       const Glib::ustring &tag_string)
-  : Monitor(tag_string, interval), max_value(max), fixed_max_priv(fixed_max)
+                                       const Glib::ustring &tag_string,
+                                       Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), max_value(max),
+    fixed_max_priv(fixed_max)
 {
 }
 
@@ -835,8 +871,9 @@ int LoadAverageMonitor::update_interval()
 int const MemoryUsageMonitor::update_interval_default = 10 * 1000;
 
 MemoryUsageMonitor::MemoryUsageMonitor(int interval, bool fixed_max,
-                                       const Glib::ustring &tag_string)
-  : Monitor(tag_string, interval), max_value(0), fixed_max_priv(fixed_max)
+                                       const Glib::ustring &tag_string,
+                                       Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), max_value(0), fixed_max_priv(fixed_max)
 {
 }
 
@@ -921,9 +958,10 @@ int const DiskUsageMonitor::update_interval_default = 60 * 1000;
 
 DiskUsageMonitor::DiskUsageMonitor(const std::string &dir, bool free,
                                    int interval, bool fixed_max,
-                                   const Glib::ustring &tag_string)
-  : Monitor(tag_string, interval), max_value(0), fixed_max_priv(fixed_max),
-    mount_dir(dir), show_free(free)
+                                   const Glib::ustring &tag_string,
+                                   Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), max_value(0),
+    fixed_max_priv(fixed_max), mount_dir(dir), show_free(free)
 {
 }
 
@@ -1042,8 +1080,9 @@ int const DiskStatsMonitor::update_interval_default = 1000;
 DiskStatsMonitor::DiskStatsMonitor(const Glib::ustring &device_name,
                                    const Stat &stat_to_monitor,
                                    int interval, bool fixed_max, double max,
-                                   const Glib::ustring &tag_string)
-  : Monitor(tag_string, interval), device_name(device_name),
+                                   const Glib::ustring &tag_string,
+                                   Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), device_name(device_name),
     stat_to_monitor(stat_to_monitor), previous_value(-1), max_value(max),
     fixed_max_priv(fixed_max), time_stamp_secs(0), time_stamp_usecs(0)
 {
@@ -1331,6 +1370,11 @@ void DiskStatsMonitor::save(XfceRc *settings_w)
   xfce_rc_write_int_entry(settings_w, "max", int(max_value));
   xfce_rc_write_int_entry(settings_w, "update_interval", update_interval());
   xfce_rc_write_entry(settings_w, "tag", tag.c_str());
+
+  // Debug code
+  /*plugin_priv.debug_log(
+        String::ucompose("XFCE4 Hardware Monitor Plugin: DiskStatsMonitor::save "
+                         "ran - current max value: %1", max_value));*/
 }
 
 void DiskStatsMonitor::set_fixed_max(bool fixed_max)
@@ -1458,10 +1502,10 @@ bool NetworkLoadMonitor::interface_names_configured = false;
 NetworkLoadMonitor::NetworkLoadMonitor(InterfaceType &inter_type, Direction dir,
                                        int interval, bool fixed_max, double max,
                                        const Glib::ustring &tag_string,
-                                       XfcePanelPlugin* xfce_plugin)
-  : Monitor(tag_string, interval), max_value(max), fixed_max_priv(fixed_max),
-    byte_count(0), time_stamp_secs(0), time_stamp_usecs(0),
-    interface_type(inter_type), direction(dir), xfce_plugin(xfce_plugin)
+                                       Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), max_value(max),
+    fixed_max_priv(fixed_max), byte_count(0), time_stamp_secs(0),
+    time_stamp_usecs(0), interface_type(inter_type), direction(dir)
 {
 }
 
@@ -1718,7 +1762,8 @@ double NetworkLoadMonitor::do_measure()
 
   /* Obtaining interface name - this can change after monitor is instantiated
    * hence fetching each time */
-  Glib::ustring interface = get_interface_name(interface_type, xfce_plugin);
+  Glib::ustring interface = get_interface_name(interface_type,
+                                               plugin_priv.xfce_plugin);
 
   glibtop_get_netload(&netload, interface.c_str());
   guint64 val, measured_bytes;
@@ -1987,6 +2032,11 @@ void NetworkLoadMonitor::save(XfceRc *settings_w)
   xfce_rc_write_int_entry(settings_w, "max", int(max_value));
   xfce_rc_write_int_entry(settings_w, "update_interval", update_interval());
   xfce_rc_write_entry(settings_w, "tag", tag.c_str());
+
+  // Debug code
+  /*plugin_priv.debug_log(
+        String::ucompose("XFCE4 Hardware Monitor Plugin: NetworkLoadMonitor::save "
+                         "ran - current max value: %1", max_value));*/
 }
 
 void NetworkLoadMonitor::save_interfaces(XfceRc *settings_w)
@@ -2178,8 +2228,9 @@ int const TemperatureMonitor::update_interval_default = 20 * 1000;
 
 TemperatureMonitor::TemperatureMonitor(int no, int interval, bool fixed_max,
                                        double max,
-                                       const Glib::ustring &tag_string)
-  : Monitor(tag_string, interval), sensors_no(no), max_value(max),
+                                       const Glib::ustring &tag_string,
+                                       Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), sensors_no(no), max_value(max),
     fixed_max_priv(fixed_max)
 {
   Sensors::FeatureInfo info
@@ -2285,8 +2336,8 @@ int const FanSpeedMonitor::update_interval_default = 20 * 1000;
 
 FanSpeedMonitor::FanSpeedMonitor(int no, int interval, bool fixed_max,
                                  double max,
-                                 const Glib::ustring &tag_string)
-  : Monitor(tag_string, interval), sensors_no(no), max_value(max),
+                                 const Glib::ustring &tag_string, Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), sensors_no(no), max_value(max),
     fixed_max_priv(fixed_max)
 {
   Sensors::FeatureInfo info
@@ -2398,8 +2449,9 @@ GenericMonitor::GenericMonitor(const Glib::ustring &file_path,
                                const Glib::ustring &units_long,
                                const Glib::ustring &units_short,
                                int interval, bool fixed_max, double max,
-                               const Glib::ustring &tag_string)
-  : Monitor(tag_string, interval), max_value(max), fixed_max_priv(fixed_max),
+                               const Glib::ustring &tag_string, Plugin& plugin)
+  : Monitor(tag_string, interval, plugin), max_value(max),
+    fixed_max_priv(fixed_max),
     previous_value(std::numeric_limits<double>::min()),
     file_path(file_path), value_from_contents(value_from_contents),
     follow_change(follow_change), dir(dir),
diff --git a/src/monitor-impls.hpp b/src/monitor-impls.hpp
index d43c9bd..7a39459 100644
--- a/src/monitor-impls.hpp
+++ b/src/monitor-impls.hpp
@@ -51,12 +51,12 @@ public:
 
   // Monitor all CPUs
   CpuUsageMonitor(bool fixed_max, bool incl_low_prio, bool incl_iowait,
-                  int interval, const Glib::ustring &tag_string);
+                  int interval, const Glib::ustring &tag_string, Plugin& plugin);
 
   // Monitor only CPU no.
   CpuUsageMonitor(int cpu_no, bool fixed_max, bool incl_low_prio,
                   bool incl_iowait, int interval,
-                  const Glib::ustring &tag_string);
+                  const Glib::ustring &tag_string, Plugin& plugin);
 
   virtual bool fixed_max();
   virtual Glib::ustring format_value(double val, bool compact = false);
@@ -96,7 +96,8 @@ private:
 class SwapUsageMonitor: public Monitor
 {
 public:
-  SwapUsageMonitor(int interval, bool fixed_max, const Glib::ustring &tag_string);
+  SwapUsageMonitor(int interval, bool fixed_max, const Glib::ustring &tag_string,
+                   Plugin& plugin);
 
   virtual bool fixed_max();
   virtual Glib::ustring format_value(double val, bool compact = false);
@@ -125,7 +126,7 @@ class LoadAverageMonitor: public Monitor
 {
 public:
   LoadAverageMonitor(int interval, bool fixed_max, double max,
-                     const Glib::ustring &tag_string);
+                     const Glib::ustring &tag_string, Plugin& plugin);
 
   virtual bool fixed_max();
   virtual Glib::ustring format_value(double val, bool compact = false);
@@ -158,7 +159,7 @@ class MemoryUsageMonitor: public Monitor
 {
 public:
   MemoryUsageMonitor(int interval, bool fixed_max,
-                     const Glib::ustring &tag_string);
+                     const Glib::ustring &tag_string, Plugin& plugin);
 
   virtual bool fixed_max();
   virtual Glib::ustring format_value(double val, bool compact = false);
@@ -187,7 +188,8 @@ class DiskUsageMonitor: public Monitor
 {
 public:
   DiskUsageMonitor(const std::string &mount_dir, bool show_free, int interval,
-                   bool fixed_max, const Glib::ustring &tag_string);
+                   bool fixed_max, const Glib::ustring &tag_string,
+                   Plugin& plugin);
 
   virtual bool fixed_max();
   virtual Glib::ustring format_value(double val, bool compact= false);
@@ -237,7 +239,7 @@ public:
 
   DiskStatsMonitor(const Glib::ustring &device_name, const Stat &stat_to_monitor,
                    int interval, bool fixed_max, double max,
-                   const Glib::ustring &tag_string);
+                   const Glib::ustring &tag_string, Plugin& plugin);
 
   virtual bool fixed_max();
   virtual Glib::ustring format_value(double val, bool compact=false);
@@ -315,8 +317,7 @@ public:
 
   NetworkLoadMonitor(InterfaceType &interface_type,
                      Direction dir, int interval, bool fixed_max, double max,
-                     const Glib::ustring &tag_string,
-                     XfcePanelPlugin *xfce_plugin);
+                     const Glib::ustring &tag_string, Plugin& plugin);
 
   virtual bool fixed_max();
   virtual Glib::ustring format_value(double val, bool compact = false);
@@ -395,7 +396,7 @@ public:
 
   // no. in the temperature features
   TemperatureMonitor(int no, int interval, bool fixed_max, double max,
-                     const Glib::ustring &tag_string);
+                     const Glib::ustring &tag_string, Plugin& plugin);
 
   virtual bool fixed_max();
   virtual Glib::ustring format_value(double val, bool compact = false);
@@ -429,7 +430,7 @@ public:
 
   // no. in the fan features
   FanSpeedMonitor(int no, int interval, bool fixed_max, double max,
-                  const Glib::ustring &tag_string);
+                  const Glib::ustring &tag_string, Plugin& plugin);
 
   virtual bool fixed_max();
   virtual Glib::ustring format_value(double val, bool compact = false);
@@ -479,7 +480,7 @@ public:
                  const Glib::ustring &units_long,
                  const Glib::ustring &units_short,
                  int interval, bool fixed_max, double max,
-                 const Glib::ustring &tag_string);
+                 const Glib::ustring &tag_string, Plugin& plugin);
 
   virtual bool fixed_max();
   virtual Glib::ustring format_value(double val, bool compact=false);
diff --git a/src/monitor.hpp b/src/monitor.hpp
index b98d235..f7b1746 100644
--- a/src/monitor.hpp
+++ b/src/monitor.hpp
@@ -31,12 +31,16 @@ extern "C"
 
 #include "helpers.hpp"
 
+/* No use including plugin.hpp here - plugin.hpp itself includes monitor.hpp
+ * before the Plugin class is declared */
+class Plugin;
 
 class Monitor: noncopyable
 {
 public:
-  Monitor(const Glib::ustring &tag_string, int interval)
-    : measured_value(0), tag(tag_string), update_interval_priv(interval)
+  Monitor(const Glib::ustring &tag_string, int interval, Plugin& plugin)
+    : measured_value(0), tag(tag_string), update_interval_priv(interval),
+      plugin_priv(plugin)
   {
   }
   
@@ -114,6 +118,9 @@ protected:
   double measured_value;
   int update_interval_priv;
 
+  /* This is maintained in order for debug logging */
+  Plugin& plugin_priv;
+
 private:
 
   // Perform actual measurement, for derived classes
@@ -133,8 +140,9 @@ typedef monitor_seq::iterator monitor_iter;
 /* Forward declaration for load_monitors - including the panel header at the top
  * causes glibmm/object.h to complain that X11/Xlib.h has been included ahead
  * of it?? Why is the include tolerated in plugin.hpp then? */
-typedef struct _XfcePanelPlugin        XfcePanelPlugin;
+//typedef struct _XfcePanelPlugin        XfcePanelPlugin;
+class Plugin;
 
-monitor_seq load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin);
+monitor_seq load_monitors(XfceRc *settings_ro, Plugin& plugin);
 
 #endif
diff --git a/src/plugin.cpp b/src/plugin.cpp
index 54e78f2..deebbbf 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -237,7 +237,9 @@ Plugin::Plugin(XfcePanelPlugin *xfce_plugin)
    * seems that it needs to be done in or after the mainloop kicks off */
 
   // Loading up monitors
-  monitor_seq mon = load_monitors(settings_ro, xfce_plugin);
+  /* Plugin& is initialised from non-transient address of this ('this' itself
+   * is an rvalue so not allowed for a reference) */
+  monitor_seq mon = load_monitors(settings_ro, *this);
   for (monitor_iter i = mon.begin(), end = mon.end(); i != end; ++i)
     add_monitor(*i);
 
@@ -292,6 +294,9 @@ Plugin::Plugin(XfcePanelPlugin *xfce_plugin)
 
 Plugin::~Plugin()
 {
+  // Debug code
+  //std::cerr << "XFCE4 Hardware Monitor Plugin: Plugin destructor running...\n";
+
   timer.disconnect();
   
   // Make sure noone is trying to read the monitors before we kill them
@@ -843,3 +848,31 @@ void Plugin::on_about_activated()
     about->raise();
   }
 }
+
+void Plugin::debug_log(const Glib::ustring &msg)
+{
+  /* When Plugin stream reference goes out of scope, it will be automatically
+   * flushed and closed etc */
+  if (!debug_log_stream)
+  {
+      /* Work out a suitable log path in the same directory as the writeable
+       * configuration path for this instance of the plugin - 'create_for_path'
+       * doesn't actually create anything, but just instantiates the virtual
+       * File object */
+      gchar* file_path = xfce_panel_plugin_save_location(xfce_plugin, FALSE);
+      Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(file_path)
+              ->get_parent()
+              ->get_child(
+                  String::ucompose("%1-debug.log",
+                                   xfce_panel_plugin_get_unique_id(xfce_plugin)));
+      g_free(file_path);
+      debug_log_stream = file->append_to();
+
+      // Debug code
+      std::cerr << "XFCE4 Hardware Monitor Plugin: Debug log file created at "
+                << file->get_path() << "\n";
+  }
+
+  debug_log_stream->write(String::ucompose("%1\n", msg));
+  std::cerr << msg << "\n";
+}
diff --git a/src/plugin.hpp b/src/plugin.hpp
index 445b64e..a437f50 100644
--- a/src/plugin.hpp
+++ b/src/plugin.hpp
@@ -27,6 +27,7 @@
 
 #include <sigc++/connection.h>
 
+#include <giomm/file.h>
 #include <gtkmm/eventbox.h>
 #include <gtkmm/window.h>
 #include <gtkmm/tooltips.h>
@@ -101,6 +102,12 @@ public:
   void remove_monitor(Monitor *monitor); // get rid of the monitor
   void replace_monitor(Monitor *prev_monitor, Monitor *new_monitor);
 
+  /* Log a message to a debug log file and output to stderr. Have had many
+   * examples of stderr messages resulting in supposedly no output from the
+   * perspective of xfce4-panel's stderr - this should demonstrate that the
+   * events actually happen */
+  void debug_log(const Glib::ustring &msg);
+
   // For opening settings file associated with the plugin
   XfcePanelPlugin *xfce_plugin;
 
@@ -138,6 +145,7 @@ private:
   std::auto_ptr<View> view;
   std::auto_ptr<PreferencesWindow> preferences_window;
   Gtk::Tooltips tooltips;
+  Glib::RefPtr<Gio::OutputStream> debug_log_stream;
 
   friend void display_preferences(Plugin *plugin);
   friend void display_about(Plugin *plugin);
diff --git a/src/preferences-window.cpp b/src/preferences-window.cpp
index fdb1022..cc90ff1 100644
--- a/src/preferences-window.cpp
+++ b/src/preferences-window.cpp
@@ -1062,7 +1062,7 @@ bool PreferencesWindow::on_closed(GdkEventAny *)
 
 Monitor *PreferencesWindow::run_choose_monitor_window(const Glib::ustring &str)
 {
-  ChooseMonitorWindow chooser(plugin.xfce_plugin, *window);
+  ChooseMonitorWindow chooser(plugin, *window);
 
   return chooser.run(str);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list