1Net::DBus::ProxyObject(U3s)er Contributed Perl DocumentatNieotn::DBus::ProxyObject(3)
2
3
4

NAME

6       Net::DBus::ProxyObject - 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         # Create our application's object instance
18         my $object = Demo::HelloWorld->new()
19
20         # Acquire a service 'org.demo.Hello'
21         my $service = $bus->export_service("org.demo.Hello");
22
23         # Finally export the object to the bus
24         my $proxy = Demo::HelloWorld::DBus->new($object);
25
26         ....rest of program...
27
28
29         # Define a new package for the object we're going
30         # to export
31         package Demo::HelloWorld;
32
33         sub new {
34             my $class = shift;
35             my $service = shift;
36             my $self = {};
37
38             $self->{sighandler} = undef;
39
40             bless $self, $class;
41
42             return $self;
43         }
44
45         sub sighandler {
46             my $self = shift;
47             my $callback = shift;
48
49             $self->[sighandler} = $callback;
50         }
51
52         sub Hello {
53           my $self = shift;
54           my $name = shift;
55
56           &{$self->{sighandler}}("Greeting", "Hello $name");
57           return "Said hello to $name";
58         }
59
60         sub Goodbye {
61           my $self = shift;
62           my $name = shift;
63
64           &{$self->{sighandler}}("Greeting", "Goodbye $name");
65           return "Said goodbye to $name";
66         }
67
68
69         # Define a new package for the object we're going
70         # to export
71         package Demo::HelloWorld::DBus;
72
73         # Specify the main interface provided by our object
74         use Net::DBus::Exporter qw(org.example.demo.Greeter);
75
76         # We're going to be a DBus object
77         use base qw(Net::DBus::ProxyObject);
78
79         # Export a 'Greeting' signal taking a stringl string parameter
80         dbus_signal("Greeting", ["string"]);
81
82         # Export 'Hello' as a method accepting a single string
83         # parameter, and returning a single string value
84         dbus_method("Hello", ["string"], ["string"]);
85
86         sub new {
87             my $class = shift;
88             my $service = shift;
89             my $impl = shfit;
90             my $self = $class->SUPER::new($service, "/org/demo/HelloWorld", $impl);
91
92             bless $self, $class;
93
94             $self->sighandler(sub {
95                 my $signame = shift;
96                 my $arg = shift;
97                 $self->emit_signal($signame, $arg);
98             });
99
100             return $self;
101         }
102
103         # Export 'Goodbye' as a method accepting a single string
104         # parameter, and returning a single string, but put it
105         # in the 'org.exaple.demo.Farewell' interface
106
107         dbus_method("Goodbye", ["string"], ["string"], "org.example.demo.Farewell");
108

DESCRIPTION

110       This the base for creating a proxy between a bus object and an
111       application's object. It allows the application's object model to
112       remain separate from the RPC object model. The proxy object will
113       forward method calls from the bus, to the implementation object. The
114       proxy object can also register callbacks against the application
115       object, which it can use to then emit signals on the bus.
116

METHODS

118       my $object = Net::DBus::ProxyObject->new($service, $path, $impl)
119           This creates a new DBus object with an path of $path registered
120           within the service $service. The $path parameter should be a string
121           complying with the usual DBus requirements for object paths, while
122           the $service parameter should be an instance of Net::DBus::Service.
123           The latter is typically obtained by calling the "export_service"
124           method on the Net::DBus object. The $impl parameter is the
125           application object which will implement the methods being exported
126           to the bus.
127
128       my $object = Net::DBus::ProxyObject->new($parentobj, $subpath, $impl)
129           This creates a new DBus child object with an path of $subpath
130           relative to its parent $parentobj. The $subpath parameter should be
131           a string complying with the usual DBus requirements for object
132           paths, while the $parentobj parameter should be an instance of
133           Net::DBus::BaseObject or a subclass. The $impl parameter is the
134           application object which will implement the methods being exported
135           to the bus.
136

AUTHOR

138       Daniel P. Berrange
139
141       Copyright (C) 2005-2011 Daniel P. Berrange
142

SEE ALSO

144       Net::DBus, Net::DBus::Service, Net::DBus::BaseObject,
145       Net::DBus::ProxyObject, Net::DBus::Exporter, Net::DBus::RemoteObject
146
147
148
149perl v5.36.0                      2023-01-20         Net::DBus::ProxyObject(3)
Impressum