Wrap constant and predicate registries into a single environment type
This commit is contained in:
parent
011772a24a
commit
2676b5acdf
12
config.c
12
config.c
|
@ -449,3 +449,15 @@ resolve_event_predicate(EventPredicateHandleRegistry * registry, const ConstantR
|
||||||
}
|
}
|
||||||
return load_single_predicate(setting, registry, constants);
|
return load_single_predicate(setting, registry, constants);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long long
|
||||||
|
env_resolve_constant_or(InitializationEnvironment * env, const config_setting_t * setting, long long dflt)
|
||||||
|
{
|
||||||
|
return resolve_constant_or(&env->constants, setting, dflt);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventPredicateHandle
|
||||||
|
env_resolve_event_predicate(InitializationEnvironment * env, const config_setting_t * setting)
|
||||||
|
{
|
||||||
|
return resolve_event_predicate(&env->predicates, &env->constants, setting);
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ predicates = {
|
||||||
max = "event_type.KEY";
|
max = "event_type.KEY";
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
nodes = {
|
nodes = {
|
||||||
|
|
23
config.h
23
config.h
|
@ -31,12 +31,21 @@ typedef struct {
|
||||||
|
|
||||||
typedef TYPED_HASH_TABLE(long long) ConstantRegistry;
|
typedef TYPED_HASH_TABLE(long long) ConstantRegistry;
|
||||||
typedef TYPED_HASH_TABLE(EventPredicateHandle) EventPredicateHandleRegistry;
|
typedef TYPED_HASH_TABLE(EventPredicateHandle) EventPredicateHandleRegistry;
|
||||||
|
typedef struct initialization_environment InitializationEnvironment;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GraphNodeConfigSection nodes;
|
GraphNodeConfigSection nodes;
|
||||||
GraphChannelConfigSection channels;
|
GraphChannelConfigSection channels;
|
||||||
ConstantRegistry constants;
|
union {
|
||||||
EventPredicateHandleRegistry predicates;
|
struct {
|
||||||
|
ConstantRegistry constants;
|
||||||
|
EventPredicateHandleRegistry predicates;
|
||||||
|
};
|
||||||
|
struct initialization_environment {
|
||||||
|
const ConstantRegistry constants;
|
||||||
|
EventPredicateHandleRegistry predicates;
|
||||||
|
} environment;
|
||||||
|
};
|
||||||
} FullConfig;
|
} FullConfig;
|
||||||
|
|
||||||
bool load_config(const config_setting_t *config_root, FullConfig *config);
|
bool load_config(const config_setting_t *config_root, FullConfig *config);
|
||||||
|
@ -44,10 +53,20 @@ void reset_config(FullConfig *config);
|
||||||
long long resolve_constant_or(const ConstantRegistry * registry, const config_setting_t * setting, long long dflt);
|
long long resolve_constant_or(const ConstantRegistry * registry, const config_setting_t * setting, long long dflt);
|
||||||
EventPredicateHandle resolve_event_predicate(EventPredicateHandleRegistry * registry, const ConstantRegistry * constants, const config_setting_t * setting);
|
EventPredicateHandle resolve_event_predicate(EventPredicateHandleRegistry * registry, const ConstantRegistry * constants, const config_setting_t * setting);
|
||||||
|
|
||||||
|
// These are not inline to make non-breaking ABI changes
|
||||||
|
long long env_resolve_constant_or(InitializationEnvironment * env, const config_setting_t * setting, long long dflt);
|
||||||
|
EventPredicateHandle env_resolve_event_predicate(InitializationEnvironment * env, const config_setting_t * setting);
|
||||||
|
|
||||||
__attribute__((unused)) inline static long long
|
__attribute__((unused)) inline static long long
|
||||||
resolve_constant(const ConstantRegistry * registry, const config_setting_t * setting)
|
resolve_constant(const ConstantRegistry * registry, const config_setting_t * setting)
|
||||||
{
|
{
|
||||||
return resolve_constant_or(registry, setting, 0);
|
return resolve_constant_or(registry, setting, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((unused)) inline static long long
|
||||||
|
env_resolve_constant(InitializationEnvironment * env, const config_setting_t * setting)
|
||||||
|
{
|
||||||
|
return env_resolve_constant_or(env, setting, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* end of include guard: CONFIG_H_ */
|
#endif /* end of include guard: CONFIG_H_ */
|
||||||
|
|
4
graph.c
4
graph.c
|
@ -88,12 +88,12 @@ graph_channel_init(GraphChannel * ch, GraphNode * start, size_t start_idx, Graph
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphNode *
|
GraphNode *
|
||||||
graph_node_new(GraphNodeSpecification * spec, GraphNodeConfig * config, const ConstantRegistry * constants)
|
graph_node_new(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
|
||||||
{
|
{
|
||||||
if (!spec || !spec->create) {
|
if (!spec || !spec->create) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return spec->create(spec, config, constants);
|
return spec->create(spec, config, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
4
graph.h
4
graph.h
|
@ -29,14 +29,14 @@ struct graph_channel {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct graph_node_specification {
|
struct graph_node_specification {
|
||||||
GraphNode * (*create)(GraphNodeSpecification * self, GraphNodeConfig * config, const ConstantRegistry * constants);
|
GraphNode * (*create)(GraphNodeSpecification * self, GraphNodeConfig * config, InitializationEnvironment * env);
|
||||||
void (*destroy)(GraphNodeSpecification * self, GraphNode * target);
|
void (*destroy)(GraphNodeSpecification * self, GraphNode * target);
|
||||||
void (*register_io)(GraphNodeSpecification * self, GraphNode * target, ProcessingState * state);
|
void (*register_io)(GraphNodeSpecification * self, GraphNode * target, ProcessingState * state);
|
||||||
char *name;
|
char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
void graph_channel_init(GraphChannel * ch, GraphNode * start, size_t start_idx, GraphNode * end, size_t end_idx);
|
void graph_channel_init(GraphChannel * ch, GraphNode * start, size_t start_idx, GraphNode * end, size_t end_idx);
|
||||||
GraphNode *graph_node_new(GraphNodeSpecification * spec, GraphNodeConfig * config, const ConstantRegistry * constants);
|
GraphNode *graph_node_new(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env);
|
||||||
void graph_node_delete(GraphNode * self);
|
void graph_node_delete(GraphNode * self);
|
||||||
void graph_node_register_io(GraphNode * self, ProcessingState * state);
|
void graph_node_register_io(GraphNode * self, ProcessingState * state);
|
||||||
void graph_channel_list_init(GraphChannelList * lst);
|
void graph_channel_list_init(GraphChannelList * lst);
|
||||||
|
|
2
main.c
2
main.c
|
@ -39,7 +39,7 @@ main(int argc, char ** argv)
|
||||||
fprintf(stderr, "Unknown node type \"%s\" for node %ld \"%s\"\n", type_name, i, loaded_config.nodes.items[i].name);
|
fprintf(stderr, "Unknown node type \"%s\" for node %ld \"%s\"\n", type_name, i, loaded_config.nodes.items[i].name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (!(nodes[i] = graph_node_new(spec, &loaded_config.nodes.items[i], &loaded_config.constants))) {
|
if (!(nodes[i] = graph_node_new(spec, &loaded_config.nodes.items[i], &loaded_config.environment))) {
|
||||||
perror("Failed to create node");
|
perror("Failed to create node");
|
||||||
fprintf(stderr, "%ld \"%s\"\n", i, loaded_config.nodes.items[i].name);
|
fprintf(stderr, "%ld \"%s\"\n", i, loaded_config.nodes.items[i].name);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -69,7 +69,7 @@ handle_io(EventPositionBase * self, int fd, bool is_output)
|
||||||
}
|
}
|
||||||
|
|
||||||
static GraphNode *
|
static GraphNode *
|
||||||
create(GraphNodeSpecification * spec, GraphNodeConfig * config, const ConstantRegistry * constants)
|
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
|
||||||
{
|
{
|
||||||
EvdevGraphNode * node = T_ALLOC(1, EvdevGraphNode);
|
EvdevGraphNode * node = T_ALLOC(1, EvdevGraphNode);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
|
@ -77,7 +77,7 @@ create(GraphNodeSpecification * spec, GraphNodeConfig * config, const ConstantRe
|
||||||
}
|
}
|
||||||
const char *filename = NULL;
|
const char *filename = NULL;
|
||||||
if (config) {
|
if (config) {
|
||||||
node->namespace = resolve_constant(constants, config_setting_get_member(config->options, "namespace"));
|
node->namespace = env_resolve_constant(env, config_setting_get_member(config->options, "namespace"));
|
||||||
config_setting_lookup_string(config->options, "file", &filename);
|
config_setting_lookup_string(config->options, "file", &filename);
|
||||||
}
|
}
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ handle_io(EventPositionBase * self, int fd, bool is_output)
|
||||||
}
|
}
|
||||||
|
|
||||||
static GraphNode *
|
static GraphNode *
|
||||||
create(GraphNodeSpecification * spec, GraphNodeConfig * config, const ConstantRegistry * constants)
|
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
|
||||||
{
|
{
|
||||||
GetcharGraphNode * node = T_ALLOC(1, GetcharGraphNode);
|
GetcharGraphNode * node = T_ALLOC(1, GetcharGraphNode);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
|
@ -70,7 +70,7 @@ create(GraphNodeSpecification * spec, GraphNodeConfig * config, const ConstantRe
|
||||||
.handle_io = handle_io,
|
.handle_io = handle_io,
|
||||||
.enabled = true,
|
.enabled = true,
|
||||||
},
|
},
|
||||||
.namespace = resolve_constant(constants, config_setting_get_member(config->options, "namespace")),
|
.namespace = env_resolve_constant(env, config_setting_get_member(config->options, "namespace")),
|
||||||
};
|
};
|
||||||
return &node->as_GraphNode;
|
return &node->as_GraphNode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,10 @@ handle_event(EventPositionBase * self, EventNode * event)
|
||||||
}
|
}
|
||||||
|
|
||||||
static GraphNode *
|
static GraphNode *
|
||||||
create(GraphNodeSpecification * spec, GraphNodeConfig * config, const ConstantRegistry * constants)
|
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
|
||||||
{
|
{
|
||||||
(void) config;
|
(void) config;
|
||||||
(void) constants;
|
(void) env;
|
||||||
GraphNode * node = T_ALLOC(1, GraphNode);
|
GraphNode * node = T_ALLOC(1, GraphNode);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return node;
|
return node;
|
||||||
|
|
|
@ -21,10 +21,10 @@ handle_event(EventPositionBase * self, EventNode * event)
|
||||||
}
|
}
|
||||||
|
|
||||||
static GraphNode *
|
static GraphNode *
|
||||||
create(GraphNodeSpecification * spec, GraphNodeConfig * config, const ConstantRegistry * constants)
|
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
|
||||||
{
|
{
|
||||||
(void) config;
|
(void) config;
|
||||||
(void) constants;
|
(void) env;
|
||||||
GraphNode * node = T_ALLOC(1, GraphNode);
|
GraphNode * node = T_ALLOC(1, GraphNode);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return node;
|
return node;
|
||||||
|
|
Loading…
Reference in New Issue