From a87a917724fee6c31f5393e62292947424863e85 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Sun, 7 Oct 2007 07:33:20 +0100 Subject: [PATCH] Do not use NameHasOwner() for single instance detection --- examples/TestExport.cs | 19 +++++++++---------- examples/TestSystemBus.cs | 18 +++++++++--------- examples/TestUI.cs | 17 +++++++---------- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/examples/TestExport.cs b/examples/TestExport.cs index 380609d..a360a31 100644 --- a/examples/TestExport.cs +++ b/examples/TestExport.cs @@ -36,22 +36,21 @@ public class TestGLib win.Destroyed += delegate {Application.Quit ();}; win.ShowAll (); - bus = Bus.Session; - string myNameReq = "org.ndesk.gtest"; - ObjectPath myPath = new ObjectPath ("/org/ndesk/test"); + string bus_name = "org.ndesk.gtest"; + ObjectPath path = new ObjectPath ("/org/ndesk/test"); - if (bus.NameHasOwner (myNameReq)) { - demo = bus.GetObject (myNameReq, myPath); - } else { + if (bus.RequestName (bus_name) == RequestNameReply.PrimaryOwner) { + //create a new instance of the object to be exported demo = new DemoObject (); - bus.Register (myNameReq, myPath, demo); - - RequestNameReply nameReply = bus.RequestName (myNameReq); - Console.WriteLine ("RequestNameReply: " + nameReply); + bus.Register (bus_name, path, demo); + } else { + //import a remote to a local proxy + demo = bus.GetObject (bus_name, path); } + //run the main loop Application.Run (); } } diff --git a/examples/TestSystemBus.cs b/examples/TestSystemBus.cs index c142aab..a7a039d 100644 --- a/examples/TestSystemBus.cs +++ b/examples/TestSystemBus.cs @@ -28,20 +28,20 @@ public class TestGLib bus = Bus.Session; sysBus = Bus.System.GetObject ("org.freedesktop.DBus", new ObjectPath ("/org/freedesktop/DBus")); - string myNameReq = "org.ndesk.gtest"; - ObjectPath myPath = new ObjectPath ("/org/ndesk/test"); + string bus_name = "org.ndesk.gtest"; + ObjectPath path = new ObjectPath ("/org/ndesk/test"); - if (bus.NameHasOwner (myNameReq)) { - demo = bus.GetObject (myNameReq, myPath); - } else { + if (bus.RequestName (bus_name) == RequestNameReply.PrimaryOwner) { + //create a new instance of the object to be exported demo = new DemoObject (); sysBus.NameOwnerChanged += demo.FireChange; - bus.Register (myNameReq, myPath, demo); - - RequestNameReply nameReply = bus.RequestName (myNameReq, NameFlag.None); - Console.WriteLine ("RequestNameReply: " + nameReply); + bus.Register (bus_name, path, demo); + } else { + //import a remote to a local proxy + demo = bus.GetObject (bus_name, path); } + //run the main loop Application.Run (); } } diff --git a/examples/TestUI.cs b/examples/TestUI.cs index e1b9fda..71a240b 100644 --- a/examples/TestUI.cs +++ b/examples/TestUI.cs @@ -43,20 +43,17 @@ public class TestGLib bus = Bus.Session; - string myNameReq = "org.ndesk.gtest"; - ObjectPath myPath = new ObjectPath ("/org/ndesk/btn"); - - if (bus.NameHasOwner (myNameReq)) { - rbtn = bus.GetObject