From ba10c1e0258a3f13620ef7da97e99c9ced990047 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Sun, 29 Jan 2012 03:28:53 +0000 Subject: (list,get_mount_point,mount,mount_hal,eject,unmount_hal) adapt to udisks API --- lib/Hal/Cdroms.pm | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/Hal/Cdroms.pm b/lib/Hal/Cdroms.pm index 5e32c7d..64b6a4c 100644 --- a/lib/Hal/Cdroms.pm +++ b/lib/Hal/Cdroms.pm @@ -76,7 +76,8 @@ sub list { my $manager = $o->{hal}->get_object("/org/freedesktop/UDisks", $hal_dn); - @{$manager->FindDeviceByCapability('volume.disc')}; + + grep { _GetProperty(_get_device($o, $_), 'DeviceIsOpticalDisc') } @{$manager->EnumerateDevices}; } =head2 $hal_cdroms->get_mount_point($hal_path) @@ -109,8 +110,8 @@ sub get_mount_point { my ($o, $hal_path) = @_; my $device = _get_device($o, $hal_path); - eval { $device->GetProperty('volume.is_mounted') - && $device->GetProperty('volume.mount_point') }; + eval { _GetProperty($device, 'DeviceIsMounted') + && @{_GetProperty($device, 'DeviceMountPaths')}[0] }; } sub _try { @@ -151,14 +152,11 @@ If the cdrom is listed in fstab, HAL will refuse to mount it. sub mount_hal { my ($o, $hal_path) = @_; - my $device = _get_device($o, $hal_path); - my $volume = _get_volume($o, $hal_path); - - my $fstype = $device->GetProperty('volume.fstype'); + my $device = _get_udisks_device($o, $hal_path); - _try($o, sub { $volume->Mount("", $fstype, []) }) or return; - - eval { $device->GetProperty('volume.mount_point') }; + my $mountpoint; + _try($o, sub { $mountpoint = $device->FilesystemMount(undef, []) }) or return; + $mountpoint; } =head2 $hal_cdroms->mount($hal_path) @@ -174,7 +172,9 @@ sub mount { my $mntpoint = mount_hal($o, $hal_path); if (!$mntpoint) { # this usually means HAL refused to mount a cdrom listed in fstab - my $dev = _get_device($o, $hal_path)->GetProperty('block.device'); + my $dev = _GetProperty(_get_device($o, $hal_path), 'NativePath'); + # try to get real path: + $dev =~ s!.*/!/dev/!; if (my $wanted = $dev && _rdev($dev)) { my ($fstab_dev) = grep { $wanted == _rdev($_) } _fstab_devices(); system("mount", $fstab_dev) == 0 @@ -203,8 +203,8 @@ If the cdrom is listed in not mounted by HAL, HAL will refuse to unmount it. sub unmount_hal { my ($o, $hal_path) = @_; - my $volume = _get_volume($o, $hal_path); - _try($o, sub { $volume->Unmount([]) }); + my $volume = _get_udisks_device($o, $hal_path); + _try($o, sub { $volume->FilesystemUnmount([]) }); } =head2 $hal_cdroms->unmount($hal_path) @@ -231,8 +231,8 @@ Ejects the C. Return true on success (see $hal_cdroms->{error} on fail sub eject { my ($o, $hal_path) = @_; - my $volume = _get_volume($o, $hal_path); - _try($o, sub { $volume->Eject([]) }); + my $volume = _get_udisks_device($o, $hal_path); + _try($o, sub { $volume->FilesystemUnmount([]); $volume->DriveEject([]) }); } =head2 $hal_cdroms->wait_for_insert([$timeout]) @@ -247,9 +247,13 @@ You can give an optional timeout in milliseconds. sub wait_for_insert { my ($o, $o_timeout) = @_; + return if $o->list; + _reactor_wait($o->{dbus}, $hal_dn, $o_timeout, sub { my ($msg) = @_; - $msg->get_member eq 'DeviceAdded' && ($msg->get_args_list)[0]; + my $path; + return unless member($msg->get_member, 'DeviceChanged', 'DeviceAdded') && ($path = ($msg->get_args_list)[0]); + _GetProperty(_get_device($o, $path), 'DeviceIsOpticalDisc'); }); } @@ -275,8 +279,7 @@ sub wait_for_mounted { my $hal_path = $msg->get_path; my $device = _get_device($o, $hal_path); - eval { $device->QueryCapability('volume.disc') && - $device->GetProperty('volume.is_mounted') } && $hal_path; + eval { _GetProperty($device, 'DeviceIsMounted') } && $hal_path; }); } -- cgit v1.2.1