ibus-daemon: use GFileMonitor instead of polling
[platform/upstream/ibus.git] / bus / main.c
index 5d43dd1..791a524 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 #include <config.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <fcntl.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <locale.h>
-#include <signal.h>
 #include <glib.h>
 #include <gio/gio.h>
 #include <ibus.h>
-#include "server.h"
-#include "ibusimpl.h"
+#include <locale.h>
+#include <pwd.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
-gchar **g_argv = NULL;
+#include "global.h"
+#include "ibusimpl.h"
+#include "server.h"
 
 static gboolean daemonize = FALSE;
 static gboolean single = FALSE;
@@ -44,14 +44,6 @@ static gboolean restart = FALSE;
 static gchar *panel = "default";
 static gchar *config = "default";
 static gchar *desktop = "gnome";
-gchar *g_address = "unix:tmpdir=/tmp";
-gchar *g_cache = "auto";
-gboolean g_mempro = FALSE;
-gboolean g_verbose = FALSE;
-gint   g_dbus_timeout = 5000;
-#ifdef G_THREADS_ENABLED
-gint   g_monitor_timeout = 0;
-#endif
 
 static void
 show_version_and_quit (void)
@@ -72,10 +64,7 @@ static const GOptionEntry entries[] =
     { "address",   'a', 0, G_OPTION_ARG_STRING, &g_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 },
     { "cache",     't', 0, G_OPTION_ARG_STRING, &g_cache,   "specify the cache mode. [auto/refresh/none]", NULL },
-    { "timeout",   'o', 0, G_OPTION_ARG_INT,    &g_dbus_timeout, "dbus reply timeout in milliseconds.", "timeout [default is 2000]" },
-#ifdef G_THREADS_ENABLED
-    { "monitor-timeout", 'j', 0, G_OPTION_ARG_INT,    &g_monitor_timeout, "timeout of poll changes of engines in seconds. 0 to disable it. ", "timeout [default is 0]" },
-#endif
+    { "timeout",   'o', 0, G_OPTION_ARG_INT,    &g_gdbus_timeout, "gdbus reply timeout in milliseconds. pass -1 to use the default timeout of gdbus.", "timeout [default is 5000]" },
     { "mem-profile", 'm', 0, G_OPTION_ARG_NONE,   &g_mempro,   "enable memory profile, send SIGUSR2 to print out the memory profile.", NULL },
     { "restart",     'R', 0, G_OPTION_ARG_NONE,   &restart,    "restart panel and config processes when they die.", NULL },
     { "verbose",   'v', 0, G_OPTION_ARG_NONE,   &g_verbose,   "verbose.", NULL },
@@ -190,6 +179,10 @@ main (gint argc, gchar **argv)
        g_error_free (error);
         exit (-1);
     }
+    if (g_gdbus_timeout < -1) {
+        g_printerr ("Bad timeout (must be >= -1): %d\n", g_gdbus_timeout);
+        exit (-1);
+    }
 
     if (g_mempro) {
         g_mem_set_vtable (glib_mem_profiler_table);
@@ -247,12 +240,12 @@ main (gint argc, gchar **argv)
     if (!single) {
         /* execute config component */
         if (g_strcmp0 (config, "default") == 0) {
-            IBusComponent *component;
+            BusComponent *component;
             component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_CONFIG);
             if (component) {
-                ibus_component_set_restart (component, restart);
+                bus_component_set_restart (component, restart);
             }
-            if (component == NULL || !ibus_component_start (component, g_verbose)) {
+            if (component == NULL || !bus_component_start (component, g_verbose)) {
                 g_printerr ("Can not execute default config program\n");
                 exit (-1);
             }
@@ -263,12 +256,12 @@ main (gint argc, gchar **argv)
 
         /* execute panel component */
         if (g_strcmp0 (panel, "default") == 0) {
-            IBusComponent *component;
+            BusComponent *component;
             component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_PANEL);
             if (component) {
-                ibus_component_set_restart (component, restart);
+                bus_component_set_restart (component, restart);
             }
-            if (component == NULL || !ibus_component_start (component, g_verbose)) {
+            if (component == NULL || !bus_component_start (component, g_verbose)) {
                 g_printerr ("Can not execute default panel program\n");
                 exit (-1);
             }