static void seek (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); const char *value = afb_req_value (request, "value"); json_object *jresp; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } /* no "?value=" parameter : return error */ if (!value) { afb_req_fail (request, "failed", "you must provide a time"); return; } if (!_rygel_do (ctx, SEEK, (char *)value)) { afb_req_fail (request, "failed", "could not seek chosen media"); return; } jresp = json_object_new_object(); json_object_object_add (jresp, "seek", json_object_new_string ("success")); afb_req_success (request, jresp, "Media - Sought"); }
static void call_appid_callback(int status, struct json_object *obj, struct memo *memo) { if (afb_interface->verbosity) fprintf(stderr, "(afm-main-plugin) %s -> %s\n", memo->method, obj ? json_object_to_json_string(obj) : "NULL"); if (obj == NULL) { afb_req_fail(memo->request, "failed", "framework daemon failure"); } else { obj = json_object_get(obj); afb_req_success(memo->request, obj, NULL); } afb_req_unref(memo->request); free(memo); }
static void selecting (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); const char *value = afb_req_value (request, "value"); json_object *jresp; unsigned int index; char index_str[5]; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } /* no "?value=" parameter : return current index */ if (!value) { snprintf (index_str, sizeof(index_str), "%d", ctx->index); jresp = json_object_new_object(); json_object_object_add (jresp, "index", json_object_new_string (index_str)); } /* "?value=" parameter is negative */ else if (atoi(value) < 0) { afb_req_fail (request, "failed", "chosen index cannot be negative"); return; } /* "?value=" parameter is positive */ else if (atoi(value) >= 0) { index = (unsigned int) atoi(value); if (!_rygel_select (ctx, index)) { afb_req_fail (request, "failed", "chosen index superior to current media count"); return; } ctx->index = index; jresp = json_object_new_object(); json_object_object_add (jresp, "index", json_object_new_string (value)); } else jresp = NULL; afb_req_success (request, jresp, "Media - Listed"); }
static void start(struct afb_req request) { struct json_object *obj; const char *id, *mode; char *query; int rc; /* get the id */ id = afb_req_value(request, _id_); if (id == NULL) { afb_req_fail(request, "bad-request", "missing 'id'"); return; } /* get the mode */ mode = afb_req_value(request, _mode_); if (mode == NULL || !strcmp(mode, _auto_)) { mode = afb_interface->mode == AFB_MODE_REMOTE ? _remote_ : _local_; } /* create the query */ rc = asprintf(&query, "{\"id\":\"%s\",\"mode\":\"%s\"}", id, mode); if (rc < 0) { afb_req_fail(request, "server-error", "out of memory"); return; } /* calls the service */ obj = jbus_call_sj_sync(jbus, _start_, query); if (afb_interface->verbosity) fprintf(stderr, "(afm-main-plugin) start(%s) -> %s\n", query, obj ? json_object_to_json_string(obj) : "NULL"); free(query); /* check status */ obj = json_object_get(obj); if (obj == NULL) { afb_req_fail(request, "failed", "framework daemon failure"); return; } /* embed if needed */ if (json_object_get_type(obj) == json_type_int) obj = embed(_runid_, obj); afb_req_success(request, obj, NULL); }
static void init (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); json_object *jresp; /* create a private client context */ if (!ctx) { ctx = initMediaCtx(); afb_req_context_set (request, ctx, free); } /* initialize server connection */ if (!ctx->media_server) _rygel_init (ctx); jresp = json_object_new_object (); json_object_object_add (jresp, "init", json_object_new_string ("success")); afb_req_success (request, jresp, "Media - Initialized"); }
static void call_runid(struct afb_req request, const char *method) { struct json_object *obj; const char *id = afb_req_value(request, _runid_); if (id == NULL) { afb_req_fail(request, "bad-request", "missing 'runid'"); return; } obj = jbus_call_sj_sync(jbus, method, id); if (afb_interface->verbosity) fprintf(stderr, "(afm-main-plugin) %s(%s) -> %s\n", method, id, obj ? json_object_to_json_string(obj) : "NULL"); if (obj == NULL) { afb_req_fail(request, "failed", "framework daemon failure"); return; } obj = json_object_get(obj); afb_req_success(request, obj, NULL); }
static void list (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); json_object *jresp; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } jresp = _rygel_list (ctx); if (!jresp) { afb_req_fail (request, "failed", "no content found in media server"); return; } afb_req_success (request, jresp, "Media - Listed"); }
static void pausing (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); json_object *jresp; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } if (!_rygel_do (ctx, PAUSE, NULL)) { afb_req_fail (request, "failed", "could not pause chosen media"); return; } jresp = json_object_new_object(); json_object_object_add (jresp, "pause", json_object_new_string ("success")); afb_req_success (request, jresp, "Media - Paused"); }
static void install(struct afb_req request) { struct json_object *obj, *added; char *query; const char *filename; struct afb_arg arg; /* get the argument */ arg = afb_req_get(request, "widget"); filename = arg.path; if (filename == NULL) { afb_req_fail(request, "bad-request", "missing 'widget' file"); return; } /* makes the query */ if (0 >= asprintf(&query, "\"%s\"", filename)) { afb_req_fail(request, "server-error", "out of memory"); return; } obj = jbus_call_sj_sync(jbus, _install_, query); if (afb_interface->verbosity) fprintf(stderr, "(afm-main-plugin) install(%s) -> %s\n", query, obj ? json_object_to_json_string(obj) : "NULL"); free(query); /* check status */ if (obj == NULL) { afb_req_fail(request, "failed", "framework daemon failure"); return; } /* embed if needed */ if (json_object_object_get_ex(obj, _added_, &added)) obj = added; obj = json_object_get(obj); obj = embed(_id_, obj); afb_req_success(request, obj, NULL); }
/* callback when received answer */ static int api_dbus_client_on_reply(sd_bus_message *message, void *userdata, sd_bus_error *ret_error) { int rc; struct dbus_memo *memo; const char *first, *second; uint8_t type; uint32_t flags; /* retrieve the recorded data */ memo = userdata; /* get the answer */ rc = sd_bus_message_read(message, "yssu", &type, &first, &second, &flags); if (rc < 0) { /* failing to have the answer */ afb_req_fail(memo->req, "error", "dbus error"); } else { /* report the answer */ memo->context->flags = (unsigned)flags; switch(type) { case RETOK: afb_req_success(memo->req, json_tokener_parse(first), second); break; case RETERR: afb_req_fail(memo->req, first, second); break; case RETRAW: afb_req_send(memo->req, first, strlen(first)); break; default: afb_req_fail(memo->req, "error", "dbus link broken"); break; } } api_dbus_client_free_memo(memo); return 1; }
static void ping (struct afb_req request) { /* AFB_SESSION_NONE */ afb_req_success (request, NULL, "Media - Ping succeeded"); }