static void resource_set_lua_destroy(void *data) { resource_set_lua_t *rset = (resource_set_lua_t *) data; mrp_debug("lua destructor for rset %p", rset); /* remove resources from the resource set -- they are finally cleaned from * their own lua destructors */ if (rset->resource_set) mrp_resource_set_destroy(rset->resource_set); if (rset->resources) { mrp_debug("deleting htbl at %p", rset->resources); mrp_htbl_destroy(rset->resources, TRUE); rset->resources = NULL; } mrp_free(rset->zone); mrp_free(rset->application_class); if (rset->initialized) { n_sets--; if (n_sets == 0) { mrp_resource_client_destroy(client); client = NULL; } } return; }
static void print_utterance(context_t *ctx, srs_srec_utterance_t *utt) { decoder_set_t *decset; decoder_t *dec; srs_srec_candidate_t *cand; srs_srec_token_t *tkn; size_t i,j; if (ctx && (decset = ctx->decset) && (dec = decset->curdec)) { mrp_debug("utterance %15s (score %.4lf, length %u), %zd candidates", utt->id, utt->score, utt->length, utt->ncand); for (i = 0; (cand = utt->cands[i]) != NULL; i++) { mrp_debug(" (score %.4lf) ----------------------", cand->score); for (j = 0; j < cand->ntoken; j++) { tkn = cand->tokens + j; mrp_debug(" %d - %d %s", tkn->start, tkn->end, tkn->token); } } mrp_debug(" ----------------------"); } }
static int resource_set_release(lua_State *L) { resource_set_lua_t *rset; mrp_debug("> release"); rset = resource_set_lua_check(L, 1); if (!rset) return luaL_error(L, "internal error"); if (!rset->committed) { /* Committing the resource set here means that the resource set stays * in released state but already receives events. */ if (mrp_application_class_add_resource_set(rset->application_class, rset->zone, rset->resource_set, 0) < 0) return luaL_error(L, "failed to commit the resource set"); rset->committed = TRUE; } mrp_resource_set_release(rset->resource_set, 0); return 0; }
static int resource_set_acquire(lua_State *L) { resource_set_lua_t *rset; mrp_debug("acquire"); rset = resource_set_lua_check(L, 1); if (!rset) return luaL_error(L, "internal error"); if (!rset->committed) { /* Application backend requires us to "commit" the resource set before * we can use the resource set. It can be done only after all resources * have been added to the resource set and all the attributes * configured. */ if (mrp_application_class_add_resource_set(rset->application_class, rset->zone, rset->resource_set, 0) < 0) return luaL_error(L, "failed to commit the resource set"); rset->committed = TRUE; } mrp_resource_set_acquire(rset->resource_set, 0); return 0; }
static void unregister_client(client_t *c, srs_req_unregister_t *req) { mrp_debug("received unregister request from native client #%d", c->id); reply_unregister(c, req->reqno, SRS_STATUS_OK, "OK"); destroy_client(c); }
static void cancel_voice(client_t *c, srs_ccl_voice_t *req) { mrp_debug("received voice cancel request from native client #%d", c->id); client_cancel_voice(c->c, req->id); reply_status(c, req->reqno, SRS_STATUS_OK, "OK"); }
static void register_client(client_t *c, srs_req_register_t *req) { static srs_client_ops_t ops = { .notify_focus = focus_notify, .notify_command = command_notify, .notify_render = voice_notify, }; srs_context_t *srs = c->s->self->srs; char *name = req->name; char *appcls = req->appclass; char **cmds = req->commands; int ncmd = req->ncommand; char id[64]; snprintf(id, sizeof(id), "native-client-%d", c->id); mrp_debug("received register request from native client #%d", c->id); c->c = client_create(srs, SRS_CLIENT_TYPE_EXTERNAL, name, appcls, cmds, ncmd, id, &ops, c); if (c->c != NULL) reply_register(c, req->reqno, SRS_STATUS_OK, "OK"); else { reply_register(c, req->reqno, SRS_STATUS_FAILED, "failed"); destroy_client(c); } }
static int cdpa_read(rnc_dev_t *dev, void *buf, size_t size) { cdpa_t *cdpa = dev->data; char *s, *p; size_t n; mrp_debug("reading %zu bytes", size); if ((size % CDIO_CD_FRAMESIZE_RAW) != 0) goto invalid; p = buf; n = size; while (n > 0) { s = (char *)cdio_paranoia_read(cdpa->cdpa, read_status); if (s == NULL) goto ioerror; memcpy(p, s, CDIO_CD_FRAMESIZE_RAW); p += CDIO_CD_FRAMESIZE_RAW; n -= CDIO_CD_FRAMESIZE_RAW; } return size; invalid: errno = EINVAL; return -1; ioerror: errno = EIO; return -1; }
static inline void dump_message(void *data, uint32_t type_id) { char buf[1024]; if (mrp_print_native(buf, sizeof(buf), data, type_id) > 0) mrp_debug("got message of type 0x%x: %s", type_id, buf); }
static int glib_check(void *user_data, struct pollfd *fds, int nfd) { glib_glue_t *glue = (glib_glue_t *)user_data; int ready; mrp_debug("*** GMainLoop <%p>: checking...", user_data); glib_acquire(glue); ready = g_main_context_check(glue->mc, glue->maxprio, (GPollFD *)fds, nfd); glib_release(glue); mrp_debug("GmainLoop <%p>: %s dispatch", user_data, ready ? "ready for" : "nothing to"); return ready; }
static int glib_prepare(void *user_data) { glib_glue_t *glue = (glib_glue_t *)user_data; int ready; mrp_debug("*** GMainLoop <%p>: preparing...", user_data); glib_acquire(glue); ready = g_main_context_prepare(glue->mc, &glue->maxprio); glib_release(glue); mrp_debug("GMainLoop <%p>: prepared and %s", user_data, ready ? "ready" : "not ready"); return ready; }
static int focus_req(mrp_dbus_t *dbus, mrp_dbus_msg_t *req, void *user_data) { dbusif_t *bus = (dbusif_t *)user_data; srs_context_t *srs = bus->self->srs; const char *id, *errmsg; int focus, err; srs_client_t *c; err = parse_focus(req, &id, &focus, &errmsg); if (err == 0) { mrp_debug("got 0x%x focus request from %s", focus, id); c = client_lookup_by_id(srs, id); if (c != NULL) { if (client_request_focus(c, focus)) reply_focus(dbus, req, 0, NULL); else reply_focus(dbus, req, 1, "focus request failed"); } else reply_focus(dbus, req, 1, "you don't exist, go away"); } else reply_focus(dbus, req, err, errmsg); return TRUE; }
void event_cb(uint32_t request_id, mrp_resource_set_t *resource_set, void *user_data) { resource_set_lua_t *rset = (resource_set_lua_t *) user_data; mrp_resource_mask_t grant, advice; int top; MRP_UNUSED(request_id); MRP_UNUSED(resource_set); mrp_debug("> event_cb"); top = lua_gettop(rset->L); grant = mrp_get_resource_set_grant(rset->resource_set); advice = mrp_get_resource_set_advice(rset->resource_set); /* update resource set */ rset->acquired = !!grant; rset->available = !!advice; if (mrp_lua_object_deref_value(rset, rset->L, rset->callback, false)) { mrp_lua_push_object(rset->L, rset); if (lua_pcall(rset->L, 1, 0, 0) != 0) mrp_log_error("failed to invoke Lua resource set callback: %s", lua_tostring(rset->L, -1)); } lua_settop(rset->L, top); }
static bool cdpa_probe(rnc_dev_api_t *api, const char *device) { int fd, is_cd; MRP_UNUSED(api); mrp_debug("probing device '%s' with cdparanoia", device); if (!strcmp(device, "/dev/cdrom")) return true; if (!strncmp(device, "/dev/cd", 7)) return true; if (!strncmp(device, "/dev/sr", 7)) return true; fd = open(device, O_RDONLY); if (fd < 0) return -1; is_cd = (ioctl(fd, CDROM_DRIVE_STATUS) != -1); close(fd); return is_cd; }
static int unregister_req(mrp_dbus_t *dbus, mrp_dbus_msg_t *req, void *user_data) { dbusif_t *bus = (dbusif_t *)user_data; srs_context_t *srs = bus->self->srs; const char *id, *errmsg; srs_client_t *c; int err; err = parse_unregister(req, &id, &errmsg); if (!err) { mrp_debug("got unregister request from %s", id); c = client_lookup_by_id(srs, id); if (c != NULL) { mrp_dbus_forget_name(dbus, c->id, name_change_cb, bus); client_destroy(c); reply_unregister(dbus, req, 0, NULL); } else reply_unregister(dbus, req, 1, "you don't exist, go away"); } else reply_unregister(dbus, req, err, errmsg); return TRUE; }
static void attribute_lua_destroy(void *data) { attribute_lua_t *attribute = (attribute_lua_t *) data; mrp_debug("lua destructor for attribute table %p", attribute); return; }
static int cdpa_get_blocksize(rnc_dev_t *dev) { MRP_UNUSED(dev); mrp_debug("getting device block size"); return CDIO_CD_FRAMESIZE_RAW; }
static void resource_lua_changed(void *data, lua_State *L, int member) { MRP_UNUSED(data); MRP_UNUSED(L); MRP_UNUSED(member); mrp_debug("> resource_changed"); }
static int glib_query(void *user_data, struct pollfd *fds, int nfd, int *timeout) { glib_glue_t *glue = (glib_glue_t *)user_data; int n; mrp_debug("*** GMainLoop <%p>: querying...", user_data); glib_acquire(glue); n = g_main_context_query(glue->mc, glue->maxprio, timeout, (GPollFD *)fds, nfd); glib_release(glue); mrp_debug("GMainLoop <%p>: %d fds, timeout %d", user_data, n, *timeout); return n; }
static void stop_wrtc(srs_plugin_t *plugin) { wrtc_t *wrtc = (wrtc_t *)plugin->plugin_data; mrp_debug("stop WRT media client plugin"); return; }
static int attribute_lua_getfield(lua_State *L) { attribute_lua_t *attribute = attribute_lua_check(L, 1); resource_lua_t *res = attribute->parent; resource_set_lua_t *rset = res->parent; mrp_attr_t attribute_list[MAX_ATTRS], *attrs; const char *key; mrp_debug("> attribute_lua_getfield"); /* attributes are indexed by string */ if (lua_type(L, 2) != LUA_TSTRING) return luaL_error(L, "invalid attribute index type (needs to be string)"); key = lua_tostring(L, 2); attrs = mrp_resource_set_read_all_attributes(rset->resource_set, res->resource_name, MAX_ATTRS-1, attribute_list); if (!attrs) return luaL_error(L, "internal resource library error"); while (attrs->name != NULL) { if (strcmp(attrs->name, key) == 0) { switch (attrs->type) { case mqi_string: lua_pushstring(L, attrs->value.string); return 1; case mqi_integer: lua_pushinteger(L, attrs->value.integer); return 1; case mqi_unsignd: if (attrs->value.unsignd > INT_MAX) { /* too big! */ mrp_log_error("Sorry, we don't support big unsigned values right now"); return luaL_error(L, "too big value in attribute"); } else { lua_pushinteger(L, attrs->value.unsignd); } return 1; case mqi_floating: lua_pushnumber(L, attrs->value.floating); return 1; default: mrp_log_error("Unhandled attribute type"); return 1; } } attrs++; } return luaL_error(L, "trying to get a non-existing attribute"); }
static void attribute_lua_destroy(void *data) { attribute_lua_t *attribute = (attribute_lua_t *) data; mrp_debug("> attribute_destroy"); mrp_free(attribute); return; }
static void attribute_lua_changed(void *data, lua_State *L, int member) { MRP_UNUSED(data); MRP_UNUSED(L); MRP_UNUSED(member); mrp_debug("> attribute_changed"); return; }
static void request_focus(client_t *c, srs_req_focus_t *req) { mrp_debug("received focus request from native client #%d", c->id); if (client_request_focus(c->c, req->focus)) reply_focus(c, req->reqno, SRS_STATUS_OK, "OK"); else reply_focus(c, req->reqno, SRS_STATUS_FAILED, "failed"); }
static int start_dbusif(srs_plugin_t *plugin) { dbusif_t *bus = (dbusif_t *)plugin->plugin_data; MRP_UNUSED(bus); mrp_debug("start D-Bus client interface plugin"); return TRUE; }
static void glib_dispatch(void *user_data) { glib_glue_t *glue = (glib_glue_t *)user_data; mrp_debug("*** GMainLoop <%p>: dispatching...", user_data); glib_acquire(glue); g_main_context_dispatch(glue->mc); glib_release(glue); }
static void stop_dbusif(srs_plugin_t *plugin) { dbusif_t *bus = (dbusif_t *)plugin->plugin_data; MRP_UNUSED(bus); mrp_debug("stop D-Bus client interface plugin"); return; }
static int start_wrtc(srs_plugin_t *plugin) { wrtc_t *wrtc = (wrtc_t *)plugin->plugin_data; MRP_UNUSED(wrtc); mrp_debug("start WRT media client plugin"); return wrtc_setup(wrtc); }
static void read_status(long int i, paranoia_cb_mode_t mode) { #if 1 MRP_UNUSED(i); MRP_UNUSED(mode); #else mrp_debug("roffset: %ld, mode: 0x%x (%s)", i, mode, paranoia_cb_mode2str[mode]); #endif }
static void query_voices(client_t *c, srs_req_voiceqry_t *req) { srs_voice_actor_t *actors = NULL; int nactor; mrp_debug("received voice query request from native client #%d", c->id); nactor = client_query_voices(c->c, req->lang, &actors); reply_voiceqry(c, req->reqno, actors, nactor); client_free_queried_voices(actors); }