summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2023-10-22 20:57:24 +0100
committerdakkar <dakkar@thenautilus.net>2023-10-22 20:59:17 +0100
commit943149067814dfa24c55abac679722d8471e5f02 (patch)
treebda4ff3fe5758655eb236d69d455709767e15237
parentv1.0.3 (diff)
downloadxscreensaver-dbus-943149067814dfa24c55abac679722d8471e5f02.tar.gz
xscreensaver-dbus-943149067814dfa24c55abac679722d8471e5f02.tar.bz2
xscreensaver-dbus-943149067814dfa24c55abac679722d8471e5f02.zip
simpler proxy object
turns out you can get the name of the sender by using `caller` as a parameter type (it's documented in Net::DBus::Exporter, section "magic types")
-rw-r--r--Changes1
-rw-r--r--lib/App/XScreenSaver/DBus/Saver.pm16
-rw-r--r--lib/App/XScreenSaver/DBus/SaverProxy.pm38
3 files changed, 9 insertions, 46 deletions
diff --git a/Changes b/Changes
index d3a7242..4f77b7e 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,5 @@
{{$NEXT}}
+ - simpler proxy object
1.0.3 2021-05-06 15:16:13+01:00 Europe/London
- lock the screen when (e)logind says so
diff --git a/lib/App/XScreenSaver/DBus/Saver.pm b/lib/App/XScreenSaver/DBus/Saver.pm
index 6eae4ed..1f48a7f 100644
--- a/lib/App/XScreenSaver/DBus/Saver.pm
+++ b/lib/App/XScreenSaver/DBus/Saver.pm
@@ -95,7 +95,7 @@ a logger
has log => ( is => 'lazy', builder => sub { Log::Any->get_logger } );
-has _impls => ( is => 'rw' );
+has _proxies => ( is => 'rw' );
has _prod_id => ( is => 'rw' );
has _inhibits => ( is => 'rw', default => sub { +{} } );
@@ -111,16 +111,12 @@ to be notified when that happens, and release that inhibition.
=cut
sub start($self) {
- my $inhibit_cb = $self->curry::weak::_inhibit;
- my $uninhibit_cb = $self->curry::weak::_uninhibit;
-
# export to dbus
- $self->_impls([ map {
+ $self->_proxies([ map {
App::XScreenSaver::DBus::SaverProxy->new(
$self->service,
$_,
- $inhibit_cb,
- $uninhibit_cb,
+ $self,
)
} $self->paths->@* ]);
@@ -142,13 +138,12 @@ sub start($self) {
return;
}
-sub _inhibit($self,$name,$reason,$message) {
+sub Inhibit($self,$name,$reason,$sender) {
my $cookie;
do {
$cookie = int(rand(2**31))
} until !exists $self->_inhibits->{$cookie};
- my $sender = $message->get_sender;
$self->_inhibits->{$cookie} = [ $name, $reason, $sender ];
$self->log->debugf(
@@ -162,11 +157,10 @@ sub _inhibit($self,$name,$reason,$message) {
return $cookie;
}
-sub _uninhibit($self,$cookie,$message) {
+sub Uninhibit($self,$cookie,$this_sender) {
my $inhibit = delete $self->_inhibits->{$cookie}
or return;
my ($name, $reason, $sender) = @$inhibit;
- my $this_sender = $message->get_sender;
$self->log->debugf(
'<%s> (was %s, is %s) resumed screensaver for <%s> (cookie %d) - %d left',
diff --git a/lib/App/XScreenSaver/DBus/SaverProxy.pm b/lib/App/XScreenSaver/DBus/SaverProxy.pm
index 858dcba..69a689c 100644
--- a/lib/App/XScreenSaver/DBus/SaverProxy.pm
+++ b/lib/App/XScreenSaver/DBus/SaverProxy.pm
@@ -2,45 +2,13 @@ package App::XScreenSaver::DBus::SaverProxy;
use v5.20;
use strict;
use warnings;
-use experimental qw(signatures postderef);
# this is the interface name
use Net::DBus::Exporter qw(org.freedesktop.ScreenSaver);
-use parent 'Net::DBus::Object';
+use parent 'Net::DBus::ProxyObject';
# VERSION
# ABSTRACT: proxy dbus object
-=head1 DESCRIPTION
-
-This is functionally the same as L<< C<Net::DBus::ObjectProxy> >>, but
-specialised for this application, and with a hack to allow L<<
-C<App::XScreenSaver::DBus::Saver> >> to access the sender of the
-message.
-
-=cut
-
-dbus_method('Inhibit',['string','string'],['uint32']);
-dbus_method('UnInhibit',['uint32'],[]);
-
-sub new($class,$service,$path,$inhibit_cb,$uninhibit_cb) {
- my $self = $class->SUPER::new($service, $path);
- bless $self, $class;
- $self->{__inhibit_cb} = $inhibit_cb;
- $self->{__uninhibit_cb} = $uninhibit_cb;
- return $self;
-}
-
-our $_message;
-sub _dispatch_object($self,$connection,$message,@etc) {
- local $_message = $message;
- return $self->SUPER::_dispatch_object($connection,$message,@etc);
-}
-
-sub Inhibit($self,$name,$reason) {
- return $self->{__inhibit_cb}->($name,$reason,$_message);
-}
-
-sub UnInhibit($self,$cookie) {
- return $self->{__uninhibit_cb}->($cookie,$_message);
-}
+dbus_method('Inhibit',['string','string','caller'],['uint32']);
+dbus_method('UnInhibit',['uint32','caller'],[]);
1;