2024-08-14 23:23:21 +03:00
|
|
|
#ifndef CONFIG_H_
|
|
|
|
#define CONFIG_H_
|
|
|
|
|
|
|
|
#include <libconfig.h>
|
|
|
|
#include "defs.h"
|
2024-08-16 11:12:20 +03:00
|
|
|
#include "hash_table.h"
|
2024-08-16 23:48:09 +03:00
|
|
|
#include "event_predicate.h"
|
2024-08-14 23:23:21 +03:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
const char *type;
|
|
|
|
config_setting_t *options;
|
|
|
|
} GraphNodeConfig;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
size_t length;
|
|
|
|
GraphNodeConfig *items;
|
|
|
|
} GraphNodeConfigSection;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
struct {
|
|
|
|
const char *name;
|
|
|
|
size_t index;
|
|
|
|
} from, to;
|
|
|
|
} GraphChannelConfig;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
size_t length;
|
|
|
|
GraphChannelConfig *items;
|
|
|
|
} GraphChannelConfigSection;
|
|
|
|
|
2024-08-16 11:12:20 +03:00
|
|
|
typedef TYPED_HASH_TABLE(long long) ConstantRegistry;
|
2024-08-16 23:48:09 +03:00
|
|
|
typedef TYPED_HASH_TABLE(EventPredicateHandle) EventPredicateHandleRegistry;
|
2024-08-17 12:02:26 +03:00
|
|
|
typedef struct initialization_environment InitializationEnvironment;
|
2024-08-16 11:12:20 +03:00
|
|
|
|
2024-08-14 23:23:21 +03:00
|
|
|
typedef struct {
|
|
|
|
GraphNodeConfigSection nodes;
|
|
|
|
GraphChannelConfigSection channels;
|
2024-08-17 12:02:26 +03:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
ConstantRegistry constants;
|
|
|
|
EventPredicateHandleRegistry predicates;
|
|
|
|
};
|
|
|
|
struct initialization_environment {
|
|
|
|
const ConstantRegistry constants;
|
|
|
|
EventPredicateHandleRegistry predicates;
|
|
|
|
} environment;
|
|
|
|
};
|
2024-08-14 23:23:21 +03:00
|
|
|
} FullConfig;
|
|
|
|
|
|
|
|
bool load_config(const config_setting_t *config_root, FullConfig *config);
|
2024-08-15 22:25:18 +03:00
|
|
|
void reset_config(FullConfig *config);
|
2024-08-16 12:56:04 +03:00
|
|
|
long long resolve_constant_or(const ConstantRegistry * registry, const config_setting_t * setting, long long dflt);
|
2024-08-16 23:48:09 +03:00
|
|
|
EventPredicateHandle resolve_event_predicate(EventPredicateHandleRegistry * registry, const ConstantRegistry * constants, const config_setting_t * setting);
|
2024-08-16 12:56:04 +03:00
|
|
|
|
2024-08-17 12:02:26 +03:00
|
|
|
// 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);
|
|
|
|
|
2024-08-16 12:56:04 +03:00
|
|
|
__attribute__((unused)) inline static long long
|
|
|
|
resolve_constant(const ConstantRegistry * registry, const config_setting_t * setting)
|
|
|
|
{
|
|
|
|
return resolve_constant_or(registry, setting, 0);
|
|
|
|
}
|
2024-08-14 23:23:21 +03:00
|
|
|
|
2024-08-17 12:02:26 +03:00
|
|
|
__attribute__((unused)) inline static long long
|
|
|
|
env_resolve_constant(InitializationEnvironment * env, const config_setting_t * setting)
|
|
|
|
{
|
|
|
|
return env_resolve_constant_or(env, setting, 0);
|
|
|
|
}
|
|
|
|
|
2024-08-14 23:23:21 +03:00
|
|
|
#endif /* end of include guard: CONFIG_H_ */
|