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 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 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 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 call_appid(struct afb_req request, const char *method) { struct memo *memo; char *sid; const char *id = afb_req_value(request, _id_); if (id == NULL) { afb_req_fail(request, "bad-request", "missing 'id'"); return; } memo = make_memo(request, method); if (asprintf(&sid, "\"%s\"", id) <= 0 || memo == NULL) { afb_req_fail(request, "server-error", "out of memory"); free(memo); return; } if (jbus_call_sj(jbus, method, sid, (void*)call_appid_callback, memo) < 0) { afb_req_fail(request, "failed", "dbus failure"); free(memo); } free(sid); }