[longomatch] Add IService interface.



commit dc2eeaa882229f1cb6742eb7edf3206d42726c69
Author: Julien Moutte <julien fluendo com>
Date:   Mon Apr 13 11:41:35 2015 +0200

    Add IService interface.
    
    Services are now registered first then started and stopped by the CoreServices methods. This will allow 
for plugins to register services that should get started together with the core services.

 LongoMatch.Core/Interfaces/IService.cs      |   47 +++++++++++++++++++++++++
 LongoMatch.Core/LongoMatch.Core.csproj      |    1 +
 LongoMatch.Core/Makefile.am                 |    1 +
 LongoMatch.Services/CoreServices.cs         |   49 +++++++++++++++++++++++----
 LongoMatch.Services/DataBaseManager.cs      |   27 ++++++++++++++-
 LongoMatch.Services/EventsManager.cs        |   28 +++++++++++++++-
 LongoMatch.Services/HotKeysManager.cs       |   29 +++++++++++++++-
 LongoMatch.Services/PlaylistManager.cs      |   28 ++++++++++++++-
 LongoMatch.Services/ProjectsManager.cs      |   27 ++++++++++++++-
 LongoMatch.Services/RenderingJobsManager.cs |   28 +++++++++++++++-
 LongoMatch.Services/TemplatesService.cs     |   28 +++++++++++++++-
 LongoMatch.Services/ToolsManager.cs         |   28 +++++++++++++++-
 LongoMatch.Services/UpdatesNotifier.cs      |   29 +++++++++++++++-
 13 files changed, 333 insertions(+), 17 deletions(-)
---
diff --git a/LongoMatch.Core/Interfaces/IService.cs b/LongoMatch.Core/Interfaces/IService.cs
new file mode 100644
index 0000000..dbc9d0c
--- /dev/null
+++ b/LongoMatch.Core/Interfaces/IService.cs
@@ -0,0 +1,47 @@
+//
+//  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;
+
+namespace LongoMatch.Core.Interfaces
+{
+       public interface IService
+       {
+               /// <summary>
+               /// Gets the level of the service. Services are started in ascending level order and stopped 
in descending level order.
+               /// </summary>
+               /// <value>The level.</value>
+               int Level { get; }
+
+               /// <summary>
+               /// Gets the name of the service
+               /// </summary>
+               /// <value>The name of the service.</value>
+               string Name { get; }
+
+               /// <summary>
+               /// Start the service.
+               /// </summary>
+               bool Start ();
+
+               /// <summary>
+               /// Stop the service.
+               /// </summary>
+               bool Stop ();
+       }
+}
+
diff --git a/LongoMatch.Core/LongoMatch.Core.csproj b/LongoMatch.Core/LongoMatch.Core.csproj
index 1f202b5..5357d07 100644
--- a/LongoMatch.Core/LongoMatch.Core.csproj
+++ b/LongoMatch.Core/LongoMatch.Core.csproj
@@ -145,6 +145,7 @@
     </Compile>
     <Compile Include="Interfaces\GUI\IViewPort.cs" />
     <Compile Include="Store\ActionLink.cs" />
+    <Compile Include="Interfaces\IService.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Common\" />
diff --git a/LongoMatch.Core/Makefile.am b/LongoMatch.Core/Makefile.am
index ff81a26..53604df 100644
--- a/LongoMatch.Core/Makefile.am
+++ b/LongoMatch.Core/Makefile.am
@@ -55,6 +55,7 @@ SOURCES = ../AssemblyInfo/AssemblyInfo.cs \
        Interfaces/IPlaylistElement.cs \
        Interfaces/IProjectsImporter.cs \
        Interfaces/IRenderingJobsManager.cs \
+       Interfaces/IService.cs \
        Interfaces/IStorable.cs \
        Interfaces/IStorage.cs \
        Interfaces/ITemplates.cs \
diff --git a/LongoMatch.Services/CoreServices.cs b/LongoMatch.Services/CoreServices.cs
index 58a7ebd..e0f47c7 100644
--- a/LongoMatch.Services/CoreServices.cs
+++ b/LongoMatch.Services/CoreServices.cs
@@ -17,6 +17,8 @@
 // 
 using System;
 using System.IO;
+using System.Linq;
+using System.Collections.Generic;
 using LongoMatch;
 using LongoMatch.DB;
 using LongoMatch.Core.Common;
@@ -43,6 +45,7 @@ namespace LongoMatch.Services
                static ToolsManager toolsManager;
                static TemplatesService ts;
                static UpdatesNotifier updatesNotifier;
+               static List<IService> services = new List<IService> ();
 
                public static IProjectsImporter ProjectsImporter;
                #if OSTYPE_WINDOWS
@@ -79,41 +82,73 @@ namespace LongoMatch.Services
                        Config.MultimediaToolkit = multimediaToolkit;
                        Config.GUIToolkit = guiToolkit;
                        Config.EventsBroker.QuitApplicationEvent += HandleQuitApplicationEvent;
-                       StartServices (guiToolkit, multimediaToolkit);
+                       RegisterServices (guiToolkit, multimediaToolkit);
+                       StartServices ();
                }
 
-               public static void StartServices (IGUIToolkit guiToolkit, IMultimediaToolkit 
multimediaToolkit)
+               public static void RegisterServices (IGUIToolkit guiToolkit, IMultimediaToolkit 
multimediaToolkit)
                {
                        ts = new TemplatesService (new FileStorage (Config.DBDir));
+                       services.Add (ts);
                        Config.TeamTemplatesProvider = ts.TeamTemplateProvider;
                        Config.CategoriesTemplatesProvider = ts.CategoriesTemplateProvider;
 
                        /* Start DB services */
                        dbManager = new DataBaseManager (Config.DBDir, guiToolkit);
                        dbManager.SetActiveByName (Config.CurrentDatabase);
+                       services.Add (dbManager);
                        Config.DatabaseManager = dbManager;
-                       
+
                        /* Start the rendering jobs manager */
                        videoRenderer = new RenderingJobsManager (multimediaToolkit, guiToolkit);
+                       services.Add (videoRenderer);
                        Config.RenderingJobsManger = videoRenderer;
-                       
+
                        projectsManager = new ProjectsManager (guiToolkit, multimediaToolkit, ts);
-                       
+                       services.Add (projectsManager);
+
                        /* State the tools manager */
                        toolsManager = new ToolsManager (guiToolkit, dbManager);
+                       services.Add (toolsManager);
                        ProjectsImporter = toolsManager;
-                       
+
                        /* Start the events manager */
                        eManager = new EventsManager (guiToolkit, videoRenderer);
-                       
+                       services.Add (eManager);
+
                        /* Start the hotkeys manager */
                        hkManager = new HotKeysManager ();
+                       services.Add (hkManager);
 
                        /* Start playlists manager */
                        plManager = new PlaylistManager (Config.GUIToolkit, videoRenderer);
+                       services.Add (plManager);
 
                        /* Start the Update Notifier */
                        updatesNotifier = new UpdatesNotifier ();
+                       services.Add (updatesNotifier);
+               }
+
+               public static void StartServices ()
+               {
+                       foreach (IService service in services.OrderBy (s => s.Level)) {
+                               if (service.Start ()) {
+                                       Log.Information ("Started service {0} successfully");
+                               } else {
+                                       Log.Information ("Failed starting service {0}");
+                               }
+                       }
+               }
+
+               public static void StopServices ()
+               {
+                       foreach (IService service in services.OrderByDescending (s => s.Level)) {
+                               if (service.Stop ()) {
+                                       Log.Information ("Stopped service {0} successfully");
+                               } else {
+                                       Log.Information ("Failed stopping service {0}");
+                               }
+                       }
                }
 
                public static void CheckDirs ()
diff --git a/LongoMatch.Services/DataBaseManager.cs b/LongoMatch.Services/DataBaseManager.cs
index aa810bd..b478d41 100644
--- a/LongoMatch.Services/DataBaseManager.cs
+++ b/LongoMatch.Services/DataBaseManager.cs
@@ -27,7 +27,7 @@ using LongoMatch.Core.Common;
 
 namespace LongoMatch.DB
 {
-       public class DataBaseManager: IDataBaseManager
+       public class DataBaseManager: IDataBaseManager, IService
        {
                string DBDir;
                IGUIToolkit guiToolkit;
@@ -149,6 +149,31 @@ namespace LongoMatch.DB
                        }
                }
 
+               #region IService
+
+               public int Level {
+                       get {
+                               return 20;
+                       }
+               }
+
+               public string Name {
+                       get {
+                               return "Database manager";
+                       }
+               }
+
+               public bool Start ()
+               {
+                       return true;
+               }
+
+               public bool Stop ()
+               {
+                       return true;
+               }
+
+               #endregion
        }
 }
 
