Added support for pausing Panucci
[headphoned] / src / headphoned.c
index 0279237..2daaf69 100644 (file)
@@ -17,6 +17,7 @@
 #include <glib.h>
 #include <gconf/gconf-client.h>
 #include <libosso.h>
+#include <dbus/dbus.h>
 
 #define STATE_FILE "/sys/devices/platform/gpio-switch/headphone/state"
 #define STATE_CONNECTED_STR "connected"
 #define MEDIA_SERVER_PATH "/com/nokia/osso_media_server"
 #define MEDIA_SERVER_INTF "com.nokia.osso_media_server.music"
 
+#define PANUCCI_SRVC "org.panucci.panucciInterface"
+#define PANUCCI_PATH "/panucciInterface"
+#define PANUCCI_INTF "org.panucci.panucciInterface"
+
 // Volume control is currently broken, as something is messing
 // with the controls from outside this process in GConf..
 //#define ENABLE_VOLUME_CONTROL
@@ -38,6 +43,7 @@ enum { STATE_UNKNOWN, STATE_CONNECTED, STATE_DISCONNECTED, STATE_COUNT };
 
 typedef struct {
        GConfClient* client;
+       DBusConnection* session_bus;
        osso_context_t* osso;
        guint state;
        gint volume[STATE_COUNT];
@@ -69,6 +75,8 @@ headphoned_new()
        gconf_client_notify_add(this->client, GCONF_VOLUME_CONTROL,
                        on_volume_changed, this, NULL, NULL);
 #endif
+
+       this->session_bus = dbus_bus_get(DBUS_BUS_SESSION, NULL);
        this->initial = TRUE;
 
        return this;
@@ -93,6 +101,7 @@ on_file_changed(GIOChannel* source, GIOCondition condition, gpointer data)
                headphoned->state = STATE_DISCONNECTED;
 #ifdef ENABLE_PAUSE_ON_DISCONNECT
                if (headphoned->initial == FALSE) {
+                       /* Nokia Media Player */
                        osso_rpc_run(headphoned->osso,
                                        MEDIA_SERVER_SRVC,
                                        MEDIA_SERVER_PATH,
@@ -100,6 +109,19 @@ on_file_changed(GIOChannel* source, GIOCondition condition, gpointer data)
                                        "pause",
                                        NULL,
                                        DBUS_TYPE_INVALID);
+
+                       /* Panucci */
+                       if (dbus_bus_name_has_owner(headphoned->session_bus,
+                                                       PANUCCI_SRVC,
+                                                       NULL)) {
+                               osso_rpc_run(headphoned->osso,
+                                               PANUCCI_SRVC,
+                                               PANUCCI_PATH,
+                                               PANUCCI_INTF,
+                                               "pause",
+                                               NULL,
+                                               DBUS_TYPE_INVALID);
+                       }
                }
 #endif
        }