forked from external/yambar
tag: add a refresh_in() interface function
E.g. particles may use this to force a refresh after a certain amount of time. Note that it can only be used with 'realtime' tags.
This commit is contained in:
parent
5008008079
commit
20b3299afd
2 changed files with 25 additions and 0 deletions
23
tag.c
23
tag.c
|
@ -3,6 +3,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
|
||||||
|
@ -40,6 +41,12 @@ no_realtime(const struct tag *tag)
|
||||||
return TAG_REALTIME_NONE;
|
return TAG_REALTIME_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
unimpl_refresh_in(const struct tag *tag, long milli_seconds)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_int_and_float(struct tag *tag)
|
destroy_int_and_float(struct tag *tag)
|
||||||
{
|
{
|
||||||
|
@ -109,6 +116,19 @@ int_as_float(const struct tag *tag)
|
||||||
return priv->value_as_int.value;
|
return priv->value_as_int.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
int_refresh_in(const struct tag *tag, long milli_seconds)
|
||||||
|
{
|
||||||
|
const struct private *priv = tag->private;
|
||||||
|
if (priv->value_as_int.realtime_unit == TAG_REALTIME_NONE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (tag->owner == NULL || tag->owner->refresh_in == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return tag->owner->refresh_in(tag->owner, milli_seconds);
|
||||||
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
bool_as_string(const struct tag *tag)
|
bool_as_string(const struct tag *tag)
|
||||||
{
|
{
|
||||||
|
@ -260,6 +280,7 @@ tag_new_bool(struct module *owner, const char *name, bool value)
|
||||||
tag->min = &unimpl_min_max;
|
tag->min = &unimpl_min_max;
|
||||||
tag->max = &unimpl_min_max;
|
tag->max = &unimpl_min_max;
|
||||||
tag->realtime = &no_realtime;
|
tag->realtime = &no_realtime;
|
||||||
|
tag->refresh_in = &unimpl_refresh_in;
|
||||||
tag->as_string = &bool_as_string;
|
tag->as_string = &bool_as_string;
|
||||||
tag->as_int = &bool_as_int;
|
tag->as_int = &bool_as_int;
|
||||||
tag->as_bool = &bool_as_bool;
|
tag->as_bool = &bool_as_bool;
|
||||||
|
@ -282,6 +303,7 @@ tag_new_float(struct module *owner, const char *name, double value)
|
||||||
tag->min = &unimpl_min_max;
|
tag->min = &unimpl_min_max;
|
||||||
tag->max = &unimpl_min_max;
|
tag->max = &unimpl_min_max;
|
||||||
tag->realtime = &no_realtime;
|
tag->realtime = &no_realtime;
|
||||||
|
tag->refresh_in = &unimpl_refresh_in;
|
||||||
tag->as_string = &float_as_string;
|
tag->as_string = &float_as_string;
|
||||||
tag->as_int = &float_as_int;
|
tag->as_int = &float_as_int;
|
||||||
tag->as_bool = &float_as_bool;
|
tag->as_bool = &float_as_bool;
|
||||||
|
@ -304,6 +326,7 @@ tag_new_string(struct module *owner, const char *name, const char *value)
|
||||||
tag->min = &unimpl_min_max;
|
tag->min = &unimpl_min_max;
|
||||||
tag->max = &unimpl_min_max;
|
tag->max = &unimpl_min_max;
|
||||||
tag->realtime = &no_realtime;
|
tag->realtime = &no_realtime;
|
||||||
|
tag->refresh_in = &unimpl_refresh_in;
|
||||||
tag->as_string = &string_as_string;
|
tag->as_string = &string_as_string;
|
||||||
tag->as_int = &string_as_int;
|
tag->as_int = &string_as_int;
|
||||||
tag->as_bool = &string_as_bool;
|
tag->as_bool = &string_as_bool;
|
||||||
|
|
2
tag.h
2
tag.h
|
@ -25,6 +25,8 @@ struct tag {
|
||||||
long (*min)(const struct tag *tag);
|
long (*min)(const struct tag *tag);
|
||||||
long (*max)(const struct tag *tag);
|
long (*max)(const struct tag *tag);
|
||||||
enum tag_realtime_unit (*realtime)(const struct tag *tag);
|
enum tag_realtime_unit (*realtime)(const struct tag *tag);
|
||||||
|
|
||||||
|
bool (*refresh_in)(const struct tag *tag, long milli_seconds);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tag_set {
|
struct tag_set {
|
||||||
|
|
Loading…
Add table
Reference in a new issue