banshee r4542 - in trunk/banshee: . src/Clients/Beroe src/Clients/Beroe/Beroe src/Clients/Booter src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.Collection.Indexer.RemoteHelper



Author: abock
Date: Mon Sep 15 18:50:41 2008
New Revision: 4542
URL: http://svn.gnome.org/viewvc/banshee?rev=4542&view=rev

Log:
2008-09-15  Aaron Bockover  <abock gnome org>

    * src/Clients/Beroe/Beroe/IndexerClient.cs: Support a --client option to
    run the fake indexer client

    * src/Clients/Beroe/Beroe/RemoteClient.cs: An example client indexer
    that doesn't really do anything

    * src/Core/Banshee.Services/Banshee.Collection.Indexer.RemoteHelper/IndexerClient.cs:
    First pass at a wrapper implementing the proper logic for interacting
    with the Banshee indexer and respecting the boot sequence and client
    startup hints



Added:
   trunk/banshee/src/Clients/Beroe/Beroe/RemoteClient.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer.RemoteHelper/
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer.RemoteHelper/IndexerClient.cs
Modified:
   trunk/banshee/Banshee.sln
   trunk/banshee/ChangeLog
   trunk/banshee/src/Clients/Beroe/Beroe.csproj
   trunk/banshee/src/Clients/Beroe/Beroe/IndexerClient.cs
   trunk/banshee/src/Clients/Beroe/Makefile.am
   trunk/banshee/src/Clients/Booter/Booter.csproj
   trunk/banshee/src/Core/Banshee.Services/Banshee.Services.csproj
   trunk/banshee/src/Core/Banshee.Services/Makefile.am

Modified: trunk/banshee/Banshee.sln
==============================================================================
--- trunk/banshee/Banshee.sln	(original)
+++ trunk/banshee/Banshee.sln	Mon Sep 15 18:50:41 2008
@@ -14,12 +14,12 @@
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nereid", "src\Clients\Nereid\Nereid.csproj", "{4F66A4DE-5204-4150-8D0B-CE21CA52E309}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Beroe", "src\Clients\Beroe\Beroe.csproj", "{E0E10333-9B05-4463-8A15-6738C186BF87}"
-EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Halie", "src\Clients\Halie\Halie.csproj", "{B574AEB0-59F1-4FB7-A91A-8E5A651970CE}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Booter", "src\Clients\Booter\Booter.csproj", "{4B890CB0-F5C8-4B1B-A1B8-3813BF5126C0}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Beroe", "src\Clients\Beroe\Beroe.csproj", "{E0E10333-9B05-4463-8A15-6738C186BF87}"
+EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{48EA1A64-29EE-4555-9E79-49453EB51976}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Banshee.Widgets", "src\Core\Banshee.Widgets\Banshee.Widgets.csproj", "{A3701765-E571-413D-808C-9788A22791AF}"
@@ -215,10 +215,9 @@
 		{4F47D6F1-4047-4A89-AE85-3AE5EF9F2961} = {E6AD3714-5EA3-49D9-BA8D-12C69B2B8067}
 		{EABA3019-7539-4430-9935-D36CEA96F250} = {EB1FDF3F-048C-4010-80F5-D936A312580F}
 		{4F66A4DE-5204-4150-8D0B-CE21CA52E309} = {EB1FDF3F-048C-4010-80F5-D936A312580F}
-		{E0E10333-9B05-4463-8A15-6738C186BF87} = {EB1FDF3F-048C-4010-80F5-D936A312580F}
 		{B574AEB0-59F1-4FB7-A91A-8E5A651970CE} = {EB1FDF3F-048C-4010-80F5-D936A312580F}
-		{E0E10333-9B05-4463-8A15-6738C186BF87} = {EB1FDF3F-048C-4010-80F5-D936A312580F}
 		{4B890CB0-F5C8-4B1B-A1B8-3813BF5126C0} = {EB1FDF3F-048C-4010-80F5-D936A312580F}
+		{E0E10333-9B05-4463-8A15-6738C186BF87} = {EB1FDF3F-048C-4010-80F5-D936A312580F}
 		{A3701765-E571-413D-808C-9788A22791AF} = {48EA1A64-29EE-4555-9E79-49453EB51976}
 		{B28354F0-BA87-44E8-989F-B864A3C7C09F} = {48EA1A64-29EE-4555-9E79-49453EB51976}
 		{2ADB831A-A050-47D0-B6B9-9C19D60233BB} = {48EA1A64-29EE-4555-9E79-49453EB51976}

Modified: trunk/banshee/src/Clients/Beroe/Beroe.csproj
==============================================================================
--- trunk/banshee/src/Clients/Beroe/Beroe.csproj	(original)
+++ trunk/banshee/src/Clients/Beroe/Beroe.csproj	Mon Sep 15 18:50:41 2008
@@ -46,6 +46,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Beroe\IndexerClient.cs" />
+    <Compile Include="Beroe\RemoteClient.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ProjectExtensions>

Modified: trunk/banshee/src/Clients/Beroe/Beroe/IndexerClient.cs
==============================================================================
--- trunk/banshee/src/Clients/Beroe/Beroe/IndexerClient.cs	(original)
+++ trunk/banshee/src/Clients/Beroe/Beroe/IndexerClient.cs	Mon Sep 15 18:50:41 2008
@@ -48,6 +48,9 @@
             if (!DBusConnection.Enabled) {
                 Log.Error ("All commands ignored, DBus support is disabled");
                 return;
+            } else if (ApplicationContext.CommandLine.Contains ("client")) {
+                ActAsRemoteClient ();
+                return;
             } else if (DBusConnection.ApplicationInstanceAlreadyRunning) {
                 Log.Error ("Banshee is already running");
                 return;
@@ -59,6 +62,16 @@
             Startup ();
         }
         
+        private static void ActAsRemoteClient ()
+        {
+            BusG.Init ();
+        
+            RemoteClient remote_client = new RemoteClient ();
+            remote_client.Start ();
+            
+            DBusConnection.RunMainLoop ();
+        }
+        
         private static void Startup ()
         {
             ThreadAssist.InitializeMainThread ();

Added: trunk/banshee/src/Clients/Beroe/Beroe/RemoteClient.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Clients/Beroe/Beroe/RemoteClient.cs	Mon Sep 15 18:50:41 2008
@@ -0,0 +1,79 @@
+//
+// RemoteClient.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Threading;
+
+namespace Beroe
+{
+    public class RemoteClient : Banshee.Collection.Indexer.RemoteHelper.IndexerClient
+    {
+        private object shutdown_mutex = new object ();
+        private bool indexer_running;
+        private bool shutdown_requested;
+        
+        protected override void ResetState ()
+        {
+            lock (shutdown_mutex) {
+                if (indexer_running) {
+                    Console.WriteLine ("Triggering reset");
+                    shutdown_requested = true;
+                }
+            }
+        }
+        
+        protected override void UpdateIndex ()
+        {
+            lock (shutdown_mutex) {
+                indexer_running = true;
+                shutdown_requested = false;
+            }
+            
+            int i = 0;
+            Console.Write ("UPDATING INDEX... ");
+            while (i++ < 20 && !Shutdown) {
+                Console.Write ("{0} ", i);
+                System.Threading.Thread.Sleep (1000);
+            }
+            Console.WriteLine (": Done");
+            
+            lock (shutdown_mutex) {
+                indexer_running = false;
+                shutdown_requested = false;
+            }
+        }
+        
+        private bool Shutdown {
+            get { lock (shutdown_mutex) { return shutdown_requested || CleanupAndShutdown; } }
+        }
+        
+        protected override bool HasCollectionChanged {
+            get { return true; }
+        }
+    }
+}

Modified: trunk/banshee/src/Clients/Beroe/Makefile.am
==============================================================================
--- trunk/banshee/src/Clients/Beroe/Makefile.am	(original)
+++ trunk/banshee/src/Clients/Beroe/Makefile.am	Mon Sep 15 18:50:41 2008
@@ -1,7 +1,9 @@
 ASSEMBLY = Beroe
 TARGET = exe
 LINK = $(REF_BEROE)
-SOURCES = Beroe/IndexerClient.cs
+SOURCES =  \
+	Beroe/IndexerClient.cs \
+	Beroe/RemoteClient.cs
 
 include $(top_srcdir)/build/build.mk
 

Modified: trunk/banshee/src/Clients/Booter/Booter.csproj
==============================================================================
--- trunk/banshee/src/Clients/Booter/Booter.csproj	(original)
+++ trunk/banshee/src/Clients/Booter/Booter.csproj	Mon Sep 15 18:50:41 2008
@@ -64,4 +64,4 @@
       </Properties>
     </MonoDevelop>
   </ProjectExtensions>
-</Project>
+</Project>
\ No newline at end of file

Added: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer.RemoteHelper/IndexerClient.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer.RemoteHelper/IndexerClient.cs	Mon Sep 15 18:50:41 2008
@@ -0,0 +1,184 @@
+//
+// IndexerClient.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Threading;
+
+using NDesk.DBus;
+using org.freedesktop.DBus;
+
+using Banshee.Collection.Indexer;
+
+namespace Banshee.Collection.Indexer.RemoteHelper
+{
+    public abstract class IndexerClient
+    {
+        private const string application_bus_name = "org.bansheeproject.Banshee";
+        private const string indexer_bus_name = "org.bansheeproject.CollectionIndexer";
+        
+        private const string service_interface = "org.bansheeproject.CollectionIndexer.Service";
+        private static ObjectPath service_path = new ObjectPath ("/org/bansheeproject/Banshee/CollectionIndexerService");
+    
+        private IBus session_bus;
+        private bool listening;
+        private ICollectionIndexerService service;
+        private bool cleanup_and_shutdown;
+        private ManualResetEvent indexer_reset_event = new ManualResetEvent (true);
+        
+        public void Start ()
+        {
+            session_bus = Bus.Session.GetObject<IBus> ("org.freedesktop.DBus", new ObjectPath ("/org/freedesktop/DBus"));
+            session_bus.NameOwnerChanged += OnBusNameOwnerChanged;
+            
+            if (Bus.Session.NameHasOwner (indexer_bus_name)) {
+                ConnectToIndexerService ();
+            } else {
+                Bus.Session.StartServiceByName (indexer_bus_name);
+            }
+        }
+
+        private void OnBusNameOwnerChanged (string name, string oldOwner, string newOwner)
+        {
+            if (name == indexer_bus_name) {
+                if (String.IsNullOrEmpty (newOwner)) {
+                    // Do not disconnect since we're already disconnected
+                    ResetInternalState ();
+                } else {
+                    ConnectToIndexerService ();
+                }
+            }
+        }
+        
+        private void Index ()
+        {
+            if (HasCollectionChanged) {
+                ThreadPool.QueueUserWorkItem (delegate {
+                    try {
+                        UpdateIndex ();
+                    } catch (Exception e) {
+                        Console.Error.WriteLine (e);
+                    }
+                    
+                    if (!ApplicationAvailable || !listening) {
+                        DisconnectFromIndexerService ();
+                    }
+                });
+            }
+        }
+        
+        private void ConnectToIndexerService ()
+        {
+            DisconnectFromIndexerService ();
+            ResolveIndexerService ();
+            
+            service.CleanupAndShutdown += OnCleanupAndShutdown;
+            
+            if (ApplicationAvailable) {
+                listening = true;
+                service.CollectionChanged += OnCollectionChanged;
+            }
+            
+            Index ();
+        }
+        
+        private void DisconnectFromIndexerService ()
+        {
+            if (service == null) {
+                return;
+            }
+            
+            if (listening) {
+                try {
+                    listening = false;
+                    service.CollectionChanged -= OnCollectionChanged;
+                } catch {
+                }
+            }
+            
+            try {
+                service.Shutdown ();
+                service.CleanupAndShutdown -= OnCleanupAndShutdown;
+            } catch {
+            }
+            
+            ResetInternalState ();
+        }
+        
+        private void ResetInternalState ()
+        {
+            service = null;
+            listening = false;
+            cleanup_and_shutdown = false;
+            ResetState ();
+        }
+        
+        private void ResolveIndexerService ()
+        {
+            int attempts = 0;
+            
+            while (attempts++ < 4) {
+                try {
+                    service = Bus.Session.GetObject<ICollectionIndexerService> (indexer_bus_name, service_path);
+                    service.Hello ();
+                    return;
+                } catch { 
+                    service = null;
+                    System.Threading.Thread.Sleep (2000);
+                }
+            }
+        }
+        
+        private void OnCollectionChanged ()
+        {
+            Index ();
+        }
+        
+        private void OnCleanupAndShutdown ()
+        {
+            cleanup_and_shutdown = true;
+        }
+        
+        protected abstract bool HasCollectionChanged { get; }
+        
+        protected abstract void UpdateIndex ();
+        
+        protected abstract void ResetState ();
+        
+        protected bool CleanupAndShutdown {
+            get { return cleanup_and_shutdown; }
+        }
+        
+        protected ICollectionIndexerService Service {
+            get { return service; }
+        }
+        
+        protected bool ApplicationAvailable {
+            get { return Bus.Session.NameHasOwner (application_bus_name); }
+        }
+    }
+}

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Services.csproj
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Services.csproj	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Services.csproj	Mon Sep 15 18:50:41 2008
@@ -234,6 +234,7 @@
     <Compile Include="Banshee.Configuration\DefaultApplicationHelper.cs" />
     <Compile Include="Banshee.Collection.Indexer\IIndexerClient.cs" />
     <Compile Include="Banshee.Collection\RescanPipeline.cs" />
+    <Compile Include="Banshee.Collection.Indexer.RemoteHelper\IndexerClient.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Banshee.Services.addin.xml" />

Modified: trunk/banshee/src/Core/Banshee.Services/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Makefile.am	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Makefile.am	Mon Sep 15 18:50:41 2008
@@ -22,6 +22,7 @@
 	Banshee.Collection.Database/IDatabaseTrackModelCache.cs \
 	Banshee.Collection.Database/IDatabaseTrackModelProvider.cs \
 	Banshee.Collection.Database/QueryFilterInfo.cs \
+	Banshee.Collection.Indexer.RemoteHelper/IndexerClient.cs \
 	Banshee.Collection.Indexer/CollectionIndexer.cs \
 	Banshee.Collection.Indexer/CollectionIndexerService.cs \
 	Banshee.Collection.Indexer/ICollectionIndexer.cs \



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