Make main loop setupable.
authorPeng Huang <shawn.p.huang@gmail.com>
Thu, 30 Apr 2009 03:09:41 +0000 (11:09 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Thu, 30 Apr 2009 03:09:41 +0000 (11:09 +0800)
src/Makefile.am
src/ibus.h
src/ibusconnection.c
src/ibusmainloop.c [new file with mode: 0644]
src/ibusmainloop.h [new file with mode: 0644]
src/ibusserver.c

index 9b3eafe..45da441 100644 (file)
@@ -67,6 +67,7 @@ ibus_public_h_sources = \
        ibusenginedesc.h \
        ibusobservedpath.h \
        ibuscomponent.h \
+       ibusmainloop.h \
        $(NULL)
 ibus_h_sources = \
        ibusinternal.h \
@@ -102,6 +103,7 @@ ibus_c_sources = \
        ibusenginedesc.c \
        ibusobservedpath.c \
        ibuscomponent.c \
+       ibusmainloop.c \
        $(NULL)
 ibusincludedir = $(includedir)/ibus-1.0
 ibusinclude_HEADERS = \
index 23b270a..03c7312 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef __IBUS_H_
 #define __IBUS_H_
 
+#include <ibusmainloop.h>
 #include <ibusshare.h>
 #include <ibusobject.h>
 #include <ibusserializable.h>
index 6d0be92..6859055 100644 (file)
@@ -370,7 +370,7 @@ ibus_connection_set_connection (IBusConnection *connection, DBusConnection *dbus
                     (DBusHandleMessageFunction) _connection_handle_message_cb,
                     connection, NULL);
 
-    dbus_connection_setup (priv->connection, NULL);
+    ibus_dbus_connection_setup (priv->connection);
     g_warn_if_fail (result);
 }
 
diff --git a/src/ibusmainloop.c b/src/ibusmainloop.c
new file mode 100644 (file)
index 0000000..581380c
--- /dev/null
@@ -0,0 +1,50 @@
+/* vim:set et sts=4: */
+/* ibus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "ibusmainloop.h"
+#include "ibusinternal.h"
+
+static DBusConnectionSetupFunc _connection_setup_func = dbus_connection_setup;
+static DBusServerSetupFunc _server_setup_func = dbus_server_setup;
+static gpointer _user_data = NULL;
+
+void
+ibus_mainloop_setup (DBusConnectionSetupFunc connection_func,
+                     DBusServerSetupFunc     server_func,
+                     gpointer                user_data)
+{
+    _connection_setup_func = connection_func;
+    _server_setup_func = server_func;
+    _user_data = user_data;
+}
+
+void
+ibus_dbus_connection_setup (DBusConnection *connection)
+{
+    if (_connection_setup_func != NULL)
+        (_connection_setup_func) (connection, _user_data);
+}
+
+void
+ibus_dbus_server_setup (DBusServer *server)
+{
+    if (_server_setup_func != NULL)
+        (_server_setup_func) (server, _user_data);
+}
+
diff --git a/src/ibusmainloop.h b/src/ibusmainloop.h
new file mode 100644 (file)
index 0000000..c622a75
--- /dev/null
@@ -0,0 +1,38 @@
+/* vim:set et sts=4: */
+/* ibus - The Input Bus
+ * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __IBUS_MAINLOOP_H_
+#define __IBUS_MAINLOOP_H_
+
+#include <glib.h>
+#include <dbus/dbus.h>
+
+typedef void (* DBusConnectionSetupFunc)    (DBusConnection *connection,
+                                             gpointer        user_data);
+typedef void (* DBusServerSetupFunc)        (DBusServer     *server,
+                                             gpointer        user_data);
+
+void    ibus_mainloop_setup         (DBusConnectionSetupFunc      connection_func,
+                                     DBusServerSetupFunc          server_func,
+                                     gpointer                     user_data);
+void    ibus_dbus_server_setup      (DBusServer                  *server);
+void    ibus_dbus_connection_setup  (DBusConnection              *connection);
+
+#endif
+
index 0c3ee8b..bc41482 100644 (file)
@@ -265,7 +265,7 @@ ibus_server_listen_internal (IBusServer  *server,
 
     dbus_server_set_auth_mechanisms (priv->server, NULL);
 
-    dbus_server_setup (priv->server, NULL);
+    ibus_dbus_server_setup (priv->server);
     return TRUE;
 }