/usr/lib/x86_64-linux-gnu/perl5/5.26/Net/DBus/ProxyObject.pm is in libnet-dbus-perl 1.1.0-4build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | # -*- perl -*-
#
# Copyright (C) 2004-2011 Daniel P. Berrange
#
# This program is free software; You can redistribute it and/or modify
# it under the same terms as Perl itself. Either:
#
# a) the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any
# later version,
#
# or
#
# b) the "Artistic License"
#
# The file "COPYING" distributed along with this file provides full
# details of the terms and conditions of the two licenses.
=pod
=head1 NAME
Net::DBus::ProxyObject - Implement objects to export to the bus
=head1 SYNOPSIS
# Connecting an object to the bus, under a service
package main;
use Net::DBus;
# Attach to the bus
my $bus = Net::DBus->find;
# Create our application's object instance
my $object = Demo::HelloWorld->new()
# Acquire a service 'org.demo.Hello'
my $service = $bus->export_service("org.demo.Hello");
# Finally export the object to the bus
my $proxy = Demo::HelloWorld::DBus->new($object);
....rest of program...
# Define a new package for the object we're going
# to export
package Demo::HelloWorld;
sub new {
my $class = shift;
my $service = shift;
my $self = {};
$self->{sighandler} = undef;
bless $self, $class;
return $self;
}
sub sighandler {
my $self = shift;
my $callback = shift;
$self->[sighandler} = $callback;
}
sub Hello {
my $self = shift;
my $name = shift;
&{$self->{sighandler}}("Greeting", "Hello $name");
return "Said hello to $name";
}
sub Goodbye {
my $self = shift;
my $name = shift;
&{$self->{sighandler}}("Greeting", "Goodbye $name");
return "Said goodbye to $name";
}
# Define a new package for the object we're going
# to export
package Demo::HelloWorld::DBus;
# 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::ProxyObject);
# 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 $impl = shfit;
my $self = $class->SUPER::new($service, "/org/demo/HelloWorld", $impl);
bless $self, $class;
$self->sighandler(sub {
my $signame = shift;
my $arg = shift;
$self->emit_signal($signame, $arg);
});
return $self;
}
# 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");
=head1 DESCRIPTION
This the base for creating a proxy between a bus object and an
application's object. It allows the application's object model
to remain separate from the RPC object model. The proxy object
will forward method calls from the bus, to the implementation
object. The proxy object can also register callbacks against
the application object, which it can use to then emit signals
on the bus.
=head1 METHODS
=over 4
=cut
package Net::DBus::ProxyObject;
use 5.006;
use strict;
use warnings;
use base qw(Net::DBus::BaseObject);
=item my $object = Net::DBus::ProxyObject->new($service, $path, $impl)
This creates a new DBus object with an path of C<$path>
registered within the service C<$service>. The C<$path>
parameter should be a string complying with the usual
DBus requirements for object paths, while the C<$service>
parameter should be an instance of L<Net::DBus::Service>.
The latter is typically obtained by calling the C<export_service>
method on the L<Net::DBus> object. The C<$impl> parameter is
the application object which will implement the methods being
exported to the bus.
=item my $object = Net::DBus::ProxyObject->new($parentobj, $subpath, $impl)
This creates a new DBus child object with an path of C<$subpath>
relative to its parent C<$parentobj>. The C<$subpath>
parameter should be a string complying with the usual
DBus requirements for object paths, while the C<$parentobj>
parameter should be an instance of L<Net::DBus::BaseObject> or
a subclass. The C<$impl> parameter is the application object
which will implement the methods being exported to the bus.
=cut
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
my ($serviceOrParent, $path, $impl) = @_;
$self->{impl} = $impl;
bless $self, $class;
return $self;
}
sub _dispatch_object {
my $self = shift;
my $connection = shift;
my $message = shift;
my $reply;
my $method_name = $message->get_member;
my $interface = $message->get_interface;
if ($self->_is_method_allowed($method_name)) {
my $ins = $self->_introspector;
my @ret = eval {
my @args;
if ($ins) {
@args = $ins->decode($message, "methods", $method_name, "params");
} else {
@args = $message->get_args_list;
}
$self->{impl}->$method_name(@args);
};
if ($@) {
my $name = UNIVERSAL::isa($@, "Net::DBus::Error") ? $@->name : "org.freedesktop.DBus.Error.Failed";
my $desc = UNIVERSAL::isa($@, "Net::DBus::Error") ? $@->message : $@;
$reply = $connection->make_error_message($message,
$name,
$desc);
} else {
$reply = $connection->make_method_return_message($message);
if ($ins) {
$self->_introspector->encode($reply, "methods", $method_name, "returns", @ret);
} else {
$reply->append_args_list(@ret);
}
}
}
return $reply;
}
sub _dispatch_property {
my $self = shift;
my $name = shift;
if (!$self->{impl}->can($name)) {
die "no method to for property '$name'";
}
return $self->{impl}->$name(@_);
}
sub _is_method_allowed {
my $self = shift;
my $method = shift;
# If this object instance doesn't have it defined, trivially can't
# allow it
return 0 unless $self->{impl}->can($method);
my $ins = $self->_introspector;
if (defined $ins) {
# Finally do check against introspection data
return $ins->is_method_allowed($method);
}
# No introspector, so have to assume its allowed
return 1;
}
1;
=pod
=back
=head1 AUTHOR
Daniel P. Berrange
=head1 COPYRIGHT
Copyright (C) 2005-2011 Daniel P. Berrange
=head1 SEE ALSO
L<Net::DBus>, L<Net::DBus::Service>, L<Net::DBus::BaseObject>,
L<Net::DBus::ProxyObject>, L<Net::DBus::Exporter>,
L<Net::DBus::RemoteObject>
=cut
|