.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "TakTuk::Pilot 3pm" .TH TakTuk::Pilot 3pm "2018-04-12" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" TakTuk::Pilot \- Perl module that ease "taktuk(1)" execution and related I/O management .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& 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}\en"; \& $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\en"; \& $taktuk\->send_command("broadcast exec [ $buffer ]"); \& } \& if (not $result) { \& print "Terminating\en"; \& $taktuk\->remove_descriptor(type=>\*(Aqread\*(Aq, \& filehandle=>$descriptor); \& $taktuk\->send_termination(); \& } \& } \& \& die "This script requires as arguments hostnames to contact\en" \& unless scalar(@ARGV); \& \& my $taktuk = TakTuk::Pilot\->new(); \& $taktuk\->add_callback(callback=>\e&output_callback, stream=>\*(Aqoutput\*(Aq, \& argument=>\e@line_counter, \& fields=>[\*(Aqhost\*(Aq, \*(Aqrank\*(Aq, \*(Aqline\*(Aq]); \& $taktuk\->add_descriptor(type=>\*(Aqread\*(Aq, filehandle=>\e*STDIN, \& callback=>\e&user_input_callback); \& $taktuk\->run(command=>"taktuk \-s \-m ".join(" \-m ", @ARGV)); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The TakTuk::Pilot Perl module ease the use of \fBTakTuk\fR from within a Perl program (see \f(CWtaktuk(1)\fR for a detailed description of \fBTakTuk\fR). It transparently manages I/O exchanges as well as \fBTakTuk\fR data demultiplexing and decoding. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .IP "\fBnew\fR\fB()\fR" 4 .IX Item "new()" Creates a new \fBTakTuk\fR object on which the following method can be called. .SH "METHODS" .IX Header "METHODS" .IP "\fBadd_callback(%)\fR" 4 .IX Item "add_callback(%)" Adds a callback function associated to some \fBTakTuk\fR output stream to the calling \fBTakTuk\fR object. This callback function will be called by \&\fBTakTuk::Pilot\fR for each batch of output data incoming from the related stream. The hash passed as argument to this function call may contain the following fields: .Sp .Vb 7 \& callback => reference to the callback fonction (mandatory) \& stream => stream related to this callback, might be \& \*(Aqdefault\*(Aq (mandatory) \& fields => reference to an array of fields names relevant \& to the user \& argument => scalar that should be passed to each callback \& function call .Ve .Sp The callback function should accept a hash as argument. This hash will be populated with the following fields : .Sp .Vb 7 \& 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 .Ve .IP "\fBsend_command($)\fR" 4 .IX Item "send_command($)" Sends to the calling \fBTakTuk\fR object the command passed as argument. Note that if the \fBTakTuk\fR object is not running, this command will be buffered and executed upon run. .IP "\fBsend_termination\fR\fB()\fR" 4 .IX Item "send_termination()" Sends to the calling \fBTakTuk\fR object a termination command. As for \&\f(CW\*(C`send_command\*(C'\fR, if the \fBTakTuk\fR object is not running, this command will be issued upon run. .IP "\fBrun(%)\fR" 4 .IX Item "run(%)" Runs \fBTakTuk\fR, executing pending commands and waiting for \fBTakTuk\fR output. Note that this function is blocking: it waits for \fBTakTuk\fR outputs, possibly calls related callback functions and returns when \fBTakTuk\fR terminates. Thus, all \fBTakTuk\fR commands should be given either before calling \f(CW\*(C`run\*(C'\fR or within a callback function. .Sp This commands takes a hash as argument that may contain the following fields: .Sp .Vb 2 \& command => TakTuk command line to be executed \& timeout => optional timeout on the wait for TakTuk output .Ve .Sp Upon occurrence of the timeout (if one has been given), \f(CW\*(C`run\*(C'\fR will returns an \&\f(CW\*(C`ETMOUT\*(C'\fR error code. Note the in this case \fBTakTuk\fR execution will not be terminated and should be resumed at some point by calling \f(CW\*(C`continue\*(C'\fR. .IP "\fBcontinue\fR\fB()\fR" 4 .IX Item "continue()" Resumes a \fBTakTuk\fR execution interrupted by timeout occurrence. .IP "\fBadd_descriptor(%)\fR" 4 .IX Item "add_descriptor(%)" Because the call to \f(CW\*(C`run\*(C'\fR is blocking, waiting for \fBTakTuk\fR output, it might be interesting to let the \f(CW\*(C`TakTuk::Pilot\*(C'\fR module monitor I/O occurrence related to other file descriptors. This is the intent of \f(CW\*(C`add_descriptor\*(C'\fR. This function takes a hash as parameter in which the following fields might be defined: .Sp .Vb 10 \& type => \*(Aqread\*(Aq, \*(Aqwrite\*(Aq or \*(Aqexception\*(Aq, 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 .Ve .Sp The callback function should also accept a hash as an argument in which the following fields will be defined: .Sp .Vb 10 \& 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 .Ve .IP "\fBremove_descriptor(%)\fR" 4 .IX Item "remove_descriptor(%)" Function that should be called to remove from the \fBTakTuk\fR object a descriptor previously added with \f(CW\*(C`add_descriptor\*(C'\fR. It takes a hash as argument in which the following fields may be defined: .Sp .Vb 2 \& type => type of I/O (see add_descriptor) \& filehandle => file descriptor to remove .Ve .IP "\fBquiet\fR\fB() / verbose\fR\fB()\fR" 4 .IX Item "quiet() / verbose()" Change verbosity of \f(CW\*(C`TakTuk::Pilot\*(C'\fR on \s-1STDOUT \s0(default is quiet). Should not be called when \fBTakTuk\fR is running. .IP "\fBcreate_session\fR\fB()\fR" 4 .IX Item "create_session()" Call \f(CW\*(C`setsid\*(C'\fR in the \fBTakTuk\fR process created by \f(CW\*(C`run\*(C'\fR. The main purpose of this call is to prevent \fBTakTuk\fR from receiving signals sent to the process group to which the pilot belong. Should not be called when \fBTakTuk\fR is running. .IP "\fBpid\fR\fB()\fR" 4 .IX Item "pid()" Returns the pid of the process spawned to run \fBTakTuk\fR. Should only be called when \fBTakTuk\fR is running. .IP "\fBerror_msg($)\fR" 4 .IX Item "error_msg($)" Static function. Returns a character string that corresponds to the error code given as argument. The error code should be one of the values returned by other \&\f(CW\*(C`TakTuk::Pilot\*(C'\fR functions (\f(CW\*(C`add_callback\*(C'\fR, \f(CW\*(C`send_command\*(C'\fR, \&\f(CW\*(C`send_termination\*(C'\fR, ...). .SH "ERRORS" .IX Header "ERRORS" 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: .IP "\fBTakTuk::Pilot::EARGCM\fR" 4 .IX Item "TakTuk::Pilot::EARGCM" Field 'command' is missing in a call to \f(CW\*(C`run\*(C'\fR. .IP "\fBTakTuk::Pilot::EARGCB\fR" 4 .IX Item "TakTuk::Pilot::EARGCB" Field 'callback' is missing in a call to \f(CW\*(C`add_callback\*(C'\fR or \f(CW\*(C`add_descriptor\*(C'\fR. .IP "\fBTakTuk::Pilot::EARGFH\fR" 4 .IX Item "TakTuk::Pilot::EARGFH" Field 'filehandle' is missing in a call to \f(CW\*(C`add_descriptor\*(C'\fR or \&\f(CW\*(C`remove_descriptor\*(C'\fR. .IP "\fBTakTuk::Pilot::EARGTP\fR" 4 .IX Item "TakTuk::Pilot::EARGTP" Field 'type' is missing in a call to \f(CW\*(C`add_descriptor\*(C'\fR or \&\f(CW\*(C`remove_descriptor\*(C'\fR. .IP "\fBTakTuk::Pilot::ETMOUT\fR" 4 .IX Item "TakTuk::Pilot::ETMOUT" A timeout occurred in a call to \f(CW\*(C`run\*(C'\fR. .IP "\fBTakTuk::Pilot::ETKTRN\fR" 4 .IX Item "TakTuk::Pilot::ETKTRN" \&\fBTakTuk\fR is alredy running but \f(CW\*(C`run\*(C'\fR, \f(CW\*(C`verbose\*(C'\fR or \f(CW\*(C`quiet\*(C'\fR has been called. .IP "\fBTakTuk::Pilot::ETKTNR\fR" 4 .IX Item "TakTuk::Pilot::ETKTNR" \&\fBTakTuk\fR is not running but \f(CW\*(C`continue\*(C'\fR has been called. .IP "\fBTakTuk::Pilot::ESPIPE\fR" 4 .IX Item "TakTuk::Pilot::ESPIPE" A call to \f(CW\*(C`pipe\*(C'\fR failed in \f(CW\*(C`TakTuk::Pilot\*(C'\fR (the error should be in $!). .IP "\fBTakTuk::Pilot::ESFORK\fR" 4 .IX Item "TakTuk::Pilot::ESFORK" A call to \f(CW\*(C`fork\*(C'\fR failed in \f(CW\*(C`TakTuk::Pilot\*(C'\fR (the error should be in $!). .IP "\fBTakTuk::Pilot::ESCLOS\fR" 4 .IX Item "TakTuk::Pilot::ESCLOS" A call to \f(CW\*(C`close\*(C'\fR failed in \f(CW\*(C`TakTuk::Pilot\*(C'\fR (the error should be in $!). .IP "\fBTakTuk::Pilot::ESELEC\fR" 4 .IX Item "TakTuk::Pilot::ESELEC" A call to \f(CW\*(C`select\*(C'\fR failed in \f(CW\*(C`TakTuk::Pilot\*(C'\fR (the error should be in $!). .IP "\fBTakTuk::Pilot::ETPBUG\fR" 4 .IX Item "TakTuk::Pilot::ETPBUG" Internal bug detected in \f(CW\*(C`TakTuk::Pilot\*(C'\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\f(CWtatkuk(1)\fR, \f(CWtaktukcomm(3)\fR, \f(CWTakTuk(3)\fR .SH "AUTHOR" .IX Header "AUTHOR" The original concept of \fBTakTuk\fR 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. .PP The author of the version 3 (perl version) and current maintainer of the package is Guillaume Huard. .SH "COPYRIGHT" .IX Header "COPYRIGHT" The \f(CW\*(C`TakTuk\*(C'\fR communication interface library is provided under the terms of the \s-1GNU\s0 General Public License version 2 or later.