1Net::DBus::Object(3)  User Contributed Perl Documentation Net::DBus::Object(3)
2
3
4

NAME

6       Net::DBus::Object - Implement objects to export to the bus
7

SYNOPSIS

9         # Connecting an object to the bus, under a service
10         package main;
11
12         use Net::DBus;
13
14         # Attach to the bus
15         my $bus = Net::DBus->find;
16
17         # Acquire a service 'org.demo.Hello'
18         my $service = $bus->export_service("org.demo.Hello");
19
20         # Export our object within the service
21         my $object = Demo::HelloWorld->new($service);
22
23         ....rest of program...
24
25         # Define a new package for the object we're going
26         # to export
27         package Demo::HelloWorld;
28
29         # Specify the main interface provided by our object
30         use Net::DBus::Exporter qw(org.example.demo.Greeter);
31
32         # We're going to be a DBus object
33         use base qw(Net::DBus::Object);
34
35         # Export a 'Greeting' signal taking a stringl string parameter
36         dbus_signal("Greeting", ["string"]);
37
38         # Export 'Hello' as a method accepting a single string
39         # parameter, and returning a single string value
40         dbus_method("Hello", ["string"], ["string"]);
41
42         sub new {
43             my $class = shift;
44             my $service = shift;
45             my $self = $class->SUPER::new($service, "/org/demo/HelloWorld");
46
47             bless $self, $class;
48
49             return $self;
50         }
51
52         sub Hello {
53           my $self = shift;
54           my $name = shift;
55
56           $self->emit_signal("Greeting", "Hello $name");
57           return "Said hello to $name";
58         }
59
60         # Export 'Goodbye' as a method accepting a single string
61         # parameter, and returning a single string, but put it
62         # in the 'org.exaple.demo.Farewell' interface
63
64         dbus_method("Goodbye", ["string"], ["string"], "org.example.demo.Farewell");
65
66         sub Goodbye {
67           my $self = shift;
68           my $name = shift;
69
70           $self->emit_signal("Greeting", "Goodbye $name");
71           return "Said goodbye to $name";
72         }
73

DESCRIPTION

75       This the base for implementing objects which are directly exported to
76       the bus. The methods implemented in a subclass are mapped to methods on
77       the bus. By using this class, an application is directly tieing the RPC
78       functionality into its object model. Applications may thus prefer to
79       use the "Net::DBus::ProxyObject" class which allows the RPC
80       functionality to be maintained separately from the core object model,
81       by proxying RPC method calls.
82

METHODS

84       my $object = Net::DBus::Object->new($service, $path)
85           This creates a new DBus object with an path of $path registered
86           within the service $service. The $path parameter should be a string
87           complying with the usual DBus requirements for object paths, while
88           the $service parameter should be an instance of Net::DBus::Service.
89           The latter is typically obtained by calling the "export_service"
90           method on the Net::DBus object.
91
92       my $object = Net::DBus::Object->new($parentobj, $subpath)
93           This creates a new DBus child object with an path of $subpath
94           relative to its parent $parentobj. The $subpath parameter should be
95           a string complying with the usual DBus requirements for object
96           paths, while the $parentobj parameter should be an instance of
97           Net::DBus::BaseObject or a subclass.
98

AUTHOR

100       Daniel P. Berrange
101
103       Copyright (C) 2005-2011 Daniel P. Berrange
104

SEE ALSO

106       Net::DBus, Net::DBus::Service, Net::DBus::BaseObject,
107       Net::DBus::ProxyObject, Net::DBus::Exporter, Net::DBus::RemoteObject
108
109
110
111perl v5.36.0                      2022-07-22              Net::DBus::Object(3)
Impressum