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-magic.pl < prev    next >
Encoding:
Perl Script  |  2008-02-20  |  1.5 KB  |  67 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", "caller"], [["array", "string"]]);
  35. sub HelloWorld {
  36.     my $self = shift;
  37.     my $message = shift;
  38.     my $caller = shift;
  39.     print "Do hello world from $caller\n";
  40.     print $message, "\n";
  41.     return ["Hello", " from example-service.pl"];
  42. }
  43.  
  44. dbus_method("GetDict", ["caller"], [["dict", "string", "string"]]);
  45. sub GetDict {
  46.     my $self = shift;
  47.     my $caller = shift;
  48.     print "Do get dict from $caller\n";
  49.     return {"first" => "Hello Dict", "second" => " from example-service.pl"};
  50. }
  51.  
  52. dbus_method("GetTuple", ["caller"], [["struct", "string", "string"]]);
  53. sub GetTuple {
  54.     my $self = shift;
  55.     my $caller = shift;
  56.     print "Do get tuple from $caller\n";
  57.     return ["Hello Tuple", " from example-service.pl"];
  58. }
  59.  
  60. package main;
  61.  
  62. my $bus = Net::DBus->session();
  63. my $service = $bus->export_service("org.designfu.SampleService");
  64. my $object = SomeObject->new($service);
  65.  
  66. Net::DBus::Reactor->main->run();
  67.