2 * Copyright (C) 2015 "IoT.bzh"
3 * Author "Fulup Ar Foll"
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "local-def.h"
22 #include "utils-jbus.h"
24 static const char _id_[] = "id";
25 static struct jbus *jbus;
27 static struct json_object *call_void(AFB_request *request)
29 struct json_object *obj = jbus_call_sj_sync(jbus, request->api, "true");
30 request->errcode = obj ? MHD_HTTP_OK : MHD_HTTP_FAILED_DEPENDENCY;
34 static struct json_object *call_appid(AFB_request *request)
36 struct json_object *obj;
38 const char *id = getQueryValue(request, _id_);
40 request->errcode = MHD_HTTP_BAD_REQUEST;
43 if (0 >= asprintf(&sid, "\"%s\"", id)) {
44 request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR;
47 obj = jbus_call_sj_sync(jbus, request->api, sid);
49 request->errcode = obj ? MHD_HTTP_OK : MHD_HTTP_FAILED_DEPENDENCY;
53 static struct json_object *call_runid(AFB_request *request)
55 struct json_object *obj;
56 const char *id = getQueryValue(request, _id_);
58 request->errcode = MHD_HTTP_BAD_REQUEST;
61 obj = jbus_call_sj_sync(jbus, request->api, id);
62 request->errcode = obj ? MHD_HTTP_OK : MHD_HTTP_FAILED_DEPENDENCY;
66 static AFB_restapi plug_apis[] =
68 {"runnables", AFB_SESSION_CHECK, (AFB_apiCB)call_void, "Get list of runnable applications"},
69 {"detail" , AFB_SESSION_CHECK, (AFB_apiCB)call_appid, "Get the details for one application"},
70 {"start" , AFB_SESSION_CHECK, (AFB_apiCB)call_appid, "Start an application"},
71 {"terminate", AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Terminate a running application"},
72 {"stop" , AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Stop (pause) a running application"},
73 {"continue" , AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Continue (resume) a stopped application"},
74 {"runners" , AFB_SESSION_CHECK, (AFB_apiCB)call_void, "Get the list of running applications"},
75 {"state" , AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Get the state of a running application"},
79 static AFB_plugin plug_desc = {
80 .type = AFB_PLUGIN_JSON,
81 .info = "Application Framework Master Service",
86 AFB_plugin *pluginRegister()
88 jbus = create_jbus(1, "/org/AGL/afmMain");
89 return jbus ? &plug_desc : NULL;