Skip to content

Commit

Permalink
add GMB::DBus::simple_call function and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
squentin committed Sep 19, 2015
1 parent 3e82d84 commit b54d9a2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
12 changes: 5 additions & 7 deletions gmusicbrowser.pl
Expand Up @@ -410,13 +410,11 @@ BEGIN
if (!$running && !$CmdLine{noDBus})
{ eval {require 'gmusicbrowser_dbus.pm'}
|| warn "Error loading gmusicbrowser_dbus.pm :\n$@ => controlling gmusicbrowser through DBus won't be possible.\n\n";
eval
{ my $bus= $GMB::DBus::bus || die;
my $service = $bus->get_service($DBus_id) || die;
my $object = $service->get_object('/org/gmusicbrowser', 'org.gmusicbrowser') || die;
$object->RunCommand($_) for @cmd;
};
$running="using DBus id=$DBus_id" unless $@;
my $object= GMB::DBus::simple_call("$DBus_id org.gmusicbrowser/org/gmusicbrowser");
if ($object)
{ $object->RunCommand($_) for @cmd;
$running="using DBus id=$DBus_id";
}
}
if ($running)
{ warn "Found a running instance ($running)\n";
Expand Down
21 changes: 21 additions & 0 deletions gmusicbrowser_dbus.pm
Expand Up @@ -151,6 +151,27 @@ sub init
0; #called in an idle, return 0 to run only once
}

use Net::DBus::Annotation qw(:call);
sub simple_call #$service_path can be service_and_path separated by space, or the object
{ my ($service_path,$method,$args,$reply)=@_;
my $return= eval
{ my $object;
if (ref $service_path) { $object=$service_path }
else
{ my ($name,$path)= split / +/,$service_path,2;
my $service= $bus->get_service($name);
return $service unless $path;
my $interface= $path=~s#^([^/]+)## ? $1 : undef;
$object = $service->get_object($path,$interface);
}
return $object unless $method;
$reply&&= $reply eq 'async' ? dbus_call_async :
$reply eq 'noreply' ? dbus_call_noreply : undef;
return $object->$method(($reply||()),@$args);
};
return $@ ? undef : $return;
}

sub DBus_mainloop_hack
{ # use Net::DBus internals to connect it to the Glib mainloop, though unlikely, it may break with future version of Net::DBus
use Net::DBus::Reactor;
Expand Down
14 changes: 5 additions & 9 deletions plugins/gnome_mmkeys.pm
Expand Up @@ -24,16 +24,12 @@ my %Names=
mate => 'org.mate.SettingsDaemon /org/mate/SettingsDaemon/MediaKeys',
);

my $bus= Net::DBus->find;
my ($service,$object);
my $object;
for my $desktop (qw/gnome mate ognome/)
{ my ($name,$path)= split /\s+/, $Names{$desktop};
eval
{ $service= $bus->get_service($name);
$object = $service->get_object($path);
$object->connect_to_signal(MediaPlayerKeyPressed => \&callback);
};
last if $object && !$@;
{ if ($object= GMB::DBus::simple_call($Names{$desktop}))
{ $object->connect_to_signal(MediaPlayerKeyPressed => \&callback);
last
}
}
die "Can't find the dbus Settings Daemon for gnome or MATE\n" if $@;

Expand Down

0 comments on commit b54d9a2

Please sign in to comment.