removing now unneeded dir from package
[drnoksnes] / platform / osso.cpp
index 38128d9..010c11d 100644 (file)
@@ -15,6 +15,19 @@ static GMainContext *mainContext;
 static GMainLoop *mainLoop;
 osso_context_t *ossoContext;
 
+// Older versions of glib don't have this.
+#ifndef g_warn_if_fail
+#define g_warn_if_fail(expr) \
+       if G_UNLIKELY(expr) { \
+               g_warning("Non critical assertion failed at %s:%d \"%s\"", \
+                       __FILE__, __LINE__, #expr); \
+       }
+#endif
+#if ! GLIB_CHECK_VERSION(2,14,0)
+#define g_timeout_add_seconds(interval, function, data) \
+       g_timeout_add((interval) * 1000, function, data)
+#endif
+
 static volatile enum {
        STARTUP_COMMAND_INVALID = -1,
        STARTUP_COMMAND_UNKNOWN = 0,
@@ -66,6 +79,16 @@ static gint ossoAppCallback(const gchar *interface, const gchar *method,
        return OSSO_OK;
 }
 
+static gboolean ossoTimeoutCallback(gpointer data)
+{
+       if (startupCommand == STARTUP_COMMAND_UNKNOWN) {
+               // Assume that after N seconds we're not going to get a startup reason.
+               startupCommand = STARTUP_COMMAND_INVALID;
+       }
+
+       return FALSE; // This is a timeout, don't call us ever again.
+}
+
 static void ossoHwCallback(osso_hw_state_t *state, gpointer data)
 {
        if (state->shutdown_ind) {
@@ -223,6 +246,12 @@ void OssoConfig()
                createActionMappingsOnly();
        }
 
+       // Time to read the startup command from D-Bus
+
+       // Timeout after 3 seconds, and assume we didn't receive any.
+       guint timeout = g_timeout_add_seconds(3, ossoTimeoutCallback, 0);
+       g_warn_if_fail(timeout > 0);
+
        // Iterate the event loop since we want to catch the initial dbus messages
        while (startupCommand == STARTUP_COMMAND_UNKNOWN) {
                // This is not busylooping since we are blocking here
@@ -262,7 +291,7 @@ void OssoPollEvents()
 {
        if (!OssoOk()) return;
 
-       //g_main_context_iteration(mainContext, FALSE);
+       g_main_context_iteration(mainContext, FALSE);
 }
 
 typedef struct ButtonEntry {