mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added some experiments with libconfig
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@6 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
39b0675bd0
commit
2c5db5ee64
3 changed files with 113 additions and 0 deletions
26
etc/s2ss.conf
Normal file
26
etc/s2ss.conf
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Example configuration file for the s2ss server
|
||||
|
||||
# The name of this node
|
||||
name = "acs";
|
||||
|
||||
# The debugging level (0 - 10)
|
||||
debug = 10;
|
||||
|
||||
nodes = (
|
||||
{
|
||||
id = 123;
|
||||
name = "acs";
|
||||
type = "opal";
|
||||
addr = "137.123.234.233";
|
||||
port = 7582;
|
||||
}
|
||||
);
|
||||
|
||||
paths = (
|
||||
{
|
||||
from = "acs";
|
||||
to = "trond";
|
||||
reverse = true; # also setup a reverse path
|
||||
log = true; # log messages
|
||||
}
|
||||
);
|
21
include/cfg.h
Normal file
21
include/cfg.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* Configuration parser
|
||||
*
|
||||
* @author Steffen Vogel <steffen.vogel@rwth-aachen.de>
|
||||
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#include <libconfig.h>
|
||||
|
||||
#include "path.h"
|
||||
#include "node.h"
|
||||
|
||||
int config_parse(config_t *c, const char *filename, struct path *paths, struct node *nodes);
|
||||
|
||||
int config_parse_path(config_setting_t *c, struct path *p);
|
||||
int config_parse_node(config_setting_t *c, struct node *n);
|
||||
|
||||
#endif /* _CONFIG_H_ */
|
66
src/cfg.c
Normal file
66
src/cfg.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Configuration parser
|
||||
*
|
||||
* @author Steffen Vogel <steffen.vogel@rwth-aachen.de>
|
||||
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "utils.h"
|
||||
|
||||
int config_parse(config_t *cfg, const char *filename, struct path *paths, struct node *nodes)
|
||||
{
|
||||
if (!config_read_file(cfg, filename)) {
|
||||
logger(ERROR, "Failed to parse configuration: %s in %s:%d",
|
||||
config_error_text(cfg), config_error_file(cfg), config_error_line(cfg));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
config_setting_t *cfg_root = config_root_setting(cfg);
|
||||
|
||||
// read global settings
|
||||
int debug;
|
||||
if (config_setting_lookup_int(cfg_root, "debug", &debug))
|
||||
logger(DEBUG, "Setting debug level to %u", debug);
|
||||
|
||||
// read nodes
|
||||
config_setting_t *cfg_nodes = config_setting_get_member(cfg_root, "nodes");
|
||||
if (cfg_nodes) {
|
||||
for (int i=0; i < config_setting_length(cfg_nodes); i++) {
|
||||
config_setting_t *cfg_node = config_setting_get_elem(cfg_nodes, i);
|
||||
config_parse_node(cfg_node, nodes);
|
||||
}
|
||||
}
|
||||
|
||||
// read paths
|
||||
config_setting_t *cfg_paths = config_setting_get_member(cfg_root, "paths");
|
||||
if (cfg_paths) {
|
||||
for (int i=0; i < config_setting_length(cfg_paths); i++) {
|
||||
for (int i=0; i < config_setting_length(cfg_paths); i++) {
|
||||
config_setting_t *cfg_path = config_setting_get_elem(cfg_paths, i);
|
||||
config_parse_path(cfg_path, &paths[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CONFIG_TRUE;
|
||||
}
|
||||
|
||||
int config_parse_path(config_setting_t *c, struct path *p)
|
||||
{
|
||||
|
||||
return CONFIG_TRUE;
|
||||
}
|
||||
|
||||
int config_parse_node(config_setting_t *c, struct node *n)
|
||||
{
|
||||
config_setting_lookup_string(c, "name", (const char **) &n->name);
|
||||
|
||||
|
||||
logger(DEBUG, "Found node: %s", n->name);
|
||||
|
||||
return CONFIG_TRUE;
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue