1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

renamed global 'config' structure to 'settings'

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@63 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-06-10 16:57:40 +00:00
parent 1635e5b192
commit 4e4230df01
5 changed files with 43 additions and 46 deletions

View file

@ -14,11 +14,9 @@ struct node;
struct path;
/** Global configuration */
struct config {
struct settings {
/** Name of this node */
const char *name;
/** Configuration filename */
const char *filename;
/** Task priority (lower is better) */
int priority;
/** Core affinity of this task */
@ -39,7 +37,7 @@ struct config {
struct path *paths;
};
/** Parse configuration file and store settings in supplied struct config.
/** Parse configuration file and store settings in supplied struct settings.
*
* @param c A libconfig object
* @param g The global configuration structure (also contains the config filename)
@ -47,7 +45,7 @@ struct config {
* - 0 on success
* - otherwise an error occured
*/
int config_parse(config_t *c, struct config *g);
int config_parse(const char *filename, config_t *c, struct settings *g);
/** Parse the global section of a configuration file.
*
@ -57,7 +55,7 @@ int config_parse(config_t *c, struct config *g);
* - 0 on success
* - otherwise an error occured
*/
int config_parse_global(config_setting_t *c, struct config *g);
int config_parse_global(config_setting_t *c, struct settings *g);
/** Parse a single path and add it to the global configuration.
*
@ -67,7 +65,7 @@ int config_parse_global(config_setting_t *c, struct config *g);
* - 0 on success
* - otherwise an error occured
*/
int config_parse_path(config_setting_t *c, struct config *g);
int config_parse_path(config_setting_t *c, struct settings *g);
/** Parse a single node and add it to the global configuration.
*
@ -77,6 +75,6 @@ int config_parse_path(config_setting_t *c, struct config *g);
* - 0 on success
* - otherwise an error occured
*/
int config_parse_node(config_setting_t *c, struct config *g);
int config_parse_node(config_setting_t *c, struct settings *g);
#endif /* _CFG_H_ */

View file

@ -13,7 +13,7 @@
#include <errno.h>
#include <string.h>
struct config;
struct settings;
struct sockaddr_in;
struct sockaddr;
@ -54,7 +54,7 @@ int resolve_addr(const char *addr, struct sockaddr_in *sa, int flags);
*
* @param g The global configuration
*/
void init_realtime(struct config *g);
void init_realtime(struct settings *g);
/** Compare two socket addresses based on their family and address.
*

View file

@ -15,11 +15,9 @@
#include "path.h"
#include "utils.h"
int config_parse(config_t *c, struct config *g)
int config_parse(const char *filename, config_t *cfg, struct settings *g)
{
config_setting_t *cfg_nodes, *cfg_paths, *cfg_root;
if (!config_read_file(cfg, g->filename)) {
if (!config_read_file(cfg, filename)) {
error("Failed to parse configuration: %s in %s:%d",
config_error_text(cfg),
config_error_file(cfg),
@ -27,20 +25,21 @@ int config_parse(config_t *c, struct config *g)
);
}
cfg_root = config_root_setting(c);
config_setting_t *cfg_root = config_root_setting(cfg);
if (!cfg_root || !config_setting_is_group(cfg_root))
error("Missing global section in config");
/* Read global settings */
config_parse_global(cfg_root, g);
/* Allocate memory for paths and nodes */
cfg_nodes = config_setting_get_member(cfg_root, "nodes");
config_setting_t *cfg_nodes = config_setting_get_member(cfg_root, "nodes");
if (!cfg_nodes || !config_setting_is_group(cfg_nodes))
error("Missing node section in config");
cfg_paths = config_setting_get_member(cfg_root, "paths");
config_setting_t *cfg_paths = config_setting_get_member(cfg_root, "paths");
if (!cfg_paths || !config_setting_is_list(cfg_paths))
error("Missing path section in config");
/* Read global settings */
config_parse_global(cfg_root, g);
int node_count = config_setting_length(cfg_nodes);
int path_count = config_setting_length(cfg_paths);
@ -66,12 +65,11 @@ int config_parse(config_t *c, struct config *g)
return CONFIG_TRUE;
}
int config_parse_global(config_setting_t *c, struct config *g)
int config_parse_global(config_setting_t *c, struct settings *g)
{
if (!config_setting_lookup_string(c, "name", &g->name))
cerror(c, "Missing node name");
config_setting_lookup_int(c, "debug", &g->debug);
config_setting_lookup_int(c, "affinity", &g->affinity);
config_setting_lookup_int(c, "priority", &g->priority);
config_setting_lookup_int(c, "protocol", &g->protocol);
@ -81,7 +79,7 @@ int config_parse_global(config_setting_t *c, struct config *g)
return CONFIG_TRUE;
}
int config_parse_path(config_setting_t *c, struct config *g)
int config_parse_path(config_setting_t *c, struct settings *g)
{
struct node *in, *out;
const char *in_str = NULL;
@ -128,7 +126,7 @@ int config_parse_path(config_setting_t *c, struct config *g)
warn(" Path is not enabled");
}
int config_parse_node(config_setting_t *c, struct config *g)
int config_parse_node(config_setting_t *c, struct settings *g)
{
const char *name = NULL;
const char *type_str = NULL;

View file

@ -21,17 +21,19 @@
#include "node.h"
/** Default settings */
static struct config config = {
static struct settings settings = {
.priority = 0,
.affinity = 0xC0,
.protocol = 0
};
static config_t config;
static void start()
{
/* Connect and bind nodes to their sockets, set socket options */
for (int i = 0; i < config.node_count; i++) {
struct node *n = &config.nodes[i];
for (int i = 0; i < settings.node_count; i++) {
struct node *n = &settings.nodes[i];
node_connect(n);
@ -40,32 +42,32 @@ static void start()
}
/* Start on thread per path for asynchronous processing */
for (int i = 0; i < config.path_count; i++) {
struct path *p = &config.paths[i];
for (int i = 0; i < settings.path_count; i++) {
struct path *p = &settings.paths[i];
path_start(p);
info("Starting path: %12s => %s => %-12s", p->in->name, config.name, p->out->name);
info("Starting path: %12s => %s => %-12s", p->in->name, settings.name, p->out->name);
}
}
static void stop()
{
/* Join all threads and print statistics */
for (int i = 0; i < config.path_count; i++) {
struct path *p = &config.paths[i];
for (int i = 0; i < settings.path_count; i++) {
struct path *p = &settings.paths[i];
path_stop(p);
info("Stopping path: %12s => %s => %-12s", p->in->name, config.name, p->out->name);
info("Stopping path: %12s => %s => %-12s", p->in->name, settings.name, p->out->name);
info(" %u messages received", p->received);
info(" %u messages duplicated", p->duplicated);
info(" %u messages delayed", p->delayed);
}
/* Close all sockets we listing on */
for (int i = 0; i < config.node_count; i++) {
struct node *n = &config.nodes[i];
for (int i = 0; i < settings.node_count; i++) {
struct node *n = &settings.nodes[i];
node_disconnect(n);
}
@ -75,9 +77,9 @@ static void quit()
{
stop();
free(config.paths);
free(config.nodes);
config_destroy(&config.obj);
free(settings.paths);
free(settings.nodes);
config_destroy(&config);
_exit(EXIT_SUCCESS);
}
@ -108,17 +110,16 @@ int main(int argc, char *argv[])
info("This is s2ss %s", VERSION);
/* Parse configuration file */
config.filename = argv[1];
config_init(&config.obj);
config_parse(&config.obj, &config);
config_init(&config);
config_parse(argv[1], &config, &settings);
if (!config.path_count)
if (!settings.path_count)
error("No paths found. Terminating...");
else
info("Parsed %u nodes and %u paths", config.node_count, config.path_count);
info("Parsed %u nodes and %u paths", settings.node_count, settings.path_count);
/* Setup various realtime related things */
init_realtime(&config);
init_realtime(&settings);
/* Connect all nodes to their sockets and start one thread per path */
start();

View file

@ -125,7 +125,7 @@ static cpu_set_t to_cpu_set_t(int set)
return cset;
}
void init_realtime(struct config *g)
void init_realtime(struct settings *g)
{
/* Prefault stack */
char dummy[MAX_SAFE_STACK];