diff --git a/LongoMatch.Services/EventsManager.cs b/LongoMatch.Services/EventsManager.cs
index b3e2819..4cda117 100644
--- a/LongoMatch.Services/EventsManager.cs
+++ b/LongoMatch.Services/EventsManager.cs
@@ -32,7 +32,7 @@ using LongoMatch.Core.Store.Templates;
 
 namespace LongoMatch.Services
 {
-       public class EventsManager
+       public class EventsManager: IService
        {
                /* Current play loaded. null if no play is loaded */
                TimelineEvent loadedPlay;
@@ -426,5 +426,31 @@ namespace LongoMatch.Services
                                break;
                        }
                }
+
+               #region IService
+
+               public int Level {
+                       get {
+                               return 60;
+                       }
+               }
+
+               public string Name {
+                       get {
+                               return "Events manager";
+                       }
+               }
+
+               public bool Start ()
+               {
+                       return true;
+               }
+
+               public bool Stop ()
+               {
+                       return true;
+               }
+
+               #endregion
        }
 }
diff --git a/LongoMatch.Services/HotKeysManager.cs b/LongoMatch.Services/HotKeysManager.cs
index c834284..3f6aacd 100644
--- a/LongoMatch.Services/HotKeysManager.cs
+++ b/LongoMatch.Services/HotKeysManager.cs
@@ -22,13 +22,14 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using LongoMatch.Core.Common;
+using LongoMatch.Core.Interfaces;
 using LongoMatch.Core.Interfaces.GUI;
 using LongoMatch.Core.Store;
 using LongoMatch.Core.Store.Templates;
 
 namespace LongoMatch.Services
 {
-       public class HotKeysManager
+       public class HotKeysManager: IService
        {
                Dictionary<HotKey, DashboardButton> dashboardHotkeys;
                IAnalysisWindow analysisWindow;
@@ -236,5 +237,31 @@ namespace LongoMatch.Services
                                }
                        }
                }
+
+               #region IService
+
+               public int Level {
+                       get {
+                               return 70;
+                       }
+               }
+
+               public string Name {
+                       get {
+                               return "HotKeys manager";
+                       }
+               }
+
+               public bool Start ()
+               {
+                       return true;
+               }
+
+               public bool Stop ()
+               {
+                       return true;
+               }
+
+               #endregion
        }
 }
diff --git a/LongoMatch.Services/PlaylistManager.cs b/LongoMatch.Services/PlaylistManager.cs
index 766a369..fd0777a 100644
--- a/LongoMatch.Services/PlaylistManager.cs
+++ b/LongoMatch.Services/PlaylistManager.cs
@@ -29,7 +29,7 @@ using System;
 
 namespace LongoMatch.Services
 {
-       public class PlaylistManager
+       public class PlaylistManager: IService
        {
                IGUIToolkit guiToolkit;
                IPlayerController player;
@@ -307,7 +307,31 @@ namespace LongoMatch.Services
                                //      return;
                        }
                }
-               
 
+               #region IService
+
+               public int Level {
+                       get {
+                               return 80;
+                       }
+               }
+
+               public string Name {
+                       get {
+                               return "Playlist manager";
+                       }
+               }
+
+               public bool Start ()
+               {
+                       return true;
+               }
+
+               public bool Stop ()
+               {
+                       return true;
+               }
+
+               #endregion
        }
 }
diff --git a/LongoMatch.Services/ProjectsManager.cs b/LongoMatch.Services/ProjectsManager.cs
index e5c8a2f..a3c001a 100644
--- a/LongoMatch.Services/ProjectsManager.cs
+++ b/LongoMatch.Services/ProjectsManager.cs
@@ -27,7 +27,7 @@ using Mono.Unix;
 
 namespace LongoMatch.Services
 {
-       public class ProjectsManager
+       public class ProjectsManager: IService
        {
                IGUIToolkit guiToolkit;
                IMultimediaToolkit multimediaToolkit;
@@ -402,5 +402,30 @@ namespace LongoMatch.Services
                        HandleCaptureFinished (true);
                }
 
+               #region IService
+
+               public int Level {
+                       get {
+                               return 40;
+                       }
+               }
+
+               public string Name {
+                       get {
+                               return "Projects manager";
+                       }
+               }
+
+               public bool Start ()
+               {
+                       return true;
+               }
+
+               public bool Stop ()
+               {
+                       return true;
+               }
+
+               #endregion
        }
 }
