idnode: added concept of class registration
this allows a class instance to be looked up by name, and in turn all instances of that class can be found.
This commit is contained in:
parent
5cb2ea0768
commit
2e13f5db01
2 changed files with 56 additions and 7 deletions
61
src/idnode.c
61
src/idnode.c
|
@ -29,12 +29,22 @@
|
|||
#include "notify.h"
|
||||
#include "settings.h"
|
||||
|
||||
static int randfd = 0;
|
||||
static RB_HEAD(,idnode) idnodes;
|
||||
static pthread_cond_t idnode_cond;
|
||||
static pthread_mutex_t idnode_mutex;
|
||||
static htsmsg_t *idnode_queue;
|
||||
static void* idnode_thread(void* p);
|
||||
typedef struct idclass_link
|
||||
{
|
||||
const idclass_t *idc;
|
||||
RB_ENTRY(idclass_link) link;
|
||||
} idclass_link_t;
|
||||
|
||||
static int randfd = 0;
|
||||
static RB_HEAD(,idnode) idnodes;
|
||||
static RB_HEAD(,idclass_link) idclasses;
|
||||
static pthread_cond_t idnode_cond;
|
||||
static pthread_mutex_t idnode_mutex;
|
||||
static htsmsg_t *idnode_queue;
|
||||
static void* idnode_thread(void* p);
|
||||
|
||||
static void
|
||||
idclass_register(const idclass_t *idc);
|
||||
|
||||
/* **************************************************************************
|
||||
* Utilities
|
||||
|
@ -153,6 +163,9 @@ idnode_insert(idnode_t *in, const char *uuid, const idclass_t *class)
|
|||
abort();
|
||||
}
|
||||
|
||||
/* Register the class */
|
||||
idclass_register(class); // Note: we never actually unregister
|
||||
|
||||
/* Fire event */
|
||||
idnode_notify(in, NULL, 0, 1);
|
||||
|
||||
|
@ -191,7 +204,7 @@ idnode_uuid_as_str(const idnode_t *in)
|
|||
/**
|
||||
*
|
||||
*/
|
||||
static const char *
|
||||
const char *
|
||||
idnode_get_title(idnode_t *in)
|
||||
{
|
||||
const idclass_t *ic = in->in_class;
|
||||
|
@ -676,6 +689,40 @@ idclass_get_class (const idclass_t *idc)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
ic_cmp ( const idclass_link_t *a, const idclass_link_t *b )
|
||||
{
|
||||
assert(a->idc->ic_class);
|
||||
assert(b->idc->ic_class);
|
||||
return strcmp(a->idc->ic_class, b->idc->ic_class);
|
||||
}
|
||||
|
||||
static void
|
||||
idclass_register(const idclass_t *idc)
|
||||
{
|
||||
static idclass_link_t *skel = NULL;
|
||||
while (idc) {
|
||||
if (!skel)
|
||||
skel = calloc(1, sizeof(idclass_link_t));
|
||||
skel->idc = idc;
|
||||
if (RB_INSERT_SORTED(&idclasses, skel, link, ic_cmp))
|
||||
break;
|
||||
skel = NULL;
|
||||
idc = idc->ic_super;
|
||||
}
|
||||
}
|
||||
|
||||
const idclass_t *
|
||||
idclass_find ( const char *class )
|
||||
{
|
||||
idclass_link_t *t, skel;
|
||||
idclass_t idc;
|
||||
skel.idc = &idc;
|
||||
idc.ic_class = class;
|
||||
t = RB_FIND(&idclasses, &skel, link, ic_cmp);
|
||||
return t ? t->idc : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Just get the class definition
|
||||
*/
|
||||
|
|
|
@ -111,6 +111,7 @@ void idnode_unlink(idnode_t *in);
|
|||
|
||||
const char *idnode_uuid_as_str (const idnode_t *in);
|
||||
idnode_set_t *idnode_get_childs (idnode_t *in);
|
||||
const char *idnode_get_title (idnode_t *in);
|
||||
int idnode_is_leaf (idnode_t *in);
|
||||
int idnode_is_instance (idnode_t *in, const idclass_t *idc);
|
||||
|
||||
|
@ -123,6 +124,7 @@ void idnode_notify
|
|||
void idnode_notify_simple (void *in);
|
||||
void idnode_notify_title_changed (void *in);
|
||||
|
||||
const idclass_t *idclass_find ( const char *name );
|
||||
htsmsg_t *idclass_serialize0 (const idclass_t *idc, int optmask);
|
||||
htsmsg_t *idnode_serialize0 (idnode_t *self, int optmask);
|
||||
void idnode_read0 (idnode_t *self, htsmsg_t *m, int optmask);
|
||||
|
|
Loading…
Add table
Reference in a new issue