X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=plugins%2Fafm-main-plugin%2Fafm-main-plugin.c;h=f07afdb1becf3fdc20a88bdcf6d9bd536706a6a7;hb=f629aad464ea5595aeea9ada8b32d412628c3c2f;hp=fa184bf869f69683ee7f551a937efc7b623f4227;hpb=cdd17e5b4a9f99361d4809317e62a585ac55521a;p=src%2Fapp-framework-binder.git
diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c
index fa184bf8..f07afdb1 100644
--- a/plugins/afm-main-plugin/afm-main-plugin.c
+++ b/plugins/afm-main-plugin/afm-main-plugin.c
@@ -16,6 +16,8 @@
* along with this program. If not, see .
*/
+#define _GNU_SOURCE /* See feature_test_macros(7) */
+#include
#include "local-def.h"
@@ -33,6 +35,11 @@ static char _runners_[] = "runners";
static char _state_[] = "state";
static char _install_[] = "install";
static char _uninstall_[] = "uninstall";
+static const char _mode_[] = "mode";
+static const char _local_[] = "local";
+static const char _remote_[]= "remote";
+static const char _auto_[] = "auto";
+static const char _uri_[] = "uri";
static struct jbus *jbus;
@@ -62,11 +69,6 @@ static struct json_object *embed(AFB_request *request, const char *tag, struct j
return result;
}
-static struct json_object *call(AFB_request *request, AFB_PostItem *item, const char *tag, struct json_object *(*fun)(AFB_request*,AFB_PostItem*))
-{
- return embed(request, tag, fun(request, item));
-}
-
static struct json_object *call_void(AFB_request *request, AFB_PostItem *item)
{
struct json_object *obj = jbus_call_sj_sync(jbus, request->api, "true");
@@ -117,9 +119,43 @@ static struct json_object *call_void__runnables(AFB_request *request, AFB_PostIt
return embed(request, _runnables_, call_void(request, item));
}
-static struct json_object *call_appid__runid(AFB_request *request, AFB_PostItem *item)
+static struct json_object *call_start(AFB_request *request, AFB_PostItem *item)
{
- return embed(request, _runid_, call_appid(request, item));
+ struct json_object *resp;
+ const char *id, *mode;
+ char *query;
+ int rc;
+
+ /* get the id */
+ id = getQueryValue(request, _id_);
+ if (id == NULL) {
+ request->errcode = MHD_HTTP_BAD_REQUEST;
+ return NULL;
+ }
+ /* get the mode */
+ mode = getQueryValue(request, _mode_);
+ if (mode == NULL || !strcmp(mode, _auto_)) {
+ mode = request->config->mode == AFB_MODE_REMOTE ? _remote_ : _local_;
+ }
+
+ /* create the query */
+ rc = asprintf(&query, "{\"id\":\"%s\",\"mode\":\"%s\"}", id, mode);
+ if (rc < 0) {
+ request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ return NULL;
+ }
+
+ /* calls the service */
+ resp = jbus_call_sj_sync(jbus, _start_, query);
+ if (verbose)
+ fprintf(stderr, "(afm-main-plugin) call_start: %s -> %s\n", query, resp ? json_object_to_json_string(resp) : "NULL");
+ free(query);
+
+ /* embed if needed */
+ if (json_object_get_type(resp) == json_type_int)
+ resp = embed(request, _runid_, resp);
+ request->errcode = resp ? MHD_HTTP_OK : MHD_HTTP_FAILED_DEPENDENCY;
+ return resp;
}
static struct json_object *call_void__runners(AFB_request *request, AFB_PostItem *item)
@@ -157,7 +193,7 @@ static AFB_restapi plug_apis[] =
{
{_runnables_, AFB_SESSION_CHECK, (AFB_apiCB)call_void__runnables, "Get list of runnable applications"},
{_detail_ , AFB_SESSION_CHECK, (AFB_apiCB)call_appid, "Get the details for one application"},
- {_start_ , AFB_SESSION_CHECK, (AFB_apiCB)call_appid__runid, "Start an application"},
+ {_start_ , AFB_SESSION_CHECK, (AFB_apiCB)call_start, "Start an application"},
{_terminate_, AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Terminate a running application"},
{_stop_ , AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Stop (pause) a running application"},
{_continue_ , AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Continue (resume) a stopped application"},
@@ -165,7 +201,7 @@ static AFB_restapi plug_apis[] =
{_state_ , AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Get the state of a running application"},
{_install_ , AFB_SESSION_CHECK, (AFB_apiCB)call_file__appid, "Install an application using a widget file"},
{_uninstall_, AFB_SESSION_CHECK, (AFB_apiCB)call_appid, "Uninstall an application"},
- {NULL}
+ { NULL, 0, NULL, NULL }
};
static AFB_plugin plug_desc = {
@@ -177,7 +213,7 @@ static AFB_plugin plug_desc = {
AFB_plugin *pluginRegister()
{
- jbus = create_jbus(1, "/org/AGL/afm/user");
+ jbus = create_jbus_session("/org/AGL/afm/user");
if (jbus)
return &plug_desc;
fprintf(stderr, "ERROR: %s:%d: can't connect to DBUS session\n", __FILE__, __LINE__);