NAME
Net::DBus::Exporter - exports methods and signals to the bus
SYNOPSIS
# Connecting an object to the bus, under a service
package main;
use Net::DBus;
# Attach to the bus
my $bus = Net::DBus->find;
# Acquire a service 'org.demo.Hello'
my $service = $bus->export_service("org.demo.Hello");
# Export our object within the service
my $object = Demo::HelloWorld->new($service);
....rest of program...
# Define a new package for the object we're going
# to export
package Demo::HelloWorld;
# Specify the main interface provided by our object
use Net::DBus::Exporter qw(org.example.demo.Greeter);
# We're going to be a DBus object
use base qw(Net::DBus::Object);
# Export a 'Greeting' signal taking a stringl string parameter
dbus_signal("Greeting", ["string"]);
# Export 'Hello' as a method accepting a single string
# parameter, and returning a single string value
dbus_method("Hello", ["string"], ["string"]);
sub new {
my $class = shift;
my $service = shift;
my $self = $class->SUPER::new("/org/demo/HelloWorld", $service);
bless $self, $class;
return $self;
}
sub Hello {
my $self = shift;
my $name = shift;
$self->emit_signal("Greeting", "Hello $name");
return "Said hello to $name";
}
# Export 'Goodbye' as a method accepting a single string
# parameter, and returning a single string, but put it
# in the 'org.exaple.demo.Farewell' interface
dbus_method("Goodbye", ["string"], ["string"], "org.example.demo.Farewell");
sub Goodbye {
my $self = shift;
my $name = shift;
$self->emit_signal("Greeting", "Goodbye $name");
return "Said goodbye to $name";
}
DESCRIPTION
This the base of all objects which are exported to the message bus. It provides the core support for type introspection required for objects exported to the message. When sub-classing this object, methods can be created & tested as per normal Perl modules. Then just as the Exporter module is used to export methods within a script, the Net::DBus::Exporter module is used to export methods (and signals) to the message bus.
All packages inheriting from this, will automatically have the interface org.freedesktop.DBus.Introspectable registered with Net::DBus::Exporter, and the Introspect method within this exported.
METHODS
- my $object = Net::DBus::Object->new($path, $service)
-
This creates a new DBus object with an path of
$pathregistered within the service$service. The$pathparameter should be a string complying with the usual DBus requirements for object paths, while the$serviceparameter should be an instrance of Net::DBus::Service. The latter is typically obtained by calling theexport_servicemethod on the Net::DBus object. - my $service = $self->get_service
-
Retrieves the Net::DBus::Service object within which this object is exported.
- my $path = $self->get_object_path
-
Retrieves the path under which this object is exported
- $self->emit_signal($name, @args);
-
Emits a signal from the object, with a name of
$name. The signal and the data types of the arguments@argsmust have been registered with Net::DBus::Exporter by calling thedbus_signalmethod. The signal will be broadcast to all clients on the bus. - $self->emit_signal_to($name, $client, @args);
-
Emits a signal from the object, with a name of
$name. The signal and the data types of the arguments@argsmust have been registered with Net::DBus::Exporter by calling thedbus_signalmethod. The signal will be sent only to the client named by the$clientparameter.
SEE ALSO
Net::DBus, Net::DBus::Service, Net::DBus::RemoteObject, Net::DBus::Exporter.