Net::DBus::Reactor Methods

From Alteeve Wiki
Jump to navigation Jump to search

 AN!Tools :: Net::DBus Binding Tutorial :: Net::DBus::Reactor Methods

new

Usage:

my $reactor=Net::DBus::Reactor->new();

This creates a new event loop that is ready to monitor filehandles and timeouts.

However, you should not use this method, but instead you should use the 'main' method. Using this directly will mean that the handle returned to you will be available within the scope of your module only, requiring you to pass it around as needed.

main

Usage:

my $reactor=Net::DBus::Reactor->main;

This creates a handle to the main event loop.

This is the prefered method for creating a new event loop as it removes the need for modules to pass around handles to their privately created reactors. When this is called, it checks if there is a pre-existing reactor loop. If not, it starts one. If so, it returns it directly.

manage

Usage:

use Net::DBus;
my $bus=Net::DBus->find();
my $connection=$bus->get_connection;  # You could use the connection below, if
                                      # not using a well known bus.
#my $connection=Net::DBus::Binding::Connection->new(address => "unix:path=/path/to/socket");
$reactor->manage($connection);

Or

use Net::DBus;
my $server = Net::DBus::Binding::Server->new(address => "unix:path=/path/to/socket");
$reactor->manage($server);

This registers a handle to the 'Net::DBus::Binding::Connection' or 'Net::DBus::Binding::Server' object with the main reactor event loop.

Generally you will not need to call this directly, as the Net::DBus->new call will handle this.

run

Usage:

$reactor->run();

Once you have registered at least one filehandle with the reactor, you can call this method to start the event loop. Calling this without a registered filehandle will cause it to immediately exit.

This reactor will run until all registered filehandles and timeouts have been removed or disabled, or until the 'shutdown' method is called.

shutdown

Usage:

$reactor->shutdown();

This shuts down the reactor as soon as all events currently being processed have finished.

step

$reactor->step();

This steps through one iteration of the reactor loop. Generally you should not need to call this.

add_read

Usage:

use Net::DBus;
my $bus=Net::DBus->find;
my $service=$bus->get_service("org.freedesktop.DBus");
my $object=$service->get_object("/org/freedesktop/DBus");
my $name="SomeMethod";
$callback=Net::DBus::Callback->new(
        object => $object,
        method => $name);
my $filehandle=""; # I need an example of where this might come from. IO::Handle->new, likely but what about objects?
$status="1";       # Optional boolean value, set to '1' to monitor this event
                   # right away, '0' to disable initially. Default is '1'.
$reactor->add_read($filehandle, $callback[, $status]);

This registers the '$filehandle' with the reactor event loop which will react to read events. When ever a read event is detected, the '$callback' will be invoked. The optional '$status' value is a boolean value that tells the reactor loop whether the filehandle is initially watched ('1') or not ('0'). By default, it is.

add_write

Usage:

use Net::DBus;
my $bus=Net::DBus->find;
my $service=$bus->get_service("org.freedesktop.DBus");
my $object=$service->get_object("/org/freedesktop/DBus");
my $name="SomeMethod";
$callback=Net::DBus::Callback->new(
        object => $object,
        method => $name);
my $filehandle="";
$status="1";       # Optional boolean value, set to '1' to monitor this event
                   # right away, '0' to disable initially. Default is '1'.
$reactor->add_write($filehandle, $callback[, $status]);

This registers the '$filehandle' with the reactor event loop which will react to write events. When ever a write event is detected, the '$callback' will be invoked. The optional '$status' value is a boolean value that tells the reactor loop whether the filehandle is initially watched ('1') or not ('0'). By default, it is.

add_exception

Usage:

use Net::DBus;
my $bus=Net::DBus->find;
my $service=$bus->get_service("org.freedesktop.DBus");
my $object=$service->get_object("/org/freedesktop/DBus");
my $name="SomeMethod";
$callback=Net::DBus::Callback->new(
        object => $object,
        method => $name);
my $filehandle="";
$status="1";       # Optional boolean value, set to '1' to monitor this event
                   # right away, '0' to disable initially. Default is '1'.
$reactor->add_exception($filehandle, $callback[, $status]);

This registers the '$filehandle' with the reactor event loop which will react to exceptions raised by this file handle. When ever an exception event is detected, the '$callback' will be invoked. The optional '$status' value is a boolean value that tells the reactor loop whether the filehandle is initially watched ('1') or not ('0'). By default, it is.

add_timeout

Usage:

use Net::DBus;
my $bus=Net::DBus->find;
my $service=$bus->get_service("org.freedesktop.DBus");
my $object=$service->get_object("/org/freedesktop/DBus");
my $name="SomeMethod";
$callback=Net::DBus::Callback->new(
        object => $object,
        method => $name);
my $timeout=1000;    # Will loop every 1 second.
$status="1";
my $id=$reactor->add_timeout($timeout, $callback[, $status]);

This registers a timeout with the reactor loop that triggers a step every '$timeout' milliseconds. This call returns an '$id' that can later be used to disable this loop. The optional '$status' value is a boolean value that tells the reactor loop whether this timeout loop is initially watched ('1') or not ('0'). By default, it is.

remove_timeout

Usage:

$reactor->remove_timeout($id);

This removes the registered timeout loop with the given '$id' from the reactor loop.

toggle_timeout

Usage:

my $status=1;
my $new_timeout=5000;
$reactor->toggle_timeout($id, $status[, $new_timeout]);

This changes the registered timeout event with the given '$id'. The '$status' value is a boolean, with '1' (re)enabling the loop and '0' pausing it. Optionally, you can pass a '$new_timeout' value which will change the timeout period to the set number of milliseconds.

add_hook

Usage:

my $service=$bus->get_service("org.freedesktop.DBus");
my $object=$service->get_object("/org/freedesktop/DBus");
my $name="SomeMethod";
$callback=Net::DBus::Callback->new(
        object => $object,
        method => $name);
my $id=$reactor->add_hook($callback[, $status]);

This registers a '$callback' with the '$reactor' event loop that is triggered on every iteration of the loop. This call returns an '$id' that can later be used to disable this hook. The optional '$status' value is a boolean value that tells the reactor loop whether this hook is initially watched ('1') or not ('0'). By default, it is.

remove_hook

Usage:

$reactor->remove_hook($id);

This removes the registered hook with the given '$id' from the reactor loop.

toggle_hook

Usage:

my $status=1;
$reactor->toggle_timeout($id, $status);

This changes the registered timeout event with the given '$id'. The '$status' value is a boolean, with '1' (re)enabling the loop and '0' pausing it. Optionally, you can pass a '$new_timeout' value which will change the timeout period to the set number of milliseconds.

remove_read

Usage:

$reactor->remove_read($filehandle);

This removes the registered '$filehandle' read events from the reactor loop.

remove_write

Usage:

$reactor->remove_write($filehandle);

This removes the registered '$filehandle' write events from the reactor loop.

remove_exception

Usage:

$reactor->remove_exception($filehandle);

This removes the registered '$filehandle' exception events from the reactor loop.

toggle_read

Usage:

my $status=0;
$reactor->toggle_read($filehandle, $status);

This enables or pauses the registered '$filehandle' read events in the '$reactor' loop. Setting '$status' to '1' will (re)enable it and '0' will pause it.

toggle_write

Usage:

my $status=0;
$reactor->toggle_write($filehandle, $status);

This enables or pauses the registered '$filehandle' write events in the '$reactor' loop. Setting '$status' to '1' will (re)enable it and '0' will pause it.

toggle_exception

Usage:

my $status=0;
$reactor->toggle_exception($filehandle, $status);

This enables or pauses the registered '$filehandle' exception events in the '$reactor' loop. Setting '$status' to '1' will (re)enable it and '0' will pause it.

 

Any questions, feedback, advice, complaints or meanderings are welcome.
Alteeve's Niche! Enterprise Support:
Alteeve Support
Community Support
© Alteeve's Niche! Inc. 1997-2024   Anvil! "Intelligent Availability®" Platform
legal stuff: All info is provided "As-Is". Do not use anything here unless you are willing and able to take responsibility for your own actions.