From: <br...@us...> - 2008-08-31 07:34:42
|
Revision: 3557 http://openvrml.svn.sourceforge.net/openvrml/?rev=3557&view=rev Author: braden Date: 2008-08-31 07:34:53 +0000 (Sun, 31 Aug 2008) Log Message: ----------- Signal shutdown from the host so that we can clean up in openvrml-xembed. Modified Paths: -------------- branches/dbus/src/openvrml-player/curlcontrolhost.cpp branches/dbus/src/openvrml-xembed/control_factory.cpp branches/dbus/src/openvrml-xembed/vrml-control-host.xml Modified: branches/dbus/src/openvrml-player/curlcontrolhost.cpp =================================================================== --- branches/dbus/src/openvrml-player/curlcontrolhost.cpp 2008-08-31 03:53:02 UTC (rev 3556) +++ branches/dbus/src/openvrml-player/curlcontrolhost.cpp 2008-08-31 07:34:53 UTC (rev 3557) @@ -105,6 +105,13 @@ enum curl_control_host_property_id { object_path_id = 1 }; + + enum curl_control_host_signal_id { + shutdown_id, + last_signal_id + }; + + G_GNUC_INTERNAL guint signals[last_signal_id]; } void @@ -120,6 +127,15 @@ GTK_WIDGET_CLASS(klass)->unrealize = openvrml_player_curl_control_host_unrealize; + signals[shutdown_id] = + g_signal_new("shutdown", + G_OBJECT_CLASS_TYPE(klass), + GSignalFlags(G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED), + 0, + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + GError * error = 0; scope_guard error_guard = make_guard(g_error_free, boost::ref(error)); klass->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); @@ -302,6 +318,8 @@ curl_multi_cleanup(control_host->priv->multi_handle); g_object_unref(control_host->priv->control); + g_signal_emit(widget, signals[shutdown_id], 0); + GtkWidgetClass * klass = GTK_WIDGET_CLASS( g_type_class_peek(OPENVRML_PLAYER_TYPE_CURL_CONTROL_HOST)); Modified: branches/dbus/src/openvrml-xembed/control_factory.cpp =================================================================== --- branches/dbus/src/openvrml-xembed/control_factory.cpp 2008-08-31 03:53:02 UTC (rev 3556) +++ branches/dbus/src/openvrml-xembed/control_factory.cpp 2008-08-31 07:34:53 UTC (rev 3557) @@ -85,6 +85,25 @@ error_guard.dismiss(); } +extern "C" +G_GNUC_INTERNAL +gboolean vrml_control_factory_on_host_shutdown_event(DBusGProxy * proxy, + gpointer user_data); + +namespace { + struct on_host_shutdown_data { + VrmlControlFactory * factory; + gchar * control_obj_path; + }; +} + +extern "C" +G_GNUC_INTERNAL +void delete_on_host_shutdown_data(gpointer data, GClosure * /* closure */) +{ + delete static_cast<on_host_shutdown_data *>(data); +} + char * vrml_control_factory_create_control( VrmlControlFactory * const control_factory, @@ -113,13 +132,39 @@ control_obj_path, G_OBJECT(control)); + on_host_shutdown_data * const data = new on_host_shutdown_data; + data->factory = control_factory; // // Note that D-Bus frees the return value; so we need to strdup the one // in the hash map. // + data->control_obj_path = g_strdup(control_obj_path); + + dbus_g_proxy_add_signal(host, "Shutdown", G_TYPE_INVALID); + + dbus_g_proxy_connect_signal( + host, + "Shutdown", + G_CALLBACK(vrml_control_factory_on_host_shutdown_event), + data, + delete_on_host_shutdown_data); + g_hash_table_insert(control_factory->controls, - g_strdup(control_obj_path), - control); + data->control_obj_path, // was strdup'd above + g_object_ref(control)); return control_obj_path; } + +gboolean vrml_control_factory_on_host_shutdown_event(DBusGProxy * /* proxy */, + const gpointer user_data) +{ + on_host_shutdown_data * const data = + static_cast<on_host_shutdown_data *>(user_data); + + gboolean removed = g_hash_table_remove(data->factory->controls, + data->control_obj_path); + g_assert(removed); + + return false; +} Modified: branches/dbus/src/openvrml-xembed/vrml-control-host.xml =================================================================== --- branches/dbus/src/openvrml-xembed/vrml-control-host.xml 2008-08-31 03:53:02 UTC (rev 3556) +++ branches/dbus/src/openvrml-xembed/vrml-control-host.xml 2008-08-31 07:34:53 UTC (rev 3557) @@ -14,5 +14,6 @@ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="vrml_control_host_set_world_url"/> <arg type="s" name="url" direction="in"/> </method> + <signal name="Shutdown"/> </interface> </node> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |