[tpm] Net::DBus question
Madison Kelly
linux at alteeve.com
Thu Feb 14 06:10:00 PST 2008
Hi all,
I'm working on a program which needs to keep track of what (block)
devices are available and what their individual details are. Also, I
want to be able to keep similar track of what network filesystems are
currently mounted and their details.
From what I have been reading, it looks like DBus and HAL are right
up my alley. To that end, I've been reading up on them and I think I've
got a fairly good handle on the concepts, but I've not been able find
much in the way of perl-specific stuff.
So, has anyone here played much with Net::DBus? I've looked at the
code in 'examples' in the DBus docs directory, but it's pretty sparse,
as are the notes on CPAN.
This is what I am trying to figure out; pointers to more docs would
be perfect in lieu of code samples!
1: I want to initially query to the system bus for a list of current
devices.
1.1: For each device detected, see if it is a block device (HDD, USB
storage, Optical, etc).
1.2: If it is a block device, query it's details (max/used capacity,
FS type, mount location [less important is make, model, serial,
removable, optical media capability, SMART codes, etc).
2: After the initial scan, "subscribe" to the system bus and wait for
new signals/messages.
2.1: Whenever a new message arrives, check if it's for a block device
and, if so, repeat 1.2.
3: Do the same for Network Block devices.
If anyone can help get me started, I would be much appreciated. As of
now, I've been able to do this much, which queries the 'Manager' system
bus, but no more. I am not even sure how to find out what objects are on
a given (ie: system) bus. =/
A confused Madi.
-=] test.pl [=-
#!/usr/bin/perl
#
# My crappy Net::DBus script for learning.
use strict;
use warnings;
use IO::Handle;
use Net::DBus;
my @key_words=("volume", "usb", "storage");
# Connect to DBus.
my $bus = Net::DBus->system;
# Get a handle to the HAL service
my $hal = $bus->get_service("org.freedesktop.Hal");
# Get the device manager
# my $manager = $hal->get_object("/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager");
my $manager = $hal->get_object("/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager");
# Show the devices currently seen by DBus
foreach my $dev (sort { $a cmp $b } @{$manager->GetAllDevices})
{
my $want=0;
foreach my $key (@key_words)
{
if ( $dev=~/$key/ )
{
$want=1;
last;
}
}
if ( $want == 1 )
{
print "Yar!: $dev\n";
}
else
{
print "Boo!: $dev\n";
}
}
More information about the toronto-pm
mailing list