diff --git a/LongoMatch.Services/RenderingJobsManager.cs b/LongoMatch.Services/RenderingJobsManager.cs
index 1882e31..8e2ae52 100644
--- a/LongoMatch.Services/RenderingJobsManager.cs
+++ b/LongoMatch.Services/RenderingJobsManager.cs
@@ -28,7 +28,7 @@ using LongoMatch.Core.Store.Playlists;
 
 namespace LongoMatch.Services
 {
-       public class RenderingJobsManager: IRenderingJobsManager
+       public class RenderingJobsManager: IRenderingJobsManager, IService
        {
                /* List of pending jobs */
                List<Job> jobs, pendingJobs;
@@ -409,6 +409,32 @@ namespace LongoMatch.Services
                {
                        MainLoopOnProgress (progress);
                }
+
+               #region IService
+
+               public int Level {
+                       get {
+                               return 30;
+                       }
+               }
+
+               public string Name {
+                       get {
+                               return "Rendering jobs manager";
+                       }
+               }
+
+               public bool Start ()
+               {
+                       return true;
+               }
+
+               public bool Stop ()
+               {
+                       return true;
+               }
+
+               #endregion
        }
 }
 
diff --git a/LongoMatch.Services/TemplatesService.cs b/LongoMatch.Services/TemplatesService.cs
index 7168dc6..20853c1 100644
--- a/LongoMatch.Services/TemplatesService.cs
+++ b/LongoMatch.Services/TemplatesService.cs
@@ -29,7 +29,7 @@ using LongoMatch.Services.Services;
 
 namespace LongoMatch.Services
 {
-       public class TemplatesService: ITemplatesService
+       public class TemplatesService: ITemplatesService, IService
        {
                private Dictionary<Type, ITemplateProvider> dict;
 
@@ -60,6 +60,32 @@ namespace LongoMatch.Services
                                return (ICategoriesTemplatesProvider)dict [typeof(Dashboard)]; 
                        }
                }
+
+               #region IService
+
+               public int Level {
+                       get {
+                               return 10;
+                       }
+               }
+
+               public string Name {
+                       get {
+                               return "Templates provider";
+                       }
+               }
+
+               public bool Start ()
+               {
+                       return true;
+               }
+
+               public bool Stop ()
+               {
+                       return true;
+               }
+
+               #endregion
        }
 
        public class TemplatesProvider<T>: ITemplateProvider<T> where T: ITemplate
diff --git a/LongoMatch.Services/ToolsManager.cs b/LongoMatch.Services/ToolsManager.cs
index e7d3f3d..b2d6435 100644
--- a/LongoMatch.Services/ToolsManager.cs
+++ b/LongoMatch.Services/ToolsManager.cs
@@ -31,7 +31,7 @@ using System.Diagnostics;
 
 namespace LongoMatch.Services
 {
-       public class ToolsManager: IProjectsImporter
+       public class ToolsManager: IProjectsImporter, IService
        {
                
                Project openedProject;
@@ -227,6 +227,32 @@ namespace LongoMatch.Services
                                dbManager.SetActiveByName (dbManager.ActiveDB.Name);
                        }
                }
+
+               #region IService
+
+               public int Level {
+                       get {
+                               return 50;
+                       }
+               }
+
+               public string Name {
+                       get {
+                               return "Tools manager";
+                       }
+               }
+
+               public bool Start ()
+               {
+                       return true;
+               }
+
+               public bool Stop ()
+               {
+                       return true;
+               }
+
+               #endregion
        }
 
        public class ProjectImporter
diff --git a/LongoMatch.Services/UpdatesNotifier.cs b/LongoMatch.Services/UpdatesNotifier.cs
index 95807c8..095c534 100644
--- a/LongoMatch.Services/UpdatesNotifier.cs
+++ b/LongoMatch.Services/UpdatesNotifier.cs
@@ -11,12 +11,13 @@ using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using Mono.Unix;
 using LongoMatch.Core.Common;
+using LongoMatch.Core.Interfaces;
 
 namespace LongoMatch.Services
 {
 
 
-       public class UpdatesNotifier
+       public class UpdatesNotifier: IService
        {
                readonly Version currentVersion;
                Version latestVersion;
@@ -83,5 +84,31 @@ namespace LongoMatch.Services
                        }
                }
                #endregion
+
+               #region IService
+
+               public int Level {
+                       get {
+                               return 90;
+                       }
+               }
+
+               public string Name {
+                       get {
+                               return "Updates notifier";
+                       }
+               }
+
+               public bool Start ()
+               {
+                       return true;
+               }
+
+               public bool Stop ()
+               {
+                       return true;
+               }
+
+               #endregion
        }
 }


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