summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiacomo Bagnoli <g.bagnoli@asidev.com>2010-03-13 17:30:13 +0100
committerGiacomo Bagnoli <g.bagnoli@asidev.com>2010-03-13 17:30:13 +0100
commit089cad8789d713ac505859726f263205f67d4590 (patch)
tree132c087e6101d3cc9cc96d827014342a3b3d2a01
parent34b77fc8905ee69e77500a6c68da87697f166c9f (diff)
Initial parsing for yaml file
-rw-r--r--src/Makefile.am2
-rw-r--r--src/rt-app_args.c24
-rw-r--r--src/rt-app_args.h3
-rw-r--r--src/rt-app_parse_config.c166
-rw-r--r--src/rt-app_parse_config.h43
5 files changed, 233 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2e4ca9b..396f000 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,6 @@
ACLOCAL_AMFLAGS = -I m4
AM_CPPFLAGS = -I$(srcdir)/../libdl/
bin_PROGRAMS = rt-app
-rt_app_SOURCES= rt-app_types.h rt-app_args.h rt-app_utils.h rt-app_utils.c rt-app_args.c rt-app.h rt-app.c # dl_syscalls.c dl_syscalls.h
+rt_app_SOURCES= rt-app_types.h rt-app_args.h rt-app_utils.h rt-app_utils.c rt-app_args.c rt-app.h rt-app.c rt-app_parse_config.h rt-app_parse_config.c
rt_app_LDADD = $(QRESLIB) ../libdl/libdl.a $(LIBYAML)
diff --git a/src/rt-app_args.c b/src/rt-app_args.c
index 7d8289d..3a5842f 100644
--- a/src/rt-app_args.c
+++ b/src/rt-app_args.c
@@ -22,7 +22,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
void
usage (const char* msg)
{
- printf("usage: rt-app [options] -t <period>:<exec>[:cpu affinity"
+#ifdef YAML
+ printf("usage:\n"
+ "rt-app <taskset.yml>\nOR\n");
+#endif
+ printf("rt-app [options] -t <period>:<exec>[:cpu affinity"
"[:policy[:deadline[:prio]]]] -t ...\n\n");
printf("-h, --help\t:\tshow this help\n");
printf("-f, --fifo\t:\tset default policy for threads to SCHED_FIFO\n");
@@ -205,8 +209,8 @@ parse_thread_args(char *arg, thread_data_t *tdata, policy_t def_policy)
free(str);
}
-void
-parse_command_line(int argc, char **argv, rtapp_options_t *opts)
+static void
+parse_command_line_options(int argc, char **argv, rtapp_options_t *opts)
{
char tmp[PATH_LENGTH];
char ch;
@@ -332,4 +336,18 @@ parse_command_line(int argc, char **argv, rtapp_options_t *opts)
}
+void
+parse_command_line(int argc, char **argv, rtapp_options_t *opts)
+{
+#ifdef YAML
+ if (argc < 2)
+ usage("");
+ struct stat config_file_stat;
+ if (stat(argv[1], &config_file_stat) == 0) {
+ parse_config(argv[1], opts);
+ }
+ else
+#endif
+ parse_command_line_options(argc, argv, opts);
+}
diff --git a/src/rt-app_args.h b/src/rt-app_args.h
index 2a89e73..dc74d31 100644
--- a/src/rt-app_args.h
+++ b/src/rt-app_args.h
@@ -34,8 +34,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifdef DLSCHED
#include "dl_syscalls.h"
#endif
+
#ifdef YAML
-#include <yaml.h>
+#include "rt-app_parse_config.h"
#endif
#define DEFAULT_THREAD_PRIORITY 10
diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c
new file mode 100644
index 0000000..a5cd4f4
--- /dev/null
+++ b/src/rt-app_parse_config.c
@@ -0,0 +1,166 @@
+/*
+This file is part of rt-app - https://launchpad.net/rt-app
+Copyright (C) 2010 Giacomo Bagnoli <g.bagnoli@asidev.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include "rt-app_parse_config.h"
+
+#define PFX "[yaml] "
+#define PFL " "PFX
+
+static void
+log_parser_error(yaml_parser_t *parser)
+{
+ switch (parser->error)
+ {
+ case YAML_MEMORY_ERROR:
+ log_critical(PFX "Memory error: Not enough memory for "
+ "parsing");
+ break;
+
+ case YAML_READER_ERROR:
+ if (parser->problem_value != -1) {
+ log_critical(PFX "Reader error: %s: #%X at %d",
+ parser->problem,
+ parser->problem_value,
+ (int) parser->problem_offset);
+ }
+ else {
+ log_critical(PFX "Reader error: %s at %d",
+ parser->problem,
+ (int) parser->problem_offset);
+ }
+ break;
+
+ case YAML_SCANNER_ERROR:
+ if (parser->context) {
+ log_critical(PFX
+ "Scanner error: %s at line %d,"
+ "column %d\n"PFL "%s at line %d,"
+ "column %d", parser->context,
+ (int) parser->context_mark.line+1,
+ (int) parser->context_mark.column+1,
+ parser->problem,
+ (int) parser->problem_mark.line+1,
+ (int) parser->problem_mark.column+1);
+ }
+ else {
+ log_critical(PFX "Scanner error:"
+ " %s at line %d, column %d",
+ parser->problem,
+ (int) parser->problem_mark.line+1,
+ (int) parser->problem_mark.column+1);
+ }
+ break;
+
+ case YAML_PARSER_ERROR:
+ if (parser->context) {
+ log_critical(PFX "Parser error: %s at line %d,"
+ " column %d\n"PFL "%s at line %d,"
+ " column %d", parser->context,
+ (int) parser->context_mark.line+1,
+ (int) parser->context_mark.column+1,
+ parser->problem,
+ (int) parser->problem_mark.line+1,
+ (int) parser->problem_mark.column+1);
+ }
+ else {
+ log_critical(PFX "Parser error: %s at line %d,"
+ " column %d",
+ parser->problem,
+ (int) parser->problem_mark.line+1,
+ (int) parser->problem_mark.column+1);
+ }
+ break;
+
+ default:
+ /* Couldn't happen. */
+ log_critical(PFX "Internal error");
+ break;
+ }
+ yaml_parser_delete(parser);
+ exit(EXIT_FAILURE);
+}
+
+int
+parse_token(yaml_token_t *token, int *done)
+{
+ yaml_token_type_t t = token->type;
+ switch (token->type) {
+ case YAML_STREAM_START_TOKEN:
+ log_info(PFX "Start stream");
+ break;
+ case YAML_STREAM_END_TOKEN:
+ log_info(PFX "End stream");
+ *done = 1;
+ break;
+ case YAML_DOCUMENT_START_TOKEN:
+ log_info(PFX "Start document");
+ break;
+ case YAML_DOCUMENT_END_TOKEN:
+ log_info(PFX "End document");
+ break;
+ case YAML_KEY_TOKEN:
+ log_info(PFX "Key token %s", token->data.scalar.value);
+ default:
+ /* ignore */
+ log_info(PFX "Ingnoring token %d", token->type);
+ break;
+ }
+ return 0;
+}
+
+void
+parse_config(const char *filename, rtapp_options_t *opts)
+{
+ yaml_parser_t parser;
+ yaml_token_t token;
+ FILE *config;
+ int done;
+
+ log_info(PFX "Reading %s filename", filename);
+ config = fopen(filename, "r");
+ if (!config)
+ log_error(PFX "Cannot open %s, aborting", filename);
+
+ if (!yaml_parser_initialize(&parser))
+ log_parser_error(&parser);
+
+ yaml_parser_set_input_file(&parser, config);
+
+ while (!done)
+ {
+ /* Get the next event. */
+ if (!yaml_parser_scan(&parser, &token))
+ log_parser_error(&parser);
+
+ /* TODO maintain status */
+ parse_token(&token, &done);
+
+ /* Are we finished? */
+ done = (token.type == YAML_STREAM_END_TOKEN);
+ yaml_token_delete(&token);
+ }
+
+ log_info(PFX "Successfully read config file %s", filename);
+ yaml_parser_delete(&parser);
+ fclose(config);
+ exit(EXIT_SUCCESS);
+ return;
+
+
+}
diff --git a/src/rt-app_parse_config.h b/src/rt-app_parse_config.h
new file mode 100644
index 0000000..eba3a84
--- /dev/null
+++ b/src/rt-app_parse_config.h
@@ -0,0 +1,43 @@
+/*
+This file is part of rt-app - https://launchpad.net/rt-app
+Copyright (C) 2010 Giacomo Bagnoli <g.bagnoli@asidev.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _RTAPP_PARSE_CONFIG_H
+#define _RTAPP_PARSE_CONFIG_H
+/* for CPU_SET macro */
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sched.h>
+#include <string.h>
+#include "rt-app_types.h"
+#include "rt-app_utils.h"
+#ifdef DLSCHED
+#include "dl_syscalls.h"
+#endif
+#include <yaml.h>
+
+#define DEFAULT_THREAD_PRIORITY 10
+#define PATH_LENGTH 256
+
+void
+parse_config(const char *filename, rtapp_options_t *opts);
+
+#endif // _RTAPP_PARSE_CONFIG_H