[Xfce4-commits] <parole:master> Exit after 60 seconds of inactivity on the browser plugin to avoid any zombie process. Please enter the commit message for your changes.

Ali Abdallah noreply at xfce.org
Wed Nov 25 17:34:01 CET 2009


Updating branch refs/heads/master
         to 24d93ed1a3b0e1a873bf07de5277589eb4930960 (commit)
       from 4f346ff0919050d3467cb3743b5e0b8d65365ede (commit)

commit 24d93ed1a3b0e1a873bf07de5277589eb4930960
Author: Ali Abdallah <ali at ali-xfce.org>
Date:   Wed Nov 25 17:29:48 2009 +0100

    Exit after 60 seconds of inactivity on the browser plugin to avoid
    any zombie process. Please enter the commit message for your changes.

 browser-plugin/media-plugin/main.c                 |    1 +
 .../media-plugin/org.parole.media.plugin.xml       |    3 +
 browser-plugin/media-plugin/parole-plugin-player.c |   58 ++++++++++++++++++--
 browser-plugin/plugin.cpp                          |   26 +++++++++-
 browser-plugin/plugin.h                            |    1 +
 5 files changed, 83 insertions(+), 6 deletions(-)

diff --git a/browser-plugin/media-plugin/main.c b/browser-plugin/media-plugin/main.c
index a3a8761..9004474 100644
--- a/browser-plugin/media-plugin/main.c
+++ b/browser-plugin/media-plugin/main.c
@@ -132,6 +132,7 @@ int main (int argc, char **argv)
     parole_plugin_player_play (player);
     
     gtk_main ();
+    g_object_unref (player);
     gtk_widget_destroy (plug);
     parole_dbus_release_name (dbus_name);
     g_free (dbus_name);
diff --git a/browser-plugin/media-plugin/org.parole.media.plugin.xml b/browser-plugin/media-plugin/org.parole.media.plugin.xml
index 62bd80d..de8762a 100644
--- a/browser-plugin/media-plugin/org.parole.media.plugin.xml
+++ b/browser-plugin/media-plugin/org.parole.media.plugin.xml
@@ -10,6 +10,9 @@
     
     <method name="Stop">
     </method>
+
+    <method name="Ping">
+    </method>
     
     </interface>
 </node>
