Do not use NameHasOwner() for single instance detection
This commit is contained in:
Родитель
75562f224c
Коммит
a87a917724
|
@ -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<DemoObject> (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<DemoObject> (bus_name, path);
|
||||
}
|
||||
|
||||
//run the main loop
|
||||
Application.Run ();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,20 +28,20 @@ public class TestGLib
|
|||
bus = Bus.Session;
|
||||
sysBus = Bus.System.GetObject<IBus> ("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<DemoObject> (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<DemoObject> (bus_name, path);
|
||||
}
|
||||
|
||||
//run the main loop
|
||||
Application.Run ();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Button> (myNameReq, myPath);
|
||||
} else {
|
||||
bus.Register (myNameReq, myPath, btn);
|
||||
|
||||
RequestNameReply nameReply = bus.RequestName (myNameReq);
|
||||
Console.WriteLine ("RequestNameReply: " + nameReply);
|
||||
string bus_name = "org.ndesk.gtest";
|
||||
ObjectPath path = new ObjectPath ("/org/ndesk/btn");
|
||||
|
||||
if (bus.RequestName (bus_name) == RequestNameReply.PrimaryOwner) {
|
||||
bus.Register (bus_name, path, btn);
|
||||
rbtn = btn;
|
||||
} else {
|
||||
rbtn = bus.GetObject<Button> (bus_name, path);
|
||||
}
|
||||
|
||||
//run the main loop
|
||||
Application.Run ();
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче