From eaa8c24c7cf95a3cefdae961a0bf935d5a84f61a Mon Sep 17 00:00:00 2001 From: José Bollo Date: Tue, 9 Feb 2016 10:23:08 +0100 Subject: afm-main-plugin: improves error reporting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I766f96f74434dfc0ec578e20769f91ce0796363e Signed-off-by: José Bollo --- plugins/afm-main-plugin/afm-main-plugin.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c index 5315da9d..3feeafe3 100644 --- a/plugins/afm-main-plugin/afm-main-plugin.c +++ b/plugins/afm-main-plugin/afm-main-plugin.c @@ -171,6 +171,9 @@ static AFB_plugin plug_desc = { AFB_plugin *pluginRegister() { jbus = create_jbus(1, "/org/AGL/afm/user"); - return jbus ? &plug_desc : NULL; + if (jbus) + return &plug_desc; + fprintf(stderr, "ERROR: %s:%d: can't connect to DBUS session\n", __FILE__, __LINE__); + return NULL; } -- cgit 1.2.3-korg From cdd17e5b4a9f99361d4809317e62a585ac55521a Mon Sep 17 00:00:00 2001 From: José Bollo Date: Tue, 9 Feb 2016 13:36:53 +0100 Subject: afm-main-plugin: Adds verbose prompts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I85f1ca065cd659f974f699ab6b5540afd89bf5eb Signed-off-by: José Bollo --- plugins/afm-main-plugin/afm-main-plugin.c | 65 +++++++++++++++++-------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'plugins') diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c index 3feeafe3..fa184bf8 100644 --- a/plugins/afm-main-plugin/afm-main-plugin.c +++ b/plugins/afm-main-plugin/afm-main-plugin.c @@ -21,18 +21,18 @@ #include "utils-jbus.h" -static const char _id_[] = "id"; -static const char _runid_[] = "runid"; -static char _runnables_[] = "runnables"; -static char _detail_[] = "detail"; -static char _start_[] = "start"; -static char _terminate_[] = "terminate"; -static char _stop_[] = "stop"; -static char _continue_[] = "continue"; -static char _runners_[] = "runners"; -static char _state_[] = "state"; -static char _install_[] = "install"; -static char _uninstall_[] = "uninstall"; +static const char _id_[] = "id"; +static const char _runid_[] = "runid"; +static char _runnables_[] = "runnables"; +static char _detail_[] = "detail"; +static char _start_[] = "start"; +static char _terminate_[] = "terminate"; +static char _stop_[] = "stop"; +static char _continue_[] = "continue"; +static char _runners_[] = "runners"; +static char _state_[] = "state"; +static char _install_[] = "install"; +static char _uninstall_[] = "uninstall"; static struct jbus *jbus; @@ -70,6 +70,8 @@ static struct json_object *call(AFB_request *request, AFB_PostItem *item, const static struct json_object *call_void(AFB_request *request, AFB_PostItem *item) { struct json_object *obj = jbus_call_sj_sync(jbus, request->api, "true"); + if (verbose) + fprintf(stderr, "(afm-main-plugin) call_void: true -> %s\n", obj ? json_object_to_json_string(obj) : "NULL"); request->errcode = obj ? MHD_HTTP_OK : MHD_HTTP_FAILED_DEPENDENCY; return obj; } @@ -88,6 +90,8 @@ static struct json_object *call_appid(AFB_request *request, AFB_PostItem *item) return NULL; } obj = jbus_call_sj_sync(jbus, request->api, sid); + if (verbose) + fprintf(stderr, "(afm-main-plugin) call_appid: %s -> %s\n", sid, obj ? json_object_to_json_string(obj) : "NULL"); free(sid); request->errcode = obj ? MHD_HTTP_OK : MHD_HTTP_FAILED_DEPENDENCY; return obj; @@ -102,6 +106,8 @@ static struct json_object *call_runid(AFB_request *request, AFB_PostItem *item) return NULL; } obj = jbus_call_sj_sync(jbus, request->api, id); + if (verbose) + fprintf(stderr, "(afm-main-plugin) call_runid: %s -> %s\n", id, obj ? json_object_to_json_string(obj) : "NULL"); request->errcode = obj ? MHD_HTTP_OK : MHD_HTTP_FAILED_DEPENDENCY; return obj; } @@ -124,24 +130,25 @@ static struct json_object *call_void__runners(AFB_request *request, AFB_PostItem static struct json_object *call_file__appid(AFB_request *request, AFB_PostItem *item) { if (item == NULL) { - struct json_object *obj; - char *query; const char *filename = getPostPath(request); - - if (filename != NULL) { - request->jresp = NULL; - if (0 >= asprintf(&query, "\"%s\"", filename)) - request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR; - else { - obj = jbus_call_sj_sync(jbus, request->api, query); - free(query); - if (obj) - request->jresp = embed(request, _id_, obj); - else - request->errcode = MHD_HTTP_FAILED_DEPENDENCY; - } - unlink(filename); - } + if (filename != NULL) { + struct json_object *obj; + char *query; + request->jresp = NULL; + if (0 >= asprintf(&query, "\"%s\"", filename)) + request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR; + else { + obj = jbus_call_sj_sync(jbus, request->api, query); + if (verbose) + fprintf(stderr, "(afm-main-plugin) call_file_appid: %s -> %s\n", query, obj ? json_object_to_json_string(obj) : "NULL"); + free(query); + if (obj) + request->jresp = embed(request, _id_, obj); + else + request->errcode = MHD_HTTP_FAILED_DEPENDENCY; + } + unlink(filename); + } } return getPostFile (request, item, "/tmp/upload"); } -- cgit 1.2.3-korg From 0d81cd0332e72d6c2ed91dc58184229a92b28196 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Tue, 9 Feb 2016 17:43:41 +0100 Subject: afm-main-plugin: utils-jbus: fix bug that blocked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id31e2c93a1a128d768f9a55fdc739b0067b85121 Signed-off-by: José Bollo --- plugins/afm-main-plugin/utils-jbus.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/afm-main-plugin/utils-jbus.c b/plugins/afm-main-plugin/utils-jbus.c index 1f85a4cd..67e3ce4c 100644 --- a/plugins/afm-main-plugin/utils-jbus.c +++ b/plugins/afm-main-plugin/utils-jbus.c @@ -669,6 +669,7 @@ int jbus_dispatch_multiple(struct jbus **jbuses, int njbuses, int maxcount) for (i = r = 0 ; i < njbuses && r < maxcount ; i++) { dbus_connection_read_write(jbuses[i]->connection, 0); + sts = dbus_connection_get_dispatch_status(jbuses[i]->connection); while(sts == DBUS_DISPATCH_DATA_REMAINS && r < maxcount) { sts = dbus_connection_dispatch(jbuses[i]->connection); r++; @@ -690,10 +691,17 @@ int jbus_read_write_dispatch_multiple(struct jbus **jbuses, int njbuses, int tom assert(fds != NULL); r = jbus_dispatch_multiple(jbuses, njbuses, maxcount); + if (r) + return r; n = jbus_fill_pollfds(jbuses, njbuses, fds); - s = poll(fds, n, toms); - if (s < 0) - return r ? r : s; + for(;;) { + s = poll(fds, n, toms); + if (s >= 0) + break; + if (errno != EINTR) + return r ? r : s; + toms = 0; + } n = jbus_dispatch_pollfds(jbuses, njbuses, fds, maxcount - r); return n >= 0 ? r + n : r ? r : n; } -- cgit 1.2.3-korg From 3a6db27dec6fee245708074c301b42e1cbedd716 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Sun, 14 Feb 2016 15:16:48 +0100 Subject: adds mode management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I73240e346a06924c314961871e789c69e279cb48 Signed-off-by: José Bollo --- include/local-def.h | 2 +- plugins/afm-main-plugin/afm-main-plugin.c | 46 +++++++++++++++++++++++++++++-- src/config.c | 3 +- src/main.c | 7 ++--- 4 files changed, 49 insertions(+), 9 deletions(-) (limited to 'plugins') diff --git a/include/local-def.h b/include/local-def.h index bf353e94..7ad4e705 100644 --- a/include/local-def.h +++ b/include/local-def.h @@ -184,8 +184,8 @@ typedef struct { int apiTimeout; int cntxTimeout; // Client Session Context timeout int pluginCount; // loaded plugins count - AFB_aliasdir *aliasdir; // alias mapping for icons,apps,... AFB_Mode mode; // mode of listening + AFB_aliasdir *aliasdir; // alias mapping for icons,apps,... } AFB_config; typedef struct { diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c index fa184bf8..3f9de713 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,10 @@ 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 _uri_[] = "uri"; static struct jbus *jbus; @@ -117,9 +123,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) { + 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_string) + 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 +197,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"}, diff --git a/src/config.c b/src/config.c index bd03b6ff..a64e131f 100644 --- a/src/config.c +++ b/src/config.c @@ -61,7 +61,8 @@ PUBLIC AFB_error configLoadFile (AFB_session * session, AFB_config *cliconfig) { // TBD integrate alias-dir array with config-file session->config->aliasdir = cliconfig->aliasdir; - + session->config->mode = cliconfig->mode; + // default HTTP port if (cliconfig->httpdPort == 0) session->config->httpdPort=1234; else session->config->httpdPort=cliconfig->httpdPort; diff --git a/src/main.c b/src/main.c index 533776a1..57660edf 100644 --- a/src/main.c +++ b/src/main.c @@ -419,10 +419,9 @@ int main(int argc, char *argv[]) { case SET_MODE: if (optarg == 0) goto needValueForOption; - /* TODO setting directly session->config isn't the expected path but... see configLoadFile, configStoreFile (JOBOL) */ - if (!strcmp(optarg, "local")) session->config->mode = AFB_MODE_LOCAL; - else if (!strcmp(optarg, "remote")) session->config->mode = AFB_MODE_REMOTE; - else if (!strcmp(optarg, "global")) session->config->mode = AFB_MODE_GLOBAL; + if (!strcmp(optarg, "local")) cliconfig.mode = AFB_MODE_LOCAL; + else if (!strcmp(optarg, "remote")) cliconfig.mode = AFB_MODE_REMOTE; + else if (!strcmp(optarg, "global")) cliconfig.mode = AFB_MODE_GLOBAL; else goto badMode; break; -- cgit 1.2.3-korg From a0eb62f43459f17961db16256199b4bbb936d863 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Mon, 15 Feb 2016 11:59:53 +0100 Subject: afm-main-plugin: adds mode auto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic707b52dd6029bd60242f03fcc04b6596f1cb017 Signed-off-by: José Bollo --- plugins/afm-main-plugin/afm-main-plugin.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c index 3f9de713..f6b44a0a 100644 --- a/plugins/afm-main-plugin/afm-main-plugin.c +++ b/plugins/afm-main-plugin/afm-main-plugin.c @@ -38,6 +38,7 @@ 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; @@ -138,7 +139,7 @@ static struct json_object *call_start(AFB_request *request, AFB_PostItem *item) } /* get the mode */ mode = getQueryValue(request, _mode_); - if (mode == NULL) { + if (mode == NULL || !strcmp(mode, _auto_)) { mode = request->config->mode == AFB_MODE_REMOTE ? _remote_ : _local_; } -- cgit 1.2.3-korg From 8ea2dc9f4df0a6d61e430d53d19eb0ea3633bf23 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Tue, 16 Feb 2016 08:18:31 +0100 Subject: afm-main-plugin: fix bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia39f4d38b6ace8fba9731bf1f0c700487a0e8063 Signed-off-by: José Bollo --- plugins/afm-main-plugin/afm-main-plugin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c index f6b44a0a..1fcc554b 100644 --- a/plugins/afm-main-plugin/afm-main-plugin.c +++ b/plugins/afm-main-plugin/afm-main-plugin.c @@ -157,7 +157,7 @@ static struct json_object *call_start(AFB_request *request, AFB_PostItem *item) free(query); /* embed if needed */ - if (json_object_get_type(resp) == json_type_string) + 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; -- cgit 1.2.3-korg From fcfb3c0951b6e2e06e7bf282e867576d8abb00c4 Mon Sep 17 00:00:00 2001 From: Manuel Bachmann Date: Wed, 17 Feb 2016 11:31:59 +0100 Subject: Audio plugin: choose between Pulse/ALSA at runtime If the AFB_AUDIO_OUTPUT environment variable is defined to "Pulse/Alsa", it will try to initialize the given backend (still falling back to Alsa for now). Signed-off-by: Manuel Bachmann --- plugins/audio/audio-alsa.c | 2 ++ plugins/audio/audio-api.c | 14 +++++++++++--- plugins/audio/audio-pulse.c | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/audio/audio-alsa.c b/plugins/audio/audio-alsa.c index 7310ea89..bc777fce 100644 --- a/plugins/audio/audio-alsa.c +++ b/plugins/audio/audio-alsa.c @@ -130,6 +130,8 @@ PUBLIC unsigned char _alsa_init (const char *name, audioCtxHandleT *ctx) { ctx->mute = _alsa_get_mute (num); ctx->idx = num; + if (verbose) fprintf (stderr, "Successfully initialized ALSA backend.\n"); + return 0; } diff --git a/plugins/audio/audio-api.c b/plugins/audio/audio-api.c index 4a8d0da1..637f9d03 100644 --- a/plugins/audio/audio-api.c +++ b/plugins/audio/audio-api.c @@ -22,10 +22,18 @@ void _backend_init (const char *name, audioCtxHandleT *ctx) { + char *backend_env = getenv ("AFB_AUDIO_OUTPUT"); + unsigned char res = -1; + # ifdef HAVE_PULSE - if (_pulse_init (name, ctx) < 0) -# endif - _alsa_init (name, ctx); + if (!backend_env || (strcasecmp (backend_env, "Alsa") != 0)) + res = _pulse_init (name, ctx); + if (res < 0) +#endif + res = _alsa_init (name, ctx); + + if (res < 0 && verbose) + fprintf (stderr, "Could not initialize Audio backend\n"); } void _backend_free (audioCtxHandleT *ctx) { diff --git a/plugins/audio/audio-pulse.c b/plugins/audio/audio-pulse.c index 4caf3db5..ceffcf7d 100644 --- a/plugins/audio/audio-pulse.c +++ b/plugins/audio/audio-pulse.c @@ -94,6 +94,8 @@ PUBLIC unsigned char _pulse_init (const char *name, audioCtxHandleT *ctx) { client_count++; + if (verbose) fprintf (stderr, "Successfully initialized PulseAudio backend.\n"); + return 0; } -- cgit 1.2.3-korg