/******************************************************************************
* Copyright (c) 2000-2019 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
*  Jozsef Gyurusi - initial implementation and initial documentation
*  Adam Delic
*  Antal Wuh.Hen.Chang
*  Attila Balasko
*  Gabor Szalai
*  Istvan Sandor
*  Peter Kremer
*  Zoltan Jasz
******************************************************************************/
//
//  File:         PIPEasp_Types.ttcn
//  Description:  PIPE (ASP) definitions
//  Rev:          R7D
//  Prodnr:       CNL 113 334
//

module PIPEasp_Types
{//start of the module


// Function definition to process the exit status of the process
// The returned code is the full status information code of the executed process
// These functions have the same functionality as the posix compliant 
// WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG macros.


external function f_PIPE_WIFEXITED(in integer code) return boolean;
external function f_PIPE_WEXITSTATUS(in integer code) return integer;
external function f_PIPE_WIFSIGNALED(in integer code) return boolean;
external function f_PIPE_WTERMSIG(in integer code) return integer;

// *************************************************************************
// *  Type Definitions Part                                                *
// *************************************************************************

// This ASP can be used to execute the given command with given standard input.
// The PResult ASP is sent as an answer, unless there is already a process
// executing which results in the ASP PError being sent.
//
// This ASP can only be sent from the test suite: $DIRECTION OUT
  type record ASP_PExecute {
    charstring command,
    charstring stdin
  };
  
  type record ASP_PExecutePty {
    charstring command,
    charstring stdin
  };

// This ASP is sent as an answer to the PExecute ASP. It provides
// information about the standard output and error of the executed command,
// as well as the exit code of the command.
// 
// This ASP can only be received by the test suite: $DIRECTION IN
  type record ASP_PResult {
    charstring stdout,
    charstring stderr,
    integer    code
  };
  
// This ASP is similar to the PExecute ASP, except that binary data is
// sent instead of a string as the contents of standard input. This means that
// the data can be, for instance, the encode form of a PDU.
// 
// This ASP can only be sent from the test suite: $DIRECTION OUT
  type record ASP_PExecuteBinary {
    charstring  command,
    octetstring stdin
  };
  
