home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / libnet-dbus-perl / examples / example-service.pl < prev    next >
Encoding:
Perl Script  |  2006-02-19  |  1.4 KB  |  61 lines

  1. #!/usr/bin/perl
  2.  
  3. use Carp qw(confess cluck);
  4. use Net::DBus;
  5. use Net::DBus::Service;
  6. use Net::DBus::Reactor;
  7.  
  8. #...  continued at botom
  9.  
  10.  
  11. package SomeObject;
  12.  
  13. use base qw(Net::DBus::Object);
  14. use Net::DBus::Exporter qw(org.designfu.SampleInterface);
  15.  
  16. #use Class::MethodMaker [ scalar => [ qw(name email age) ]];
  17.  
  18. #dbus_property("name", "string");
  19. #dbus_property("email", "string", "read");
  20. #dbus_property("age", "int32", "write");
  21.  
  22. sub new {
  23.     my $class = shift;
  24.     my $service = shift;
  25.     my $self = $class->SUPER::new($service, "/SomeObject");
  26.     bless $self, $class;
  27.     
  28.     return $self;
  29. }
  30.  
  31. dbus_method("HelloWorld", ["string"], [["array", "string"]]);
  32. sub HelloWorld {
  33.     my $self = shift;
  34.     my $message = shift;
  35.     print "Do hello world\n";
  36.     print $message, "\n";
  37.     return ["Hello", " from example-service.pl"];
  38. }
  39.  
  40. dbus_method("GetDict", [], [["dict", "string", "string"]]);
  41. sub GetDict {
  42.     my $self = shift;
  43.     print "Do get dict\n";
  44.     return {"first" => "Hello Dict", "second" => " from example-service.pl"};
  45. }
  46.  
  47. dbus_method("GetTuple", [], [["struct", "string", "string"]]);
  48. sub GetTuple {
  49.     my $self = shift;
  50.     print "Do get tuple\n";
  51.     return ["Hello Tuple", " from example-service.pl"];
  52. }
  53.  
  54. package main;
  55.  
  56. my $bus = Net::DBus->session();
  57. my $service = $bus->export_service("org.designfu.SampleService");
  58. my $object = SomeObject->new($service);
  59.  
  60. Net::DBus::Reactor->main->run();
  61.