mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 12:27:52 +00:00
apcupsd: convert to callbacks.print
This commit is contained in:
parent
ac80e6f55f
commit
974d28a667
@ -25,6 +25,7 @@
|
||||
#include "conky.h"
|
||||
#include "apcupsd.h"
|
||||
#include "logging.h"
|
||||
#include "text_object.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
@ -227,3 +228,65 @@ void update_apcupsd(void) {
|
||||
memcpy(info.apcupsd.items, apc.items, sizeof(info.apcupsd.items));
|
||||
return;
|
||||
}
|
||||
|
||||
/* this is just a NOP for the $apcupsd object */
|
||||
void print_apcupsd_nop(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
(void)obj;
|
||||
(void)p;
|
||||
(void)p_max_size;
|
||||
}
|
||||
|
||||
void print_apcupsd_loadgraph(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
double progress;
|
||||
|
||||
if (!p_max_size)
|
||||
return;
|
||||
|
||||
progress = atof(info.apcupsd.items[APCUPSD_LOAD]);
|
||||
new_graph(obj, p, p_max_size, (int)progress);
|
||||
}
|
||||
|
||||
void print_apcupsd_loadgauge(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
double progress;
|
||||
|
||||
if (!p_max_size)
|
||||
return;
|
||||
|
||||
progress = atof(info.apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
|
||||
new_gauge(obj, p, p_max_size, (int)progress);
|
||||
}
|
||||
|
||||
void print_apcupsd_loadbar(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
double progress;
|
||||
|
||||
if (!p_max_size)
|
||||
return;
|
||||
|
||||
progress = atof(info.apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
|
||||
new_bar(obj, p, p_max_size, (int) progress);
|
||||
}
|
||||
|
||||
#define APCUPSD_PRINT_GENERATOR(name, idx) \
|
||||
void print_apcupsd_##name(struct text_object *obj, char *p, int p_max_size) \
|
||||
{ \
|
||||
(void)obj; \
|
||||
snprintf(p, p_max_size, "%s", info.apcupsd.items[APCUPSD_##idx]); \
|
||||
}
|
||||
|
||||
APCUPSD_PRINT_GENERATOR(name, NAME)
|
||||
APCUPSD_PRINT_GENERATOR(model, MODEL)
|
||||
APCUPSD_PRINT_GENERATOR(upsmode, UPSMODE)
|
||||
APCUPSD_PRINT_GENERATOR(cable, CABLE)
|
||||
APCUPSD_PRINT_GENERATOR(status, STATUS)
|
||||
APCUPSD_PRINT_GENERATOR(linev, LINEV)
|
||||
APCUPSD_PRINT_GENERATOR(load, LOAD)
|
||||
APCUPSD_PRINT_GENERATOR(charge, CHARGE)
|
||||
APCUPSD_PRINT_GENERATOR(timeleft, TIMELEFT)
|
||||
APCUPSD_PRINT_GENERATOR(temp, TEMP)
|
||||
APCUPSD_PRINT_GENERATOR(lastxfer, LASTXFER)
|
||||
|
||||
#undef APCUPSD_PRINT_GENERATOR
|
||||
|
@ -51,4 +51,21 @@ typedef struct apcupsd_s {
|
||||
/* Service routine for the conky main thread */
|
||||
void update_apcupsd(void);
|
||||
|
||||
void print_apcupsd_nop(struct text_object *, char *, int);
|
||||
void print_apcupsd_loadgraph(struct text_object *, char *, int);
|
||||
void print_apcupsd_loadgauge(struct text_object *, char *, int);
|
||||
void print_apcupsd_loadbar(struct text_object *, char *, int);
|
||||
|
||||
void print_apcupsd_name(struct text_object *, char *, int);
|
||||
void print_apcupsd_model(struct text_object *, char *, int);
|
||||
void print_apcupsd_upsmode(struct text_object *, char *, int);
|
||||
void print_apcupsd_cable(struct text_object *, char *, int);
|
||||
void print_apcupsd_status(struct text_object *, char *, int);
|
||||
void print_apcupsd_linev(struct text_object *, char *, int);
|
||||
void print_apcupsd_load(struct text_object *, char *, int);
|
||||
void print_apcupsd_charge(struct text_object *, char *, int);
|
||||
void print_apcupsd_timeleft(struct text_object *, char *, int);
|
||||
void print_apcupsd_temp(struct text_object *, char *, int);
|
||||
void print_apcupsd_lastxfer(struct text_object *, char *, int);
|
||||
|
||||
#endif /*APCUPSD_H_*/
|
||||
|
66
src/conky.c
66
src/conky.c
@ -1801,72 +1801,6 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
print_nvidia_value(obj, display, p, p_max_size);
|
||||
}
|
||||
#endif /* NVIDIA */
|
||||
#ifdef APCUPSD
|
||||
OBJ(apcupsd) {
|
||||
/* This is just a meta-object to set host:port */
|
||||
}
|
||||
OBJ(apcupsd_name) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_NAME]);
|
||||
}
|
||||
OBJ(apcupsd_model) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_MODEL]);
|
||||
}
|
||||
OBJ(apcupsd_upsmode) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_UPSMODE]);
|
||||
}
|
||||
OBJ(apcupsd_cable) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_CABLE]);
|
||||
}
|
||||
OBJ(apcupsd_status) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_STATUS]);
|
||||
}
|
||||
OBJ(apcupsd_linev) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_LINEV]);
|
||||
}
|
||||
OBJ(apcupsd_load) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_LOAD]);
|
||||
}
|
||||
OBJ(apcupsd_loadbar) {
|
||||
double progress;
|
||||
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
|
||||
new_bar(obj, p, p_max_size, (int) progress);
|
||||
}
|
||||
#ifdef X11
|
||||
OBJ(apcupsd_loadgraph) {
|
||||
double progress;
|
||||
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
|
||||
new_graph(obj, p, p_max_size, (int)progress);
|
||||
}
|
||||
#endif /* X11 */
|
||||
OBJ(apcupsd_loadgauge) {
|
||||
double progress;
|
||||
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
|
||||
new_gauge(obj, p, p_max_size, (int)progress);
|
||||
}
|
||||
OBJ(apcupsd_charge) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_CHARGE]);
|
||||
}
|
||||
OBJ(apcupsd_timeleft) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_TIMELEFT]);
|
||||
}
|
||||
OBJ(apcupsd_temp) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_TEMP]);
|
||||
}
|
||||
OBJ(apcupsd_lastxfer) {
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->apcupsd.items[APCUPSD_LASTXFER]);
|
||||
}
|
||||
#endif /* APCUPSD */
|
||||
break;
|
||||
}
|
||||
#undef DO_JUMP
|
||||
|
15
src/core.c
15
src/core.c
@ -1343,27 +1343,42 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
info.apcupsd.port = htons(port);
|
||||
strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
|
||||
}
|
||||
obj->callbacks.print = &print_apcupsd_nop;
|
||||
END OBJ(apcupsd_name, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_name;
|
||||
END OBJ(apcupsd_model, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_model;
|
||||
END OBJ(apcupsd_upsmode, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_upsmode;
|
||||
END OBJ(apcupsd_cable, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_cable;
|
||||
END OBJ(apcupsd_status, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_status;
|
||||
END OBJ(apcupsd_linev, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_linev;
|
||||
END OBJ(apcupsd_load, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_load;
|
||||
END OBJ(apcupsd_loadbar, &update_apcupsd)
|
||||
scan_bar(obj, arg);
|
||||
obj->callbacks.print = &print_apcupsd_loadbar;
|
||||
#ifdef X11
|
||||
END OBJ(apcupsd_loadgraph, &update_apcupsd)
|
||||
char* buf = 0;
|
||||
buf = scan_graph(obj, arg, 0);
|
||||
if (buf) free(buf);
|
||||
obj->callbacks.print = &print_apcupsd_loadgraph;
|
||||
#endif /* X11 */
|
||||
END OBJ(apcupsd_loadgauge, &update_apcupsd)
|
||||
scan_gauge(obj, arg);
|
||||
obj->callbacks.print = &print_apcupsd_loadgauge;
|
||||
END OBJ(apcupsd_charge, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_charge;
|
||||
END OBJ(apcupsd_timeleft, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_timeleft;
|
||||
END OBJ(apcupsd_temp, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_temp;
|
||||
END OBJ(apcupsd_lastxfer, &update_apcupsd)
|
||||
obj->callbacks.print = &print_apcupsd_lastxfer;
|
||||
#endif /* APCUPSD */
|
||||
END {
|
||||
char buf[text_buffer_size];
|
||||
|
Loading…
Reference in New Issue
Block a user