3 # Copyright (C) 2004-2011 Daniel P. Berrange
5 # This program is free software; You can redistribute it and/or modify
6 # it under the same terms as Perl itself. Either:
8 # a) the GNU General Public License as published by the Free
9 # Software Foundation; either version 2, or (at your option) any
14 # b) the "Artistic License"
16 # The file "COPYING" distributed along with this file provides full
17 # details of the terms and conditions of the two licenses.
23 Net::DBus::RemoteService - Access services provided on the bus
27 my $bus = Net::DBus->find;
28 my $service = $bus->get_service("org.freedesktop.DBus");
30 my $object = $service->get_object("/org/freedesktop/DBus");
31 foreach (@{$object->ListNames}) {
37 This object provides a handle to a remote service on the
38 bus. From this handle it is possible to access objects
39 associated with the service. If a service is not running,
40 an attempt will be made to activate it the first time a
41 method is called against one of its objects.
49 package Net::DBus::RemoteService;
55 use Net::DBus::RemoteObject;
57 =item my $service = Net::DBus::RemoteService->new($bus, $owner, $service_name);
59 Creates a new handle for a remote service. The C<$bus> parameter is an
60 instance of L<Net::DBus>, C<$owner> is the name of the client providing the
61 service, while C<$service_name> is the well known name of the service on
62 the bus. Service names consist of two or more tokens, separated
63 by periods, while the tokens comprise the letters a-z, A-Z, 0-9 and _,
64 for example C<org.freedesktop.DBus>. There is generally no need to call
65 this constructor, instead the C<get_service> method on L<Net::DBus> should
66 be used. This caches handles to remote services, eliminating repeated
67 retrieval of introspection data.
76 $self->{owner_name} = shift;
77 $self->{service_name} = shift;
78 $self->{objects} = {};
86 =item my $bus = $service->get_bus;
88 Retrieves a handle for the bus to which this service is attached.
89 The returned object will be an instance of L<Net::DBus>.
100 =item my $service_name = $service->get_service_name
102 Retrieves the name of the remote service as known to the bus.
106 sub get_service_name {
108 return $self->{service_name};
111 =item my $owner_name = $service->get_owner_name;
113 Retrieves the name of the client owning the service at the
114 time it was connected to.
120 return $self->{owner_name};
123 =item my $object = $service->get_object($object_path[, $interface]);
125 Retrieves a handle to the remote object provided by the service with
126 the name of C<$object_path>. If the optional C<$interface> parameter is
127 provided, the object will immediately be cast to the designated
128 interface. NB, it is only neccessary to cast an object to a specific
129 interface if there are multiple interfaces on the object providing
130 methods with the same name, or the remote object does support
131 introspection. The returned object will be an instance of L<Net::DBus::RemoteObject>.
137 my $object_path = shift;
139 unless (defined $self->{objects}->{$object_path}) {
140 $self->{objects}->{$object_path} = Net::DBus::RemoteObject->new($self,
145 my $interface = shift;
146 return $self->{objects}->{$object_path}->as_interface($interface);
148 return $self->{objects}->{$object_path};
161 Daniel Berrange <dan@berrange.com>
165 Copright (C) 2004-2011, Daniel Berrange.
169 L<Net::DBus::RemoteObject>, L<Net::DBus::Service>, L<Net::DBus>