Add verbose argument for ibus_component_start function 1.1.0.20090531
authorPeng Huang <shawn.p.huang@gmail.com>
Sun, 31 May 2009 03:13:11 +0000 (11:13 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Sun, 31 May 2009 03:13:11 +0000 (11:13 +0800)
Do not use g_usleep

bus/ibusimpl.c
bus/main.c
src/ibuscomponent.c
src/ibuscomponent.h

index 9baf74f..77a0fe5 100644 (file)
@@ -64,6 +64,8 @@ static void     _factory_destroy_cb             (BusFactoryProxy      *factory,
 
 static IBusServiceClass  *parent_class = NULL;
 
+extern gboolean g_verbose;
+
 GType
 bus_ibus_impl_get_type (void)
 {
@@ -233,7 +235,7 @@ bus_ibus_impl_set_preload_engines (BusIBusImpl *ibus,
 
         component = ibus_component_get_from_engine ((IBusEngineDesc *) ibus->engine_list->data);
         if (component && !ibus_component_is_running (component)) {
-            ibus_component_start (component);
+            ibus_component_start (component, g_verbose);
         }
     }
 }
@@ -616,6 +618,7 @@ bus_ibus_impl_create_engine (IBusEngineDesc *engine_desc)
     IBusComponent *comp;
     BusFactoryProxy *factory;
     BusEngineProxy *engine;
+    GTimeVal t1, t2;
 
     factory = bus_factory_proxy_get_from_engine (engine_desc);
 
@@ -625,24 +628,26 @@ bus_ibus_impl_create_engine (IBusEngineDesc *engine_desc)
         g_assert (comp);
 
         if (!ibus_component_is_running (comp)) {
-            ibus_component_start (comp);
+            ibus_component_start (comp, g_verbose);
 
             gint time = 0;
-            while (time < G_USEC_PER_SEC * 3) {
+            g_get_current_time (&t1);
+            while (1) {
                 if (g_main_context_pending (NULL)) {
                     g_main_context_iteration (NULL, FALSE);
+                    factory = bus_factory_proxy_get_from_engine (engine_desc);
+                    if (factory != NULL) {
+                        break;
+                    }
                 }
-                else {
-                    g_usleep (50 * 1000);
-                    time += 50 * 1000;
-                }
-                factory = bus_factory_proxy_get_from_engine (engine_desc);
-                if (factory != NULL) {
+                g_get_current_time (&t2);
+                if (t2.tv_sec - t1.tv_sec >= 5)
                     break;
-                }
             }
         }
-        factory = bus_factory_proxy_get_from_engine (engine_desc);
+        else {
+            factory = bus_factory_proxy_get_from_engine (engine_desc);
+        }
     }
 
     if (factory == NULL) {
index ab4786e..2e227ea 100644 (file)
@@ -39,7 +39,7 @@ static gchar *config = "default";
 static gchar *desktop = "gnome";
 static gchar *address = "";
 gboolean g_rescan = FALSE;
-static gboolean verbose = FALSE;
+gboolean g_verbose = FALSE;
 
 static const GOptionEntry entries[] =
 {
@@ -52,7 +52,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 },
-    { "verbose",   'v', 0, G_OPTION_ARG_NONE,   &verbose,   "verbose.", NULL },
+    { "verbose",   'v', 0, G_OPTION_ARG_NONE,   &g_verbose,   "verbose.", NULL },
     { NULL },
 };
 
@@ -138,7 +138,7 @@ _my_log_handler (const gchar    *log_domain,
                  const gchar    *message,
                  gpointer        user_data)
 {
-    if (verbose) {
+    if (g_verbose) {
         g_log_default_handler (log_domain, log_level, message, user_data);
     }
 }
@@ -219,7 +219,7 @@ main (gint argc, gchar **argv)
         if (g_strcmp0 (config, "default") == 0) {
             IBusComponent *component;
             component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_CONFIG);
-            if (component == NULL || !ibus_component_start (component)) {
+            if (component == NULL || !ibus_component_start (component, g_verbose)) {
                 g_printerr ("Can not execute default config program\n");
                 exit (-1);
             }
@@ -232,7 +232,7 @@ main (gint argc, gchar **argv)
         if (g_strcmp0 (panel, "default") == 0) {
             IBusComponent *component;
             component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_PANEL);
-            if (component == NULL || !ibus_component_start (component)) {
+            if (component == NULL || !ibus_component_start (component, g_verbose)) {
                 g_printerr ("Can not execute default panel program\n");
                 exit (-1);
             }
index a3fca11..cb5bf32 100644 (file)
@@ -656,7 +656,7 @@ ibus_component_child_cb (GPid            pid,
 }
 
 gboolean
-ibus_component_start (IBusComponent *component)
+ibus_component_start (IBusComponent *component, gboolean verbose)
 {
     g_assert (IBUS_IS_COMPONENT (component));
 
@@ -667,6 +667,7 @@ ibus_component_start (IBusComponent *component)
     gchar **argv;
     gboolean retval;
     GError *error;
+    GSpawnFlags flags;
 
     error = NULL;
     if (!g_shell_parse_argv (component->exec, &argc, &argv, &error)) {
@@ -676,8 +677,12 @@ ibus_component_start (IBusComponent *component)
     }
 
     error = NULL;
+    flags = G_SPAWN_DO_NOT_REAP_CHILD;
+    if (!verbose) {
+        flags |= G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL;
+    }
     retval = g_spawn_async (NULL, argv, NULL,
-                            G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
+                            flags,
                             NULL, NULL,
                             &(component->pid), &error);
     g_strfreev (argv)
index 18a9f06..b737d1d 100644 (file)
@@ -227,11 +227,13 @@ gboolean         ibus_component_check_modification
 /**
  * ibus_component_start:
  * @component: An IBusComponent.
+ * @verbose: if redirect the child output to /dev/null
  * @returns: TRUE if the component is started; FALSE otherwise.
  *
  * Whether the IBusComponent is started.
  */
-gboolean         ibus_component_start           (IBusComponent  *component);
+gboolean         ibus_component_start           (IBusComponent  *component,
+                                                 gboolean        verbose);
 
 /**
  * ibus_component_stop: