public static int Main(string[] args) { new QCoreApplication(args); if (!QDBusConnection.SessionBus().IsConnected()) { Console.WriteLine("Cannot connect to the D-BUS session bus.\n" + "To start it, run:\n" + "\teval `dbus-launch --auto-syntax`\n"); return 1; } QDBusInterface iface = new QDBusInterface(SERVICE_NAME, "/", "", QDBusConnection.SessionBus()); if (iface.IsValid()) { QDBusMessage message = iface.Call("ping", args.Length > 0 ? args[0] : ""); QDBusReply<string> reply = new QDBusReply<string>(message); if (reply.IsValid()) { Console.WriteLine("Reply was: {0}", reply.Value()); return 0; } Console.WriteLine("Call failed: {0}\n", reply.Error().Message()); return 1; } Console.WriteLine(QDBusConnection.SessionBus().LastError().Message()); return 1; }
public static int Main(string[] args) { new QCoreApplication(args); if (!QDBusConnection.SessionBus().IsConnected()) { Console.WriteLine("Cannot connect to the D-BUS session bus.\n" + "To start it, run:\n" + "\teval `dbus-launch --auto-syntax`\n"); return(1); } QDBusInterface iface = new QDBusInterface(SERVICE_NAME, "/", "", QDBusConnection.SessionBus()); if (iface.IsValid()) { QDBusMessage message = iface.Call("ping", args.Length > 0 ? args[0] : ""); QDBusReply <string> reply = new QDBusReply <string>(message); if (reply.IsValid()) { Console.WriteLine("Reply was: {0}", reply.Value()); return(0); } Console.WriteLine("Call failed: {0}\n", reply.Error().Message()); return(1); } Console.WriteLine(QDBusConnection.SessionBus().LastError().Message()); return(1); }
public void Start(string name, string oldValue, string newValue) { if (name != SERVICE_NAME || newValue == "") { return; } // find our remote iface = new QDBusInterface(SERVICE_NAME, "/", "com.trolltech.QtDBus.ComplexPong.Pong", QDBusConnection.SessionBus(), this); if (!iface.IsValid()) { Console.Error.WriteLine(QDBusConnection.SessionBus().LastError().Message()); QCoreApplication.Quit(); } Connect(iface, SIGNAL("aboutToQuit()"), QCoreApplication.Instance(), SLOT("quit()")); while (true) { Console.Write("Ask your question: "); string line = Console.ReadLine().Trim(); if (line == "") { iface.Call("quit"); return; } else if (line == "value") { QVariant reply = iface.Property("value"); if (!reply.IsNull()) { Console.WriteLine("value = {0}",reply.ToString()); } } else if (line.StartsWith("value=")) { iface.SetProperty("value",new QVariant(line.Substring(6))); } else { QDBusReply <string> reply = new QDBusReply <string>(iface.Call("query",new QVariant(line))); if (reply.IsValid()) { Console.WriteLine("Reply was: {0}",reply.Value()); } } if (iface.LastError().IsValid()) { Console.Error.WriteLine("Call failed: {0}",iface.LastError().Message()); } } }
public static void Method1() { Console.WriteLine("Method 1:"); QDBusReply <List <string> > reply = QDBusConnection.SessionBus().Interface().RegisteredServiceNames(); if (!reply.IsValid()) { Console.WriteLine("Error:{0}", reply.Error().Message()); return; } foreach (string name in reply.Value()) { Console.WriteLine(name); } }
public void Start(string name, string oldValue, string newValue) { if (name != SERVICE_NAME || newValue == "") return; // find our remote iface = new QDBusInterface(SERVICE_NAME, "/", "com.trolltech.QtDBus.ComplexPong.Pong", QDBusConnection.SessionBus(), this); if (!iface.IsValid()) { Console.Error.WriteLine(QDBusConnection.SessionBus().LastError().Message()); QCoreApplication.Quit(); } Connect(iface, SIGNAL("aboutToQuit()"), QCoreApplication.Instance(), SLOT("quit()")); while (true) { Console.Write("Ask your question: "); string line = Console.ReadLine().Trim(); if (line == "") { iface.Call("quit"); return; } else if (line == "value") { QVariant reply = iface.Property("value"); if (!reply.IsNull()) Console.WriteLine("value = {0}", reply.ToString()); } else if (line.StartsWith("value=")) { iface.SetProperty("value", new QVariant(line.Substring(6))); } else { QDBusReply<string> reply = new QDBusReply<string>(iface.Call("query", new QVariant(line))); if (reply.IsValid()) Console.WriteLine("Reply was: {0}", reply.Value()); } if (iface.LastError().IsValid()) Console.Error.WriteLine("Call failed: {0}", iface.LastError().Message()); } }