| TakTuk::Pilot(3pm) | User Contributed Perl Documentation | TakTuk::Pilot(3pm) |
TakTuk::Pilot - Perl module that ease "taktuk(1)" execution and related I/O management
use TakTuk::Pilot;
our @line_counter;
sub output_callback(%) {
my %parameters = @_;
my $field = $parameters{fields};
my $rank = $field->{rank};
my $argument = $parameters{argument};
$argument->[$rank] = 1 unless defined($argument->[$rank]);
print "$field->{host}-$rank : ".
"$argument->[$rank] > $field->{line}\n";
$argument->[$rank]++;
}
sub user_input_callback(%) {
my %parameters = @_;
my $taktuk = $parameters{taktuk};
my $descriptor = $parameters{filehandle};
my $buffer;
my $result = sysread($descriptor, $buffer, 1024);
warn "Read error $!" if not defined($result);
# basic parsing, we assume input is buffered on a line basis
chomp($buffer);
if (length($buffer)) {
print "Executing $buffer\n";
$taktuk->send_command("broadcast exec [ $buffer ]");
}
if (not $result) {
print "Terminating\n";
$taktuk->remove_descriptor(type=>'read',
filehandle=>$descriptor);
$taktuk->send_termination();
}
}
die "This script requires as arguments hostnames to contact\n"
unless scalar(@ARGV);
my $taktuk = TakTuk::Pilot->new();
$taktuk->add_callback(callback=>\&output_callback, stream=>'output',
argument=>\@line_counter,
fields=>['host', 'rank', 'line']);
$taktuk->add_descriptor(type=>'read', filehandle=>\*STDIN,
callback=>\&user_input_callback);
$taktuk->run(command=>"taktuk -s -m ".join(" -m ", @ARGV));
The TakTuk::Pilot Perl module ease the use of TakTuk from within a Perl program (see taktuk(1) for a detailed description of TakTuk). It transparently manages I/O exchanges as well as TakTuk data demultiplexing and decoding.
callback => reference to the callback fonction (mandatory)
stream => stream related to this callback, might be
'default' (mandatory)
fields => reference to an array of fields names relevant
to the user
argument => scalar that should be passed to each callback
function call
The callback function should accept a hash as argument. This hash will be populated with the following fields :
taktuk => reference to the taktuk object calling this
callback
argument => scalar given at callback addition or undef
stream => stream on which output data came
fields => reference to a hash containing a
fieldname/value pair for each field requested
upon callback addition
This commands takes a hash as argument that may contain the following fields:
command => TakTuk command line to be executed
timeout => optional timeout on the wait for TakTuk output
Upon occurrence of the timeout (if one has been given), "run" will returns an "ETMOUT" error code. Note the in this case TakTuk execution will not be terminated and should be resumed at some point by calling "continue".
type => 'read', 'write' or 'exception', this is the
type of I/O possibilities that should be
monitored on the descriptor, as in select
system call (mandatory).
filehandle => file descriptor to monitor (mandatory).
callback => reference to the callback function that
should be called when I/O is possible on the
file descriptor.
argument => optional scalar value that will be passed
with each call to the callback function
The callback function should also accept a hash as an argument in which the following fields will be defined:
taktuk => reference to the TakTuk object from which
the function was called.
type => type of I/O occurring (as in add_callback)
filehandle => the related file descriptor. Notice that the
user is in charge of performing the I/O
operation itself (sysread or syswrite).
Notice also that, because of the use of a
select in TakTuk::Pilot, the use of buffered
I/O on this descriptor is strongly discouraged
argument => the argument that was given to add_descriptor
type => type of I/O (see add_descriptor)
filehandle => file descriptor to remove
When an error occur in one of these functions, it returns a non nul numeric error code. This code can take one of the following values:
tatkuk(1), taktukcomm(3), TakTuk(3)
The original concept of TakTuk has been proposed by Cyrille Martin in his PhD thesis. People involved in this work include Jacques Briat, Olivier Richard, Thierry Gautier and Guillaume Huard.
The author of the version 3 (perl version) and current maintainer of the package is Guillaume Huard.
The "TakTuk" communication interface library is provided under the terms of the GNU General Public License version 2 or later.
| 2024-04-01 | perl v5.38.2 |