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-signal-emitter.pl < prev    next >
Encoding:
Perl Script  |  2008-02-20  |  964 b   |  51 lines

  1. #!/usr/bin/perl -w
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. use Net::DBus;
  7. use Net::DBus::Reactor;
  8. use Net::DBus::Service;
  9. use Net::DBus::Object;
  10.  
  11. use Carp qw(confess cluck);
  12.  
  13. #$SIG{__WARN__} = sub { cluck $_[0] };
  14. #$SIG{__DIE__} = sub { confess $_[0] };
  15.  
  16. package TestObject;
  17.  
  18. use base qw(Net::DBus::Object);
  19. use Net::DBus::Exporter qw(org.designfu.TestService);
  20.  
  21. sub new {
  22.     my $class = shift;
  23.     my $service = shift;
  24.     my $self = $class->SUPER::new($service, "/org/designfu/TestService/object");
  25.                   
  26.     
  27.     bless $self, $class;
  28.     
  29.     return $self;
  30. }
  31.  
  32. dbus_signal("HelloSignal", ["string"]);
  33. dbus_method("emitHelloSignal");
  34. sub emitHelloSignal {
  35.     my $self = shift;
  36.     print "Got request to send hello signal\n";
  37.     return $self->emit_signal("HelloSignal", "Hello");
  38. }
  39.  
  40.  
  41. package main;
  42.  
  43.  
  44. my $bus = Net::DBus->session();
  45. my $service = $bus->export_service("org.designfu.TestService");
  46. my $object = TestObject->new($service);
  47.  
  48. Net::DBus::Reactor->main->run();
  49.  
  50.  
  51.