summaryrefslogtreecommitdiffstats
path: root/src/tests/test-unit/test-unit.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-10-11 17:07:16 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-01-26 21:40:08 +0100
commit1d4de11a907e41c06063a2cd5028dc4101690f50 (patch)
tree69af98bbe6512cdbcab33267574c131f85ffd597 /src/tests/test-unit/test-unit.c
parentbfc9c138b1a9e87f9d387e2f900c14807c9da9b9 (diff)
Prepare the Integration with systemd
This is an intermediate commit providing basic functionnalities for setting up integration of the framework with systemd. - file afm-unit.conf is a mustache template - translation of config.xml to json object - mustache (extended) application of the json to the template - post processing of the result for extracting unit files This processing is currently available as a test (and a tool) and will be integrated after more developement, test and validation. Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/tests/test-unit/test-unit.c')
-rw-r--r--src/tests/test-unit/test-unit.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/tests/test-unit/test-unit.c b/src/tests/test-unit/test-unit.c
new file mode 100644
index 0000000..09b7c86
--- /dev/null
+++ b/src/tests/test-unit/test-unit.c
@@ -0,0 +1,89 @@
+/*
+ Copyright 2016, 2017 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <json-c/json.h>
+
+#include <wgt.h>
+#include <utils-json.h>
+#include <wgt-json.h>
+#include <wgtpkg-mustach.h>
+#include <wgtpkg-unit.h>
+
+
+#define error(...) fprintf(stderr,__VA_ARGS__),exit(1)
+
+
+
+static int process1(const struct unitdesc *desc)
+{
+ int isuser = desc->scope == unitscope_user;
+ int issystem = desc->scope == unitscope_system;
+ int issock = desc->type == unittype_socket;
+ int isserv = desc->type == unittype_service;
+ const char *name = desc->name;
+ const char *content = desc->content;
+
+printf("\n##########################################################");
+printf("\n### usr=%d sys=%d soc=%d srv=%d name %s%s", isuser, issystem, issock, isserv, name?:"?", issock?".socket":isserv?".service":"");
+printf("\n##########################################################");
+printf("\n%s\n\n",content);
+ return 0;
+}
+
+static int process(void *closure, const struct unitdesc descs[], unsigned count)
+{
+ while (count--)
+ process1(descs++);
+ return 0;
+}
+
+int main(int ac, char **av)
+{
+ struct json_object *obj;
+ int rc;
+
+ rc = unit_generator_on(*++av);
+ if (rc < 0)
+ error("can't read template %s: %m",*av);
+ while(*++av) {
+ obj = wgt_path_to_json(*av);
+ if (!obj)
+ error("can't read widget config at %s: %m",*av);
+
+ j_add_string_m(obj, "#metadata.install-dir", "INSTALL-DIR");
+ j_add_string_m(obj, "#metadata.app-data-dir", "%h/app-data");
+ j_add_string_m(obj, "#metadata.icons-dir", "ICONS-DIR");
+ j_add_string_m(obj, "#metadata.http-port", "HTTP-PORT");
+
+ puts(json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY));
+ rc = unit_generator_process(obj, process, NULL);
+ if (rc)
+ error("can't apply generate units, error %d",rc);
+ json_object_put(obj);
+ }
+ return 0;
+}
+
+