From b68421bc7f4f36342463498b44e2a3fb4b11fe7e Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Sep 2010 12:35:15 +0100 Subject: async the root dbus method calls --- src/mpris2-controller.vala | 8 ++++---- src/sound-service.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index bab20ae..696fd09 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -28,8 +28,8 @@ public interface MprisRoot : DBus.Object { public abstract string Identity{owned get; set;} public abstract string DesktopEntry{owned get; set;} // methods - public abstract void Quit() throws DBus.Error; - public abstract void Raise() throws DBus.Error; + public abstract async void Quit() throws DBus.Error; + public abstract async void Raise() throws DBus.Error; } [DBus (name = "org.mpris.MediaPlayer2.Player")] @@ -215,12 +215,12 @@ public class Mpris2Controller : GLib.Object } return true; } - + public void expose() { if(this.connected() == true){ try{ - this.mpris2_root.Raise(); + this.mpris2_root.Raise.begin(); } catch(DBus.Error e){ error("Exception thrown while calling function Raise - %s", e.message); diff --git a/src/sound-service.c b/src/sound-service.c index f19379d..51f5f37 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From edb20cb04d9f977c7ddf70f6edc707546e2997c0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Sep 2010 12:43:23 +0100 Subject: all dbus method calls now async --- src/mpris2-controller.vala | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 696fd09..2f5bcde 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -40,11 +40,9 @@ public interface MprisPlayer : DBus.Object { public abstract int32 Position{owned get; set;} public abstract string PlaybackStatus{owned get; set;} // methods - public abstract void SetPosition(DBus.ObjectPath path, int64 pos) throws DBus.Error; - public abstract void PlayPause() throws DBus.Error; - public abstract void Pause() throws DBus.Error; - public abstract void Next() throws DBus.Error; - public abstract void Previous() throws DBus.Error; + public abstract async void PlayPause() throws DBus.Error; + public abstract async void Next() throws DBus.Error; + public abstract async void Previous() throws DBus.Error; // signals public signal void Seeked(int64 new_position); } @@ -176,7 +174,7 @@ public class Mpris2Controller : GLib.Object if(command == TransportMenuitem.action.PLAY_PAUSE){ debug("transport_event PLAY_PAUSE"); try{ - this.player.PlayPause(); + this.player.PlayPause.begin(); } catch(DBus.Error error){ warning("DBus Error calling the player objects PlayPause method %s", @@ -185,7 +183,7 @@ public class Mpris2Controller : GLib.Object } else if(command == TransportMenuitem.action.PREVIOUS){ try{ - this.player.Previous(); + this.player.Previous.begin(); } catch(DBus.Error error){ warning("DBus Error calling the player objects Previous method %s", @@ -194,7 +192,7 @@ public class Mpris2Controller : GLib.Object } else if(command == TransportMenuitem.action.NEXT){ try{ - this.player.Next(); + this.player.Next.begin(); } catch(DBus.Error error){ warning("DBus Error calling the player objects Next method %s", -- cgit v1.2.3 From 484518d33c44914196f85c19b92f3fac07d1b2e0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Sep 2010 18:21:02 +0100 Subject: indicator should handle any service problems gracefully --- src/dbus-menu-manager.c | 19 ++++++++++-- src/indicator-sound.c | 82 ++++++++++++++++++++++++++++++------------------- src/pulse-manager.c | 10 +++--- src/slider-menu-item.c | 3 +- src/volume-widget.c | 21 +++++++++++-- src/volume-widget.h | 2 ++ 6 files changed, 94 insertions(+), 43 deletions(-) diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 5ea561f..222affa 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -50,8 +50,11 @@ static gdouble volume_percent = 0.0; static void set_global_mute_from_ui(); static gboolean idle_routine (gpointer data); -static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service); +static void rebuild_sound_menu(DbusmenuMenuitem *root, + SoundServiceDbus *service); static void refresh_menu(); +static void remove_previous_children(gpointer obj, gpointer user_data); + /*-------------------------------------------------------------------------*/ // Public Methods @@ -71,10 +74,22 @@ DbusmenuMenuitem* dbus_menu_manager_setup() DbusmenuServer *server = dbusmenu_server_new(INDICATOR_SOUND_DBUS_OBJECT); dbusmenu_server_set_root(server, root_menuitem); + + /*GList* previous_children = dbusmenu_menuitem_get_children(root_menuitem); + if(previous_children != NULL){ + g_list_foreach(previous_children, remove_previous_children, NULL); + }*/ establish_pulse_activities(dbus_interface); return root_menuitem; } +/*static void remove_previous_children(gpointer obj, gpointer user_data) +{ + DbusmenuMenuitem *child = (DbusmenuMenuitem*)obj; + if(child != NULL){ + dbusmenu_menuitem_child_delete(root_menuitem, child); + } +}*/ void dbus_menu_manager_update_volume(gdouble volume) { @@ -213,7 +228,7 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service // Sound preferences dialog DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(settings_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sound Preferences...")); -//_("Sound Preferences...")); + //_("Sound Preferences...")); dbusmenu_menuitem_child_append(root, settings_mi); g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_sound_settings_dialog), NULL); diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 7f3b94b..0aa93b3 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -156,7 +156,9 @@ indicator_sound_init (IndicatorSound *self) IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); priv->volume_widget = NULL; - g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); + g_signal_connect(G_OBJECT(self->service), + INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, + G_CALLBACK(connection_changed), self); return; } @@ -307,7 +309,7 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, volume_widget = volume_widget_new (newitem); io = g_object_get_data (G_OBJECT (client), "indicator"); IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); - priv->volume_widget = volume_widget; + priv->volume_widget = volume_widget; GtkWidget* ido_slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); @@ -321,47 +323,65 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_item, - parent); - - fetch_mute_value_from_dbus(); - fetch_sink_availability_from_dbus(INDICATOR_SOUND (io)); - + parent); return TRUE; } static void -connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) +connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) { if (connected) { - if (sound_dbus_proxy == NULL) { - GError * error = NULL; + gboolean service_restart = FALSE; + if (sound_dbus_proxy != NULL) { + g_object_unref (sound_dbus_proxy); + sound_dbus_proxy = NULL; + service_restart = TRUE; + } + GError * error = NULL; - DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - sound_dbus_proxy = dbus_g_proxy_new_for_name_owner(sbus, - INDICATOR_SOUND_DBUS_NAME, - INDICATOR_SOUND_SERVICE_DBUS_OBJECT, - INDICATOR_SOUND_SERVICE_DBUS_INTERFACE, - &error); + sound_dbus_proxy = dbus_g_proxy_new_for_name_owner(sbus, + INDICATOR_SOUND_DBUS_NAME, + INDICATOR_SOUND_SERVICE_DBUS_OBJECT, + INDICATOR_SOUND_SERVICE_DBUS_INTERFACE, + &error); - if (error != NULL) { - g_warning("Unable to get status proxy: %s", error->message); - g_error_free(error); - } - g_debug("about to connect to the signals"); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), userdata, NULL); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_CALLBACK(catch_signal_sink_availability_update), NULL, NULL); - - g_return_if_fail(IS_INDICATOR_SOUND(userdata)); - + if (error != NULL) { + g_warning("Unable to get status proxy: %s", error->message); + g_error_free(error); } + g_debug("about to connect to the signals"); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), user_data, NULL); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_CALLBACK(catch_signal_sink_availability_update), NULL, NULL); + if( service_restart == TRUE){ + fetch_mute_value_from_dbus(); + // Ensure UI is in sync with service again. + IndicatorSound* indicator = INDICATOR_SOUND(user_data); + fetch_sink_availability_from_dbus(indicator); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); + determine_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); + } + } + else{ + g_warning("Indicator has been disconnected from the service -> SHOCK HORROR"); + IndicatorSound* indicator = INDICATOR_SOUND(user_data); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); + + if(priv->volume_widget != NULL){ + g_warning("indicator still has a slider, service must have crashed"); + volume_widget_tidy_up(priv->volume_widget); + g_object_unref(G_OBJECT(priv->volume_widget)); + priv->volume_widget = NULL; + } + device_available = FALSE; + update_state(STATE_SINKS_NONE); } - return; } /* diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 4ff9e1d..f93368e 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -50,8 +50,8 @@ static pa_cvolume construct_mono_volume(const pa_cvolume* vol); /** Future Refactoring notes - - Push all UI updates out through update PA state in the service. - - Collapse 3 update_sink_info into one. The essentially do the same thing from different contexts. + - rewrite in vala. + - make sure all state is kept in the service for volume icon switching. **/ /** @@ -147,7 +147,7 @@ static gboolean determine_sink_availability() // Firstly check to see if we have any sinks // if not get the hell out of here ! if (g_hash_table_size(sink_hash) < 1) { - /* g_debug("Sink_available returning false because sinks_hash is empty !!!"); */ + g_debug("Sink_available returning false because sinks_hash is empty !!!"); DEFAULT_SINK_INDEX = -1; return FALSE; } @@ -163,7 +163,7 @@ static gboolean determine_sink_availability() // Thirdly ensure the default sink index does not have the name "auto_null" sink_info* s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); - // Up until now the most rebust method to test this is to manually remove the available sink device + // Up until now the most robust method to test this is to manually remove the available sink device // kernel module and then reload (rmmod & modprobe). // TODO: Edge case of dynamic loading and unloading of sinks should be handled also. /* g_debug("About to test for to see if the available sink is null - s->name = %s", s->name);*/ @@ -211,7 +211,6 @@ static void mute_each_sink(gpointer key, gpointer value, gpointer user_data) if (GPOINTER_TO_INT(user_data) == 1) { sound_service_dbus_update_sink_mute(dbus_service, TRUE); } else { - //sound_service_dbus_update_sink_volume(dbus_service, get_default_sink_volume()); dbus_menu_manager_update_volume(get_default_sink_volume()); } @@ -411,7 +410,6 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v pa_volume_t vol = pa_cvolume_max(&s->volume); gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; /* g_debug("Updating volume from PA manager with volume = %f", volume_percent);*/ - //sound_service_dbus_update_sink_volume(dbus_service, volume_percent); dbus_menu_manager_update_volume(volume_percent); } } diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index 77c8635..c850cdc 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -88,8 +88,7 @@ handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, g SliderMenuItem* slider_menu_item_new(gboolean sinks_available, gdouble start_volume) -{ - +{ SliderMenuItem *self = g_object_new(SLIDER_MENU_ITEM_TYPE, NULL); dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_VOLUME_MENUITEM_TYPE); diff --git a/src/volume-widget.c b/src/volume-widget.c index 5e7cf9f..1cfdcc4 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -61,6 +61,7 @@ static void volume_widget_parent_changed (GtkWidget *widget, gpointer user_data) G_DEFINE_TYPE (VolumeWidget, volume_widget, G_TYPE_OBJECT); + static void volume_widget_class_init (VolumeWidgetClass *klass) { @@ -201,8 +202,6 @@ volume_widget_update(VolumeWidget* self, gdouble update) dbusmenu_menuitem_handle_event (priv->twin_item, "update", &value, 0); } - - GtkWidget* volume_widget_get_ido_slider(VolumeWidget* self) { @@ -234,6 +233,24 @@ volume_widget_slider_released(GtkWidget *widget, gpointer user_data) priv->grabbed = FALSE; } +void +volume_widget_tidy_up (GtkWidget *widget) +{ + VolumeWidget* mitem = VOLUME_WIDGET(widget); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + gtk_widget_destroy (priv->ido_volume_slider); +} + +gdouble +volume_widget_get_current_volume ( GtkWidget *widget ) +{ + VolumeWidget* mitem = VOLUME_WIDGET(widget); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + gdouble vol = g_value_get_double ( dbusmenu_menuitem_property_get_value( priv->twin_item, + DBUSMENU_VOLUME_MENUITEM_LEVEL)); + return vol; +} + /** * volume_widget_new: * @returns: a new #VolumeWidget. diff --git a/src/volume-widget.h b/src/volume-widget.h index d4929ec..202bbb3 100644 --- a/src/volume-widget.h +++ b/src/volume-widget.h @@ -47,6 +47,8 @@ GType volume_widget_get_type (void) G_GNUC_CONST; GtkWidget* volume_widget_new(DbusmenuMenuitem* twin_item); GtkWidget* volume_widget_get_ido_slider(VolumeWidget* self); void volume_widget_update(VolumeWidget* self, gdouble update); +void volume_widget_tidy_up (GtkWidget *widget); +gdouble volume_widget_get_current_volume ( GtkWidget *widget ); G_END_DECLS -- cgit v1.2.3 From 21c38af8ec53f8ccdcf5b434b5cda807f27c9a3c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Sep 2010 18:21:32 +0100 Subject: tidy up --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sound-service.c b/src/sound-service.c index 51f5f37..f19379d 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From bab2f6616d4ad90243d3551513ad9e90c0df692e Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Sep 2010 18:30:03 +0100 Subject: removed redundant code --- src/dbus-menu-manager.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 222affa..63e91b4 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -53,7 +53,6 @@ static gboolean idle_routine (gpointer data); static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service); static void refresh_menu(); -static void remove_previous_children(gpointer obj, gpointer user_data); /*-------------------------------------------------------------------------*/ @@ -74,23 +73,10 @@ DbusmenuMenuitem* dbus_menu_manager_setup() DbusmenuServer *server = dbusmenu_server_new(INDICATOR_SOUND_DBUS_OBJECT); dbusmenu_server_set_root(server, root_menuitem); - - /*GList* previous_children = dbusmenu_menuitem_get_children(root_menuitem); - if(previous_children != NULL){ - g_list_foreach(previous_children, remove_previous_children, NULL); - }*/ establish_pulse_activities(dbus_interface); return root_menuitem; } -/*static void remove_previous_children(gpointer obj, gpointer user_data) -{ - DbusmenuMenuitem *child = (DbusmenuMenuitem*)obj; - if(child != NULL){ - dbusmenu_menuitem_child_delete(root_menuitem, child); - } -}*/ - void dbus_menu_manager_update_volume(gdouble volume) { GValue value = {0}; -- cgit v1.2.3