resctl_t *resctl_init(void) { resctl_t *ctl; mrp_resource_client_t *client; mrp_resource_set_t *set; const char *zone = "driver"; const char *play = "audio_playback"; const char *rec = "audio_recording"; const char *cls = "phone"; bool ar = false; uint32_t prio = 1; /* what is this ? */ ctl = NULL; client = NULL; set = NULL; ctl = mrp_allocz(sizeof(*ctl)); if (ctl == NULL) { mrp_log_error("Failed to initialize telephony resource control."); goto fail; } client = mrp_resource_client_create("telephony", ctl); if (client == NULL) { mrp_log_error("Failed to create telephony resource client."); goto fail; } set = mrp_resource_set_create(client, ar, prio, event_cb, ctl); if (set == NULL) { mrp_log_error("Failed to create telephony resource set."); goto fail; } if (mrp_resource_set_add_resource(set, play, false, NULL, true) < 0 || mrp_resource_set_add_resource(set, rec , false, NULL, true) < 0) { mrp_log_error("Failed to initialize telephony resource set."); goto fail; } if (mrp_application_class_add_resource_set(cls, zone, set, 0) != 0) { mrp_log_error("Failed to assign telephony resource set with class."); goto fail; } ctl->client = client; ctl->set = set; ctl->seqno = 1; return ctl; fail: if (set != NULL) mrp_resource_set_destroy(set); if (client != NULL) mrp_resource_client_destroy(client); mrp_free(ctl); return NULL; }
static int resource_set_lua_create(lua_State *L) { char e[128] = ""; resource_set_lua_t *rset; int narg; mrp_htbl_config_t conf; mrp_debug("create"); narg = lua_gettop(L); rset = (resource_set_lua_t *) mrp_lua_create_object(L, RESOURCE_SET_LUA_CLASS, NULL, 0); if (!rset) return luaL_error(L, "could not create Lua object"); rset->L = L; /* user can affect these values */ rset->zone = mrp_strdup("default"); rset->application_class = NULL; rset->autorelease = FALSE; rset->dont_wait = FALSE; rset->priority = 0; rset->committed = FALSE; rset->initialized = FALSE; switch (narg) { case 2: /* argument table */ if (mrp_lua_init_members(rset, L, -2, e, sizeof(e)) != 1) return luaL_error(L, "failed to initialize resource members (%s)", e); break; default: return luaL_error(L, "expecting a constructor argument, " "got %d", narg); } if (rset->application_class == NULL) return luaL_error(L, "application_class is a mandatory parameter"); if (rset->priority < 0) rset->priority = 0; /* initial state, these cannot be set by user */ rset->available = FALSE; rset->acquired = FALSE; /* initialize resource map */ conf.nbucket = 0; conf.nentry = 10; conf.comp = mrp_string_comp; conf.hash = mrp_string_hash; conf.free = htbl_free_resource; rset->resources = mrp_htbl_create(&conf); if (!rset->resources) goto error; /* do the actual resource work */ if (!client) { /* create the resource client */ client = mrp_resource_client_create("lua", NULL); if (!client) goto error; } rset->resource_set = mrp_resource_set_create(client, rset->autorelease, rset->dont_wait, rset->priority, event_cb, rset); if (rset->resource_set) n_sets++; else goto error; rset->initialized = TRUE; mrp_lua_push_object(L, rset); return 1; error: return luaL_error(L, "internal resource library error"); }