Don't like ads? PRO users don't see any ads ;-)
Guest

Perl DBus USB Monitor Sample

By: a guest on Mar 25th, 2011  |  syntax: Perl  |  size: 0.56 KB  |  hits: 289  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Net::DBus;
  4. use Net::DBus::Reactor;
  5.  
  6. my $bus = Net::DBus->system;
  7. my $service = $bus->get_service ( 'org.freedesktop.Hal' );
  8. my $object = $service->get_object ( '/org/freedesktop/Hal/Manager' , 'org.freedesktop.Hal.Manager' );
  9.  
  10. print "Monitoring ..\n";
  11.  
  12. $object->connect_to_signal ( "DeviceAdded" , sub {
  13.                 my ($infos) = @_;
  14.                 print "Added: $infos\n";
  15.         });
  16. $object->connect_to_signal ( "DeviceRemoved" , sub {
  17.                 my ($infos) = @_;
  18.                 print "Removed: $infos\n";
  19.         });
  20.  
  21. my $reactor = Net::DBus::Reactor->main();
  22. $reactor->run();