[banshee] [Services] Refactoring of the Service addition and retrieval
- From: Andrés Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] [Services] Refactoring of the Service addition and retrieval
- Date: Thu, 29 Jul 2010 01:05:00 +0000 (UTC)
commit f714fe74c7f0575122b3623305b0a72a241b11ce
Author: Andrés G. Aragoneses <knocte gmail com>
Date: Thu Jul 29 03:01:20 2010 +0200
[Services] Refactoring of the Service addition and retrieval
This refactoring fixes the ambiguities about registering
and retrieving services, as the method Contains(string)
checks for a serviceName, while Contains<T>() checks for
the name of the class, and there could be problems if you
defined your ServiceName property with a different name
than your class. Now, after this commit:
1) When registering a service, it gets added by 2 keys
in the dictionary so you can retrieve it either way.
2) The Get<T>(string) is removed to be more in line with
the Contains overloads, and to remove clutter since T
already has the IService as a "where:" restriction and
thus can already have both ServiceName and class name.
These changes are done in ServiceManager.cs. The rest
of the changes are just to track API. A commit on b-c-e
to track API will follow this too.
Signed-off-by: Alexander Kojevnikov <alexander kojevnikov com>
.../Banshee.GStreamer/PlayerEngine.cs | 2 +-
.../Banshee.ServiceStack/ServiceManager.cs | 26 ++++++++++++++-----
.../Banshee.Gui/BansheeActionGroup.cs | 2 +-
.../Banshee.ThickClient/Banshee.Gui/BookmarkUI.cs | 2 +-
.../Banshee.Gui/SourceActions.cs | 2 +-
.../Banshee.Gui/TrackActions.cs | 4 +-
src/Dap/Banshee.Dap/Banshee.Dap/DapSync.cs | 2 +-
.../AudioscrobblerService.cs | 2 +-
.../Banshee.MiniMode/MiniModeService.cs | 2 +-
9 files changed, 28 insertions(+), 16 deletions(-)
---
diff --git a/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs b/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs
index d64f4c7..d65c31b 100644
--- a/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs
+++ b/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs
@@ -221,7 +221,7 @@ namespace Banshee.GStreamer
// needs to bring up the plugin installer so it can be transient to
// the main window.
if (!xid_is_set) {
- IPropertyStoreExpose service = ServiceManager.Get<IService> ("GtkElementsService") as IPropertyStoreExpose;
+ var service = ServiceManager.Get ("GtkElementsService") as IPropertyStoreExpose;
if (service != null) {
bp_set_application_gdk_window (handle, service.PropertyStore.Get<IntPtr> ("PrimaryWindow.RawHandle"));
}
diff --git a/src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs b/src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs
index 0a77406..e838f84 100644
--- a/src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs
+++ b/src/Core/Banshee.Services/Banshee.ServiceStack/ServiceManager.cs
@@ -227,7 +227,7 @@ namespace Banshee.ServiceStack
} else if (args.Change == ExtensionChange.Remove && extension_services.ContainsKey (node.Path)) {
IExtensionService service = extension_services[node.Path];
extension_services.Remove (node.Path);
- services.Remove (service.ServiceName);
+ Remove (service);
((IDisposable)service).Dispose ();
Log.DebugFormat ("Extension service disposed ({0})", service.ServiceName);
@@ -293,7 +293,7 @@ namespace Banshee.ServiceStack
public static void RegisterService (IService service)
{
lock (self_mutex) {
- services.Add (service.ServiceName, service);
+ Add (service);
if(service is IDBusExportable) {
DBusServiceManager.RegisterObject ((IDBusExportable)service);
@@ -333,11 +333,6 @@ namespace Banshee.ServiceStack
return null;
}
- public static T Get<T> (string serviceName) where T : class, IService
- {
- return Get (serviceName) as T;
- }
-
public static T Get<T> () where T : class, IService
{
Type type = typeof (T);
@@ -349,6 +344,23 @@ namespace Banshee.ServiceStack
return service;
}
+ private static void Add (IService service)
+ {
+ services.Add (service.ServiceName, service);
+ //because Get<T>() works this way:
+ var type_name = service.GetType ().Name;
+ if (type_name != service.ServiceName) {
+ services.Add (type_name, service);
+ }
+ }
+
+ private static void Remove (IService service)
+ {
+ services.Remove (service.ServiceName);
+ //because Add () works this way:
+ services.Remove (service.GetType ().Name);
+ }
+
private static void OnStartupBegin ()
{
EventHandler handler = StartupBegin;
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/BansheeActionGroup.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/BansheeActionGroup.cs
index fb76d61..b5e365a 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/BansheeActionGroup.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/BansheeActionGroup.cs
@@ -103,7 +103,7 @@ namespace Banshee.Gui
}
public Gtk.Window PrimaryWindow {
- get { return ServiceManager.Get<GtkElementsService> ("GtkElementsService").PrimaryWindow; }
+ get { return ServiceManager.Get<GtkElementsService> ().PrimaryWindow; }
}
}
}
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/BookmarkUI.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/BookmarkUI.cs
index c967224..d071147 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/BookmarkUI.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/BookmarkUI.cs
@@ -78,7 +78,7 @@ namespace Banshee.Gui
private BookmarkUI ()
{
- action_service = ServiceManager.Get<InterfaceActionService> ("InterfaceActionService");
+ action_service = ServiceManager.Get<InterfaceActionService> ();
actions = new ActionGroup ("Bookmarks");
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
index 306f6fd..33562fa 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
@@ -419,7 +419,7 @@ namespace Banshee.Gui
}
Hyena.Widgets.HigMessageDialog dialog = new Hyena.Widgets.HigMessageDialog (
- ServiceManager.Get<GtkElementsService> ("GtkElementsService").PrimaryWindow,
+ ServiceManager.Get<GtkElementsService> ().PrimaryWindow,
Gtk.DialogFlags.Modal,
Gtk.MessageType.Question,
Gtk.ButtonsType.Cancel,
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
index 368f6a4..06d385d 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
@@ -440,7 +440,7 @@ namespace Banshee.Gui
}
var md = new HigMessageDialog (
- ServiceManager.Get<GtkElementsService> ("GtkElementsService").PrimaryWindow,
+ ServiceManager.Get<GtkElementsService> ().PrimaryWindow,
DialogFlags.DestroyWithParent, MessageType.Warning,
ButtonsType.None, Catalog.GetString ("The folder could not be found."),
Catalog.GetString ("Please check that the track's location is accessible by the system.")
@@ -527,7 +527,7 @@ namespace Banshee.Gui
}
HigMessageDialog md = new HigMessageDialog (
- ServiceManager.Get<GtkElementsService> ("GtkElementsService").PrimaryWindow,
+ ServiceManager.Get<GtkElementsService> ().PrimaryWindow,
DialogFlags.DestroyWithParent, delete ? MessageType.Warning : MessageType.Question,
ButtonsType.None, header, message
);
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap/DapSync.cs b/src/Dap/Banshee.Dap/Banshee.Dap/DapSync.cs
index 6e38d30..a2d401c 100644
--- a/src/Dap/Banshee.Dap/Banshee.Dap/DapSync.cs
+++ b/src/Dap/Banshee.Dap/Banshee.Dap/DapSync.cs
@@ -368,7 +368,7 @@ namespace Banshee.Dap
string message = Catalog.GetString ("Are you sure you want to continue?");
HigMessageDialog md = new HigMessageDialog (
- ServiceManager.Get<GtkElementsService> ("GtkElementsService").PrimaryWindow,
+ ServiceManager.Get<GtkElementsService> ().PrimaryWindow,
DialogFlags.DestroyWithParent, MessageType.Warning,
ButtonsType.None, header, message
);
diff --git a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs
index 098c148..83821cc 100644
--- a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs
+++ b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs
@@ -109,7 +109,7 @@ namespace Banshee.Lastfm.Audioscrobbler
PlayerEvent.Seek |
PlayerEvent.Iterate);
- action_service = ServiceManager.Get<InterfaceActionService> ("InterfaceActionService");
+ action_service = ServiceManager.Get<InterfaceActionService> ();
InterfaceInitialize ();
}
diff --git a/src/Extensions/Banshee.MiniMode/Banshee.MiniMode/MiniModeService.cs b/src/Extensions/Banshee.MiniMode/Banshee.MiniMode/MiniModeService.cs
index 7603399..bee3c84 100644
--- a/src/Extensions/Banshee.MiniMode/Banshee.MiniMode/MiniModeService.cs
+++ b/src/Extensions/Banshee.MiniMode/Banshee.MiniMode/MiniModeService.cs
@@ -19,7 +19,7 @@ namespace Banshee.MiniMode
void IExtensionService.Initialize ()
{
- action_service = ServiceManager.Get<InterfaceActionService> ("InterfaceActionService");
+ action_service = ServiceManager.Get<InterfaceActionService> ();
viewMenu = (action_service.UIManager.GetWidget ("/MainMenu/ViewMenu") as MenuItem).Submenu as Menu;
menuItem = new MenuItem (Catalog.GetString ("_Mini Mode"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]