mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
tcp_portmon: convert to generic object payload
This commit is contained in:
parent
8d1640f30b
commit
d2be5980ca
@ -2234,8 +2234,7 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
}
|
}
|
||||||
#ifdef TCP_PORT_MONITOR
|
#ifdef TCP_PORT_MONITOR
|
||||||
OBJ(tcp_portmon) {
|
OBJ(tcp_portmon) {
|
||||||
tcp_portmon_action(p, p_max_size,
|
tcp_portmon_action(obj, p, p_max_size);
|
||||||
&obj->data.tcp_port_monitor);
|
|
||||||
}
|
}
|
||||||
#endif /* TCP_PORT_MONITOR */
|
#endif /* TCP_PORT_MONITOR */
|
||||||
|
|
||||||
|
@ -1060,7 +1060,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
#endif /* HDDTEMP */
|
#endif /* HDDTEMP */
|
||||||
#ifdef TCP_PORT_MONITOR
|
#ifdef TCP_PORT_MONITOR
|
||||||
END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments")
|
END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments")
|
||||||
tcp_portmon_init(arg, &obj->data.tcp_port_monitor);
|
tcp_portmon_init(obj, arg);
|
||||||
#endif /* TCP_PORT_MONITOR */
|
#endif /* TCP_PORT_MONITOR */
|
||||||
END OBJ(entropy_avail, &update_entropy)
|
END OBJ(entropy_avail, &update_entropy)
|
||||||
END OBJ(entropy_perc, &update_entropy)
|
END OBJ(entropy_perc, &update_entropy)
|
||||||
@ -1737,6 +1737,11 @@ void free_text_objects(struct text_object *root, int internal)
|
|||||||
case OBJ_apcupsd_lastxfer:
|
case OBJ_apcupsd_lastxfer:
|
||||||
break;
|
break;
|
||||||
#endif /* APCUPSD */
|
#endif /* APCUPSD */
|
||||||
|
#ifdef TCP_PORT_MONITOR
|
||||||
|
case OBJ_tcp_portmon:
|
||||||
|
tcp_portmon_free(obj);
|
||||||
|
break;
|
||||||
|
#endif /* TCP_PORT_MONITOR */
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
case OBJ_desktop:
|
case OBJ_desktop:
|
||||||
case OBJ_desktop_number:
|
case OBJ_desktop_number:
|
||||||
|
@ -21,15 +21,17 @@
|
|||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "tcp-portmon.h"
|
#include "tcp-portmon.h"
|
||||||
|
#include "text_object.h"
|
||||||
#include "libtcp-portmon.h"
|
#include "libtcp-portmon.h"
|
||||||
|
|
||||||
static tcp_port_monitor_collection_t *pmc = NULL;
|
static tcp_port_monitor_collection_t *pmc = NULL;
|
||||||
static tcp_port_monitor_args_t pma;
|
static tcp_port_monitor_args_t pma;
|
||||||
|
|
||||||
int tcp_portmon_init(const char *arg, struct tcp_port_monitor_data *pmd)
|
int tcp_portmon_init(struct text_object *obj, const char *arg)
|
||||||
{
|
{
|
||||||
int argc, port_begin, port_end, item, connection_index;
|
int argc, port_begin, port_end, item, connection_index;
|
||||||
char itembuf[32];
|
char itembuf[32];
|
||||||
|
struct tcp_port_monitor_data *pmd;
|
||||||
|
|
||||||
memset(itembuf, 0, sizeof(itembuf));
|
memset(itembuf, 0, sizeof(itembuf));
|
||||||
connection_index = 0;
|
connection_index = 0;
|
||||||
@ -75,10 +77,13 @@ int tcp_portmon_init(const char *arg, struct tcp_port_monitor_data *pmd)
|
|||||||
CRIT_ERR(NULL, NULL, "tcp_portmon: connection index must be non-negative");
|
CRIT_ERR(NULL, NULL, "tcp_portmon: connection index must be non-negative");
|
||||||
}
|
}
|
||||||
/* ok, args looks good. save the text object data */
|
/* ok, args looks good. save the text object data */
|
||||||
|
pmd = malloc(sizeof(struct tcp_port_monitor_data));
|
||||||
|
memset(pmd, 0, sizeof(struct tcp_port_monitor_data));
|
||||||
pmd->port_range_begin = (in_port_t) port_begin;
|
pmd->port_range_begin = (in_port_t) port_begin;
|
||||||
pmd->port_range_end = (in_port_t) port_end;
|
pmd->port_range_end = (in_port_t) port_end;
|
||||||
pmd->item = item;
|
pmd->item = item;
|
||||||
pmd->connection_index = connection_index;
|
pmd->connection_index = connection_index;
|
||||||
|
obj->data.opaque = pmd;
|
||||||
|
|
||||||
/* if the port monitor collection hasn't been created,
|
/* if the port monitor collection hasn't been created,
|
||||||
* we must create it */
|
* we must create it */
|
||||||
@ -108,10 +113,14 @@ int tcp_portmon_init(const char *arg, struct tcp_port_monitor_data *pmd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcp_portmon_action(char *p, int p_max_size, struct tcp_port_monitor_data *pmd)
|
int tcp_portmon_action(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
|
struct tcp_port_monitor_data *pmd = obj->data.opaque;
|
||||||
tcp_port_monitor_t *p_monitor;
|
tcp_port_monitor_t *p_monitor;
|
||||||
|
|
||||||
|
if (!pmd)
|
||||||
|
return 1;
|
||||||
|
|
||||||
/* grab a pointer to this port monitor */
|
/* grab a pointer to this port monitor */
|
||||||
p_monitor = find_tcp_port_monitor(pmc, pmd->port_range_begin,
|
p_monitor = find_tcp_port_monitor(pmc, pmd->port_range_begin,
|
||||||
pmd->port_range_end);
|
pmd->port_range_end);
|
||||||
@ -153,3 +162,10 @@ int tcp_portmon_set_max_connections(int max)
|
|||||||
return (max < 0) ? 1 : 0;
|
return (max < 0) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tcp_portmon_free(struct text_object *obj)
|
||||||
|
{
|
||||||
|
if (obj->data.opaque) {
|
||||||
|
free(obj->data.opaque);
|
||||||
|
obj->data.opaque = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -35,10 +35,14 @@ struct tcp_port_monitor_data {
|
|||||||
int connection_index;
|
int connection_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
int tcp_portmon_init(const char *, struct tcp_port_monitor_data *);
|
/* forward declare to make gcc happy */
|
||||||
int tcp_portmon_action(char *, int, struct tcp_port_monitor_data *);
|
struct text_object;
|
||||||
|
|
||||||
|
int tcp_portmon_init(struct text_object *, const char *);
|
||||||
|
int tcp_portmon_action(struct text_object *, char *, int);
|
||||||
void tcp_portmon_update(void);
|
void tcp_portmon_update(void);
|
||||||
int tcp_portmon_clear(void);
|
int tcp_portmon_clear(void);
|
||||||
int tcp_portmon_set_max_connections(int);
|
int tcp_portmon_set_max_connections(int);
|
||||||
|
void tcp_portmon_free(struct text_object *);
|
||||||
|
|
||||||
#endif /* _TCP_PORTMON_H */
|
#endif /* _TCP_PORTMON_H */
|
||||||
|
@ -495,9 +495,6 @@ struct text_object {
|
|||||||
struct {
|
struct {
|
||||||
int a, b;
|
int a, b;
|
||||||
} pair; /* 2 */
|
} pair; /* 2 */
|
||||||
#ifdef TCP_PORT_MONITOR
|
|
||||||
struct tcp_port_monitor_data tcp_port_monitor;
|
|
||||||
#endif
|
|
||||||
#ifdef EVE
|
#ifdef EVE
|
||||||
struct {
|
struct {
|
||||||
char *apikey;
|
char *apikey;
|
||||||
|
Loading…
Reference in New Issue
Block a user