WIP change object model

This commit is contained in:
Wim Taymans 2016-11-14 12:42:00 +01:00
parent 190f01d88e
commit c25ccbb4ba
44 changed files with 1557 additions and 2525 deletions

View file

@ -112,6 +112,9 @@ pinos_array_add_fixed (PinosArray *arr,
return p;
}
#define pinos_array_add_ptr(a,p) \
*((void**) pinos_array_add (a, sizeof (void*))) = (p)
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -14,6 +14,7 @@ pinos_headers = [
'subscribe.h',
'thread-mainloop.h',
'transport.h',
'utils.h',
]
pinos_sources = [
@ -33,6 +34,7 @@ pinos_sources = [
'subscribe.c',
'thread-mainloop.c',
'transport.c',
'utils.c',
gdbus_target,
]

View file

@ -47,7 +47,8 @@ struct _PinosObject {
uint32_t id;
PinosObjectFlags flags;
PinosDestroyFunc destroy;
PinosSignal destroy_signal;
PINOS_SIGNAL (destroy_signal, (PinosListener *listener,
PinosObject *object));
unsigned int n_interfaces;
PinosInterface *interfaces;
};
@ -81,7 +82,7 @@ static inline void
pinos_object_destroy (PinosObject *object)
{
object->flags |= PINOS_OBJECT_FLAG_DESTROYING;
pinos_signal_emit (&object->destroy_signal, object, NULL);
pinos_signal_emit (&object->destroy_signal, object);
if (object->destroy)
object->destroy (object);
}

View file

@ -32,6 +32,7 @@ extern const char g_log_domain_pinos[];
#include <pinos/client/ringbuffer.h>
#include <pinos/client/stream.h>
#include <pinos/client/subscribe.h>
#include <pinos/client/utils.h>
#include <spa/include/spa/id-map.h>

View file

@ -31,25 +31,31 @@ typedef struct _PinosListener PinosListener;
struct _PinosListener {
SpaList link;
void (*notify) (PinosListener *listener, void *object, void *data);
void (*notify) (void *);
};
#if 0
struct _PinosSignal {
SpaList listeners;
void (*notify) (PinosListener *listener, void *object, void *data);
};
#endif
static inline void
pinos_signal_init (PinosSignal *signal)
{
spa_list_init (&signal->listeners);
}
#define PINOS_SIGNAL(name,func) \
union { \
SpaList listeners; \
void (*notify) func; \
} name;
static inline void
pinos_signal_add (PinosSignal *signal,
PinosListener *listener)
{
spa_list_insert (signal->listeners.prev, &listener->link);
}
#define pinos_signal_init(signal) \
spa_list_init (&(signal)->listeners);
#define pinos_signal_add(signal,listener,func) \
do { \
__typeof__((signal)->notify) n = (func); \
(listener)->notify = (void (*) (void *)) n; \
spa_list_insert ((signal)->listeners.prev, &(listener)->link); \
} while (false);
static inline void
pinos_signal_remove (PinosListener *listener)
@ -57,16 +63,12 @@ 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, object, data);
}
#define pinos_signal_emit(signal,...) \
do { \
PinosListener *l, *next; \
spa_list_for_each_safe (l, next, &(signal)->listeners, link) \
((__typeof__((signal)->notify))l->notify) (l,__VA_ARGS__); \
} while (false);
#ifdef __cplusplus
}

83
pinos/client/utils.c Normal file
View file

@ -0,0 +1,83 @@
/* Simple Plugin API
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <string.h>
#include <pinos/client/array.h>
#include <pinos/client/log.h>
#include <pinos/client/utils.h>
const char *
pinos_split_walk (const char *str,
const char *delimiter,
size_t *len,
const char **state)
{
const char *s = *state ? *state : str;
if (*s == '\0')
return NULL;
*len = strcspn (s, delimiter);
*state = s + *len;
*state += strspn (*state, delimiter);
return s;
}
char **
pinos_split_strv (const char *str,
const char *delimiter,
int max_tokens,
int *n_tokens)
{
const char *state = NULL, *s = NULL;
PinosArray arr;
size_t len;
int n = 0;
pinos_array_init (&arr);
s = pinos_split_walk (str, delimiter, &len, &state);
while (s && n + 1 < max_tokens) {
pinos_array_add_ptr (&arr, strndup (s, len));
s = pinos_split_walk (str, delimiter, &len, &state);
n++;
}
if (s) {
pinos_array_add_ptr (&arr, strdup (s));
n++;
}
pinos_array_add_ptr (&arr, NULL);
*n_tokens = n;
return arr.data;
}
void
pinos_free_strv (char **str)
{
int i;
for (i = 0; str[i]; i++)
free (str[i]);
free (str);
}

45
pinos/client/utils.h Normal file
View file

@ -0,0 +1,45 @@
/* Simple Plugin API
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __PINOS_UTILS_H__
#define __PINOS_UTILS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/defs.h>
const char * pinos_split_walk (const char *str,
const char *delimiter,
size_t *len,
const char **state);
char ** pinos_split_strv (const char *str,
const char *delimiter,
int max_tokens,
int *n_tokens);
void pinos_free_strv (char **str);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __PINOS_UTILS_H__ */