Add support for pausing MPlayer
[headphoned] / src / headphoned.c
index 0279237..adfdf55 100644 (file)
@@ -17,6 +17,8 @@
 #include <glib.h>
 #include <gconf/gconf-client.h>
 #include <libosso.h>
+#include <dbus/dbus.h>
+#include <fcntl.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"
+
+#define MPLAYER_FIFO "/etc/headphoned/mplayer-input"
+
 // Volume control is currently broken, as something is messing
 // with the controls from outside this process in GConf..
 //#define ENABLE_VOLUME_CONTROL
@@ -38,6 +46,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 +78,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;
@@ -82,6 +93,7 @@ on_file_changed(GIOChannel* source, GIOCondition condition, gpointer data)
        gint volume = headphoned->volume[headphoned->state];
 #endif
        gchar* result;
+       int mplayer_fifo;
 
        g_io_channel_seek_position(source, 0, G_SEEK_SET, NULL);
        g_io_channel_read_line(source, &result, NULL, NULL, NULL);
@@ -93,6 +105,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 +113,26 @@ 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);
+                       }
+
+                       /* MPlayer */
+                       if ((mplayer_fifo = open(MPLAYER_FIFO,
+                                               O_WRONLY | O_NONBLOCK)) != -1) {
+                               write(mplayer_fifo, "pause\n", 6);
+                               close(mplayer_fifo);
+                       }
                }
 #endif
        }