<?php
include ("dbus_session.php");
header ("Content-Type: text/plain");

$dbus_session = new direct_dbus_session ("unix:///var/run/dbus/system_bus_socket");

// Print data from asynchronous replies
// This is the callback function for this example

function dbus_print_r ($f_message,$f_body)
{
  echo "---\nType:".($f_message->dclass_get_header ("type"))."\n";

 $dbusheader = $f_message->dclass_get_header (1);
 echo "Path:".$dbusheader[1]."\n";

 $dbusheader = $f_message->dclass_get_header (3);
 echo "Member:".$dbusheader[1]."\n\n";

 print_r ($f_body);
 echo "---\n";
}

// Connect to the D-BUS - please check the response in reallife applications ... it may fail and return false!

$dbus_session->dclass_connect ();

// Register a callback for signals of any type

$dbus_session->dclass_callback_register_listener ("signal","","","","dbus_print_r");

// Make a synchronous call and print out the  (partly binary) response via print_r

print_r ($dbus_session->dclass_send_method_call_sync_response ("/","org.freedesktop.DBus","GetNameOwner","org.freedesktop.DBus",NULL,"s",(array ("org.freedesktop.DBus"))));

// Register two callbacks for Hal

$dbus_session->dclass_send_method_call_async_response  ("dbus_print_r","/org/freedesktop/Hal/Manager","org.freedesktop.Hal.Manager","GetAllDevices","org.freedesktop.Hal");
$dbus_session->dclass_send_method_call_async_response  ("dbus_print_r","/org/freedesktop/Hal/Manager","org.freedesktop.Hal.Manager","DeviceExists","org.freedesktop.Hal",NULL,"s",(array ("/org/freedesktop/Hal/devices/acpi_CPU0")));

echo "\n---\nReceive asynchronous replies\n---\n";

$dbus_session->dclass_callback_listen ();

// Disconnect "cleanly"

$dbus_session->dclass_disconnect ();
?>