diff --git a/browser-plugin/media-plugin/parole-plugin-player.c b/browser-plugin/media-plugin/parole-plugin-player.c
index 72379ad..a75edd4 100644
--- a/browser-plugin/media-plugin/parole-plugin-player.c
+++ b/browser-plugin/media-plugin/parole-plugin-player.c
@@ -58,6 +58,9 @@ static void parole_plugin_player_get_property (GObject *object,
 #define PAROLE_PLUGIN_PLAYER_GET_PRIVATE(o) \
 (G_TYPE_INSTANCE_GET_PRIVATE ((o), PAROLE_TYPE_PLUGINPLAYER, ParolePluginPlayerPrivate))
 
+static GTimer *idle_timer = NULL;
+static GThread *idle_thread = NULL;
+
 struct ParolePluginPlayerPrivate
 {
     ParoleGst    *gst;
@@ -275,11 +278,6 @@ parole_plugin_player_media_state_cb (ParoleGst *gst, const ParoleStream *stream,
     {
 	if ( player->priv->terminate )
 	{
-	    if ( player )
-	    {
-		g_object_unref (player);
-		player = NULL;
-	    }
 	    gtk_main_quit ();
 	}
 	parole_plugin_player_change_range_value (player, 0);
@@ -630,6 +628,28 @@ parole_plugin_player_window_delete_event_cb (ParolePluginPlayer *player)
     return TRUE;
 }
 
+static gpointer *check_idle_thread (gpointer data)
+{
+    ParolePluginPlayer *player;
+    
+    player = PAROLE_PLUGIN_PLAYER (data);
+    
+    do
+    {
+	g_usleep (1000000);
+	if ( g_timer_elapsed (idle_timer, NULL ) > 60.f )
+	{
+	    g_debug ("Idle timeout expired, exiting...");
+	    g_debug ("Here");
+	    gtk_main_quit ();
+	    g_debug ("Yalla");
+	}
+	
+    } while ( player->priv->terminate == FALSE ); 
+
+    return NULL;
+}
+
 static void
 parole_plugin_player_class_init (ParolePluginPlayerClass *klass)
 {
@@ -667,6 +687,8 @@ parole_plugin_player_class_init (ParolePluginPlayerClass *klass)
 static void
 parole_plugin_player_init (ParolePluginPlayer *player)
 {
+    GError *error = NULL;
+    
     player->priv = PAROLE_PLUGIN_PLAYER_GET_PRIVATE (player);
     
     player->priv->gst  = NULL;
@@ -692,7 +714,18 @@ parole_plugin_player_init (ParolePluginPlayer *player)
 		      G_CALLBACK (parole_plugin_player_window_key_press_cb), player);
     
     
+    idle_timer = g_timer_new ();
+    idle_thread = g_thread_create ((GThreadFunc)check_idle_thread, player, FALSE, &error);
+    
+    if ( error )
+    {
+        g_warning ("%s", error->message);
+	g_error_free (error);
+    }
+
+    
     parole_plugin_player_dbus_init (player);
+    
 }
 
 static void parole_plugin_player_set_property (GObject *object,
@@ -811,6 +844,9 @@ static gboolean parole_plugin_player_dbus_quit (ParolePluginPlayer *player,
 static gboolean parole_plugin_player_dbus_stop (ParolePluginPlayer *player,
 						GError **error);
 
+static gboolean parole_plugin_player_dbus_ping (ParolePluginPlayer *player,
+						GError **error);
+
 #include "org.parole.media.plugin.h"
 
 /*
@@ -852,3 +888,15 @@ parole_plugin_player_dbus_stop (ParolePluginPlayer *player, GError **error)
     
     return TRUE;
 }
+
+static gboolean parole_plugin_player_dbus_ping (ParolePluginPlayer *player,
+						GError **error)
+{
+    g_debug ("Ping");
+    
+    if ( idle_timer )
+	g_timer_reset (idle_timer);
+	
+    return TRUE;
+}
+						
diff --git a/browser-plugin/plugin.cpp b/browser-plugin/plugin.cpp
index 8a873ab..3fe6603 100644
--- a/browser-plugin/plugin.cpp
+++ b/browser-plugin/plugin.cpp
@@ -120,7 +120,7 @@ void CPlugin::StopPlayer()
 	    else
 		break;
 	    
-	} while (num_tries  < 3 );
+	} while (num_tries  < 4 );
     }   
     
 }
@@ -129,6 +129,9 @@ CPlugin::~CPlugin()
 {
     g_debug ("Destructor");
     
+    if ( ping_id ) 
+	g_source_remove (ping_id);
+    
     StopPlayer ();
     
     if ( bus )
@@ -187,6 +190,20 @@ NPBool CPlugin::isInitialized()
     return mInitialized;
 }
 
+static gboolean
+ping_process (gpointer data)
+{
+    DBusGProxy *proxy;
+    
+    proxy = (DBusGProxy *) data;
+    
+    dbus_g_proxy_call (proxy, "Ping",
+		       G_TYPE_INVALID,
+		       G_TYPE_INVALID);
+		       
+    return TRUE;
+}
+
 void CPlugin::GetProxy ()
 {
     g_return_if_fail (proxy == NULL);
@@ -248,7 +265,9 @@ NPError CPlugin::NewStream(NPMIMEType type, NPStream * stream, NPBool seekable,
 	    g_error_free (error);
 	    return NPERR_GENERIC_ERROR;
 	}
+	
 	child_spawned = TRUE;
+	
 	g_free (socket);
 	g_free (app);
 	
@@ -260,6 +279,11 @@ NPError CPlugin::NewStream(NPMIMEType type, NPStream * stream, NPBool seekable,
 	    g_error_free (error);
 	    return NPERR_GENERIC_ERROR;
 	}
+	
+	GetProxy ();
+	if ( proxy )
+	    ping_id = g_timeout_add_seconds (5, (GSourceFunc) ping_process, proxy);
+	
     }
     return NPERR_NO_ERROR;
 }
diff --git a/browser-plugin/plugin.h b/browser-plugin/plugin.h
index dec40e9..f31f1e5 100644
--- a/browser-plugin/plugin.h
+++ b/browser-plugin/plugin.h
@@ -87,6 +87,7 @@ class CPlugin {
     gchar           *url;
     Window           window;
     GPid	     child_pid;
+    gulong	     ping_id;
     
   public:
     NPP mInstance;



More information about the Xfce4-commits mailing list