mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-06 12:18:46 +00:00
ccurpcd: Multi RPC process support
git-svn-id: https://svn.fhem.de/fhem/trunk@10505 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
b38225a9e7
commit
68a86c24c1
@ -3,7 +3,7 @@
|
||||
#########################################################
|
||||
# ccurpcd.pl
|
||||
#
|
||||
# Version 1.4
|
||||
# Version 1.5
|
||||
#
|
||||
# RPC server for Homematic CCU.
|
||||
#
|
||||
@ -27,7 +27,6 @@ use warnings;
|
||||
# use File::Queue;
|
||||
use RPC::XML::Server;
|
||||
use RPC::XML::Client;
|
||||
# use XML::Simple qw(:strict);
|
||||
use IO::Socket::INET;
|
||||
use FindBin qw($Bin);
|
||||
use lib "$Bin";
|
||||
@ -41,7 +40,7 @@ my $logfile;
|
||||
my $shutdown = 0;
|
||||
my $eventcount = 0;
|
||||
|
||||
sub CheckProcess ($);
|
||||
sub CheckProcess ($$);
|
||||
sub Log ($);
|
||||
|
||||
|
||||
@ -49,18 +48,21 @@ sub Log ($);
|
||||
# Get PID of running RPC server or 0
|
||||
#####################################
|
||||
|
||||
sub CheckProcess ($)
|
||||
sub CheckProcess ($$)
|
||||
{
|
||||
my ($prcname) = @_;
|
||||
my ($prcname, $port) = @_;
|
||||
|
||||
my $filename = $prcname;
|
||||
my $pdump = `ps -ef | grep $prcname | grep -v grep`;
|
||||
my @plist = split "\n", $pdump;
|
||||
foreach my $proc (@plist) {
|
||||
# Remove leading blanks, fix for MacOS. Thanks to mcdeck
|
||||
$proc =~ s/^\s+//;
|
||||
my @procattr = split /\s+/, $proc;
|
||||
if ($procattr[1] != $$ && $procattr[7] =~ /perl$/ && $procattr[8] eq $prcname) {
|
||||
Log "Process $proc is running";
|
||||
if ($procattr[1] != $$ && $procattr[7] =~ /perl$/ &&
|
||||
($procattr[8] eq $prcname || $procattr[8] =~ /\/ccurpcd\.pl$/) &&
|
||||
$procattr[10] eq "$port") {
|
||||
Log "Process $proc is running connected to CCU port $port";
|
||||
return $procattr[1];
|
||||
}
|
||||
}
|
||||
@ -131,22 +133,24 @@ sub CCURPC_Initialize ($$)
|
||||
# Detect local IP
|
||||
my $socket = IO::Socket::INET->new (PeerAddr => $serveraddr, PeerPort => $serverport);
|
||||
if (!$socket) {
|
||||
Log "Can't connect to CCU";
|
||||
Log "Can't connect to CCU port $serverport";
|
||||
return undef;
|
||||
}
|
||||
my $localaddr = $socket->sockhost ();
|
||||
close ($socket);
|
||||
|
||||
# Create RPC client
|
||||
$client = RPC::XML::Client->new ("http://$serveraddr:$serverport/");
|
||||
|
||||
# Check if RPC daemon on CCU is running
|
||||
my $resp = $client->send_request ('system.listMethods');
|
||||
if (!ref($resp)) {
|
||||
Log "No response from CCU. Error message follows in next line";
|
||||
Log "No response from CCU on port $serverport. Error message follows in next line";
|
||||
Log $resp;
|
||||
return undef;
|
||||
}
|
||||
|
||||
# Create RPC server
|
||||
$server = RPC::XML::Server->new (port=>$callbackport);
|
||||
if (!ref($server))
|
||||
{
|
||||
@ -154,7 +158,7 @@ sub CCURPC_Initialize ($$)
|
||||
return undef;
|
||||
}
|
||||
else {
|
||||
Log "callback server created";
|
||||
Log "callback server created listening on port $callbackport";
|
||||
}
|
||||
|
||||
# Callback for events
|
||||
@ -201,15 +205,13 @@ sub CCURPC_Initialize ($$)
|
||||
}
|
||||
);
|
||||
|
||||
# $CCURPC_SERVERSOCKET = $server->{__daemon};
|
||||
# $CCURPC_FD = $CCURPC_SERVERSOCKET->fileno();
|
||||
my $ccurpcport = $server->{__daemon}->sockport();
|
||||
|
||||
# Register callback
|
||||
my $callbackurl = "http://".$localaddr.":".$ccurpcport."/fh";
|
||||
Log "Registering callback";
|
||||
my $callbackurl = "http://".$localaddr.":".$ccurpcport."/fh".$serverport;
|
||||
Log "Registering callback $callbackurl with ID CB".$serverport;
|
||||
|
||||
$client->send_request ("init",$callbackurl,"CB1");
|
||||
$client->send_request ("init",$callbackurl,"CB".$serverport);
|
||||
Log "RPC callback with URL ".$callbackurl." initialized";
|
||||
|
||||
return $callbackurl;
|
||||
@ -310,10 +312,10 @@ my $ccuport = $ARGV[1];
|
||||
my $queuefile = $ARGV[2];
|
||||
$logfile = $ARGV[3];
|
||||
|
||||
my $pid = CheckProcess ($name);
|
||||
my $pid = CheckProcess ($name, $ccuport);
|
||||
if ($pid > 0) {
|
||||
Log "Error: ccurpcd.pl is already running (PID=$pid)";
|
||||
die "Error: ccurpcd.pl is already running (PID=$pid)\n";
|
||||
Log "Error: ccurpcd.pl is already running (PID=$pid) for CCU port $ccuport";
|
||||
die "Error: ccurpcd.pl is already running (PID=$pid) for CCU port $ccuport\n";
|
||||
}
|
||||
|
||||
# Create or open queue
|
||||
|
Loading…
x
Reference in New Issue
Block a user