[Xfce4-commits] <parole:master> Rework the way to shutdown the backend in the browser plugin.

Ali Abdallah noreply at xfce.org
Tue Nov 24 14:04:01 CET 2009


Updating branch refs/heads/master
         to d334dd46416008b13767c1cb1a9183002c161a6f (commit)
       from 630767eac71c35b6f4055f7b1ec322a65d7929c7 (commit)

commit d334dd46416008b13767c1cb1a9183002c161a6f
Author: Ali Abdallah <ali at ali-xfce.org>
Date:   Tue Nov 24 12:53:48 2009 +0100

    Rework the way to shutdown the backend in the browser plugin.

 .../media-plugin/org.parole.media.plugin.xml       |    2 +-
 browser-plugin/media-plugin/parole-plugin-player.c |   47 ++++++--
 browser-plugin/plugin.cpp                          |   82 ++++++++------
 browser-plugin/plugin.h                            |    1 +
 parole/parole.h                                    |   35 ------
 parole/parole.h.in                                 |  120 ++++++++++++++++++++
 6 files changed, 204 insertions(+), 83 deletions(-)

diff --git a/browser-plugin/media-plugin/org.parole.media.plugin.xml b/browser-plugin/media-plugin/org.parole.media.plugin.xml
index a83d6bf..62bd80d 100644
--- a/browser-plugin/media-plugin/org.parole.media.plugin.xml
+++ b/browser-plugin/media-plugin/org.parole.media.plugin.xml
@@ -8,7 +8,7 @@
     <method name="Quit">
     </method>
     
-    <method name="Terminate">
+    <method name="Stop">
     </method>
     
     </interface>
diff --git a/browser-plugin/media-plugin/parole-plugin-player.c b/browser-plugin/media-plugin/parole-plugin-player.c
index ab39d59..72379ad 100644
--- a/browser-plugin/media-plugin/parole-plugin-player.c
+++ b/browser-plugin/media-plugin/parole-plugin-player.c
@@ -275,7 +275,11 @@ parole_plugin_player_media_state_cb (ParoleGst *gst, const ParoleStream *stream,
     {
 	if ( player->priv->terminate )
 	{
-	    g_object_unref (player);
+	    if ( player )
+	    {
+		g_object_unref (player);
+		player = NULL;
+	    }
 	    gtk_main_quit ();
 	}
 	parole_plugin_player_change_range_value (player, 0);
@@ -499,8 +503,6 @@ parole_plugin_player_construct (GObject *object)
      */
     gstbox = gtk_hbox_new (TRUE, 0);
     
-    player->priv->gst = PAROLE_GST (parole_gst_new (TRUE, NULL));
-    
     gtk_box_pack_start (GTK_BOX (gstbox), GTK_WIDGET (player->priv->gst), TRUE, TRUE, 0);
     gtk_box_pack_start (GTK_BOX (vbox), gstbox, TRUE, TRUE, 0);
     
@@ -677,6 +679,8 @@ parole_plugin_player_init (ParolePluginPlayer *player)
     player->priv->internal_range_change = FALSE;
     player->priv->state = PAROLE_MEDIA_STATE_STOPPED;
     
+    player->priv->gst = PAROLE_GST (parole_gst_new (TRUE, NULL));
+    
     player->priv->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     gtk_window_set_keep_above (GTK_WINDOW (player->priv->window), TRUE);
     gtk_window_set_decorated (GTK_WINDOW (player->priv->window), FALSE);
@@ -736,25 +740,41 @@ parole_plugin_player_finalize (GObject *object)
 
     player = PAROLE_PLUGIN_PLAYER (object);
 
+    g_debug ("Finalize...");
+
     g_object_unref (player->priv->saver);
+    
+    if ( player->priv->url )
+	g_free (player->priv->url);
 
     G_OBJECT_CLASS (parole_plugin_player_parent_class)->finalize (object);
 }
 
 static gboolean
-parole_plugin_player_quit_idl (gpointer data)
+parole_plugin_player_quit_idle (gpointer data)
 {
     ParolePluginPlayer *player;
     
     player = PAROLE_PLUGIN_PLAYER (data);
     
-    player->priv->terminate = TRUE;
     parole_gst_terminate (player->priv->gst);
-    gtk_main_quit ();
     
     return FALSE;
 }
 
+static gboolean
+parole_plugin_player_stop_idle (gpointer data)
+{
+    ParolePluginPlayer *player;
+    
+    player = PAROLE_PLUGIN_PLAYER (data);
+    
+    if (player->priv->gst )
+	parole_gst_stop (player->priv->gst);
+	
+    return FALSE;
+}
+
 ParolePluginPlayer *
 parole_plugin_player_new (GtkWidget *plug, gchar *url)
 {
@@ -788,8 +808,8 @@ static gboolean parole_plugin_player_dbus_quit (ParolePluginPlayer *player,
 						GError **error);
 
 
-static gboolean parole_plugin_player_dbus_terminate (ParolePluginPlayer *player,
-						     GError **error);
+static gboolean parole_plugin_player_dbus_stop (ParolePluginPlayer *player,
+						GError **error);
 
 #include "org.parole.media.plugin.h"
 
@@ -818,14 +838,17 @@ parole_plugin_player_dbus_quit (ParolePluginPlayer *player,
 				GError **error)
 {
     g_debug ("Quit message received");
-    g_idle_add ((GSourceFunc) parole_plugin_player_quit_idl, player);
+    player->priv->terminate = TRUE;
+    g_idle_add ((GSourceFunc) parole_plugin_player_quit_idle, player);
     return TRUE;
 }
 
 static gboolean 
-parole_plugin_player_dbus_terminate (ParolePluginPlayer *player, GError **error)
+parole_plugin_player_dbus_stop (ParolePluginPlayer *player, GError **error)
 {
-    g_debug ("Terminate message received");
-    parole_plugin_player_exit (player);
+    g_debug ("Stop message received");
+    player->priv->terminate = TRUE;
+    g_idle_add ((GSourceFunc)parole_plugin_player_stop_idle, player);
+    
     return TRUE;
 }
diff --git a/browser-plugin/plugin.cpp b/browser-plugin/plugin.cpp
index 6899113..8a873ab 100644
--- a/browser-plugin/plugin.cpp
+++ b/browser-plugin/plugin.cpp
@@ -79,48 +79,57 @@ CPlugin::CPlugin (NPP pNPInstance)
     proxy = NULL;
 }
 
-void kill_child (GPid child_pid)
+void CPlugin::StopPlayer()
 {
-    /*
-    gchar *command;
-	    
-    command = g_strdup_printf ("kill -9 %d", child_pid);
-    g_spawn_command_line_async (command, NULL);
-    g_free (command);
-    */
-}
-
-CPlugin::~CPlugin()
-{
-    g_debug ("Destructor");
+    gint num_tries = 0;
     
     if ( !proxy )
 	GetProxy ();
     
     if ( proxy )
     {
-	GError *error = NULL;
-	
-	dbus_g_proxy_call (proxy, "Quit", &error,
-			   G_TYPE_INVALID,
-			   G_TYPE_INVALID);
-		
-	/*
-	 * This might happen if the browser unload the plugin quickly
-	 * while the process didn't get the dbus name.
-	 */
-	if ( error )
+	do
 	{
+	    GError *error = NULL;
+	    g_debug ("Sending Quit message");
+	    dbus_g_proxy_call (proxy, "Quit", &error,
+			       G_TYPE_INVALID,
+			       G_TYPE_INVALID);
+		
+	    /*
+	     * This might happen if the browser unload the plugin quickly
+	     * while the process didn't get the dbus name.
+	     */
+	    if ( error )
+	    {
 #ifdef DEBUG
-	    g_debug ("Failed to stop the backend via D-Bus killing the process %d", child_pid);
+		g_debug ("Failed to stop the backend via D-Bus %s", error->message);
 #endif
-	    kill_child (child_pid);
-	}
+		if ( g_error_matches (error, DBUS_GERROR, DBUS_GERROR_NO_REPLY ) ||
+		     g_error_matches (error, DBUS_GERROR, DBUS_GERROR_SERVICE_UNKNOWN) )
+		{
+		    g_error_free (error);
+		    g_main_context_iteration(NULL, FALSE);
+		    g_usleep (100000);
+		    num_tries++;
+		    g_debug ("No reply, probably not ready, re-trying");
+		}
+		else
+		    break;
+	    }
+	    else
+		break;
+	    
+	} while (num_tries  < 3 );
     }   
-    else if ( child_spawned )
-    {
-	kill_child (child_pid);
-    }
+    
+}
+
+CPlugin::~CPlugin()
+{
+    g_debug ("Destructor");
+    
+    StopPlayer ();
     
     if ( bus )
 	dbus_g_connection_unref (bus);
@@ -166,7 +175,8 @@ void CPlugin::shut()
     
     if ( proxy )
     {
-        dbus_g_proxy_call_no_reply (proxy, "Terminate",
+	g_debug ("Sending Stop signal");
+        dbus_g_proxy_call_no_reply (proxy, "Stop",
                                     G_TYPE_INVALID,
                                     G_TYPE_INVALID);
     }   
@@ -256,9 +266,11 @@ NPError CPlugin::NewStream(NPMIMEType type, NPStream * stream, NPBool seekable,
 
 NPError CPlugin::DestroyStream(NPStream * stream, NPError reason)
 {
-    g_debug ("Destroy stream %s reason %i ", stream->url, reason);
-    
-    shut ();
+    if ( reason != NPRES_DONE )
+    {
+	g_debug ("Destroy stream %s reason %i ", stream->url, reason);
+	shut ();
+    }
     
     return NPERR_NO_ERROR;
 }
diff --git a/browser-plugin/plugin.h b/browser-plugin/plugin.h
index 4bc10fa..dec40e9 100644
--- a/browser-plugin/plugin.h
+++ b/browser-plugin/plugin.h
@@ -76,6 +76,7 @@ class CPlugin {
     
     
     void	GetProxy ();
+    void	StopPlayer();
     
   private:
     DBusGConnection *bus;
diff --git a/parole/parole.h b/parole/parole.h
deleted file mode 100644
index 26c39af..0000000
--- a/parole/parole.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * * Copyright (C) 2009 Ali <aliov at xfce.org>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifndef __PAROLE_H_
-#define __PAROLE_H_
-
-#define __PAROLE_H_INSIDE__
-
-#include <glib-object.h>
-
-#include <parole/parole-provider-plugin.h>
-#include <parole/parole-provider-player.h>
-#include <parole/parole-file.h>
-#include <parole/parole-stream.h>
-
-#undef __PAROLE_H_INSIDE__
-
-#endif /*__PAROLE_H_*/
diff --git a/parole/parole.h.in b/parole/parole.h.in
new file mode 100644
index 0000000..19c5ad7
--- /dev/null
+++ b/parole/parole.h.in
@@ -0,0 +1,120 @@
+/*
+ * * Copyright (C) 2009 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __PAROLE_H_
+#define __PAROLE_H_
+
+#define __PAROLE_H_INSIDE__
+
+#include <glib-object.h>
+
+#include <parole/parole-provider-plugin.h>
+#include <parole/parole-provider-player.h>
+#include <parole/parole-file.h>
+#include <parole/parole-stream.h>
+
+#define PAROLE_MAJOR_VERSION		@PAROLE_VERSION_MAJOR@
+#define PAROLE_MINOR_VERSION		@PAROLE_VERSION_MINOR@
+#define PAROLE_MICRO_VERSION		@PAROLE_VERSION_MICRO@
+
+#define	PAROLE_CHECK_VERSION(major,minor,micro)					\
+    (PAROLE_MAJOR_VERSION > (major) || 						\
+    (PAROLE_MAJOR_VERSION == (major) && PAROLE_MINOR_VERSION > (minor)) || 	\
+    (PAROLE_MAJOR_VERSION == (major) && PAROLE_MINOR_VERSION == (minor) && 	\
+     PAROLE_MICRO_VERSION >= (micro)))
+
+/*
+ * GType module registration macros.
+ */
+#define PAROLE_DEFINE_TYPE(TN, t_n, T_P)			PAROLE_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
+#define PAROLE_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)	_PAROLE_DEFINE_TYPE_EXTENDED_BEGIN(TN, t_n, T_P, _f_) {_C_;} _PAROLE_DEFINE_TYPE_EXTENDED_END()
+#define PAROLE_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_)		_PAROLE_DEFINE_TYPE_EXTENDED_BEGIN(TN, t_n, T_P, 0) {_C_;} _PAROLE_DEFINE_TYPE_EXTENDED_END()
+#define PAROLE_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P)		PAROLE_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {})
+#define PAROLE_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P)	PAROLE_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, _C_)
+
+
+#define _PAROLE_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
+										\
+static gpointer type_name##_parent_class = NULL; 				\
+static GType    type_name##_type = G_TYPE_INVALID; 				\
+										\
+static void     type_name##_init              (TypeName        *self); 		\
+static void     type_name##_class_init        (TypeName##Class *klass); 	\
+static void     type_name##_class_intern_init (TypeName##Class *klass) 		\
+{ 										\
+    type_name##_parent_class = g_type_class_peek_parent (klass); 		\
+    type_name##_class_init (klass); 						\
+} 										\
+										\
+GType 										\
+type_name##_get_type (void) 							\
+{ 										\
+  return type_name##_type; 							\
+} 										\
+										\
+void 										\
+type_name##_register_type (ParoleProviderPlugin *provider_plugin_def) 		\
+{ 										\
+    GType parole_define_type_id; 						\
+										\
+    static const GTypeInfo parole_define_type_info = 				\
+    {										\
+	sizeof (TypeName##Class), 						\
+	NULL, 									\
+	NULL, 									\
+	(GClassInitFunc) type_name##_class_intern_init, 			\
+	NULL, 									\
+	NULL, 									\
+	sizeof (TypeName), 							\
+	0, 									\
+	(GInstanceInitFunc) type_name##_init, 					\
+	NULL, 									\
+    }; 										\
+										\
+    parole_define_type_id = 							\
+	g_type_module_register_type ((GTypeModule*)provider_plugin_def, 	\
+				     TYPE_PARENT, 				\
+				     #TypeName, 				\
+				     &parole_define_type_info, 			\
+				     flags); 					\
+    type_name##_type = parole_define_type_id; 					\
+										\
+    { /* Code */
+#define _PAROLE_DEFINE_TYPE_EXTENDED_END()					\
+    }										\
+}
+
+#define PAROLE_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) 			\
+{ 										\
+    static const GInterfaceInfo parole_implement_interface_info = 		\
+    { 										\
+	(GInterfaceInitFunc) iface_init 					\
+    }; 										\
+										\
+    g_type_module_add_interface ((GTypeModule*)provider_plugin_def, 		\
+				 parole_define_type_id, 			\
+				 TYPE_IFACE, 					\
+				 &parole_implement_interface_info); 		\
+}
+
+
+#undef __PAROLE_H_INSIDE__
+
+#endif /*__PAROLE_H_*/



More information about the Xfce4-commits mailing list