summaryrefslogtreecommitdiff
path: root/test-backends.in
blob: 32734dbaa718ad1aa862890f61e8203a5e675c3c (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/perl

use lib "@netdbusdir@";

use Net::DBus;
use Net::DBus::Reactor;

sub print_tabified
{
  my ($tab, $str, $do_cr) = @_;

  print " " x $tab;
  print $str;
  print "\n" if ($do_cr);
}

sub print_recursive
{
  my ($obj, $tab) = @_;

  if (ref $obj eq "ARRAY")
  {
    print_tabified ($tab, "ARRAY = [", 1);

    foreach $elem (@{$obj})
    {
	 print_recursive ($elem, $tab + 2);
    }

    print_tabified ($tab, "]", 1);
  }
  elsif (ref $obj eq "HASH")
  {
    print_tabified ($tab, "HASH = {", 1);

    foreach $elem (keys %$obj)
    {
	 $sibling_ref = ref $$obj{$elem};

	 #print child arrays and hashes in a new line
      print_tabified ($tab + 2, "'$elem'\t=>" , ($sibling_ref eq "ARRAY" || $sibling_ref eq "HASH"));
      print_recursive ($$obj{$elem}, $tab + 4);
    }

    print_tabified ($tab, "}", 1);
  }
  else
  {
    print_tabified ($tab, $obj, 1);
  }
}

sub print_object
{
  my ($service, $object) = @_;
  my ($item);

  my $obj = $service->get_object ("/org/freedesktop/SystemToolsBackends/$object");
  my @arr = $obj->get ();

  foreach $i (@arr) {
    &print_recursive ($i, 0);
  }
}

# Main program
my $bus = Net::DBus->system;
my $service = $bus->get_service("org.freedesktop.SystemToolsBackends");

if (!$ARGV[0]) 
{
  print "Which backend object do you want to query? (i.e.: UsersConfig):\n";
  $object = <STDIN>;
  chomp $object;

  print_object ($service, $object);
}
else
{
  foreach $i (@ARGV)
  {
    chomp $i;
    print "$i\n================================\n";
    print_object ($service, $i);
    print "\n\n";
  }
}

print "Have a good day!\n";