static nls_string_t * nls_string_find(const char *key) { nls_string_t *ns; unsigned int hash = mystrhash(key) % NLS_STRING_HASH_WIDTH; hts_mutex_lock(&nls_mutex); LIST_FOREACH(ns, &nls_strings[hash], ns_link) if(!strcmp(rstr_get(ns->ns_key), key)) break; if(ns == NULL) { ns = calloc(1, sizeof(nls_string_t)); ns->ns_key = rstr_alloc(key); ns->ns_prop = prop_create_root(NULL); prop_set_rstring(ns->ns_prop, ns->ns_key); } else { LIST_REMOVE(ns, ns_link); } LIST_INSERT_HEAD(&nls_strings[hash], ns, ns_link); hts_mutex_unlock(&nls_mutex); return ns; }
static void update_by_url(const char *url, int dolock) { metadb_item_info_t mii; mip_get(url, &mii); metadb_item_prop_t *mip; const unsigned int hash = mystrhash(url) % MIP_HASHWIDTH; if(dolock) hts_mutex_lock(&mip_mutex); LIST_FOREACH(mip, &mip_hash[hash], mip_link) if(!strcmp(mip->mip_url, url)) mip_set(mip, &mii); if(dolock) hts_mutex_unlock(&mip_mutex); }
void playinfo_bind_url_to_prop(const char *url, prop_t *parent) { metadb_item_info_t mii; mip_get(url, &mii); metadb_item_prop_t *mip = malloc(sizeof(metadb_item_prop_t)); hts_mutex_lock(&mip_mutex); mip->mip_refcount = 2; // One per subscription created below mip->mip_destroy_sub = prop_subscribe(PROP_SUB_TRACK_DESTROY, PROP_TAG_CALLBACK, metadb_item_prop_destroyed, mip, PROP_TAG_ROOT, parent, PROP_TAG_MUTEX, &mip_mutex, NULL); assert(mip->mip_destroy_sub != NULL); mip->mip_playcount = prop_create_r(parent, "playcount"); mip->mip_lastplayed = prop_create_r(parent, "lastplayed"); mip->mip_restartpos = prop_create_r(parent, "restartpos"); mip->mip_playcount_sub = prop_subscribe(PROP_SUB_NO_INITIAL_UPDATE | PROP_SUB_TRACK_DESTROY, PROP_TAG_CALLBACK, metadb_set_playcount, mip, PROP_TAG_ROOT, mip->mip_playcount, PROP_TAG_MUTEX, &mip_mutex, NULL); assert(mip->mip_playcount_sub != NULL); mip->mip_url = strdup(url); unsigned int hash = mystrhash(url) % MIP_HASHWIDTH; LIST_INSERT_HEAD(&mip_hash[hash], mip, mip_link); mip_set(mip, &mii); hts_mutex_unlock(&mip_mutex); }