mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-23 12:35:41 +02:00
module/script: poll-interval: convert value from ‘seconds’ to ‘milliseconds’
This commit is contained in:
parent
500b051fe4
commit
c4f820e486
2 changed files with 26 additions and 6 deletions
|
@ -78,8 +78,8 @@ User defined.
|
||||||
| poll-interval
|
| poll-interval
|
||||||
: integer
|
: integer
|
||||||
: no
|
: no
|
||||||
: Number of seconds between each script run. If unset, continuous mode
|
: Number of milliseconds between each script run. If unset, or set to
|
||||||
is used.
|
0, continuous mode is used.
|
||||||
|
|
||||||
# EXAMPLES
|
# EXAMPLES
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include "../module.h"
|
#include "../module.h"
|
||||||
#include "../plugin.h"
|
#include "../plugin.h"
|
||||||
|
|
||||||
|
static const long min_poll_interval = 500;
|
||||||
|
|
||||||
struct private {
|
struct private {
|
||||||
char *path;
|
char *path;
|
||||||
size_t argc;
|
size_t argc;
|
||||||
|
@ -574,7 +576,7 @@ run(struct module *mod)
|
||||||
break;
|
break;
|
||||||
if (m->aborted)
|
if (m->aborted)
|
||||||
break;
|
break;
|
||||||
if (m->poll_interval < 0)
|
if (m->poll_interval <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
@ -583,7 +585,10 @@ run(struct module *mod)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval poll_interval = {.tv_sec = m->poll_interval};
|
struct timeval poll_interval = {
|
||||||
|
.tv_sec = m->poll_interval / 1000,
|
||||||
|
.tv_usec = (m->poll_interval % 1000) * 1000,
|
||||||
|
};
|
||||||
|
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
timeradd(&now, &poll_interval, &timeout);
|
timeradd(&now, &poll_interval, &timeout);
|
||||||
|
@ -670,7 +675,7 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited)
|
||||||
|
|
||||||
return script_new(
|
return script_new(
|
||||||
yml_value_as_string(path), argc, argv,
|
yml_value_as_string(path), argc, argv,
|
||||||
poll_interval != NULL ? yml_value_as_int(poll_interval) : -1,
|
poll_interval != NULL ? yml_value_as_int(poll_interval) : 0,
|
||||||
conf_to_particle(c, inherited));
|
conf_to_particle(c, inherited));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,13 +700,28 @@ conf_verify_args(keychain_t *chain, const struct yml_node *node)
|
||||||
return conf_verify_list(chain, node, &conf_verify_string);
|
return conf_verify_list(chain, node, &conf_verify_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
conf_verify_poll_interval(keychain_t *chain, const struct yml_node *node)
|
||||||
|
{
|
||||||
|
if (!conf_verify_unsigned(chain, node))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (yml_value_as_int(node) < min_poll_interval) {
|
||||||
|
LOG_ERR("%s: interval value cannot be less than %ldms",
|
||||||
|
conf_err_prefix(chain, node), min_poll_interval);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
verify_conf(keychain_t *chain, const struct yml_node *node)
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
{
|
{
|
||||||
static const struct attr_info attrs[] = {
|
static const struct attr_info attrs[] = {
|
||||||
{"path", true, &conf_verify_path},
|
{"path", true, &conf_verify_path},
|
||||||
{"args", false, &conf_verify_args},
|
{"args", false, &conf_verify_args},
|
||||||
{"poll-interval", false, &conf_verify_unsigned},
|
{"poll-interval", false, &conf_verify_poll_interval},
|
||||||
MODULE_COMMON_ATTRS,
|
MODULE_COMMON_ATTRS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue