X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=plugins%2Fradio%2Fradio-api.c;h=f065a8ad1d3d7eec36329f74478d295be2a2404f;hb=07fb99ec63d034983b768e8b8bd3d2b30ae37f6f;hp=02f6330c9ff2275212e31f21211e2b8732321ab9;hpb=41c462374fb25fae29f3b4a28eb99fdb639e8547;p=src%2Fapp-framework-binder.git diff --git a/plugins/radio/radio-api.c b/plugins/radio/radio-api.c index 02f6330c..f065a8ad 100644 --- a/plugins/radio/radio-api.c +++ b/plugins/radio/radio-api.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2015 "IoT.bzh" + * Author "Manuel Bachmann" * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -121,16 +122,26 @@ STATIC json_object* freeRadio (AFB_clientCtx *client) { /* ------ PUBLIC PLUGIN FUNCTIONS --------- */ -STATIC json_object* power (AFB_request *request) { /* AFB_SESSION_CREATE */ +STATIC json_object* init (AFB_request *request) { /* AFB_SESSION_CREATE */ + + radioCtxHandleT *ctx; + json_object *jresp; + + /* create a private client context */ + ctx = initRadioCtx(); + request->client->ctx = (radioCtxHandleT*)ctx; + + jresp = json_object_new_object(); + json_object_object_add(jresp, "token", json_object_new_string (request->client->token)); +} + +STATIC json_object* power (AFB_request *request) { /* AFB_SESSION_CHECK */ pluginHandleT *handle = request->client->plugin->handle; radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx; const char *value = getQueryValue (request, "value"); json_object *jresp; - /* create a private client context if needed */ - if (!ctx) ctx = initRadioCtx(); - /* no "?value=" parameter : return current state */ if (!value) { jresp = json_object_new_object(); @@ -265,7 +276,7 @@ STATIC json_object* play (AFB_request *request) { /* AFB_SESSION_CHECK */ radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx; const char *value = getQueryValue (request, "value"); - json_object *jresp; + json_object *jresp = json_object_new_object(); /* no "?value=" parameter : return current state */ if (!value) { @@ -279,8 +290,6 @@ STATIC json_object* play (AFB_request *request) { /* AFB_SESSION_CHECK */ /* radio playback */ ctx->is_playing = 1; _radio_play (ctx->idx); - - jresp = json_object_new_object(); json_object_object_add (jresp, "play", json_object_new_string ("on")); } @@ -289,8 +298,6 @@ STATIC json_object* play (AFB_request *request) { /* AFB_SESSION_CHECK */ /* radio stop */ ctx->is_playing = 0; _radio_stop (ctx->idx); - - jresp = json_object_new_object(); json_object_object_add (jresp, "play-on", json_object_new_string ("off")); } @@ -303,7 +310,8 @@ STATIC json_object* status (AFB_request *request) { STATIC AFB_restapi pluginApis[]= { - {"power" , AFB_SESSION_CREATE, (AFB_apiCB)power , "Radio API - power"}, + {"init" , AFB_SESSION_CREATE, (AFB_apiCB)init , "Radio API - init"}, + {"power" , AFB_SESSION_CHECK, (AFB_apiCB)power , "Radio API - power"}, {"mode" , AFB_SESSION_CHECK, (AFB_apiCB)mode , "Radio API - mode"}, {"freq" , AFB_SESSION_CHECK, (AFB_apiCB)freq , "Radio API - freq"}, {"mute" , AFB_SESSION_CHECK, (AFB_apiCB)mute , "Radio API - mute"},