blam r606 - trunk/src



Author: atoker
Date: Tue Jun 17 03:01:12 2008
New Revision: 606
URL: http://svn.gnome.org/viewvc/blam?rev=606&view=rev

Log:
Remove needless DBusMgr wrapper and fix a potential race condition

Removed:
   trunk/src/DBus.cs
Modified:
   trunk/src/Application.cs
   trunk/src/Makefile.am

Modified: trunk/src/Application.cs
==============================================================================
--- trunk/src/Application.cs	(original)
+++ trunk/src/Application.cs	Tue Jun 17 03:01:12 2008
@@ -19,6 +19,10 @@
 using System.Text;
 using System.Runtime.InteropServices;
 using WebKit;
+#if ENABLE_DBUS
+using NDesk.DBus;
+using org.freedesktop.DBus;
+#endif
 
 namespace Imendio.Blam {
 
@@ -32,6 +36,11 @@
 
     public class Application : Program, IFeedReader {
 
+#if ENABLE_DBUS
+        static string bus_name = "org.gnome.feed.Reader";
+        static ObjectPath obj_path = new ObjectPath("/org/gnome/feed/Reader");
+#endif
+
 	[DllImport("libc")]
 	private static extern int prctl(int option, byte [] arg2, ulong arg3, 
     	ulong arg4, ulong arg5);
@@ -80,7 +89,6 @@
 
         private uint              mAutoRefreshId;
 
-        DBusMgr dbusmgr = null;
         Gnome.Client client = null;
 
 
@@ -255,25 +263,32 @@
         private void SetupDBus()
         {
             try{
-                dbusmgr = new DBusMgr(this);
-                dbusmgr.Register();
+                BusG.Init();
+                Bus bus = Bus.Session;
 
-				/* Yes, this is the state that's returned to us. */
-                if(dbusmgr.ReqNameReply != org.freedesktop.DBus.RequestNameReply.PrimaryOwner){
-                    IFeedReader reader = DBusMgr.GetInstance();
+                if (bus.RequestName(bus_name) == RequestNameReply.PrimaryOwner) {
+                    bus.Register(obj_path, this);
+                } else {
+                    IFeedReader reader = bus.GetObject<IFeedReader>(bus_name, obj_path);
                     reader.ShowWindow();
                     Gdk.Global.NotifyStartupComplete ();
                     Environment.Exit(0);
                 }
 
-            } catch (Exception e){
-                Console.WriteLine("Unable to start DBus interface: {0}", e.Message);
+            } catch (Exception e) {
+                Console.Error.WriteLine("Unable to start D-Bus interface: {0}", e.Message);
             }
         }
 
         private void StopDBus()
         {
-            dbusmgr.Unregister();
+            try {
+                Bus bus = Bus.Session;
+                bus.Unregister(obj_path);
+                bus.ReleaseName(bus_name);
+            } catch (Exception e) {
+                Console.Error.WriteLine("Unable to stop D-Bus interface: {0}", e.Message);
+            }
         }
 #else
         private void SetupDBus ()

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Tue Jun 17 03:01:12 2008
@@ -43,7 +43,6 @@
 if ENABLE_DBUS
 FLAGS += -define:ENABLE_DBUS
 ASSEMBLIES += $(DBUS_LIBS)
-BLAM_CSFILES += DBus.cs
 endif
 
 
@@ -65,7 +64,6 @@
 EXTRA_DIST = \
 	     $(BLAM_CSFILES)   \
 	     Defines.cs.in     \
-	     DBus.cs \
 	     blam.glade
 
 CLEANFILES = blam.exe \



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