Various fixes.
authorBrenden Matthews <brenden@rty.ca>
Sun, 10 May 2009 19:11:09 +0000 (13:11 -0600)
committerBrenden Matthews <brenden@rty.ca>
Sun, 10 May 2009 19:11:09 +0000 (13:11 -0600)
Added missing apcupsd.[hc], added apcupsd_loadgauge, fixed compilation
errors, updated docs & syntax stuff.

doc/variables.xml
extras/nano/conky.nanorc
extras/vim/syntax/conkyrc.vim
src/apcupsd.c [new file with mode: 0644]
src/apcupsd.h [new file with mode: 0644]
src/conky.c
src/text_object.h

index 2f66804..1466ac1 100644 (file)
 
        <varlistentry>
                <term>
+                       <command><option>apcupsd_loadgauge</option></command>
+                       <option>(height),(width)</option>
+               </term>
+               <listitem>
+                       Gauge that shows current load.
+                       <para></para></listitem>
+       </varlistentry>
+
+       <varlistentry>
+               <term>
                        <command><option>apcupsd_charge</option></command>
                </term>
                <listitem>
index c630079..de91922 100644 (file)
@@ -11,7 +11,7 @@ color green "\<(alias|alignment|append_file|background|border_margin|border_widt
 color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|undecorated|yes)\>"
 
 ## Variables
-color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|adt746xcpu|adt746xfan|alignc|alignr|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|machine|mails|mboxscan|mem|membar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|platform|pop3_unseen|pop3_used|pre_exec|processes|replied_mails|rss|running_processes|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|time|top|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|utime|voffset|voltage_mv|voltage_v|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>"
+color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|adt746xcpu|adt746xfan|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|machine|mails|mboxscan|mem|membar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|platform|pop3_unseen|pop3_used|pre_exec|processes|replied_mails|rss|running_processes|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|time|top|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|utime|voffset|voltage_mv|voltage_v|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>"
 
 color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?"
 color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)"
index 9fbcf5d..b8886c4 100644 (file)
@@ -49,7 +49,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV
 
 syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName
 
-syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs adt746xcpu adt746xfan alignc alignr apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen ioscheduler kernel laptop_mode lines loadavg loadgraph machine mails mboxscan mem membar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery platform pop3_unseen pop3_used pre_exec processes replied_mails rss running_processes scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci time top top_mem top_time totaldown totalup trashed_mails tztime unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times utime voffset voltage_mv voltage_v wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url
+syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs adt746xcpu adt746xfan alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen ioscheduler kernel laptop_mode lines loadavg loadgraph machine mails mboxscan mem membar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery platform pop3_unseen pop3_used pre_exec processes replied_mails rss running_processes scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci time top top_mem top_time totaldown totalup trashed_mails tztime unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times utime voffset voltage_mv voltage_v wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url
 
 hi def link ConkyrcComment   Comment
 hi def link ConkyrcSetting   Keyword
