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

NAME

6       Net::DBus::Object - Provide objects to the bus for clients to use
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 of all objects which are exported to the message bus. It
76       provides the core support for type introspection required for objects
77       exported to the message. When sub-classing this object, methods can be
78       created & tested as per normal Perl modules. Then just as the Exporter
79       module is used to export methods within a script, the
80       Net::DBus::Exporter module is used to export methods (and signals) to
81       the message bus.
82
83       All packages inheriting from this, will automatically have the
84       interface "org.freedesktop.DBus.Introspectable" registered with
85       Net::DBus::Exporter, and the "Introspect" method within this exported.
86

METHODS

88       my $object = Net::DBus::Object->new($service, $path)
89           This creates a new DBus object with an path of $path registered
90           within the service $service. The $path parameter should be a string
91           complying with the usual DBus requirements for object paths, while
92           the $service parameter should be an instance of Net::DBus::Service.
93           The latter is typically obtained by calling the "export_service"
94           method on the Net::DBus object.
95
96       my $object = Net::DBus::Object->new($parentobj, $subpath)
97           This creates a new DBus child object with an path of $subpath
98           relative to its parent $parentobj. The $subpath parameter should be
99           a string complying with the usual DBus requirements for object
100           paths, while the $parentobj parameter should be an instance of
101           Net::DBus::Object.
102
103       $object->disconnect();
104           This method disconnects the object from the bus, such that it will
105           no longer receive messages sent by other clients. Any child objects
106           will be recursively disconnected too. After an object has been
107           disconnected, it is possible for Perl to garbage collect the object
108           instance. It will also make it possible to connect a newly created
109           object to the same path.
110
111       my $bool = $object->is_connected
112           Returns a true value if the object is connected to the bus, and
113           thus capable of being accessed by remote clients. Returns false if
114           the object is disconnected & thus ready for garbage collection. All
115           objects start off in the connected state, and will only transition
116           if the "disconnect" method is called.
117
118       my $service = $object->get_service
119           Retrieves the Net::DBus::Service object within which this object is
120           exported.
121
122       my $path = $object->get_object_path
123           Retrieves the path under which this object is exported
124
125       $object->emit_signal_in($name, $interface, $client, @args);
126           Emits a signal from the object, with a name of $name. If the
127           $interface parameter is defined, the signal will be scoped within
128           that interface. If the $client parameter is defined, the signal
129           will be unicast to that client on the bus. The signal and the data
130           types of the arguments @args must have been registered with
131           Net::DBus::Exporter by calling the "dbus_signal" method.
132
133       $self->emit_signal_to($name, $client, @args);
134           Emits a signal from the object, with a name of $name. The signal
135           and the data types of the arguments @args must have been registered
136           with Net::DBus::Exporter by calling the "dbus_signal" method. The
137           signal will be sent only to the client named by the $client
138           parameter.
139
140       $self->emit_signal($name, @args);
141           Emits a signal from the object, with a name of $name. The signal
142           and the data types of the arguments @args must have been registered
143           with Net::DBus::Exporter by calling the "dbus_signal" method. The
144           signal will be broadcast to all clients on the bus.
145
146       $object->connect_to_signal_in($name, $interface, $coderef);
147           Connects a callback to a signal emitted by the object. The $name
148           parameter is the name of the signal within the object, and $coderef
149           is a reference to an anonymous subroutine. When the signal $name is
150           emitted by the remote object, the subroutine $coderef will be
151           invoked, and passed the parameters from the signal. The $interface
152           parameter is used to specify the explicit interface defining the
153           signal to connect to.
154
155       $object->connect_to_signal($name, $coderef);
156           Connects a callback to a signal emitted by the object. The $name
157           parameter is the name of the signal within the object, and $coderef
158           is a reference to an anonymous subroutine. When the signal $name is
159           emitted by the remote object, the subroutine $coderef will be
160           invoked, and passed the parameters from the signal.
161

AUTHORS

163       Daniel P. Berrange
164
166       Copyright (C) 2005-2006 Daniel P. Berrange
167

SEE ALSO

169       Net::DBus, Net::DBus::Service, Net::DBus::RemoteObject,
170       Net::DBus::Exporter.
171
172
173
174perl v5.12.0                      2008-02-21              Net::DBus::Object(3)
Impressum