diff options
Diffstat (limited to 'example')
-rwxr-xr-x | example/ivyprobe.pl | 73 |
1 files changed, 47 insertions, 26 deletions
diff --git a/example/ivyprobe.pl b/example/ivyprobe.pl index 72e3439..2dd9b0e 100755 --- a/example/ivyprobe.pl +++ b/example/ivyprobe.pl @@ -25,17 +25,17 @@ use strict; use Ivy; use Getopt::Long; use Term::ReadLine; -use Tk; +#use Tk; use Carp; my $term = Term::ReadLine->new("ivyprobe.pl"); -$term->tkRunning; +#$term->tkRunning; -my $OUT = $term->OUT || $STDOUT; -#my $OUT = $STDOUT; +my $OUT = $term->OUT || *STDOUT{IO}; my $appliname = "IVYPROBE.PL"; my $bus; +my $timestamp = 0; # for each application gives the number of running instances my %connected_applications; @@ -64,14 +64,10 @@ foreach my $regexp (@ARGV) { $Ivyobj->start; -no strict 'subs'; -my $IN = $term->IN; -use strict 'subs'; - - +my $IN = *STDIN{IO}; sub cb { - my $line = $term->readline("> "); + my $line = $term->readline(""); $term->addhistory($line); chomp $line; exit if (&interpret_line ($line)); @@ -84,6 +80,11 @@ Ivy->mainLoop; #MainLoop; +sub printtime { + return if (!$timestamp); + my ($sec,$min,$hour) = localtime(); + printf $OUT "[%02d:%02d:%02d] ", $hour, $min, $sec; +} # this function has 3 additionnal parameters till Ivy Version 4.6 # and now getting the new/dying applications is straightforward. @@ -92,20 +93,25 @@ sub statusFunc { my ($ref_ready, $ref_nonReady, $ref_hashReady, $appname, $status, $host_or_regexp) = @_; if ($status eq "new") { + &printtime; print $OUT "$appname connected from $host_or_regexp\n"; $where_applications{"$appname:$host_or_regexp"}++; } elsif ($status eq "died") { + &printtime; print $OUT "$appname disconnected from $host_or_regexp\n"; $where_applications{"$appname:$host_or_regexp"}--; } elsif ($status eq 'subscribing') { + &printtime; print $OUT "$appname subscribed to '$host_or_regexp'\n"; } elsif ($status eq 'unsubscribing') { + &printtime; print $OUT "$appname unsubscribed to '$host_or_regexp'\n"; } else { + &printtime; print $OUT "Bug: unkown status; $status in &statusFunc\n"; } @@ -117,9 +123,10 @@ sub statusFunc { # return 1 if exit! sub interpret_line { my ($str) = @_; - if ($str eq "") { return 0; } print "$str\n"; - if ($str =~ /^([^\.])/) { + if ($str eq "") { return 0; } ; + if ($str =~ /^([^\.])/ or $str =~ /^\\/) { my $count=$Ivyobj->sendMsgs($str); + &printtime; print $OUT "-> Sent to $count peer"; if ($count > 1) { print $OUT "s" } print $OUT "\n"; @@ -133,8 +140,12 @@ sub interpret_line { return 0; } - if ($str =~ /^\.die\s+(\S*)/) { - $Ivyobj->sendDieTo($1); + if ($str =~ /^\.die\s+(.*)/) { + my @applis = split (/\s+/, $1); + foreach my $appli (@applis) { + &printtime; + $Ivyobj->sendDieTo($appli); + } return 0; } @@ -165,6 +176,7 @@ sub interpret_line { my $appname = $2; my $id = $3; my $data = $4; + &printtime; print $OUT "send direct to $appname id=$id $data\n"; $Ivyobj->sendDirectMsgs($appname, $id, $data); return 0; @@ -173,6 +185,7 @@ sub interpret_line { if ($str =~ /^.p(ing)?\s+(\S+)\s+(\d+)\s*$/) { my $appname = $2; my $timeout = $3; + &printtime; print $OUT "ping $appname timeout=$timeout\n"; my $res = $Ivyobj->ping($appname, $timeout); print $OUT "$res\n"; @@ -230,12 +243,19 @@ sub directCallback { sub check_options { # on traite la ligne de commande - my ($opt_help, $opt_gf); - GetOptions("help" => \$opt_help, + my ($opt_help, $opt_appliname); + GetOptions("help" => \$opt_help, "b:s" => \$bus, + "name:s" => \$opt_appliname, + "t" => \$timestamp, ); + if (defined $opt_appliname and $opt_appliname =~ /\s/) { + print $OUT "-name value should not contains blanck\n"; + &usage; + } &usage if ($opt_help && $opt_help); + $appliname = $opt_appliname if (defined $opt_appliname); } @@ -251,6 +271,9 @@ sub usage { print $OUT " -b <network>:<port>\n"; print $OUT " to defined the network adress and the port number\n"; print $OUT " defaulted to 127:2010\n"; + print $OUT " -t print a time stamp when a message is send or received\n"; + print $OUT " -name <this_appli_name>\n"; + print $OUT " to change the default appliname \'$appliname\'\n"; exit; } @@ -261,7 +284,7 @@ sub line_command_usage { print "tutu\n"; print $OUT " .q[uit] - terminate this application\n"; print $OUT " .b[ind] regexp - add a msg to receive\n"; print $OUT " .u[nbind] regexp - remove a msg to receive\n"; - print $OUT " .die appname - send die msg to appname\n"; + print $OUT " .die appname1 appname2 ... - send die msg to appnameN\n"; print $OUT " .db[ind] id - add a direct msg to receive\n"; print $OUT " .d[irect] appname id args - send direct msg to appname\n"; print $OUT " .p[ing] appname timeout - ping appname with a delay of timeout ms NYI\n"; @@ -279,15 +302,15 @@ ivyprobe.pl - simple application to test ivy, to test other ivy-application or t =head1 SYNOPSIS -B<ivyprobe.pl> [-h] [-b <network>:<port> ] ['regexp']* +B<ivyprobe.pl> [-h] [-t] [-name <the_appli_name> ] [-b <network>:<port> ] ['regexp']* =head1 DESCRIPTION -B<ivyprobe.pl> connects to the bus and offers a simple text interface to receive and send messages, and to subscribe to messages. It is very similar to the C version named ivyprobe. +B<ivyprobe.pl> connects to the bus and offers a simple text interface to receive and send messages, and to subscribe to messages. It is very similar to the C and Java version named ivyprobe. If regexps are given as parameters it subscribes to theses regexp. -To send a message, just type this message on the command line. It will be send to all applications who subscribe to this message. The number of application to which the message is sent is displayed. +To send a message, just type this message on the command line. It will be send to all applications who subscribe to this message. The number of application to which the message is sent is displayed. To send a message starting with a dot, prepend a backslash like this \.xxx The user can input the following commands: @@ -305,9 +328,9 @@ to terminate the application. to add a subscription to messages matching the regexp. -=item B<.die appname> +=item B<.die appname1 appname2 ...> -to send a die msg to appname. This application will stop. +to send a die msg to appnameN. The distant applications will stop. =item B<.db[ind] id> @@ -333,16 +356,14 @@ to get the list of all connected applications =head1 BUGS -It is currently not possible to send a message which begin with a dot. It will be interpreted as a command (usually unknown!) - -It sould be possible to use line editing capabilities, but does not work currently. +It should be possible to use line editing capabilities, but does not work currently. No other know bugs at this time. Report them to author. =head1 SEE ALSO -ivy-perl(1), perl(1) +Ivy(3pm), perl(1), ivy-java(3), ivyprobe(1) =head1 AUTHORS |