diff --git a/src/apcupsd.c b/src/apcupsd.c
new file mode 100644 (file)
index 0000000..9d9a29d
--- /dev/null
@@ -0,0 +1,220 @@
+/* apcupsd.c:  conky module for APC UPS daemon monitoring
+ *
+ * Copyright (C) 2009 Jaromir Smrcek <jaromir.smrcek@zoner.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA. */
+
+#include "conky.h"
+#include "apcupsd.h"
+
+#include <errno.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+//
+// encapsulated recv()
+//
+static int net_recv_ex(int sock, void *buf, int size, struct timeval *tv)
+{
+       
+       fd_set  fds;
+       int             res;
+
+       // wait for some data to be read
+       do {
+               errno = 0;
+               FD_ZERO(&fds);
+               FD_SET(sock, &fds);
+               res = select(sock + 1, &fds, NULL, NULL, tv);
+       } while (res < 0 && errno == EINTR);
+       if (res < 0) return 0;
+       if (res == 0) {
+               // timeout
+               errno = ETIMEDOUT;  // select was succesfull, errno is now 0
+               return 0;
+       }
+
+       // socket ready, read the data
+       do {
+               errno = 0;
+               res = recv(sock, (char*)buf, size, 0);
+       } while (res < 0 && errno == EINTR);
+       if (res < 0) return 0;
+       if (res == 0) {
+               // orderly shutdown
+               errno = ENOTCONN;
+               return 0;
+       }
+
+       return res;
+}
+
+//
+// read whole buffer or fail
+//
+static int net_recv(int sock, void* buf, int size) {
+
+       int todo = size;
+       int off = 0;
+       int len;
+       struct timeval tv = { 0, 250000 };
+
+       while (todo) {
+               len = net_recv_ex(sock, (char*)buf + off, todo, &tv);
+               if (!len) return 0;
+               todo -= len;
+               off  += len;
+       }
+       return 1;
+}
+
+//
+// get one response line
+//
+static int get_line(int sock, char line[], short linesize) {
+
+       // get the line length
+       short sz;
+       if (!net_recv(sock, &sz, sizeof(sz))) return -1;
+       sz = ntohs(sz);
+       if (!sz) return 0;
+
+       // get the line
+       while (sz > linesize) {
+               // this is just a hack (being lazy), this should not happen anyway
+               net_recv(sock, line, linesize);
+               sz -= sizeof(line);
+       }
+       if (!net_recv(sock, line, sz)) return 0;
+       line[sz] = 0;
+       return sz;
+}
+
+#define FILL(NAME,FIELD,FIRST)                                                                                                         \
+       if (!strncmp(NAME, line, sizeof(NAME)-1)) {                                                                             \
+               strncpy(apc->items[FIELD], line+11, APCUPSD_MAXSTR);                                            \
+               /* remove trailing newline and assure termination */                                            \
+               apc->items[FIELD][len-11 > APCUPSD_MAXSTR ? APCUPSD_MAXSTR : len-12] = 0;       \
+               if (FIRST) {                                                                                                                            \
+                       char* c;                                                                                                                                \
+                       for (c = apc->items[FIELD]; *c; ++c)                                                                    \
+                               if (*c == ' ' && c > apc->items[FIELD]+2) {                                                     \
+                                       *c = 0;                                                                                                                 \
+                                       break;                                                                                                                  \
+                               }                                                                                                                                       \
+               }                                                                                                                                                       \
+       }
+
+//
+// fills in the data received from a socket
+//
+static int fill_items(int sock, PAPCUPSD_S apc) {
+
+       char line[512];
+       int len;
+       while ((len = get_line(sock, line, sizeof(line)))) {
+               // fill the right types in
+               FILL("UPSNAME",         APCUPSD_NAME,           FALSE);
+               FILL("MODEL",           APCUPSD_MODEL,          FALSE);
+               FILL("UPSMODE",         APCUPSD_UPSMODE,        FALSE);
+               FILL("CABLE",           APCUPSD_CABLE,          FALSE);
+               FILL("STATUS",          APCUPSD_STATUS,         FALSE);
+               FILL("LINEV",           APCUPSD_LINEV,          TRUE);
+               FILL("LOADPCT",         APCUPSD_LOAD,           TRUE);
+               FILL("BCHARGE",         APCUPSD_CHARGE,         TRUE);
+               FILL("TIMELEFT",        APCUPSD_TIMELEFT,       TRUE);
+               FILL("ITEMP",           APCUPSD_TEMP,           TRUE);
+               FILL("LASTXFER",        APCUPSD_LASTXFER,       FALSE);
+       }
+       
+       return len == 0;
+}
+
+//
+// Conky update function for apcupsd data
+//
+void update_apcupsd(void) {
+
+       int i;
+       APCUPSD_S apc;
+       int sock;
+
+       for (i = 0; i < _APCUPSD_COUNT; ++i)
+               memcpy(apc.items[i], "N/A", 4); // including \0
+
+       do {
+               struct hostent* he = 0;
+               struct sockaddr_in addr;
+               short sz = 0;
+               //
+               // connect to apcupsd daemon
+               //
+               sock = socket(AF_INET, SOCK_STREAM, 0);
+               if (sock < 0) {
+                       perror("socket");
+                       break;
+               }
+               he = gethostbyname(info.apcupsd.host);
+               if (!he) {
+                       herror("gethostbyname");
+                       break;
+               }
+               memset(&addr, 0, sizeof(addr));
+               addr.sin_family = AF_INET;
+               addr.sin_port = info.apcupsd.port;
+               memcpy(&addr.sin_addr, he->h_addr, he->h_length);
+               if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) < 0) {
+                       // no error reporting, the daemon is probably not running
+                       break;
+               }
+       
+               //
+               // send status request - "status" - 6B
+               //
+               sz = htons(6);
+               // no waiting to become writeable is really needed
+               if (send(sock, &sz, sizeof(sz), 0) != sizeof(sz) || send(sock, "status", 6, 0) != 6) {
+                       perror("send");
+                       break;
+               }
+       
+               //
+               // read the lines of output and put them into the info structure
+               //
+               if (!fill_items(sock, &apc)) break;
+
+       } while (0);
+
+       close(sock);
+
+       //
+       // "atomically" copy the data into working set
+       //
+       memcpy(info.apcupsd.items, apc.items, sizeof(info.apcupsd.items));
+       return;
+}
+
+//
+// fills in the N/A strings and default host:port
+//
+void init_apcupsd(void) {
+
+       int i;
+       for (i = 0; i < _APCUPSD_COUNT; ++i)
+               memcpy(info.apcupsd.items[i], "N/A", 4); // including \0
+       memcpy(info.apcupsd.host, "localhost", 10);
+       info.apcupsd.port = htons(3551);
+}
diff --git a/src/apcupsd.h b/src/apcupsd.h
new file mode 100644 (file)
index 0000000..bf9ea33
--- /dev/null
@@ -0,0 +1,52 @@
+/* apcupsd.h:  conky module for APC UPS daemon monitoring
+ *
+ * Copyright (C) 2009 Jaromir Smrcek <jaromir.smrcek@zoner.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA. */
+
+#ifndef APCUPSD_H_
+#define APCUPSD_H_
+
+enum _apcupsd_items {
+       APCUPSD_NAME,
+       APCUPSD_MODEL,
+       APCUPSD_UPSMODE,
+       APCUPSD_CABLE,
+       APCUPSD_STATUS,
+       APCUPSD_LINEV,
+       APCUPSD_LOAD,
+       APCUPSD_CHARGE,
+       APCUPSD_TIMELEFT,
+       APCUPSD_TEMP,
+       APCUPSD_LASTXFER,
+       _APCUPSD_COUNT,
+};
+
+/* type for data exchange with main thread */
+#define APCUPSD_MAXSTR 32
+typedef struct apcupsd_s {
+       char items[_APCUPSD_COUNT][APCUPSD_MAXSTR+1];   /* e.g. items[APCUPSD_STATUS] */
+       char host[64];
+       int  port;
+} APCUPSD_S, *PAPCUPSD_S;
+
+/* Service routine for the conky main thread */
+void update_apcupsd(void);
+
+/* fill in the default values */
+void init_apcupsd(void);
+
+#endif /*APCUPSD_H_*/
index 7c29783..994cbd4 100644 (file)
@@ -983,6 +983,7 @@ static void free_text_objects(struct text_object *root)
                        case OBJ_apcupsd_load:
                        case OBJ_apcupsd_loadbar:
                        case OBJ_apcupsd_loadgraph:
