[longomatch] Addins can now register services as well.



commit 48bdec8906477960e5ef36aa528f0310a6c0874a
Author: Julien Moutte <julien fluendo com>
Date:   Mon Apr 13 15:39:48 2015 +0200

    Addins can now register services as well.

 LongoMatch.Addins/AddinsManager.cs                 |   15 +++++++++
 .../ExtensionPoints/IServicesPlugin.cs             |   31 ++++++++++++++++++++
 LongoMatch.Addins/LongoMatch.Addins.csproj         |    1 +
 LongoMatch.Addins/Makefile.am                      |    1 +
 LongoMatch.Services/CoreServices.cs                |   30 +++++++++++++------
 5 files changed, 69 insertions(+), 9 deletions(-)
---
diff --git a/LongoMatch.Addins/AddinsManager.cs b/LongoMatch.Addins/AddinsManager.cs
index 4e11565..e4d278f 100644
--- a/LongoMatch.Addins/AddinsManager.cs
+++ b/LongoMatch.Addins/AddinsManager.cs
@@ -149,6 +149,21 @@ namespace LongoMatch.Addins
                        }
                }
 
+               /// <summary>
+               /// Gets all Services exposed by addins through the IServicesPlugin extension point.
+               /// </summary>
+               /// <returns>A List of services provided by addins.</returns>
+               public static List<IService> GetAddinsServices ()
+               {
+                       List<IService> services = new List<IService> ();
+
+                       foreach (IServicesPlugin plugin in AddinManager.GetExtensionObjects<IServicesPlugin> 
()) {
+                               services.AddRange (plugin.Services);
+                       }
+
+                       return services;
+               }
+
                public static void ShutdownMultimediaBackends ()
                {
                        foreach (IMultimediaBackend backend in 
AddinManager.GetExtensionObjects<IMultimediaBackend> ()) {
diff --git a/LongoMatch.Addins/ExtensionPoints/IServicesPlugin.cs 
b/LongoMatch.Addins/ExtensionPoints/IServicesPlugin.cs
new file mode 100644
index 0000000..a82f548
--- /dev/null
+++ b/LongoMatch.Addins/ExtensionPoints/IServicesPlugin.cs
@@ -0,0 +1,31 @@
+//
+//  Copyright (C) 2015 FLUENDO S.A.
+//
+//  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 St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Collections.Generic;
+using Mono.Addins;
+using LongoMatch.Core.Interfaces;
+
+namespace LongoMatch.Addins.ExtensionPoints
+{
+       [TypeExtensionPoint]
+       public interface IServicesPlugin: ILongoMatchPlugin
+       {
+               List<IService> Services { get; }
+       }
+}
+
diff --git a/LongoMatch.Addins/LongoMatch.Addins.csproj b/LongoMatch.Addins/LongoMatch.Addins.csproj
index 61765ea..43faecf 100644
--- a/LongoMatch.Addins/LongoMatch.Addins.csproj
+++ b/LongoMatch.Addins/LongoMatch.Addins.csproj
@@ -41,6 +41,7 @@
     <Compile Include="..\AssemblyInfo\AssemblyInfo.cs">
       <Link>AssemblyInfo.cs</Link>
     </Compile>
+    <Compile Include="ExtensionPoints\IServicesPlugin.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="Mono.Addins, Version=0.6.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756">
diff --git a/LongoMatch.Addins/Makefile.am b/LongoMatch.Addins/Makefile.am
index e911679..d171693 100644
--- a/LongoMatch.Addins/Makefile.am
+++ b/LongoMatch.Addins/Makefile.am
@@ -14,6 +14,7 @@ SOURCES = ../AssemblyInfo/AssemblyInfo.cs \
        ExtensionPoints/IImportProject.cs \
        ExtensionPoints/ILongoMatchPlugin.cs \
        ExtensionPoints/IMultimediaBackend.cs \
+       ExtensionPoints/IServicesPlugin.cs \
        ExtensionPoints/IStatsUI.cs \
        PreferencesAttribute.cs
 
diff --git a/LongoMatch.Services/CoreServices.cs b/LongoMatch.Services/CoreServices.cs
index e572fcc..2f17e9e 100644
--- a/LongoMatch.Services/CoreServices.cs
+++ b/LongoMatch.Services/CoreServices.cs
@@ -25,6 +25,7 @@ using LongoMatch.Core.Common;
 using LongoMatch.Core.Interfaces;
 using LongoMatch.Core.Interfaces.GUI;
 using LongoMatch.Core.Interfaces.Multimedia;
+using LongoMatch.Addins;
 using Mono.Unix;
 using LongoMatch.Services.Services;
 
@@ -86,46 +87,57 @@ namespace LongoMatch.Services
                        StartServices ();
                }
 
+               public static void RegisterService (IService service)
+               {
+                       Log.InformationFormat ("Registering service {0}", service.Name);
+                       services.Add (service);
+               }
+
                public static void RegisterServices (IGUIToolkit guiToolkit, IMultimediaToolkit 
multimediaToolkit)
                {
                        ts = new TemplatesService (new FileStorage (Config.DBDir));
-                       services.Add (ts);
+                       RegisterService (ts);
                        Config.TeamTemplatesProvider = ts.TeamTemplateProvider;
                        Config.CategoriesTemplatesProvider = ts.CategoriesTemplateProvider;
 
                        /* Start DB services */
                        dbManager = new DataBaseManager (Config.DBDir, guiToolkit);
-                       services.Add (dbManager);
+                       RegisterService (dbManager);
                        Config.DatabaseManager = dbManager;
 
                        /* Start the rendering jobs manager */
                        videoRenderer = new RenderingJobsManager (multimediaToolkit, guiToolkit);
-                       services.Add (videoRenderer);
+                       RegisterService (videoRenderer);
                        Config.RenderingJobsManger = videoRenderer;
 
                        projectsManager = new ProjectsManager (guiToolkit, multimediaToolkit, ts);
-                       services.Add (projectsManager);
+                       RegisterService (projectsManager);
 
                        /* State the tools manager */
                        toolsManager = new ToolsManager (guiToolkit, dbManager);
-                       services.Add (toolsManager);
+                       RegisterService (toolsManager);
                        ProjectsImporter = toolsManager;
 
                        /* Start the events manager */
                        eManager = new EventsManager (guiToolkit, videoRenderer);
-                       services.Add (eManager);
+                       RegisterService (eManager);
 
                        /* Start the hotkeys manager */
                        hkManager = new HotKeysManager ();
-                       services.Add (hkManager);
+                       RegisterService (hkManager);
 
                        /* Start playlists manager */
                        plManager = new PlaylistManager (Config.GUIToolkit, videoRenderer);
-                       services.Add (plManager);
+                       RegisterService (plManager);
 
                        /* Start the Update Notifier */
                        updatesNotifier = new UpdatesNotifier ();
-                       services.Add (updatesNotifier);
+                       RegisterService (updatesNotifier);
+
+                       /* Register services from addins */
+                       foreach (IService service in AddinsManager.GetAddinsServices ()) {
+                               RegisterService (service);
+                       }
                }
 
                public static void StartServices ()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]