home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / libnet-dbus-perl / examples / example-service.pl < prev    next >
Encoding:
Perl Script  |  2008-02-20  |  1.5 KB  |  64 lines

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