diff options
author | dakkar <dakkar@thenautilus.net> | 2022-04-03 11:49:10 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2022-04-03 11:49:10 +0100 |
commit | 1ae568aec58b7a985c884865028eb7b09796517b (patch) | |
tree | 53beec2b2c1889bb04e5acafffdce927350995d5 /lib/Lirc | |
parent | buttons for subs/audio tracks (diff) | |
download | media-control-1ae568aec58b7a985c884865028eb7b09796517b.tar.gz media-control-1ae568aec58b7a985c884865028eb7b09796517b.tar.bz2 media-control-1ae568aec58b7a985c884865028eb7b09796517b.zip |
on-demand lirc connect
also, re-connect after failure
Diffstat (limited to 'lib/Lirc')
-rw-r--r-- | lib/Lirc/Client.rakumod | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/Lirc/Client.rakumod b/lib/Lirc/Client.rakumod index f87528c..672a3d0 100644 --- a/lib/Lirc/Client.rakumod +++ b/lib/Lirc/Client.rakumod @@ -13,17 +13,30 @@ class Lirc::Client { my sub lirc_get_local_socket(Str $socket is encoded('utf8'), int32 $verbose --> int32) is native('lirc_client') {*} my sub lirc_send_one(int32 $fd, Str $remote is encoded('utf8'), Str $keysym is encoded('utf8') --> int32) is native('lirc_client') {*} + my sub lirc_deinit(--> int32) is native('lirc_client') {*} + has Str $!socket; + has Bool $!verbose; has int $!fd; - submethod BUILD(Str :$socket=Str, Bool :$verbose=False) { - $!fd = lirc_get_local_socket($socket, $verbose ?? 1 !! 0); - X::Init.new(rc => -$!fd).throw() if $!fd < 0; + submethod BUILD(Str :$!socket=Str, Bool :$!verbose=False) { + $!fd = -1; } - + + method !ensure-connected() { + if ($!fd < 0) { + $!fd = lirc_get_local_socket($!socket, $!verbose ?? 1 !! 0); + X::Init.new(rc => -$!fd).throw() if $!fd < 0; + } + } + method !send-sync(Str :$remote!, Str :$keysym!) { + self!ensure-connected(); my $rc = lirc_send_one($!fd, $remote, $keysym); - X::Send.new().throw() if $rc != 0; + if $rc != 0 { + lirc_deinit(); $!fd = -1; + X::Send.new().throw() + } } # copied from OO::Actors |