• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

t/H22-Jun-2010-65

COPYINGH A D20-Jun-201088 42

ChangesH A D22-Jun-2010510 1712

DBus.pmH A D22-Jun-20104.4 KiB18660

MANIFESTH A D22-Jun-2010222 109

META.jsonH A D22-Jun-2010451 21

META.ymlH A D22-Jun-2010643 3130

Makefile.PLH A D21-Jun-2010436 2016

READMEH A D22-Jun-20102.8 KiB8964

README

1NAME
2    AnyEvent::DBus - adapt Net::DBus to AnyEvent
3
4SYNOPSIS
5       use AnyEvent::DBus;
6
7       # now use the Net::DBus API, preferably the non-blocking variants:
8
9       use Net::DBus::Annotation qw(:call);
10
11       $bus->get_object (...)
12           ->Method (dbus_call_async, $arg1, ...)
13           ->set_notify (sub {
14              my @data = $_[0]->get_result
15              ...
16           });
17
18       $bus->get_connection->send (...);
19
20DESCRIPTION
21    This module is an AnyEvent user, you need to make sure that you use and
22    run a supported event loop.
23
24    Loading this module will install the necessary magic to seamlessly
25    integrate Net::DBus into AnyEvent. It does this by quite brutally
26    hacking Net::DBus::Reactor so that all dbus connections created after
27    loading this module will automatically be managed by this module.
28
29    Note that a) a lot inside Net::DBus is still blocking b) if you call a
30    method that blocks, you again block your process (basically anything but
31    calls to the Net::DBus::Binding::Connection objects block, but see
32    Net::DBus::Annoation, specifically dbus_call_async) c) the underlying
33    libdbus is often blocking itself, even with infinite timeouts and d)
34    this module only implements the minimum API required to make Net::DBus
35    work - Net::DBus unfortunately has no nice hooking API.
36
37    However, unlike Net::DBus::Reactor, this module should be fully
38    non-blocking as long as you only use non-blocking APIs
39    (Net::DBus::Reactor blocks on writes). It should also be faster, but
40    Net::DBus is such a morass so unneeded method calls that speed won't
41    matter much...
42
43  EXAMPLE
44    Here is a simple example. Both work with AnyEvent::DBus and do the same
45    thing, but only the second is actually non-blocking.
46
47    Example 1: list registered named, blocking version.
48
49       use AnyEvent::DBus;
50
51       my $conn = Net::DBus->find;
52       my $bus  = $conn->get_bus_object;
53
54       for my $name (@{ $bus->ListNames }) {
55          print "  $name\n";
56       }
57
58    Example 1: list registered named, somewhat non-blocking version.
59
60       use AnyEvent;
61       use AnyEvent::DBus;
62       use Net::DBus::Annotation qw(:call);
63
64       my $conn = Net::DBus->find; # always blocks :/
65       my $bus  = $conn->get_bus_object;
66
67       my $quit = AE::cv;
68
69       # the trick here is to prepend dbus_call_async to any method
70       # arguments and then to call the set_notify method on the
71       # returned Net::DBus::AsyncReply object
72
73       $bus->ListNames (dbus_call_async)->set_notify (sub {
74          for my $name (@{ $_[0]->get_result }) {
75             print "  $name\n";
76          }
77          $quit->send;
78       });
79
80       $quit->recv;
81
82SEE ALSO
83    AnyEvent, Net::DBus.
84
85AUTHOR
86     Marc Lehmann <schmorp@schmorp.de>
87     http://home.schmorp.de/
88
89