*
* 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
*
* 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
/* free a radio device from requesting client, power it off */
STATIC AFB_error releaseRadio (pluginHandleT *handle, radioCtxHandleT *ctx) {
/* free a radio device from requesting client, power it off */
STATIC AFB_error releaseRadio (pluginHandleT *handle, radioCtxHandleT *ctx) {
- releaseRadio (client->plugin->handle, client->ctx);
- free (client->ctx);
-
- return jsonNewMessage (AFB_SUCCESS, "Released radio and client context");
+ releaseRadio (handle, context);
+ free (context);
-
- pluginHandleT *handle = request->client->plugin->handle;
- radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx;
+
+ pluginHandleT *handle = (pluginHandleT*)request->handle;
+ radioCtxHandleT *ctx = (radioCtxHandleT*)request->context;
- /* "?value=" parameter is "1" or "on" */
- else if ( atoi(value) == 1 || !strcasecmp(value, "on") ) {
+ /* "?value=" parameter is "1" or "true" */
+ else if ( atoi(value) == 1 || !strcasecmp(value, "true") ) {
if (!ctx->radio) {
if (reserveRadio (handle, ctx) == AFB_FAIL) {
request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
if (!ctx->radio) {
if (reserveRadio (handle, ctx) == AFB_FAIL) {
request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
- /* "?value=" parameter is "0" or "off" */
- else if ( atoi(value) == 0 || !strcasecmp(value, "off") ) {
+ /* "?value=" parameter is "0" or "false" */
+ else if ( atoi(value) == 0 || !strcasecmp(value, "false") ) {
if (ctx->radio) {
if (releaseRadio (handle, ctx) == AFB_FAIL) {
request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
if (ctx->radio) {
if (releaseRadio (handle, ctx) == AFB_FAIL) {
request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
ctx->mode ?
json_object_object_add (jresp, "mode", json_object_new_string ("AM"))
: json_object_object_add (jresp, "mode", json_object_new_string ("FM"));
}
ctx->mode ?
json_object_object_add (jresp, "mode", json_object_new_string ("AM"))
: json_object_object_add (jresp, "mode", json_object_new_string ("FM"));
}
else if ( atoi(value) == 1 || !strcasecmp(value, "AM") ) {
ctx->mode = AM;
_radio_set_mode (ctx->idx, ctx->mode);
else if ( atoi(value) == 1 || !strcasecmp(value, "AM") ) {
ctx->mode = AM;
_radio_set_mode (ctx->idx, ctx->mode);
else if ( atoi(value) == 0 || !strcasecmp(value, "FM") ) {
ctx->mode = FM;
_radio_set_mode (ctx->idx, ctx->mode);
else if ( atoi(value) == 0 || !strcasecmp(value, "FM") ) {
ctx->mode = FM;
_radio_set_mode (ctx->idx, ctx->mode);
const char *value = getQueryValue (request, "value");
json_object *jresp = json_object_new_object();
const char *value = getQueryValue (request, "value");
json_object *jresp = json_object_new_object();
snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
json_object_object_add (jresp, "freq", json_object_new_string (freq_str));
}
/* "?value=" parameter, set frequency */
else {
snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
json_object_object_add (jresp, "freq", json_object_new_string (freq_str));
}
/* "?value=" parameter, set frequency */
else {
- ctx->freq = strtof (value, NULL);
- _radio_set_freq (ctx->idx, ctx->freq);
-
+ freq = strtod (value, NULL);
+ _radio_set_freq (ctx->idx, freq);
+ ctx->freq = (float)freq;
+
snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
json_object_object_add (jresp, "freq", json_object_new_string (freq_str));
}
snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
json_object_object_add (jresp, "freq", json_object_new_string (freq_str));
}
ctx->mute ?
json_object_object_add (jresp, "mute", json_object_new_string ("on"))
: json_object_object_add (jresp, "mute", json_object_new_string ("off"));
}
ctx->mute ?
json_object_object_add (jresp, "mute", json_object_new_string ("on"))
: json_object_object_add (jresp, "mute", json_object_new_string ("off"));
}
- /* "?value=" parameter is "1" or "on" */
- else if ( atoi(value) == 1 || !strcasecmp(value, "on") ) {
+ /* "?value=" parameter is "1" or "true" */
+ else if ( atoi(value) == 1 || !strcasecmp(value, "true") ) {
else if ( atoi(value) == 0 || !strcasecmp(value, "off") ) {
ctx->mute = 0;
_radio_set_mute (ctx->idx, ctx->mute);
else if ( atoi(value) == 0 || !strcasecmp(value, "off") ) {
ctx->mute = 0;
_radio_set_mute (ctx->idx, ctx->mute);
const char *value = getQueryValue (request, "value");
json_object *jresp = json_object_new_object();
/* no "?value=" parameter : return current state */
const char *value = getQueryValue (request, "value");
json_object *jresp = json_object_new_object();
/* no "?value=" parameter : return current state */
ctx->is_playing ?
json_object_object_add (jresp, "play", json_object_new_string ("on"))
: json_object_object_add (jresp, "play", json_object_new_string ("off"));
}
ctx->is_playing ?
json_object_object_add (jresp, "play", json_object_new_string ("on"))
: json_object_object_add (jresp, "play", json_object_new_string ("off"));
}
- /* "?value=" parameter is "1" or "on" */
- else if ( atoi(value) == 1 || !strcasecmp(value, "on") ) {
+ /* "?value=" parameter is "1" or "true" */
+ else if ( atoi(value) == 1 || !strcasecmp(value, "true") ) {
- /* "?value=" parameter is "0" or "off" */
- else if ( atoi(value) == 0 || !strcasecmp(value, "off") ) {
+ /* "?value=" parameter is "0" or "false" */
+ else if ( atoi(value) == 0 || !strcasecmp(value, "false") ) {
{"freq" , AFB_SESSION_CHECK, (AFB_apiCB)freq , "Radio API - freq"},
{"mute" , AFB_SESSION_CHECK, (AFB_apiCB)mute , "Radio API - mute"},
{"play" , AFB_SESSION_CHECK, (AFB_apiCB)play , "Radio API - play"},
{"freq" , AFB_SESSION_CHECK, (AFB_apiCB)freq , "Radio API - freq"},
{"mute" , AFB_SESSION_CHECK, (AFB_apiCB)mute , "Radio API - mute"},
{"play" , AFB_SESSION_CHECK, (AFB_apiCB)play , "Radio API - play"},
- {"status" , AFB_SESSION_RENEW, (AFB_apiCB)status , "Radio API - status"},
+ {"ping" , AFB_SESSION_NONE, (AFB_apiCB)ping , "Radio API - ping"},
AFB_plugin *plugin = malloc (sizeof(AFB_plugin));
plugin->type = AFB_PLUGIN_JSON;
plugin->info = "Application Framework Binder - Radio plugin";
AFB_plugin *plugin = malloc (sizeof(AFB_plugin));
plugin->type = AFB_PLUGIN_JSON;
plugin->info = "Application Framework Binder - Radio plugin";