Skip to content
Browse files

examples of watching to signals

  • Loading branch information...
1 parent 706136b commit ab289d84ccff94a59e936192a0408f6802fd7bd2 @robertbasic committed Dec 21, 2011
Showing with 77 additions and 0 deletions.
  1. +29 −0 dbus/dbus-signals-kill.php
  2. +25 −0 dbus/dbus-signals-multiple.php
  3. +23 −0 dbus/dbus-signals.php
View
29 dbus/dbus-signals-kill.php
@@ -0,0 +1,29 @@
+<?php
+
+$dbus = new Dbus(Dbus::BUS_SESSION);
+
+$interface = "im.pidgin.purple.PurpleInterface";
+$method = "ReceivedImMsg";
+// watching only for this particular signal on this particular interface
+$dbus->addWatch($interface, $method);
+
+$kill = false;
+do {
+ $signal = $dbus->waitLoop(1000);
+
+ if ($signal instanceof DbusSignal) {
+ // even if we watch only for one signal on one interface
+ // we still can get rubbish, so making sure this is what we need
+ if ($signal->matches($interface, $method)) {
+ $data = $signal->getData()->getData();
+ // if we received "kill" as a message, then kill it.
+ if ($data[2] == 'kill') {
+ $kill = true;
+ echo "Goodbye, cruel world!\n";
+ } else {
+ echo "Got stuff!\n";
+ }
+ }
+ }
+
+} while (!$kill);
View
25 dbus/dbus-signals-multiple.php
@@ -0,0 +1,25 @@
+<?php
+
+$dbus = new Dbus(Dbus::BUS_SESSION);
+
+$interface = "im.pidgin.purple.PurpleInterface";
+$methodIm = "ReceivedImMsg";
+$methodChat = "ReceivedChatMsg";
+// watching for all signals on one interface
+$dbus->addWatch($interface);
+// if need to watch on more interfaces, just call addWatch(other_interface) again
+
+do {
+ $signal = $dbus->waitLoop(1000);
+
+ if ($signal instanceof DbusSignal) {
+ $data = $signal->getData()->getData();
+ // filtering out multiple signals
+ if ($signal->matches($interface, $methodIm)) {
+ echo "Got stuff via IM!\n";
+ } else if ($signal->matches($interface, $methodChat)) {
+ echo "Got stuff via Chat (IRC)!\n";
+ }
+ }
+
+} while (true);
View
23 dbus/dbus-signals.php
@@ -0,0 +1,23 @@
+<?php
+
+$dbus = new Dbus(Dbus::BUS_SESSION);
+
+$interface = "im.pidgin.purple.PurpleInterface";
+$method = "ReceivedImMsg";
+// watching only for this particular signal on this particular interface
+$dbus->addWatch($interface, $method);
+
+do {
+ $signal = $dbus->waitLoop(1000);
+
+ if ($signal instanceof DbusSignal) {
+ // even if we watch only for one signal on one interface
+ // we still can get rubbish, so making sure this is what we need
+ if ($signal->matches($interface, $method)) {
+ // data is in this weird DbusSet object thingy
+ $data = $signal->getData()->getData();
+ echo "Got stuff!\n";
+ }
+ }
+
+} while (true);

0 comments on commit ab289d8

Please sign in to comment.
Something went wrong with that request. Please try again.