From cb57c882840036ccc2d357e5cdd8a4d58db40f9f Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Thu, 30 Apr 2009 11:09:41 +0800 Subject: [PATCH] Make main loop setupable. --- src/Makefile.am | 2 ++ src/ibus.h | 1 + src/ibusconnection.c | 2 +- src/ibusmainloop.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/ibusmainloop.h | 38 ++++++++++++++++++++++++++++++++++++++ src/ibusserver.c | 2 +- 6 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/ibusmainloop.c create mode 100644 src/ibusmainloop.h diff --git a/src/Makefile.am b/src/Makefile.am index 9b3eafe..45da441 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 = \ diff --git a/src/ibus.h b/src/ibus.h index 23b270a..03c7312 100644 --- a/src/ibus.h +++ b/src/ibus.h @@ -20,6 +20,7 @@ #ifndef __IBUS_H_ #define __IBUS_H_ +#include #include #include #include diff --git a/src/ibusconnection.c b/src/ibusconnection.c index 6d0be92..6859055 100644 --- a/src/ibusconnection.c +++ b/src/ibusconnection.c @@ -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 index 0000000..581380c --- /dev/null +++ b/src/ibusmainloop.c @@ -0,0 +1,50 @@ +/* vim:set et sts=4: */ +/* ibus - The Input Bus + * Copyright (C) 2008-2009 Huang Peng + * + * 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 index 0000000..c622a75 --- /dev/null +++ b/src/ibusmainloop.h @@ -0,0 +1,38 @@ +/* vim:set et sts=4: */ +/* ibus - The Input Bus + * Copyright (C) 2008-2009 Huang Peng + * + * 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 +#include + +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 + diff --git a/src/ibusserver.c b/src/ibusserver.c index 0c3ee8b..bc41482 100644 --- a/src/ibusserver.c +++ b/src/ibusserver.c @@ -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; } -- 2.7.4