1
0
Fork 0

Turn ClutterBindingPool a GObject

ClutterBindingPool is already "problematic" in terms of memory
management for language bindings and gobject-introspection. It
also lacks a GType.

Turning ClutterBindingPool into a GBoxed would not make much
sense, since it does not adhere to the copy/free semantics. It
could be referenced/unreferenced, but in that case we can just
as well use GObject as a base class instead of reimplemeting
a ref-counted object and then boxing it.

ClutterBindingPool is obviously a terminal class, so we just
hide the instance and class structures.
This commit is contained in:
Emmanuele Bassi 2009-01-13 12:34:59 +00:00
parent be462b2ea8
commit a4c8a70c83
2 changed files with 55 additions and 19 deletions

View file

@ -104,6 +104,10 @@
#include "clutter-marshal.h"
#include "clutter-private.h"
#define CLUTTER_BINDING_POOL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), CLUTTER_TYPE_BINDING_POOL, ClutterBindingPoolClass))
#define CLUTTER_IS_BINDING_POOL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CLUTTER_TYPE_BINDING_POOL))
#define CLUTTER_BINDING_POOL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CLUTTER_TYPE_BINDING_POOL, ClutterBindingPoolClass))
#define BINDING_MOD_MASK ((CLUTTER_SHIFT_MASK | \
CLUTTER_CONTROL_MASK | \
CLUTTER_MOD1_MASK | \
@ -111,19 +115,27 @@
CLUTTER_HYPER_MASK | \
CLUTTER_META_MASK) | CLUTTER_RELEASE_MASK)
typedef struct _ClutterBindingEntry ClutterBindingEntry;
typedef struct _ClutterBindingPoolClass ClutterBindingPoolClass;
typedef struct _ClutterBindingEntry ClutterBindingEntry;
static GSList *binding_pools = NULL;
static GQuark key_class_bindings = 0;
struct _ClutterBindingPool
{
GObject parent_instance;
gchar *name; /* interned string, do not free */
GSList *entries;
GHashTable *entries_hash;
};
struct _ClutterBindingPoolClass
{
GObjectClass parent_class;
};
struct _ClutterBindingEntry
{
gchar *name; /* interned string, do not free */
@ -136,6 +148,8 @@ struct _ClutterBindingEntry
guint is_blocked : 1;
};
G_DEFINE_TYPE (ClutterBindingPool, clutter_binding_pool, G_TYPE_OBJECT);
static guint
binding_entry_hash (gconstpointer v)
{
@ -204,22 +218,37 @@ binding_entry_free (gpointer data)
}
static void
binding_pool_free (gpointer data)
clutter_binding_pool_finalize (GObject *gobject)
{
if (G_LIKELY (data))
{
ClutterBindingPool *pool = data;
ClutterBindingPool *pool = CLUTTER_BINDING_POOL (gobject);
/* remove from the pools */
binding_pools = g_slist_remove (binding_pools, pool);
/* remove from the pools */
binding_pools = g_slist_remove (binding_pools, pool);
g_hash_table_destroy (pool->entries_hash);
g_hash_table_destroy (pool->entries_hash);
g_slist_foreach (pool->entries, (GFunc) binding_entry_free, NULL);
g_slist_free (pool->entries);
g_slist_foreach (pool->entries, (GFunc) binding_entry_free, NULL);
g_slist_free (pool->entries);
g_slice_free (ClutterBindingPool, pool);
}
G_OBJECT_CLASS (clutter_binding_pool_parent_class)->finalize (gobject);
}
static void
clutter_binding_pool_class_init (ClutterBindingPoolClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = clutter_binding_pool_finalize;
}
static void
clutter_binding_pool_init (ClutterBindingPool *pool)
{
pool->entries = NULL;
pool->entries_hash = g_hash_table_new (binding_entry_hash,
binding_entry_compare);
binding_pools = g_slist_prepend (binding_pools, pool);
}
/**
@ -253,13 +282,8 @@ clutter_binding_pool_new (const gchar *name)
return NULL;
}
pool = g_slice_new (ClutterBindingPool);
pool = g_object_new (CLUTTER_TYPE_BINDING_POOL, NULL);
pool->name = (gchar *) g_intern_string (name);
pool->entries = NULL;
pool->entries_hash = g_hash_table_new (binding_entry_hash,
binding_entry_compare);
binding_pools = g_slist_prepend (binding_pools, pool);
return pool;
}
@ -306,7 +330,7 @@ clutter_binding_pool_get_for_class (gpointer klass)
pool = clutter_binding_pool_new (G_OBJECT_CLASS_NAME (klass));
g_dataset_id_set_data_full (klass, key_class_bindings,
pool,
binding_pool_free);
g_object_unref);
return pool;
}

View file

@ -33,6 +33,18 @@
G_BEGIN_DECLS
#define CLUTTER_TYPE_BINDING_POOL (clutter_binding_pool_get_type ())
#define CLUTTER_BINDING_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_BINDING_POOL, ClutterBindingPool))
#define CLUTTER_IS_BINDING_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_BINDING_POOL))
/**
* ClutterBindingPool:
*
* Container of key bindings. The #ClutterBindingPool struct is
* private.
*
* Since: 1.0
*/
typedef struct _ClutterBindingPool ClutterBindingPool;
/**