Help with simple example use of perl's Net::DBus
Daniel P. Berrange
dan at berrange.com
Mon Mar 10 07:18:39 PDT 2008
On Mon, Mar 10, 2008 at 09:46:32AM -0400, Madison Kelly wrote:
> Hi all,
>
> I've been trying to use Net::DBus for a fairly simple purpose;
> connect to the system bus and listen for signals. Nothing more. However,
> I seem to be quite daft as this simple task escapes me. I had decided to
> give up on it for now and listed to a system call to 'dbus-monitor
> --system --profile', but it turns out that is not feasible because of
> the output being buffered causing unfeasible delays in the perl code
> seeing the output.
Take a look at the code in the 'examples' directory of the Net::DBus
binding - it demonstrates how to listen for signals,
http://search.cpan.org/src/DANBERR/Net-DBus-0.33.6/examples/
eg This code from 'example-signal-receive.pl' will listen for 'HelloSignal'
and 'hello_signal_handler' will be called each time the signal is emitted:
my $bus = Net::DBus->session();
my $service = $bus->get_service("org.designfu.TestService");
my $object = $service->get_object("/org/designfu/TestService/object",
"org.designfu.TestService");
sub hello_signal_handler {
my $greeting = shift;
print "Received hello signal with greeting '$greeting'\n";
}
$object->connect_to_signal("HelloSignal", \&hello_signal_handler);
my $reactor = Net::DBus::Reactor->main();
$reactor->run();
The 'example-signal-emitter.pl' is the corresponding server side to test
with.
Regards,
Dan.
--
|: http://berrange.com/ -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://freshmeat.net/~danielpb/ -o- http://gtk-vnc.sourceforge.net :|
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/dbus/attachments/20080310/5209ae70/attachment.pgp
More information about the dbus
mailing list