Replacing evil looping code

Bastien Nocera hadess at
Mon Nov 6 05:20:33 PST 2006


Right now, we have some evil code in Totem's browser plugin, and I'd
like to see whether it would be possible to replace it using something a
bit more stable.

Here's the code:
//Launch our binary with some special args
        if (g_spawn_async_with_pipes (NULL, argv, NULL,
                                      GSpawnFlags(0), NULL, NULL, &mPlayerPID,
                                      use_fd ? &mSendFD : NULL, NULL, NULL, &err) == FALSE)

//Set up a signal to know when the service name has started
        mWaitForSvc = g_strdup_printf
                ("org.totem_%d.MozillaPluginService", mPlayerPID);
        D("waiting for signal %s", mWaitForSvc);
        dbus_g_proxy_add_signal (mProxy, "NameOwnerChanged",
                                 G_TYPE_STRING, G_TYPE_STRING,
                                 G_TYPE_STRING, G_TYPE_INVALID);
        dbus_g_proxy_connect_signal (mProxy, "NameOwnerChanged",
                                     G_CALLBACK (NameOwnerChangedCallback),
                                     this, NULL);

//Evil crappy loop to wait for the service
        g_get_current_time (&then);
        g_time_val_add (&then, G_USEC_PER_SEC * 5);
        /* FIXME FIXME! this loop is evil! */
        do {
                g_main_context_iteration (NULL, TRUE);
                g_get_current_time (&now);
        } while (scriptable->IsValid () &&
                 !mGotSvc &&
                 (now.tv_sec <= then.tv_sec));

Is it possible to replace all that crap with decent D-Bus code?

I don't think we can use a service, as we're depending on some
command-line arguments (should we pass those to the service in some
other way instead?).

Any other ideas?


Bastien Nocera <hadess at>

More information about the dbus mailing list