summaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rwxr-xr-xsamples/dbus_client.pl23
-rwxr-xr-xsamples/dbus_client.py27
-rwxr-xr-xsamples/dbus_client.sh22
3 files changed, 72 insertions, 0 deletions
diff --git a/samples/dbus_client.pl b/samples/dbus_client.pl
new file mode 100755
index 000000000..5023eccd6
--- /dev/null
+++ b/samples/dbus_client.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+
+use Net::DBus;
+use Net::DBus::Reactor;
+
+my $bus = Net::DBus->system;
+
+# Get a handle to the 'knotd' service
+my $knotd = $bus->get_service("cz.nic.knotd");
+
+# Get the device manager
+my $knotd_interface = $knotd->get_object("/cz/nic/knotd", "cz.nic.knotd.events");
+
+$knotd_interface->connect_to_signal('zone_updated', sub
+{
+ my ($zone, $serial) = @_;
+ print "Zone $zone updated, SOA serial $serial\n";
+});
+
+# Main loop
+Net::DBus::Reactor->main->run();
+
+exit 0
diff --git a/samples/dbus_client.py b/samples/dbus_client.py
new file mode 100755
index 000000000..0396048ea
--- /dev/null
+++ b/samples/dbus_client.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import dbus
+import dbus.mainloop.glib
+import signal
+from gi.repository import GLib
+
+def sigint_handler(sig, frame):
+ if sig == signal.SIGINT:
+ loop.quit()
+ else:
+ raise ValueError("Undefined handler for '{}'".format(sig))
+
+def updated(*args, **kwargs):
+ (zone, serial) = args
+ print("Zone %s updated, SOA serial %d" % (zone, serial))
+
+if __name__ == '__main__':
+ signal.signal(signal.SIGINT, sigint_handler)
+
+ loop = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+ bus = dbus.SystemBus()
+ knotd = bus.get_object('cz.nic.knotd', '/cz/nic/knotd')
+ events_iface = dbus.Interface(knotd, dbus_interface='cz.nic.knotd.events')
+ events_iface.connect_to_signal("zone_updated", updated)
+ loop = GLib.MainLoop()
+ loop.run()
diff --git a/samples/dbus_client.sh b/samples/dbus_client.sh
new file mode 100755
index 000000000..be23a97b2
--- /dev/null
+++ b/samples/dbus_client.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+cb() {
+ echo "$1 [${@:2}]"
+}
+
+gdbus monitor --system --dest cz.nic.knotd --object-path /cz/nic/knotd \
+ | awk '/^\/cz\/nic\/knotd/ {
+ gsub("cz.nic.knotd.events.", "", $2);
+ tmp="";
+ for(i=3;i<=NF;++i) {
+ if( $i ~ /[\),]$/ ) tmp=tmp$i;
+ }
+ gsub(/(^\()|(\)$)/, "", tmp);
+ split(tmp, args, ",");
+ printf "%s ", $2;
+ for (i in args) printf "%s ", args[i];
+ print "";
+ fflush(stdout); }' \
+ | while read line; do \
+ cb ${line[@]}; \
+ done