1DBus(3)               User Contributed Perl Documentation              DBus(3)
2
3
4

NAME

6       AnyEvent::DBus - adapt Net::DBus to AnyEvent
7

SYNOPSIS

9          use AnyEvent::DBus;
10
11          # now use the Net::DBus API, preferably the non-blocking variants:
12
13          use Net::DBus::Annotation qw(:call);
14
15          $bus->get_object (...)
16              ->Method (dbus_call_async, $arg1, ...)
17              ->set_notify (sub {
18                 my @data = $_[0]->get_result
19                 ...
20              });
21
22          $bus->get_connection->send (...);
23

DESCRIPTION

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

SEE ALSO

86       AnyEvent, Net::DBus.
87

AUTHOR

89        Marc Lehmann <schmorp@schmorp.de>
90        http://home.schmorp.de/
91
92
93
94perl v5.34.0                      2021-07-22                           DBus(3)
Impressum