Change object model
This commit is contained in:
Wim Taymans 2016-11-10 15:42:14 +01:00
parent d0f95fc323
commit 190f01d88e
38 changed files with 1594 additions and 3562 deletions

View file

@ -42,9 +42,9 @@ struct _PinosArray {
#define pinos_array_get_unchecked(a,idx,t) pinos_array_get_unchecked_s(a,idx,sizeof(t),t)
#define pinos_array_check_index(a,idx,t) pinos_array_check_index_s(a,idx,sizeof(t))
#define pinos_array_for_each(pos, array) \
for (pos = (array)->data; \
(const char *) pos < ((const char *) (array)->data + (array)->size); \
#define pinos_array_for_each(pos, array) \
for (pos = (array)->data; \
(const uint8_t *) pos < ((const uint8_t *) (array)->data + (array)->size); \
(pos)++)
static inline void

View file

@ -29,6 +29,7 @@ extern "C" {
#endif
typedef struct _PinosObject PinosObject;
typedef struct _PinosInterface PinosInterface;
typedef enum {
PINOS_OBJECT_FLAG_NONE = 0,
@ -37,28 +38,53 @@ typedef enum {
typedef void (*PinosDestroyFunc) (PinosObject *object);
struct _PinosInterface {
uint32_t type;
void *iface;
};
struct _PinosObject {
uint32_t type;
uint32_t id;
void *implementation;
PinosObjectFlags flags;
PinosDestroyFunc destroy;
PinosSignal destroy_signal;
unsigned int n_interfaces;
PinosInterface *interfaces;
};
static inline void
pinos_object_init (PinosObject *object,
uint32_t type,
void *implementation,
PinosDestroyFunc destroy)
PinosDestroyFunc destroy,
unsigned int n_interfaces,
PinosInterface *interfaces)
{
object->type = type;
object->id = SPA_ID_INVALID;
object->implementation = implementation;
object->flags = 0;
object->destroy = destroy;
pinos_signal_init (&object->destroy_signal);
object->n_interfaces = n_interfaces;
object->interfaces = interfaces;
}
static inline void *
pinos_object_get_interface (PinosObject *object,
uint32_t type)
{
unsigned int i;
for (i = 0; i < object->n_interfaces; i++)
if (object->interfaces[i].type == type)
return object->interfaces[i].iface;
return NULL;
}
static inline void
pinos_object_destroy (PinosObject *object)
{
object->flags |= PINOS_OBJECT_FLAG_DESTROYING;
pinos_signal_emit (&object->destroy_signal, object, NULL);
if (object->destroy)
object->destroy (object);
}
#ifdef __cplusplus
}

View file

@ -31,8 +31,7 @@ typedef struct _PinosListener PinosListener;
struct _PinosListener {
SpaList link;
void (*notify) (PinosListener *listener, void *data);
void *user_data;
void (*notify) (PinosListener *listener, void *object, void *data);
};
struct _PinosSignal {
@ -52,14 +51,21 @@ pinos_signal_add (PinosSignal *signal,
spa_list_insert (signal->listeners.prev, &listener->link);
}
static inline void
pinos_signal_remove (PinosListener *listener)
{
spa_list_remove (&listener->link);
}
static inline void
pinos_signal_emit (PinosSignal *signal,
void *object,
void *data)
{
PinosListener *l, *next;
spa_list_for_each_safe (l, next, &signal->listeners, link)
l->notify (l, data);
l->notify (l, object, data);
}
#ifdef __cplusplus