|
Packit |
3ff832 |
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
|
|
Packit |
3ff832 |
/* vim:set et sts=4: */
|
|
Packit |
3ff832 |
/* ibus - The Input Bus
|
|
Packit |
3ff832 |
* Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
|
|
Packit |
3ff832 |
* Copyright (C) 2008-2013 Red Hat, Inc.
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
3ff832 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
3ff832 |
* License as published by the Free Software Foundation; either
|
|
Packit |
3ff832 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
3ff832 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
3ff832 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
3ff832 |
* Lesser General Public License for more details.
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
3ff832 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
3ff832 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
Packit |
3ff832 |
* USA
|
|
Packit |
3ff832 |
*/
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
#include "ibusobject.h"
|
|
Packit |
3ff832 |
#include "ibusmarshalers.h"
|
|
Packit |
3ff832 |
#include "ibusinternal.h"
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
#define IBUS_OBJECT_GET_PRIVATE(o) \
|
|
Packit |
3ff832 |
(G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_OBJECT, IBusObjectPrivate))
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
enum {
|
|
Packit |
3ff832 |
DESTROY,
|
|
Packit |
3ff832 |
LAST_SIGNAL,
|
|
Packit |
3ff832 |
};
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
struct _IBusObjectPrivate {
|
|
Packit |
3ff832 |
gpointer pad;
|
|
Packit |
3ff832 |
};
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static guint object_signals[LAST_SIGNAL] = { 0 };
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
// #define DEBUG_MEMORY
|
|
Packit |
3ff832 |
#ifdef DEBUG_MEMORY
|
|
Packit |
3ff832 |
static GHashTable *_count_table;
|
|
Packit |
3ff832 |
static guint _count = 0;
|
|
Packit |
3ff832 |
#endif
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
/* functions prototype */
|
|
Packit |
3ff832 |
static GObject *ibus_object_constructor (GType type,
|
|
Packit |
3ff832 |
guint n,
|
|
Packit |
3ff832 |
GObjectConstructParam
|
|
Packit |
3ff832 |
*args);
|
|
Packit |
3ff832 |
static void ibus_object_dispose (IBusObject *obj);
|
|
Packit |
3ff832 |
static void ibus_object_finalize (IBusObject *obj);
|
|
Packit |
3ff832 |
static void ibus_object_real_destroy (IBusObject *obj);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
G_DEFINE_TYPE (IBusObject, ibus_object, G_TYPE_INITIALLY_UNOWNED)
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static void
|
|
Packit |
3ff832 |
ibus_object_class_init (IBusObjectClass *class)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
gobject_class->constructor = ibus_object_constructor;
|
|
Packit |
3ff832 |
gobject_class->dispose = (GObjectFinalizeFunc) ibus_object_dispose;
|
|
Packit |
3ff832 |
gobject_class->finalize = (GObjectFinalizeFunc) ibus_object_finalize;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
class->destroy = ibus_object_real_destroy;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
/* install signals */
|
|
Packit |
3ff832 |
/**
|
|
Packit |
3ff832 |
* IBusObject::destroy:
|
|
Packit |
3ff832 |
* @object: An IBusObject.
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* Destroy and free an IBusObject
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* See also: ibus_object_destroy().
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* <note><para>Argument @user_data is ignored in this function.</para></note>
|
|
Packit |
3ff832 |
*/
|
|
Packit |
3ff832 |
object_signals[DESTROY] =
|
|
Packit |
3ff832 |
g_signal_new (I_("destroy"),
|
|
Packit |
3ff832 |
G_TYPE_FROM_CLASS (gobject_class),
|
|
Packit |
3ff832 |
G_SIGNAL_RUN_LAST,
|
|
Packit |
3ff832 |
G_STRUCT_OFFSET (IBusObjectClass, destroy),
|
|
Packit |
3ff832 |
NULL, NULL,
|
|
Packit |
3ff832 |
_ibus_marshal_VOID__VOID,
|
|
Packit |
3ff832 |
G_TYPE_NONE, 0);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_type_class_add_private (class, sizeof (IBusObjectPrivate));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
#ifdef DEBUG_MEMORY
|
|
Packit |
3ff832 |
_count_table = g_hash_table_new (g_direct_hash, g_direct_equal);
|
|
Packit |
3ff832 |
#endif
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static void
|
|
Packit |
3ff832 |
ibus_object_init (IBusObject *obj)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
obj->flags = 0;
|
|
Packit |
3ff832 |
obj->priv = IBUS_OBJECT_GET_PRIVATE (obj);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static GObject *
|
|
Packit |
3ff832 |
ibus_object_constructor (GType type,
|
|
Packit |
3ff832 |
guint n,
|
|
Packit |
3ff832 |
GObjectConstructParam *args)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
GObject *object;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
object = G_OBJECT_CLASS (ibus_object_parent_class)->constructor (type, n ,args);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
#ifdef DEBUG_MEMORY
|
|
Packit |
3ff832 |
if (object != NULL) {
|
|
Packit |
3ff832 |
guint count;
|
|
Packit |
3ff832 |
_count ++;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
count = GPOINTER_TO_UINT (g_hash_table_lookup (_count_table, (gpointer) type));
|
|
Packit |
3ff832 |
g_hash_table_replace (_count_table, (gpointer) type, GUINT_TO_POINTER (++count));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_debug ("new %s, count = %d, all = %d", g_type_name (type), count, _count);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
#endif
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return object;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static void
|
|
Packit |
3ff832 |
ibus_object_dispose (IBusObject *obj)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
if (! (IBUS_OBJECT_FLAGS (obj) & IBUS_IN_DESTRUCTION)) {
|
|
Packit |
3ff832 |
IBUS_OBJECT_SET_FLAGS (obj, IBUS_IN_DESTRUCTION);
|
|
Packit |
3ff832 |
if (! (IBUS_OBJECT_FLAGS (obj) & IBUS_DESTROYED)) {
|
|
Packit |
3ff832 |
g_signal_emit (obj, object_signals[DESTROY], 0);
|
|
Packit |
3ff832 |
IBUS_OBJECT_SET_FLAGS (obj, IBUS_DESTROYED);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
IBUS_OBJECT_UNSET_FLAGS (obj, IBUS_IN_DESTRUCTION);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
G_OBJECT_CLASS(ibus_object_parent_class)->dispose (G_OBJECT (obj));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static void
|
|
Packit |
3ff832 |
ibus_object_finalize (IBusObject *obj)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
#ifdef DEBUG_MEMORY
|
|
Packit |
3ff832 |
guint count;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
_count --;
|
|
Packit |
3ff832 |
count = GPOINTER_TO_UINT (g_hash_table_lookup (_count_table, (gpointer)G_OBJECT_TYPE (obj)));
|
|
Packit |
3ff832 |
g_hash_table_replace (_count_table, (gpointer)G_OBJECT_TYPE (obj), GUINT_TO_POINTER (--count));
|
|
Packit |
3ff832 |
g_debug ("Finalize %s, count = %d, all = %d", G_OBJECT_TYPE_NAME (obj), count, _count);
|
|
Packit |
3ff832 |
#endif
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
G_OBJECT_CLASS(ibus_object_parent_class)->finalize (G_OBJECT (obj));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static void
|
|
Packit |
3ff832 |
ibus_object_real_destroy (IBusObject *obj)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_signal_handlers_destroy (obj);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
IBusObject *
|
|
Packit |
3ff832 |
ibus_object_new (void)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
GObject *object = g_object_new (IBUS_TYPE_OBJECT, NULL);
|
|
Packit |
3ff832 |
return IBUS_OBJECT (object);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void
|
|
Packit |
3ff832 |
ibus_object_destroy (IBusObject *obj)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_return_if_fail (IBUS_IS_OBJECT (obj));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (! (IBUS_OBJECT_FLAGS (obj) & IBUS_IN_DESTRUCTION)) {
|
|
Packit |
3ff832 |
g_object_run_dispose (G_OBJECT (obj));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
}
|