summaryrefslogtreecommitdiff
path: root/lib/RHRD/utils.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/RHRD/utils.pm')
-rwxr-xr-xlib/RHRD/utils.pm42
1 files changed, 41 insertions, 1 deletions
diff --git a/lib/RHRD/utils.pm b/lib/RHRD/utils.pm
index a4bef22..4ba8a78 100755
--- a/lib/RHRD/utils.pm
+++ b/lib/RHRD/utils.pm
@@ -89,7 +89,9 @@ use constant {
"#575329", "#00FECF", "#B05B6F", "#8CD0FF", "#1E6E00", "#66E1D3", "#CFCDAC",
"#A77500", "#6367A9", "#A05837", "#772600", "#D790FF", "#5B4E51", "#8ADBB4",
"#83AB58", "#D1F7CE", "#C8D0F6", "#A3A489", "#806C66", "#BF5650", "#66796D",
- "#DA007C", "#FF1A59"]
+ "#DA007C", "#FF1A59"],
+
+ RMLSEND_BINPATH => "/usr/bin/rmlsend"
};
sub get_musicpool_color
@@ -268,6 +270,44 @@ sub fetch_parse_json
}
+sub is_rmlsend_installed
+{
+ return 1 if -x RMLSEND_BINPATH;
+ return 0;
+}
+
+sub send_rml
+{
+ my ($rml, $host, $port) = @_;
+
+ my @script = (RMLSEND_BINPATH);
+ if(defined($host)) {
+ push(@script, '--to-host=' . $host);
+ }
+ if(defined($port)) {
+ push(@script, '--to-port=' . $port);
+ }
+ push(@script, $rml);
+
+ my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle );
+ $writer->autoflush(1);
+ local $SIG{CHLD} = 'DEFAULT';
+ my $pid = open3($writer, $reader, $error, @script);
+ binmode($reader, ":utf8");
+ binmode($writer, ":utf8");
+ binmode($error, ":utf8");
+ close $writer;
+ waitpid $pid, 0;
+ my $err_out = join('', <$error>);
+ my $read_out = join('', <$reader>);
+ if ( $? >> 8 ) {
+ my $log = "\n\nrmlsend: executing RML returned non-zero value\n";
+ $log .= "STDERR:\n" . $err_out . "\n" unless $err_out eq '';
+ $log .= "STDOUT:\n" . $read_out . "\n" unless $read_out eq '';
+ return(1, $log);
+ }
+}
+
#########################################
## PV