summaryrefslogtreecommitdiffstats
path: root/lib/MDV/Snapshot/Hal.pm
blob: 65263fd15dc22e341ca8e9d19e350ad9e7f3dedb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package MDV::Snapshot::Hal;

################################################################################
# Backup Configuration Tool                                                    # 
#                                                                              #
# Copyright (C) 2008 Mandriva                                                  #
#                                                                              #
# Thierry Vignaud <tvignaud at mandriva dot com>                               #
#                                                                              #
# This program is free software; you can redistribute it and/or modify         #
# it under the terms of the GNU General Public License Version 2 as            #
# published by the Free Software Foundation.                                   #
#                                                                              #
# This program is distributed in the hope that it will be useful,              #
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
# GNU General Public License for more details.                                 #
#                                                                              #
# You should have received a copy of the GNU General Public License            #
# along with this program; if not, write to the Free Software                  #
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.   #
################################################################################


use strict;
use lib qw(/usr/lib/libDrakX);
use MDK::Common;
use dbus_object;

use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw($hal_dn $hal_manager $manager_path find_removable_volumes get_system_bus is_proper_device);

our $hal_dn = 'org.freedesktop.Hal';
our $hal_manager = "$hal_dn.Manager";
our $manager_path = '/org/freedesktop/Hal/Manager';

sub get_system_bus() {
    eval { dbus_object::system_bus() };
}


sub is_proper_device {
    my ($device, $o_is_first_check) = @_;  # perl_checker: $device = Net::DBus::RemoteObject->new
    my $device_name = $device->QueryCapability('block') && $device->GetProperty('block.device');
    return if !$device_name;
    my $bool = $device->QueryCapability('volume') && !$device->GetProperty('volume.is_disc') &&
      $device->GetProperty('volume.is_mounted');
    return $o_is_first_check ? $bool && $device_name && cat_('/media/.hal-mtab') =~ m!^$device_name\s!sg : $bool;
}

sub find_removable_volumes {
    my ($dbus) = @_; # perl_checker: $dbus = Net::DBus->new
    my $hal = $dbus->get_service($hal_dn); # perl_checker: $dbus = Net::DBus->new
    my $manager = $hal->get_object($manager_path, $hal_manager); # perl_checker: $manager = Net::DBus::RemoteObject

    grep { is_proper_device($_, 1) } map { $hal->get_object($_, "$hal_dn.Device") } @{$manager->GetAllDevices};
}

1;