зеркало из
1
0
Форкнуть 0

Do not use NameHasOwner() for single instance detection

This commit is contained in:
Alp Toker 2007-10-07 07:33:20 +01:00
Родитель 75562f224c
Коммит a87a917724
3 изменённых файлов: 25 добавлений и 29 удалений

Просмотреть файл

@ -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 ();
}
}