blam r547 - trunk/src



Author: cmartin
Date: Sat Apr 19 08:47:19 2008
New Revision: 547
URL: http://svn.gnome.org/viewvc/blam?rev=547&view=rev

Log:
Simplify the D-Bus code a bit and unregister early.

Make the code a bit shorter and readable and unregister as soon as we've
been asked to exit.


Modified:
   trunk/src/Application.cs
   trunk/src/DBus.cs

Modified: trunk/src/Application.cs
==============================================================================
--- trunk/src/Application.cs	(original)
+++ trunk/src/Application.cs	Sat Apr 19 08:47:19 2008
@@ -72,6 +72,8 @@
 
         private uint              mAutoRefreshId;
 
+        DBusMgr dbusmgr = null;
+
 
         private MessageConnection.MessageReceivedHandler mIpcHandler;
 
@@ -233,17 +235,27 @@
         private void SetupDBus()
         {
             try{
-                DBusMgr dbusmgr = new DBusMgr(this);
+                dbusmgr = new DBusMgr(this);
                 dbusmgr.Register();
             } catch (Exception e){
                 Console.WriteLine("Unable to start DBus interface: {0}", e.Message);
             }
         }
+
+        private void StopDBus()
+        {
+            dbusmgr.Unregister();
+        }
 #else
         private void SetupDBus ()
         {
             // Do nothing
         }
+
+        private void StopDBus()
+        {
+            // Stub
+        }
 #endif
 
         private void ChannelSelected(Channel channel)
@@ -457,9 +469,9 @@
 
         public void QuitActivated(object obj, EventArgs args)
         {
+            StopDBus();
             SaveWindowState();
             mainWindow.Hide();
-
             mCollection.SaveToFile ();
             mCollection.StopAllThreads();
 

Modified: trunk/src/DBus.cs
==============================================================================
--- trunk/src/DBus.cs	(original)
+++ trunk/src/DBus.cs	Sat Apr 19 08:47:19 2008
@@ -17,7 +17,8 @@
     public class DBusMgr : IDBlam {
         
         public static string bus_name = "org.gnome.feed.Reader";
-        public static string obj_path = "/org/gnome/feed/Reader";
+        public static ObjectPath obj_path = new ObjectPath("/org/gnome/feed/Reader");
+        public static Bus bus = Bus.Session;
 
         private Application app = null;
 
@@ -37,38 +38,32 @@
             Unregister();
         }
 
-        public static bool running()
-        { /* TODO: Shouldn't we make sure we are the owners? */
-            return Bus.Session.NameHasOwner(bus_name);
-        }
-        
         public void Register()
         {
-            if(running())
-                return;
-            
-            Bus.Session.RequestName(bus_name);
-            Bus.Session.Register(new ObjectPath(obj_path), this);
-            /* TODO: We should probably try to unregister whatever we had registered
-             * when we failed.
-             */
+            if(bus.RequestName(bus_name) == RequestNameReply.PrimaryOwner){
+                bus.Register(obj_path, this);
+            }
         }
-        
+
         public void Unregister()
         {
-            if(!running())
-                return;
+            if(running()){
+                bus.Unregister(obj_path);
+                bus.ReleaseName(bus_name);
+            }
+        }
 
-            Bus.Session.Unregister(new ObjectPath(obj_path));
-            Bus.Session.ReleaseName(bus_name);
+        public static bool running()
+        { /* TODO: Shouldn't we make sure we are the owners? */
+            return bus.NameHasOwner(bus_name);
         }
-        
+
         public static DBusMgr GetInstance()
         {
             if(!running())
                 return null;
 
-            return Bus.Session.GetObject<DBusMgr>(bus_name, new ObjectPath(obj_path));
+            return bus.GetObject<DBusMgr>(bus_name, obj_path);
         }
 
         public bool Subscribe(string url)



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