From 8d630d2c1725264056adf0a07683cff5035536ad Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Sat, 3 Oct 2009 10:11:59 +0800 Subject: [PATCH] Add --timeout option. --- bus/Makefile.am | 3 ++- bus/engineproxy.c | 22 ++++++++++++++++++---- bus/factoryproxy.c | 13 ++++++++++--- bus/ibusimpl.c | 4 +--- bus/main.c | 2 ++ bus/option.h | 32 ++++++++++++++++++++++++++++++++ bus/registry.c | 3 +-- 7 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 bus/option.h diff --git a/bus/Makefile.am b/bus/Makefile.am index 7728b50e..0d7d5c6a 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -81,6 +81,7 @@ ibus_daemon_SOURCES = \ matchrule.h \ registry.c \ registry.h \ + option.h \ $(NULL) ibus_daemon_CFLAGS = \ $(AM_CFLAGS) \ @@ -115,4 +116,4 @@ $(libibus): $(MAKE) -C $(top_builddir)/src test: ibus-daemon - $(builddir)/ibus-daemon + $(builddir)/ibus-daemon -v diff --git a/bus/engineproxy.c b/bus/engineproxy.c index a16cabfc..e36822f0 100644 --- a/bus/engineproxy.c +++ b/bus/engineproxy.c @@ -22,8 +22,7 @@ #include #include "ibusimpl.h" #include "engineproxy.h" - -#define PROCESS_KEY_EVENT_TIMEOUT (10000) +#include "option.h" enum { COMMIT_TEXT, @@ -528,7 +527,8 @@ failed: typedef struct { GFunc func; gpointer user_data; -}CallData; + BusEngineProxy *engine; +} CallData; static void bus_engine_proxy_process_key_event_reply_cb (IBusPendingCall *pending, @@ -541,9 +541,19 @@ bus_engine_proxy_process_key_event_reply_cb (IBusPendingCall *pending, reply_message = dbus_pending_call_steal_reply (pending); if (reply_message == NULL) { + /* reply timeout */ + IBusObject *connection; + connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)call_data->engine); + ibus_object_destroy (connection); goto _out; } else if ((error = ibus_error_new_from_message (reply_message)) != NULL) { + if (g_strcmp0 (error->name, DBUS_ERROR_NO_REPLY) == 0) { + /* reply timeout */ + IBusObject *connection; + connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)call_data->engine); + ibus_object_destroy (connection); + } g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); goto _out; @@ -562,6 +572,7 @@ _out: if (reply_message) { ibus_message_unref (reply_message); } + g_object_unref (call_data->engine); call_data->func (GINT_TO_POINTER (retval), call_data->user_data); g_slice_free (CallData, call_data); } @@ -592,7 +603,7 @@ bus_engine_proxy_process_key_event (BusEngineProxy *engine, retval = ibus_proxy_call_with_reply ((IBusProxy *) engine, "ProcessKeyEvent", &pending, - PROCESS_KEY_EVENT_TIMEOUT, + g_dbus_timeout, &error, G_TYPE_UINT, &keyval, G_TYPE_UINT, &keycode, @@ -608,6 +619,8 @@ bus_engine_proxy_process_key_event (BusEngineProxy *engine, call_data = g_slice_new0 (CallData); call_data->func = return_cb; call_data->user_data = user_data; + g_object_ref (engine); + call_data->engine = engine; retval = ibus_pending_call_set_notify (pending, (IBusPendingCallNotifyFunction) bus_engine_proxy_process_key_event_reply_cb, @@ -616,6 +629,7 @@ bus_engine_proxy_process_key_event (BusEngineProxy *engine, ibus_pending_call_unref (pending); if (!retval) { + g_object_unref (call_data->engine); g_slice_free (CallData, call_data); g_warning ("%s : ProcessKeyEvent", DBUS_ERROR_NO_MEMORY); return_cb (GINT_TO_POINTER (FALSE), user_data); diff --git a/bus/factoryproxy.c b/bus/factoryproxy.c index 373999e6..6470679c 100644 --- a/bus/factoryproxy.c +++ b/bus/factoryproxy.c @@ -22,8 +22,7 @@ #include #include "dbusimpl.h" #include "factoryproxy.h" - -#define REPLY_TIMEOUT (-1) +#include "option.h" /* functions prototype */ static void bus_factory_proxy_class_init (BusFactoryProxyClass *klass); @@ -188,7 +187,7 @@ bus_factory_proxy_create_engine (BusFactoryProxy *factory, retval = ibus_proxy_call_with_reply ((IBusProxy *) factory, "CreateEngine", &pending, - REPLY_TIMEOUT, + g_dbus_timeout, &error, G_TYPE_STRING, &(desc->name), G_TYPE_INVALID); @@ -204,12 +203,20 @@ bus_factory_proxy_create_engine (BusFactoryProxy *factory, ibus_pending_call_unref (pending); if (reply_message == NULL) { + IBusObject *connection; + connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)factory); + ibus_object_destroy (connection); g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); return NULL; } if ((error = ibus_error_new_from_message (reply_message)) != NULL) { + if (g_strcmp0 (error->name, DBUS_ERROR_NO_REPLY) == 0) { + IBusObject *connection; + connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)factory); + ibus_object_destroy (connection); + } g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply_message); diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c index fa1ff855..70729037 100644 --- a/bus/ibusimpl.c +++ b/bus/ibusimpl.c @@ -33,7 +33,7 @@ #include "factoryproxy.h" #include "panelproxy.h" #include "inputcontext.h" - +#include "option.h" enum { LAST_SIGNAL, @@ -67,8 +67,6 @@ static void _factory_destroy_cb (BusFactoryProxy *factory, static IBusServiceClass *parent_class = NULL; -extern gboolean g_verbose; - GType bus_ibus_impl_get_type (void) { diff --git a/bus/main.c b/bus/main.c index 928c0346..d965e1ea 100644 --- a/bus/main.c +++ b/bus/main.c @@ -42,6 +42,7 @@ static gchar *address = ""; gboolean g_rescan = FALSE; gboolean g_mempro = FALSE; gboolean g_verbose = FALSE; +gint g_dbus_timeout = -1; static const GOptionEntry entries[] = { @@ -54,6 +55,7 @@ static const GOptionEntry entries[] = { "address", 'a', 0, G_OPTION_ARG_STRING, &address, "specify the address of ibus daemon.", "address" }, { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "if there is an old ibus-daemon is running, it will be replaced.", NULL }, { "re-scan", 't', 0, G_OPTION_ARG_NONE, &g_rescan, "force to re-scan components, and re-create registry cache.", NULL }, + { "timeout", 'o', 0, G_OPTION_ARG_INT, &g_dbus_timeout, "dbus reply timeout", "timeout" }, { "mem-profile", 'm', 0, G_OPTION_ARG_NONE, &g_mempro, "enable memory profile, send SIGUSR2 to print out the memory profile.", NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &g_verbose, "verbose.", NULL }, { NULL }, diff --git a/bus/option.h b/bus/option.h new file mode 100644 index 00000000..aed8a7fe --- /dev/null +++ b/bus/option.h @@ -0,0 +1,32 @@ +/* vim:set et sts=4: */ +/* bus - 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 __OPTION_H_ +#define __OPTION_H_ + +G_BEGIN_DECLS + +extern gboolean g_rescan; +extern gboolean g_mempro; +extern gboolean g_verbose; +extern gint g_dbus_timeout; + +G_END_DECLS +#endif + diff --git a/bus/registry.c b/bus/registry.c index 65488da5..e931ad43 100644 --- a/bus/registry.c +++ b/bus/registry.c @@ -22,6 +22,7 @@ #include #include #include "registry.h" +#include "option.h" enum { LAST_SIGNAL, @@ -89,8 +90,6 @@ bus_registry_init (BusRegistry *registry) registry->components = NULL; registry->engine_table = g_hash_table_new (g_str_hash, g_str_equal); - extern gboolean g_rescan; - if (g_rescan || bus_registry_load_cache (registry) == FALSE || bus_registry_check_modification (registry)) { -- 2.34.1