+                       case OBJ_apcupsd_loadgauge:
                        case OBJ_apcupsd_charge:
                        case OBJ_apcupsd_timeleft:
                        case OBJ_apcupsd_temp:
@@ -2625,6 +2626,8 @@ static struct text_object *construct_text_object(const char *s,
                        END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
                                char* buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e, &obj->showaslog);
                                if (buf) free(buf);
+                       END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
+                               scan_gauge(arg, &obj->a, &obj->b);
                        END OBJ(apcupsd_charge, INFO_APCUPSD)
                        END OBJ(apcupsd_timeleft, INFO_APCUPSD)
                        END OBJ(apcupsd_temp, INFO_APCUPSD)
@@ -5114,6 +5117,12 @@ static void generate_text_internal(char *p, int p_max_size,
                                new_graph(p, obj->a, obj->b, obj->c, obj->d,
                                                  (int)progress, 100, 1, obj->showaslog);
                        }
+                       OBJ(apcupsd_loadgauge) {
+                               double progress;
+                               progress =      atof(cur->apcupsd.items[APCUPSD_LOAD]);
+                               new_gauge(p, obj->a, obj->b,
+                                                 (int)progress);
+                       }
                        OBJ(apcupsd_charge) {
                                snprintf(p, p_max_size, "%s",
                                                 cur->apcupsd.items[APCUPSD_CHARGE]);
index c0443f8..0c001b3 100644 (file)
@@ -376,6 +376,7 @@ enum text_object_type {
        OBJ_apcupsd_load,
        OBJ_apcupsd_loadbar,
        OBJ_apcupsd_loadgraph,
+       OBJ_apcupsd_loadgauge,
        OBJ_apcupsd_charge,
        OBJ_apcupsd_timeleft,
        OBJ_apcupsd_temp,