home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / perl5 / Net / DBus / Service.pm < prev    next >
Encoding:
Perl POD Document  |  2006-04-13  |  3.2 KB  |  150 lines

  1. # -*- perl -*-
  2. #
  3. # Copyright (C) 2004-2005 Daniel P. Berrange
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. #
  19. # $Id: Service.pm,v 1.12 2006/01/27 15:34:24 dan Exp $
  20.  
  21. =pod
  22.  
  23. =head1 NAME
  24.  
  25. Net::DBus::Service - Provide a service to the bus for clients to use
  26.  
  27. =head1 SYNOPSIS
  28.  
  29.   package main;
  30.  
  31.   use Net::DBus;
  32.  
  33.   # Attach to the bus
  34.   my $bus = Net::DBus->find;
  35.  
  36.   # Acquire a service 'org.demo.Hello'
  37.   my $service = $bus->export_service("org.demo.Hello");
  38.  
  39.   # Export our object within the service
  40.   my $object = Demo::HelloWorld->new($service);
  41.  
  42.   ....rest of program...
  43.  
  44. =head1 DESCRIPTION
  45.  
  46. This module represents a service which is exported to the message
  47. bus. Once a service has been exported, it is possible to create
  48. and export objects to the bus.
  49.  
  50. =head1 METHODS
  51.  
  52. =over 4
  53.  
  54. =cut
  55.  
  56.  
  57. package Net::DBus::Service;
  58.  
  59. =item my $service = Net::DBus::Service->new($bus, $name);
  60.  
  61. Create a new service, attaching to the bus provided in
  62. the C<$bus> parameter, which should be an instance of
  63. the L<Net::DBus> object. The C<$name> parameter is the
  64. qualified service name. It is not usually neccessary to
  65. use this constructor, since services can be created via
  66. the C<export_service> method on the L<Net::DBus> object.
  67.  
  68. =cut
  69.  
  70. sub new {
  71.     my $class = shift;
  72.     my $self = {};
  73.  
  74.     $self->{bus} = shift;
  75.     $self->{service_name} = shift;
  76.     $self->{objects} = {};
  77.     
  78.     bless $self, $class;
  79.  
  80.     $self->get_bus->get_connection->request_name($self->get_service_name);
  81.  
  82.     return $self;
  83. }
  84.  
  85. =item my $bus = $service->get_bus;
  86.  
  87. Retrieves the L<Net::DBus> object to which this service is
  88. attached.
  89.  
  90. =cut
  91.  
  92. sub get_bus {
  93.     my $self = shift;
  94.     return $self->{bus};
  95. }
  96.  
  97. =item my $name = $service->get_service_name
  98.  
  99. Retrieves the qualified name by which this service is 
  100. known on the bus.
  101.  
  102. =cut
  103.  
  104. sub get_service_name {
  105.     my $self = shift;
  106.     return $self->{service_name};
  107. }
  108.  
  109.  
  110. sub _register_object {
  111.     my $self = shift;
  112.     my $object = shift;
  113.     #my $wildcard = shift || 0;
  114.     
  115. #    if ($wildcard) {
  116. #    $self->get_bus->get_connection->
  117. #        register_fallback($object->get_object_path,
  118. #                  sub {
  119. #                  $object->_dispatch(@_);
  120. #                  });
  121. #    } else {
  122.     $self->get_bus->get_connection->
  123.         register_object_path($object->get_object_path,
  124.                  sub {
  125.                      $object->_dispatch(@_);
  126.                  });
  127. #    }
  128. }
  129.  
  130.  
  131. sub _unregister_object {
  132.     my $self = shift;
  133.     my $object = shift;
  134.  
  135.     $self->get_bus->get_connection->
  136.     unregister_object_path($object->get_object_path);
  137. }
  138.  
  139. 1;
  140.  
  141. =pod
  142.  
  143. =back
  144.  
  145. =head1 SEE ALSO
  146.  
  147. L<Net::DBus>, L<Net::DBus::Object>, L<Net::DBus::RemoteService>
  148.  
  149. =cut
  150.