  type record ASP_PExecuteBinaryPty {
    charstring  command,
    octetstring stdin
  };
  
// This ASP is similar to the PResult ASP, except that the outputs are
// given as binary data.
// 
// This ASP can only be received by the test suite: $DIRECTION IN
  type record ASP_PResultBinary {
    octetstring stdout,
    octetstring stderr,
    integer     code
  };
  
// This ASP can be used to start a background process with the command
// given in the parameters. The PStdin, PStdinBinary, PStdout, PStdoutBinary,
// PStderr, and PStderrBinary ASPs can then be used to send and receive input
// and output to and from the process.
//
// This ASP can only be sent by the test suite: $DIRECTION OUT
  type record ASP_PExecuteBackground {
    charstring command
  };

// This ASP is similar to the ASP_PExecuteBackground.
// The difference is that it executes the command with forkpty(...) instead of fork(...)
// Some commands (for example ssh, scp) opens a pty for user name and password instead 
// of using stdin/stdout. The limitation of this ASP is that the stderr and 
// stdout will be received with the same ASP: ASP_PStdout
//
// If used for ssh and scp it is recommended to use lineMode = false because
// the user name and password query is sent by ssh/scp without newline.
//
// This ASP can only be sent by the test suite: $DIRECTION OUT
  type record ASP_PExecuteBackgroundPty {
    charstring command
  };

// This ASP sends input to the process started with PExecuteBackground.
// After the usage of the PStdin ASP, all outputs are sent back to the
// test suite by the PStdout and PStderr ASPs.
// 
// This ASP can only be sent by the test suite: $DIRECTION OUT
  type record ASP_PStdin {
    charstring stdin
  };

// This ASP is sent to the test suite when the background process started
// by PExecuteBackground outputs something to its standard output.
// 
// This ASP can only be received by the test suite: $DIRECTION IN
  type record ASP_PStdout {
    charstring stdout
  };
  
// This ASP is sent to the test suite when the background process started
// by PExecuteBackground outputs something to its standard error.
// 
// This ASP can only be received by the test suite: $DIRECTION IN
  type record ASP_PStderr {
    charstring stderr
  };

// This ASP is similar to the PStdin ASP, except that the inputs are in
// binary format. After sending this ASP, all the outputs produced by the
// background process are sent back to the test suite in the PStdoutBinary
// and PStderrBinary ASPs.
// 
// This ASP can only be sent by the test suite: $DIRECTION OUT
  type record ASP_PStdinBinary {
    octetstring stdin
  };

// This ASP is similar to PStdout, except that it carries binary data.
// 
// This ASP can only be received by the test suite: $DIRECTION IN
  type record ASP_PStdoutBinary {
    octetstring stdout
  };

// This ASP is similar to PStderr, except that it carries binary data.
// 
// This ASP can only be received by the test suite: $DIRECTION IN
  type record ASP_PStderrBinary {
    octetstring stderr
  };

// This ASP can be used to send a signal to the process started by
// PExecuteBackground. The parameter value is the signal number.
// 
// This ASP can only be sent by the test suite: $DIRECTION OUT
  type record ASP_PKill {
    integer signal
  };

// This ASP informs the test suite about the death of the process started
// by PExecuteBackground. The parameter value is the exit code of the process.
// 
// This ASP can only be received by the test suite: $DIRECTION IN
  type record ASP_PExit {
    integer code
  };

// This ASP determines the meaning of the strings representing the standard
// input, output, and error in the ASPs PExecute, PResult, PStdin, PStdout,
// and PStderr.  In the first two ASPs, it determines if a newline is added to
// the end of the inputs and a newline is taken away from the end of the outputs.
// TRUE determines that these changes take place, and FALSE that they do not.
// 
// In the three other ASPs, TRUE means that a newline is added to the end of
// each input string, and that the outputs are sent in separate ASPs each
// containing only one line of text (without the newline).
// 
// By default, the PIPE test port functions as if the PLineMode ASP would have
// been sent with the parameter values TRUE.
// 
// This ASP can only be sent by the test suite: $DIRECTION OUT
  type record ASP_PLineMode {
    boolean lineMode
  };

// This ASP is sent to the test suite when the PIPE test port is used
// in a wrong manner.
// 
// This ASP can only be received by the test suite: $DIRECTION IN
  type record ASP_PError {
    charstring errorMessage
  };

// This ASP can be used to notify the test port that the end of input
// is reached. Makes sense for processes started by PExecuteBackground.
// After this ASP is sent to the background process no more input can be sent
// to its stdin using PStdin(Binary)
// Note, that for processes started by PExecute(Binary) the input is
// closed automatically.
// 
// This ASP can only be sent by the test suite: $DIRECTION OUT
  type record ASP_PEndOfInput {
  };




// This ASP can be used to execute command in parallel. The p_id should be requested 
// by f_PIPE_request_p_id() function before the executing the command.
// 
// This ASP can only be sent by the test suite: $DIRECTION OUT
  type record ASP_Parallel_Command{
    integer        p_id,
    ASP_Commands   command
  }


  type union ASP_Commands{
        ASP_PExecute                   pexecute,
    	ASP_PExecutePty                pexecutePty,
        ASP_PExecuteBinary             pexecuteBinary,
        ASP_PExecuteBinaryPty          pexecuteBinaryPty,
        ASP_PExecuteBackground         pexecuteBackground,
        ASP_PExecuteBackgroundPty      pexecuteBackgroundPty,
        ASP_PStdin                     pStdin,
        ASP_PStdinBinary               pStdinBinary,
        ASP_PKill                      pKill,
        ASP_PEndOfInput                pEndOfInput
  }
  

// This ASP is sent to the test suite when the PIPE test port executes command in parallel mode.

  type record ASP_Parrallel_Result{
    integer        p_id,
    ASP_Results    result
  }

  type union ASP_Results{
        ASP_PResult                    pResult,
        ASP_PResultBinary              pResultBinary,
        ASP_PStdout                    pStdout,
        ASP_PStderr                    pStderr,
        ASP_PStdoutBinary              pStdoutBinary,
        ASP_PStderrBinary              pStedrrBinary,
        ASP_PExit                      pExit,
        ASP_PError                     pError
   }

}//end module


