dbus example added
This commit is contained in:
parent
c3d3d0efc7
commit
acfa130e92
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
dbus-send --type=method_call \
|
||||||
|
--dest=org.example.DemoService \
|
||||||
|
/org/example/demo \
|
||||||
|
org.example.DemoService.SomeMethod
|
||||||
|
|
||||||
|
dbus-send --type=method_call \
|
||||||
|
--dest=org.example.DemoService \
|
||||||
|
/org/example/demo \
|
||||||
|
org.example.DemoService.SomeMethodSender \
|
||||||
|
string:'hello world'
|
|
@ -0,0 +1,54 @@
|
||||||
|
[DBus(name = "org.example.DemoService")]
|
||||||
|
public class DemoService : Object {
|
||||||
|
/* Private field, not exported via D-Bus */
|
||||||
|
int counter;
|
||||||
|
|
||||||
|
/* Public field, not exported via D-Bus */
|
||||||
|
public int status;
|
||||||
|
|
||||||
|
/* Public property, exported via D-Bus */
|
||||||
|
public int something { get; set; }
|
||||||
|
|
||||||
|
/* Public signal, exported via D-Bus
|
||||||
|
* Can be emitted on the server side and can be connected to on the client side.
|
||||||
|
*/
|
||||||
|
public signal void sig1();
|
||||||
|
|
||||||
|
/* Public method, exported via D-Bus */
|
||||||
|
public void some_method() {
|
||||||
|
counter++;
|
||||||
|
stdout.printf("heureka! counter = %d\n", counter);
|
||||||
|
sig1(); // emit signal
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Public method, exported via D-Bus and showing the sender who is
|
||||||
|
is calling the method (not exported in the D-Bus inteface) */
|
||||||
|
public void some_method_sender(string message, GLib.BusName sender) {
|
||||||
|
counter++;
|
||||||
|
stdout.printf("heureka! counter = %d, '%s' message from sender %s\n",
|
||||||
|
counter, message, sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_bus_aquired (DBusConnection conn) {
|
||||||
|
try {
|
||||||
|
// start service and register it as dbus object
|
||||||
|
var service = new DemoService();
|
||||||
|
conn.register_object ("/org/example/demo", service);
|
||||||
|
} catch (IOError e) {
|
||||||
|
stderr.printf ("Could not register service: %s\n", e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main () {
|
||||||
|
// try to register service name in session bus
|
||||||
|
Bus.own_name (BusType.SESSION, "org.example.DemoService", /* name to register */
|
||||||
|
BusNameOwnerFlags.NONE, /* flags */
|
||||||
|
on_bus_aquired, /* callback function on registration succeded */
|
||||||
|
() => {}, /* callback on name register succeded */
|
||||||
|
() => stderr.printf ("Could not aquire name\n"));
|
||||||
|
/* callback on name lost */
|
||||||
|
|
||||||
|
// start main loop
|
||||||
|
new MainLoop ().run ();
|
||||||
|
}
|
|
@ -1,10 +1,8 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# valac --thread --target-glib=2.32 threading-sample.vala \
|
|
||||||
valac --thread threads.vala
|
valac --thread threads.vala
|
||||||
valac --thread --target-glib=2.32 threads-2.32.vala
|
valac --thread --target-glib=2.32 threads-2.32.vala
|
||||||
valac --thread philosophers.vala
|
valac --thread philosophers.vala
|
||||||
valac --thread async-queue-test.vala
|
valac --thread async-queue-test.vala
|
||||||
|
|
||||||
|
valac --pkg gio-2.0 dbus-demo-service.vala
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue