Perl and Net::DBus questions
Madison Kelly
linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Thu Feb 14 19:42:54 UTC 2008
Hi all,
I'm working on a perl 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. I've been reading the docs on the freedesktop.org website,
but most of it uses C++, Java and Python when talking about bindings.
Unfortunately, I am kind of still new to programming and am only
comfortable really with Perl, so a lot of these analogies are lost on me.
So, has anyone here played much DBus/HAL in perl (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.
I am certainly not asking for anyone to "do my work" for me, and even
a link to docs that are more perl/Net::DBus focused would be a *huge* help!
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");
# 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";
}
}
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list