Skip to content

Commit

Permalink
Merge pull request #12 from hollie/master
Browse files Browse the repository at this point in the history
Master Merge
  • Loading branch information
Wayne Gatlin authored Sep 21, 2017
2 parents d245ca5 + a5ee7ba commit 53a16cb
Show file tree
Hide file tree
Showing 49 changed files with 6,950 additions and 3,753 deletions.
34 changes: 27 additions & 7 deletions bin/mh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ my ( $user_code, $user_code_last_good );
my ( %objects_by_object_name, %file_by_object_name, %files_by_webname );
my ( %object_names_by_file, %object_names_by_type, %object_names_by_webname, $pause_mode );
my ( @Server_Ports, @Generic_Devices, %Local_Addresses, @Local_Addresses, %Passwords, @Password_Allow_Clients );
my ( %proxy_servers, %app_parms );
my ( %proxy_servers, %app_parms, %waiter_flags );
my ( $CON_IN, $CON_OUT );

my ( $state, $temp ); # Some generic useful vars
Expand Down Expand Up @@ -2556,16 +2556,20 @@ sub check_for_socket_data_http {

# See if there is a http request
my $nfound = &socket_has_data( $Socket_Ports{http}{sock} );
#print "http: below nfound ....\n" if $Debug{http};
last unless $nfound > 0; # nfound = -1 means an error occurred
#print "http: below last unless nfound ....\n" if $Debug{http};
my $sock = $Socket_Ports{http}{sock}->accept();
#print "http: below sock ....\n" if $Debug{http};
last unless $sock; # Can be undef it socket was killed
#print "http: below last unless sock ....\n" if $Debug{http};
$sock->autoflush(1); # Not sure if this does anything?
$Socket_Ports{http}{socka} = $sock;

( $leave_socket_open_passes, $leave_socket_open_action ) = &http_process_request($sock);

my $time_diff = time - $time_check;
print "http: c=$loop_count td=$time_diff sop=$leave_socket_open_passes soa=$leave_socket_open_action.\n"
print "http: c=$loop_count td=$time_diff sop=$leave_socket_open_passes soa=$leave_socket_open_action. while loop\n"
if $Debug{http};

if ($leave_socket_open_action) {
Expand All @@ -2580,6 +2584,7 @@ sub check_for_socket_data_http {
# We must sleep here for a bit, or else Netscape sometimes
# says 'Document contains no data'. Guess we don't need this anymore :)
# select undef, undef, undef, .010;
#print "http: closing socket - ". $Info{'http_socket'}->peer ." ....\n" if $Debug{http};
&socket_close('http');
}
}
Expand Down Expand Up @@ -4730,7 +4735,7 @@ sub print_speaklog_current_time {
# Return the time of most recent speak phrase

#print "db/mh/curr: time=" . &get_tickcount . " plt=$Print_Log_Time[0] slt=$Speak_Log_Time[0]\n";
return $Print_Log_Time[0]
return $Speak_Log_Time[0]
unless ( scalar @Speak_Log_Time <= 0 ); #TODO HP should return $Speak_Log_Time
#return $Speak_Log_Time[0] unless (scalar @Speak_Log_Time <= 0); #TODO HP should return $Speak_Log_Time
return 0;
Expand Down Expand Up @@ -6695,12 +6700,16 @@ sub sig_handler_pipe {
sub sig_child_death {

# my $pid = wait;
# print "reaped $pid" . ($? ? " with exit $?" : '');
# print "reaped $pid" . ($? ? " with exit $?" : '');
# Harvest potentially more than one dead child
use POSIX ":sys_wait_h";
local ($!, $?);

my $pid;
do {
$pid = waitpid( -1, WNOHANG );
print "***PID MH reaped $pid" . ($? ? " with exit $?" : '') . "\n" if $Debug{fork};

} until $pid <= 0;

# $pid = waitpid(-1, &WNOHANG);
Expand Down Expand Up @@ -6813,9 +6822,8 @@ sub socket_has_data {
my $loopmax = 8;
do {
($nfound) = select( $rbit, undef, undef, $timeout );
last
if $nfound == -1
and !( $!{EINTR} ); # break out of the retry loop if an error did occur but not EINTR
#&::print_log("http: in socket_has_data do loop");
last if $nfound == -1 and !( $!{EINTR} ); # break out of the retry loop if an error did occur but not EINTR
$loopmax--;
} until ( $loopmax == 0 or ( $nfound >= 0 ) );

Expand Down Expand Up @@ -7757,6 +7765,18 @@ sub log_inc {
print_log( 'Perl @INC contains: ' . join( ", ", @INC ) );
}

sub set_waiter_flags {
my ($flag,$value) = @_;
$waiter_flags{$flag} = $value;
}

sub get_waiter_flags {
my ($flag) = @_;
$waiter_flags{$flag} = 0 unless (exists $waiter_flags{$flag});
return $waiter_flags{$flag};
}


#---------------------------------------------------------------------------

# Lets do it. Note, we put this at the bottom so
Expand Down
2 changes: 2 additions & 0 deletions code/common/homebridge.pl
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ sub hb_thermo_set_state {
else {
print_log "Unsupported Thermostat type";
}
return "";
}

sub hb_thermo_get_setpoint {
Expand Down Expand Up @@ -414,6 +415,7 @@ sub hb_thermo_set_setpoint {
else {
print_log "Unsupported Thermostat type";
}
return "";
}

sub calc_auto_mode {
Expand Down
55 changes: 33 additions & 22 deletions code/common/ia7_notifications.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#@ IA7 v1.1 : Enables speech notifications to browsers.
#@ also includes some sample code of how to use other notifications

if ( $Startup or $Reload ) {
if ( !defined $Info{IPAddress_local} ) {
print_log "json_server.pl: \$Info{IPAddress_local} not defined. Json speech disabled";
}
else {
print_log "IA7 Speech Notifications enabled";
&Speak_parms_add_hook( \&json_speech_enable );
}
}
#if ( $Startup or $Reload ) {
# if ( !defined $Info{IPAddress_local} ) {
# print_log "json_server.pl: \$Info{IPAddress_local} not defined. Json speech disabled";
# }
# else {
# print_log "IA7 Speech Notifications enabled";
# #&Speak_parms_add_hook( \&json_speech_enable );
# }
#}

$v_ia7_test_sound = new Voice_Cmd("Test playing a sound");
$v_ia7_test_banner = new Voice_Cmd("Test [blue,green,yellow,red] Banner Notification");
Expand All @@ -29,18 +29,29 @@
&json_notification( "sound", {%data} );
}

sub json_speech_enable {
my ($parms) = @_;
push @{ $parms->{web_hook} }, \&file_ready_for_ia7;
}

sub file_ready_for_ia7 {
my (%parms) = @_;
my %data;
$data{mode} = $parms{mode};
$data{url} = "http://" . $Info{IPAddress_local} . ":" . $config_parms{http_port} . "/" . $parms{web_file};
$data{text} = $parms{raw_text};
$data{client} = $parms{requestor};
&json_notification( "speech", {%data} );
}

#sub json_speech_enable {
# my ($parms) = @_;
# push( @{ $parms->{web_hook} }, \&file_ready_for_ia7);
#}

#sub file_ready_for_ia7 {
# my (%parms) = @_;
# my %data;
# $data{mode} = $parms{mode};
# $data{url} = "http://" . $Info{IPAddress_local} . ":" . $config_parms{http_port} . "/" . $parms{web_file};
# $data{text} = $parms{raw_text};
# $data{client} = $parms{requestor};
# if (defined $Info{IPAddress_local}) {
# if ((defined $parms{forked}) and $parms{forked} ) {
# #if it's a child process we can't access the global @json_notifications array, so send a webservice call to the master process
# my $MHParent = $Info{IPAddress_local} . ":" . $config_parms{http_port};
# my $cmd = "get_url -quiet \"http://$MHParent/SUB?ia7_notify(\'speech',$data{mode},'$data{text}',$data{url})\" /dev/null";
# run "$cmd" unless (defined $config_parms{disable_json_speech} and $config_parms{disable_json_speech});
# } else {
# &json_notification( "speech", {%data} );
# }
# }
#}

Loading

0 comments on commit 53a16cb

Please sign in to comment.