aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2015-12-22 17:25:45 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2015-12-22 17:29:38 +0100
commitce714369c64051d5307ef7ac9af2c53b6edfbb4a (patch)
tree1ec943646d8e43ccbadde88d1a165a7ea38ff31e
parente2f138ca6b0f61d1a1cde1fd305dd7f0aaf4aa0e (diff)
refactoring and moving forward
Rename af-... files to afm-... Add system daemon draft Change-Id: I3f8b69ac9cc5af54be34b4ad11a512c57c0230b6
-rw-r--r--.gitignore1
-rw-r--r--src/CMakeLists.txt16
-rw-r--r--src/af-db.h33
-rw-r--r--src/afm-db.c (renamed from src/af-db.c)60
-rw-r--r--src/afm-db.h33
-rw-r--r--src/afm-launch.c (renamed from src/af-launch.c)6
-rw-r--r--src/afm-launch.h (renamed from src/af-launch.h)4
-rw-r--r--src/afm-run.c (renamed from src/af-run.c)27
-rw-r--r--src/afm-run.h26
-rw-r--r--src/afm-system-daemon.c213
-rw-r--r--src/afm-user-daemon.c75
-rw-r--r--src/afm.h (renamed from src/af-run.h)10
-rw-r--r--src/utils-jbus.c18
-rw-r--r--src/wgtpkg-install.c8
-rw-r--r--src/wgtpkg.h2
15 files changed, 398 insertions, 134 deletions
diff --git a/.gitignore b/.gitignore
index 309aaf4..3fb1099 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
src/afm-user-daemon
+src/afm-system-daemon
wgtpkg-installer
wgtpkg-pack
wgtpkg-sign
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f2d41bd..499d38a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -16,6 +16,8 @@
# limitations under the License.
###########################################################################
+cmake_minimum_required(VERSION 2.8)
+
include(FindPkgConfig)
pkg_check_modules(EXTRAS REQUIRED
@@ -78,30 +80,30 @@ add_library(secwrp
)
add_library(afm
- af-db.c
- af-launch.c
- af-run.c
+ afm-db.c
+ afm-launch.c
+ afm-run.c
)
add_executable(wgtpkg-sign wgtpkg-sign.c)
target_link_libraries(wgtpkg-sign wgtpkg utils)
-
add_executable(wgtpkg-pack wgtpkg-pack.c)
target_link_libraries(wgtpkg-pack wgtpkg utils)
-
add_executable(wgtpkg-info wgtpkg-info.c)
target_link_libraries(wgtpkg-info wgtpkg wgt utils)
-
add_executable(wgtpkg-installer wgtpkg-installer.c)
target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)
-
add_executable(afm-user-daemon afm-user-daemon.c)
target_link_libraries(afm-user-daemon afm secwrp wgt utils)
+add_executable(afm-system-daemon afm-system-daemon.c)
+target_link_libraries(afm-system-daemon wgtpkg afm secwrp wgt utils)
+
install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
+install(TARGETS afm-system-daemon DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
diff --git a/src/af-db.h b/src/af-db.h
deleted file mode 100644
index ce4d04f..0000000
--- a/src/af-db.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- Copyright 2015 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.
-*/
-
-struct af_db;
-
-extern struct af_db *af_db_create();
-extern void af_db_addref(struct af_db *afdb);
-extern void af_db_unref(struct af_db *afdb);
-
-extern int af_db_add_root(struct af_db *afdb, const char *path);
-extern int af_db_add_application(struct af_db *afdb, const char *path);
-extern int af_db_update_applications(struct af_db *afdb);
-extern int af_db_ensure_applications(struct af_db *afdb);
-
-extern struct json_object *af_db_application_list(struct af_db *afdb);
-extern struct json_object *af_db_get_application(struct af_db *afdb, const char *id);
-extern struct json_object *af_db_get_application_public(struct af_db *afdb, const char *id);
-
diff --git a/src/af-db.c b/src/afm-db.c
index 473b118..3f96821 100644
--- a/src/af-db.c
+++ b/src/afm-db.c
@@ -28,7 +28,7 @@
#include <json.h>
#include "wgt-info.h"
-#include "af-db.h"
+#include "afm-db.h"
struct afapps {
struct json_object *pubarr;
@@ -41,22 +41,22 @@ enum dir_type {
type_app
};
-struct af_db_dir {
- struct af_db_dir *next;
+struct afm_db_dir {
+ struct afm_db_dir *next;
char *path;
enum dir_type type;
};
-struct af_db {
+struct afm_db {
int refcount;
- struct af_db_dir *dirhead;
- struct af_db_dir *dirtail;
+ struct afm_db_dir *dirhead;
+ struct afm_db_dir *dirtail;
struct afapps applications;
};
-struct af_db *af_db_create()
+struct afm_db *afm_db_create()
{
- struct af_db *afdb = malloc(sizeof * afdb);
+ struct afm_db *afdb = malloc(sizeof * afdb);
if (afdb == NULL)
errno = ENOMEM;
else {
@@ -70,15 +70,15 @@ struct af_db *af_db_create()
return afdb;
}
-void af_db_addref(struct af_db *afdb)
+void afm_db_addref(struct afm_db *afdb)
{
assert(afdb);
afdb->refcount++;
}
-void af_db_unref(struct af_db *afdb)
+void afm_db_unref(struct afm_db *afdb)
{
- struct af_db_dir *dir;
+ struct afm_db_dir *dir;
assert(afdb);
if (!--afdb->refcount) {
json_object_put(afdb->applications.pubarr);
@@ -94,9 +94,9 @@ void af_db_unref(struct af_db *afdb)
}
}
-int add_dir(struct af_db *afdb, const char *path, enum dir_type type)
+int add_dir(struct afm_db *afdb, const char *path, enum dir_type type)
{
- struct af_db_dir *dir;
+ struct afm_db_dir *dir;
char *r;
assert(afdb);
@@ -135,12 +135,12 @@ int add_dir(struct af_db *afdb, const char *path, enum dir_type type)
return 0;
}
-int af_db_add_root(struct af_db *afdb, const char *path)
+int afm_db_add_root(struct afm_db *afdb, const char *path)
{
return add_dir(afdb, path, type_root);
}
-int af_db_add_application(struct af_db *afdb, const char *path)
+int afm_db_add_application(struct afm_db *afdb, const char *path)
{
return add_dir(afdb, path, type_app);
}
@@ -324,12 +324,12 @@ static int enumvers(struct enumdata *data)
}
/* regenerate the list of applications */
-int af_db_update_applications(struct af_db *afdb)
+int afm_db_update_applications(struct afm_db *afdb)
{
int rc;
struct enumdata edata;
struct afapps oldapps;
- struct af_db_dir *dir;
+ struct afm_db_dir *dir;
/* create the result */
edata.apps.pubarr = json_object_new_array();
@@ -367,28 +367,28 @@ error:
return -1;
}
-int af_db_ensure_applications(struct af_db *afdb)
+int afm_db_ensure_applications(struct afm_db *afdb)
{
- return afdb->applications.pubarr ? 0 : af_db_update_applications(afdb);
+ return afdb->applications.pubarr ? 0 : afm_db_update_applications(afdb);
}
-struct json_object *af_db_application_list(struct af_db *afdb)
+struct json_object *afm_db_application_list(struct afm_db *afdb)
{
- return af_db_ensure_applications(afdb) ? NULL : afdb->applications.pubarr;
+ return afm_db_ensure_applications(afdb) ? NULL : json_object_get(afdb->applications.pubarr);
}
-struct json_object *af_db_get_application(struct af_db *afdb, const char *id)
+struct json_object *afm_db_get_application(struct afm_db *afdb, const char *id)
{
struct json_object *result;
- if (!af_db_ensure_applications(afdb) && json_object_object_get_ex(afdb->applications.direct, id, &result))
- return result;
+ if (!afm_db_ensure_applications(afdb) && json_object_object_get_ex(afdb->applications.direct, id, &result))
+ return json_object_get(result);
return NULL;
}
-struct json_object *af_db_get_application_public(struct af_db *afdb, const char *id)
+struct json_object *afm_db_get_application_public(struct afm_db *afdb, const char *id)
{
- struct json_object *result = af_db_get_application(afdb, id);
- return result && json_object_object_get_ex(result, "public", &result) ? result : NULL;
+ struct json_object *result = afm_db_get_application(afdb, id);
+ return result && json_object_object_get_ex(result, "public", &result) ? json_object_get(result) : NULL;
}
@@ -398,9 +398,9 @@ struct json_object *af_db_get_application_public(struct af_db *afdb, const char
#include <stdio.h>
int main()
{
-struct af_db *afdb = af_db_create();
-af_db_add_root(afdb,FWK_APP_DIR);
-af_db_update_applications(afdb);
+struct afm_db *afdb = afm_db_create();
+afm_db_add_root(afdb,FWK_APP_DIR);
+afm_db_update_applications(afdb);
printf("array = %s\n", json_object_to_json_string_ext(afdb->applications.pubarr, 3));
printf("direct = %s\n", json_object_to_json_string_ext(afdb->applications.direct, 3));
printf("byapp = %s\n", json_object_to_json_string_ext(afdb->applications.byapp, 3));
diff --git a/src/afm-db.h b/src/afm-db.h
new file mode 100644
index 0000000..fff5f4c
--- /dev/null
+++ b/src/afm-db.h
@@ -0,0 +1,33 @@
+/*
+ Copyright 2015 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.
+*/
+
+struct afm_db;
+
+extern struct afm_db *afm_db_create();
+extern void afm_db_addref(struct afm_db *afdb);
+extern void afm_db_unref(struct afm_db *afdb);
+
+extern int afm_db_add_root(struct afm_db *afdb, const char *path);
+extern int afm_db_add_application(struct afm_db *afdb, const char *path);
+extern int afm_db_update_applications(struct afm_db *afdb);
+extern int afm_db_ensure_applications(struct afm_db *afdb);
+
+extern struct json_object *afm_db_application_list(struct afm_db *afdb);
+extern struct json_object *afm_db_get_application(struct afm_db *afdb, const char *id);
+extern struct json_object *afm_db_get_application_public(struct afm_db *afdb, const char *id);
+
diff --git a/src/af-launch.c b/src/afm-launch.c
index ce42221..12a481e 100644
--- a/src/af-launch.c
+++ b/src/afm-launch.c
@@ -32,7 +32,7 @@
extern char **environ;
#include "verbose.h"
-#include "af-launch.h"
+#include "afm-launch.h"
#include "secmgr-wrap.h"
/*
@@ -102,7 +102,7 @@ struct launchparam {
const char *datadir;
};
-static char **instantiate_arguments(const char **args, struct af_launch_desc *desc, struct launchparam *params)
+static char **instantiate_arguments(const char **args, struct afm_launch_desc *desc, struct launchparam *params)
{
const char **iter, *p, *v;
char *data, **result, port[20], width[20], height[20], mini[3], c;
@@ -189,7 +189,7 @@ static int mkport()
return port;
}
-int af_launch(struct af_launch_desc *desc, pid_t children[2])
+int afm_launch(struct afm_launch_desc *desc, pid_t children[2])
{
char datadir[PATH_MAX];
int ikl, nkl, rc;
diff --git a/src/af-launch.h b/src/afm-launch.h
index 301c98c..c6aaf49 100644
--- a/src/af-launch.h
+++ b/src/afm-launch.h
@@ -16,7 +16,7 @@
limitations under the License.
*/
-struct af_launch_desc {
+struct afm_launch_desc {
const char *path;
const char *tag;
const char *appid;
@@ -29,5 +29,5 @@ struct af_launch_desc {
int height;
};
-int af_launch(struct af_launch_desc *desc, pid_t children[2]);
+int afm_launch(struct afm_launch_desc *desc, pid_t children[2]);
diff --git a/src/af-run.c b/src/afm-run.c
index 6512a11..f28849a 100644
--- a/src/af-run.c
+++ b/src/afm-run.c
@@ -31,7 +31,8 @@
#include "verbose.h"
#include "utils-dir.h"
-#include "af-launch.h"
+#include "afm-run.h"
+#include "afm-launch.h"
enum appstate {
as_starting,
@@ -235,7 +236,7 @@ static void on_sigchld(int signum, siginfo_t *info, void *uctxt)
}
}
-/**************** handle af_launch_desc *********************/
+/**************** handle afm_launch_desc *********************/
static int get_jstr(struct json_object *obj, const char *key, const char **value)
{
@@ -253,7 +254,7 @@ static int get_jint(struct json_object *obj, const char *key, int *value)
&& ((*value = (int)json_object_get_int(data)), 1);
}
-static int fill_launch_desc(struct json_object *appli, struct af_launch_desc *desc)
+static int fill_launch_desc(struct json_object *appli, struct afm_launch_desc *desc)
{
json_object *pub;
@@ -284,10 +285,10 @@ static int fill_launch_desc(struct json_object *appli, struct af_launch_desc *de
/**************** API handling ************************/
-int af_run_start(struct json_object *appli)
+int afm_run_start(struct json_object *appli)
{
static struct apprun *runner;
- struct af_launch_desc desc;
+ struct afm_launch_desc desc;
int rc;
sigset_t saved, blocked;
@@ -305,11 +306,11 @@ int af_run_start(struct json_object *appli)
sigprocmask(SIG_BLOCK, &blocked, &saved);
/* launch now */
- rc = af_launch(&desc, runner->pids);
+ rc = afm_launch(&desc, runner->pids);
if (rc < 0) {
/* fork failed */
sigprocmask(SIG_SETMASK, &saved, NULL);
- ERROR("can't start, af_launch failed: %m");
+ ERROR("can't start, afm_launch failed: %m");
freerunner(runner);
return -1;
}
@@ -324,17 +325,17 @@ int af_run_start(struct json_object *appli)
return rc;
}
-int af_run_terminate(int runid)
+int afm_run_terminate(int runid)
{
return killrunner(runid, SIGTERM, as_terminating);
}
-int af_run_stop(int runid)
+int afm_run_stop(int runid)
{
return killrunner(runid, SIGSTOP, as_stopped);
}
-int af_run_continue(int runid)
+int afm_run_continue(int runid)
{
return killrunner(runid, SIGCONT, as_running);
}
@@ -392,7 +393,7 @@ error:
return NULL;
}
-struct json_object *af_run_list()
+struct json_object *afm_run_list()
{
struct json_object *result, *obj;
struct apprun *runner;
@@ -421,7 +422,7 @@ struct json_object *af_run_list()
return result;
}
-struct json_object *af_run_state(int runid)
+struct json_object *afm_run_state(int runid)
{
struct apprun *runner = getrunner(runid);
if (runner == NULL || runner->state == as_terminating || runner->state == as_terminated) {
@@ -433,7 +434,7 @@ struct json_object *af_run_state(int runid)
/**************** INITIALISATION **********************/
-int af_run_init()
+int afm_run_init()
{
char buf[2048];
char dir[PATH_MAX];
diff --git a/src/afm-run.h b/src/afm-run.h
new file mode 100644
index 0000000..4ad0de1
--- /dev/null
+++ b/src/afm-run.h
@@ -0,0 +1,26 @@
+/*
+ Copyright 2015 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.
+*/
+
+extern int afm_run_start(struct json_object *appli);
+extern int afm_run_terminate(int runid);
+extern int afm_run_stop(int runid);
+extern int afm_run_continue(int runid);
+extern struct json_object *afm_run_list();
+extern struct json_object *afm_run_state(int runid);
+
+extern int afm_run_init();
diff --git a/src/afm-system-daemon.c b/src/afm-system-daemon.c
new file mode 100644
index 0000000..f938372
--- /dev/null
+++ b/src/afm-system-daemon.c
@@ -0,0 +1,213 @@
+/*
+ Copyright 2015 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 <unistd.h>
+#include <stdio.h>
+#include <time.h>
+#include <getopt.h>
+
+#include <json.h>
+
+#include "verbose.h"
+#include "utils-jbus.h"
+#include "afm.h"
+#include "afm-db.h"
+
+static const char appname[] = "afm-system-daemon";
+
+static void usage()
+{
+ printf(
+ "usage: %s [-q] [-v] [-r rootdir]... [-a appdir]...\n"
+ "\n"
+ " -a appdir adds an application directory\n"
+ " -r rootdir adds a root directory of applications\n"
+ " -d run as a daemon\n"
+ " -q quiet\n"
+ " -v verbose\n"
+ "\n",
+ appname
+ );
+}
+
+static struct option options[] = {
+ { "root", required_argument, NULL, 'r' },
+ { "application", required_argument, NULL, 'a' },
+ { "daemon", no_argument, NULL, 'd' },
+ { "quiet", no_argument, NULL, 'q' },
+ { "verbose", no_argument, NULL, 'v' },
+ { "help", no_argument, NULL, 'h' },
+ { NULL, 0, NULL, 0 }
+};
+
+static struct jbus *jbus;
+static struct afm_db *afdb;
+
+const char error_nothing[] = "[]";
+const char error_bad_request[] = "\"bad request\"";
+const char error_not_found[] = "\"not found\"";
+const char error_cant_start[] = "\"can't start\"";
+
+static const char *getappid(struct json_object *obj)
+{
+ return json_type_string == json_object_get_type(obj) ? json_object_get_string(obj) : NULL;
+}
+
+static void reply(struct jreq *jreq, struct json_object *resp, const char *errstr)
+{
+ if (resp)
+ jbus_reply_j(jreq, resp);
+ else
+ jbus_reply_error_s(jreq, errstr);
+}
+
+static void on_runnables(struct jreq *jreq, struct json_object *obj)
+{
+ struct json_object *resp = afm_db_application_list(afdb);
+ jbus_reply_j(jreq, resp);
+ json_object_put(resp);
+}
+
+static void on_detail(struct jreq *jreq, struct json_object *obj)
+{
+ const char *appid = getappid(obj);
+ struct json_object *resp = afm_db_get_application_public(afdb, appid);
+ reply(jreq, resp, error_not_found);
+ json_object_put(resp);
+}
+
+extern void install_widget(const char *wgtfile, const char *root, int force);
+static void on_install(struct jreq *jreq, struct json_object *obj)
+{
+ jbus_reply_error_s(jreq, "\"not yet implemented\"");
+}
+
+static void on_uninstall(struct jreq *jreq, struct json_object *obj)
+{
+ jbus_reply_error_s(jreq, "\"not yet implemented\"");
+}
+
+static int daemonize()
+{
+ int rc = fork();
+ if (rc < 0)
+ return rc;
+ if (rc)
+ _exit(0);
+ return 0;
+}
+
+int main(int ac, char **av)
+{
+ int i, daemon = 0;
+
+ LOGAUTH(appname);
+
+ /* first interpretation of arguments */
+ while ((i = getopt_long(ac, av, "hdqvr:a:", options, NULL)) >= 0) {
+ switch (i) {
+ case 'h':
+ usage();
+ return 0;
+ case 'q':
+ if (verbosity)
+ verbosity--;
+ break;
+ case 'v':
+ verbosity++;
+ break;
+ case 'd':
+ daemon = 1;
+ break;
+ case 'r':
+ break;
+ case 'a':
+ break;
+ case ':':
+ ERROR("missing argument value");
+ return 1;
+ default:
+ ERROR("unrecognized option");
+ return 1;
+ }
+ }
+
+ /* init framework */
+ afdb = afm_db_create();
+ if (!afdb) {
+ ERROR("afm_create failed");
+ return 1;
+ }
+ if (afm_db_add_root(afdb, FWK_APP_DIR)) {
+ ERROR("can't add root %s", FWK_APP_DIR);
+ return 1;
+ }
+
+ /* second interpretation of arguments */
+ optind = 1;
+ while ((i = getopt_long(ac, av, "hdqvr:a:", options, NULL)) >= 0) {
+ switch (i) {
+ case 'r':
+ if (afm_db_add_root(afdb, optarg)) {
+ ERROR("can't add root %s", optarg);
+ return 1;
+ }
+ break;
+ case 'a':
+ if (afm_db_add_application(afdb, optarg)) {
+ ERROR("can't add application %s", optarg);
+ return 1;
+ }
+ break;
+ }
+ }
+
+ /* update the database */
+ if (afm_db_update_applications(afdb)) {
+ ERROR("afm_update_applications failed");
+ return 1;
+ }
+
+ if (daemon && daemonize()) {
+ ERROR("daemonization failed");
+ return 1;
+ }
+
+ /* init service */
+ jbus = create_jbus(0, AFM_SYSTEM_DBUS_PATH);
+ if (!jbus) {
+ ERROR("create_jbus failed");
+ return 1;
+ }
+ if(jbus_add_service_j(jbus, "runnables", on_runnables)
+ || jbus_add_service_j(jbus, "detail", on_detail)
+ || jbus_add_service_j(jbus, "install", on_install)
+ || jbus_add_service_j(jbus, "uninstall", on_uninstall)) {
+ ERROR("adding services failed");
+ return 1;
+ }
+
+ /* start and run */
+ if (jbus_start_serving(jbus)) {
+ ERROR("cant start server");
+ return 1;
+ }
+ while (!jbus_read_write_dispatch(jbus, -1));
+ return 0;
+}
+
diff --git a/src/afm-user-daemon.c b/src/afm-user-daemon.c
index 346c58b..1459dde 100644
--- a/src/afm-user-daemon.c
+++ b/src/afm-user-daemon.c
@@ -25,8 +25,9 @@
#include "verbose.h"
#include "utils-jbus.h"
-#include "af-db.h"
-#include "af-run.h"
+#include "afm.h"
+#include "afm-db.h"
+#include "afm-run.h"
static const char appname[] = "afm-user-daemon";
@@ -56,7 +57,8 @@ static struct option options[] = {
};
static struct jbus *jbus;
-static struct af_db *afdb;
+static struct jbus *jbusys;
+static struct afm_db *afdb;
const char error_nothing[] = "[]";
const char error_bad_request[] = "\"bad request\"";
@@ -91,17 +93,17 @@ static void reply_status(struct jreq *jreq, int status)
static void on_runnables(struct jreq *jreq, struct json_object *obj)
{
- struct json_object *resp = af_db_application_list(afdb);
+ struct json_object *resp = afm_db_application_list(afdb);
jbus_reply_j(jreq, resp);
- json_object_put(obj);
+ json_object_put(resp);
}
static void on_detail(struct jreq *jreq, struct json_object *obj)
{
const char *appid = getappid(obj);
- struct json_object *resp = af_db_get_application_public(afdb, appid);
+ struct json_object *resp = afm_db_get_application_public(afdb, appid);
reply(jreq, resp, error_not_found);
- json_object_put(obj);
+ json_object_put(resp);
}
static void on_start(struct jreq *jreq, struct json_object *obj)
@@ -115,11 +117,11 @@ static void on_start(struct jreq *jreq, struct json_object *obj)
if (appid == NULL)
jbus_reply_error_s(jreq, error_bad_request);
else {
- appli = af_db_get_application(afdb, appid);
+ appli = afm_db_get_application(afdb, appid);
if (appli == NULL)
jbus_reply_error_s(jreq, error_not_found);
else {
- runid = af_run_start(appli);
+ runid = afm_run_start(appli);
if (runid <= 0)
jbus_reply_error_s(jreq, error_cant_start);
else {
@@ -129,48 +131,50 @@ static void on_start(struct jreq *jreq, struct json_object *obj)
}
}
}
- json_object_put(obj);
}
static void on_stop(struct jreq *jreq, struct json_object *obj)
{
int runid = getrunid(obj);
- int status = af_run_stop(runid);
+ int status = afm_run_stop(runid);
reply_status(jreq, status);
- json_object_put(obj);
}
static void on_continue(struct jreq *jreq, struct json_object *obj)
{
int runid = getrunid(obj);
- int status = af_run_continue(runid);
+ int status = afm_run_continue(runid);
reply_status(jreq, status);
- json_object_put(obj);
}
static void on_terminate(struct jreq *jreq, struct json_object *obj)
{
int runid = getrunid(obj);
- int status = af_run_terminate(runid);
+ int status = afm_run_terminate(runid);
reply_status(jreq, status);
- json_object_put(obj);
}
static void on_runners(struct jreq *jreq, struct json_object *obj)
{
- struct json_object *resp = af_run_list();
+ struct json_object *resp = afm_run_list();
jbus_reply_j(jreq, resp);
json_object_put(resp);
- json_object_put(obj);
}
static void on_state(struct jreq *jreq, struct json_object *obj)
{
int runid = getrunid(obj);
- struct json_object *resp = af_run_state(runid);
+ struct json_object *resp = afm_run_state(runid);
reply(jreq, resp, error_not_found);
json_object_put(resp);
- json_object_put(obj);
+}
+
+static void on_signal_changed(struct json_object *obj)
+{
+ /* update the database */
+ afm_db_update_applications(afdb);
+ /* propagate now */
+ jbus_send_signal_j(jbus, "changed", obj);
}
static int daemonize()
@@ -222,18 +226,18 @@ int main(int ac, char **av)
srandom((unsigned int)time(NULL));
/* init runners */
- if (af_run_init()) {
- ERROR("af_run_init failed");
+ if (afm_run_init()) {
+ ERROR("afm_run_init failed");
return 1;
}
/* init framework */
- afdb = af_db_create();
+ afdb = afm_db_create();
if (!afdb) {
- ERROR("af_create failed");
+ ERROR("afm_create failed");
return 1;
}
- if (af_db_add_root(afdb, FWK_APP_DIR)) {
+ if (afm_db_add_root(afdb, FWK_APP_DIR)) {
ERROR("can't add root %s", FWK_APP_DIR);
return 1;
}
@@ -243,13 +247,13 @@ int main(int ac, char **av)
while ((i = getopt_long(ac, av, "hdqvr:a:", options, NULL)) >= 0) {
switch (i) {
case 'r':
- if (af_db_add_root(afdb, optarg)) {
+ if (afm_db_add_root(afdb, optarg)) {
ERROR("can't add root %s", optarg);
return 1;
}
break;
case 'a':
- if (af_db_add_application(afdb, optarg)) {
+ if (afm_db_add_application(afdb, optarg)) {
ERROR("can't add application %s", optarg);
return 1;
}
@@ -258,8 +262,8 @@ int main(int ac, char **av)
}
/* update the database */
- if (af_db_update_applications(afdb)) {
- ERROR("af_update_applications failed");
+ if (afm_db_update_applications(afdb)) {
+ ERROR("afm_update_applications failed");
return 1;
}
@@ -268,8 +272,19 @@ int main(int ac, char **av)
return 1;
}
+ /* init observers */
+ jbusys = create_jbus(0, AFM_SYSTEM_DBUS_PATH);
+ if (!jbusys) {
+ ERROR("create_jbus failed for system");
+ return 1;
+ }
+ if(jbus_on_signal_j(jbusys, "changed", on_signal_changed)) {
+ ERROR("adding signal observer failed");
+ return 1;
+ }
+
/* init service */
- jbus = create_jbus(1, "/org/AGL/afmMain");
+ jbus = create_jbus(1, AFM_USER_DBUS_PATH);
if (!jbus) {
ERROR("create_jbus failed");
return 1;
diff --git a/src/af-run.h b/src/afm.h
index 1dab682..e7d1690 100644
--- a/src/af-run.h
+++ b/src/afm.h
@@ -16,11 +16,7 @@
limitations under the License.
*/
-extern int af_run_start(struct json_object *appli);
-extern int af_run_terminate(int runid);
-extern int af_run_stop(int runid);
-extern int af_run_continue(int runid);
-extern struct json_object *af_run_list();
-extern struct json_object *af_run_state(int runid);
+#define AFM_DBUS_PATH "/org/AGL/afm"
+#define AFM_SYSTEM_DBUS_PATH AFM_DBUS_PATH"/system"
+#define AFM_USER_DBUS_PATH AFM_DBUS_PATH"/user"
-extern int af_run_init();
diff --git a/src/utils-jbus.c b/src/utils-jbus.c
index 7e65723..d58def9 100644
--- a/src/utils-jbus.c
+++ b/src/utils-jbus.c
@@ -272,6 +272,7 @@ static DBusHandlerResult incoming_resp(DBusConnection *connection, DBusMessage *
reply = json_tokener_parse(str);
status = reply ? 0 : -1;
jrw->onresp_j(iserror ? -1 : status, reply, jrw->data);
+ json_object_put(reply);
}
free(jrw);
@@ -318,6 +319,7 @@ static DBusHandlerResult incoming_call(DBusConnection *connection, DBusMessage *
if (query == NULL)
return reply_invalid_request(jreq);
srv->oncall_j(jreq, query);
+ json_object_put(query);
}
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -350,8 +352,10 @@ static DBusHandlerResult incoming_signal(DBusConnection *connection, DBusMessage
else {
/* handling json only */
obj = json_tokener_parse(str);
- if (obj != NULL)
+ if (obj != NULL) {
sig->onsignal_j(obj);
+ json_object_put(obj);
+ }
}
}
return DBUS_HANDLER_RESULT_HANDLED;
@@ -607,11 +611,17 @@ char *jbus_call_ss_sync(struct jbus *jbus, const char *method, const char *query
struct json_object *jbus_call_sj_sync(struct jbus *jbus, const char *method, const char *query)
{
- const char *str = jbus_call_ss_sync(jbus, method, query);
- return str ? json_tokener_parse(str) : NULL;
+ struct json_object *obj;
+ char *str = jbus_call_ss_sync(jbus, method, query);
+ if (str == NULL)
+ obj = NULL;
+ else {
+ obj = json_tokener_parse(str);
+ free(str);
+ }
+ return obj;
}
-
char *jbus_call_js_sync(struct jbus *jbus, const char *method, struct json_object *query)
{
const char *str = json_object_to_json_string(query);
diff --git a/src/wgtpkg-install.c b/src/wgtpkg-install.c
index b3e4603..933e612 100644
--- a/src/wgtpkg-install.c
+++ b/src/wgtpkg-install.c
@@ -216,12 +216,12 @@ error:
}
/* install the widget of the file */
-void install_widget(const char *wgtfile, const char *root, int force)
+int install_widget(const char *wgtfile, const char *root, int force)
{
struct wgt_info *ifo;
const struct wgt_desc *desc;
- NOTICE("-- INSTALLING widget %s --", wgtfile);
+ NOTICE("-- INSTALLING widget %s to %s --", wgtfile, root);
/* workdir */
create_directory(root, 0755, 1);
@@ -253,7 +253,7 @@ void install_widget(const char *wgtfile, const char *root, int force)
if (install_security(desc))
goto error3;
- return;
+ return 0;
error3:
wgt_info_unref(ifo);
@@ -262,6 +262,6 @@ error2:
remove_workdir();
error1:
- return;
+ return -1;
}
diff --git a/src/wgtpkg.h b/src/wgtpkg.h
index a355b4c..52a42e1 100644
--- a/src/wgtpkg.h
+++ b/src/wgtpkg.h
@@ -92,7 +92,7 @@ extern const char *file_get_prop(struct filedesc *file, const char *name);
/**************************************************************/
/* from wgtpkg-install */
-extern void install_widget(const char *wgtfile, const char *root, int force);
+extern int install_widget(const char *wgtfile, const char *root, int force);
/**************************************************************/
/* from wgtpkg-permission */