-STATIC AFB_restapi pluginApis[]= {
- {"init" , AFB_SESSION_CREATE, (AFB_apiCB)init , "Audio API - init"},
-// {"error" , AFB_SESSION_CHECK, (AFB_apiCB)wrongApi , "Ping Application Framework"},
+ audioCtxHandleT *ctx = (audioCtxHandleT*)request->client->ctx;
+ const char *value = getQueryValue (request, "value");
+ json_object *jresp;
+ int volume;
+ char volume_str[256];
+
+ /* no "?value=" parameter : return current state */
+ if (!value) {
+ ctx->volume = _alsa_get_volume (ctx->idx);
+ snprintf (volume_str, sizeof(volume_str), "%d", ctx->volume);
+ jresp = json_object_new_object();
+ json_object_object_add (jresp, "volume", json_object_new_string(volume_str));
+ }
+
+ /* "?value=" parameter, set volume */
+ else {
+ volume = atoi (value);
+ if (100 < volume < 0) {
+ request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
+ return (jsonNewMessage (AFB_FAIL, "Volume must be between 0 and 100"));
+ }
+ ctx->volume = volume;
+ _alsa_set_volume (ctx->idx, ctx->volume);
+
+ snprintf (volume_str, sizeof(volume_str), "%d", ctx->volume);
+ jresp = json_object_new_object();
+ json_object_object_add (jresp, "volume", json_object_new_string(volume_str));
+ }
+
+ return jresp;
+}
+
+STATIC json_object* channels (AFB_request *request) { /* AFB_SESSION_CHECK */
+
+ audioCtxHandleT *ctx = (audioCtxHandleT*)request->client->ctx;
+ const char *value = getQueryValue (request, "value");
+ json_object *jresp = json_object_new_object();
+ char channels_str[256];
+
+ /* no "?value=" parameter : return current state */
+ if (!value) {
+ snprintf (channels_str, sizeof(channels_str), "%d", ctx->channels);
+ json_object_object_add (jresp, "channels", json_object_new_string (channels_str));
+ }
+
+ /* "?value=" parameter, set channels */
+ else {
+ ctx->channels = atoi (value);
+ _alsa_set_channels (ctx->idx, ctx->channels);
+
+ snprintf (channels_str, sizeof(channels_str), "%d", ctx->channels);
+ json_object_object_add (jresp, "channels", json_object_new_string (channels_str));
+ }
+
+ return jresp;
+}