Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef _TOONZPROC_H_
Toshihiro Shimizu 890ddd
#define _TOONZPROC_H_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tmacro.h"
Toshihiro Shimizu 890ddd
#include "stdarg.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef TNZAPI
Toshihiro Shimizu 890ddd
#ifdef TNZ_IS_COMMONLIB
Toshihiro Shimizu 890ddd
#define TNZAPI TNZ_EXPORT_API
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define TNZAPI TNZ_IMPORT_API
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define T_PID int
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef struct T_CHAN_REC *T_CHAN;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define TPROC_OPEN_READ 0x1
Toshihiro Shimizu 890ddd
#define TPROC_OPEN_WRITE 0x2
Toshihiro Shimizu 890ddd
#define TPROC_OPEN_READ_BINARY 0x4
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
e280ae
#include "windows.h"
Toshihiro Shimizu 890ddd
#define TPROC_LIB HMODULE
Toshihiro Shimizu 890ddd
#define TPROC_FUNC FARPROC
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define TPROC_LIB void *
Toshihiro Shimizu 890ddd
typedef void (*TPROC_FUNC)(void);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*#define TPROC_FUNC void**/
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Shinya Kitaoka 120a6e
Runs without sospending executable filename. A set of arguments to be
luz paz 6454c4
passed can be set in the NULL-terminated array argv. First argument
Toshihiro Shimizu 890ddd
MUST NOT be executable name.
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI T_PID tproc_run_process(char *filename, char *argv[]);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Shinya Kitaoka 120a6e
Runs sospending executable filename. A set of arguments to be
luz paz 6454c4
passed can be set in the NULL-terminated array argv. First argument
Toshihiro Shimizu 890ddd
MUST NOT be executable name. Returns TRUE if specified process was
Toshihiro Shimizu 890ddd
successfully executed, FALSE otherwise.
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI int tproc_run_process_fg(char *filename, char *argv[]);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
(IRIX ONLY, on NT is a void function).
Toshihiro Shimizu 890ddd
Suspend execution of process until child process identified with pid
Toshihiro Shimizu 890ddd
exits.
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI void tproc_waitpid(T_PID pid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
Creates a new process, sharing the virtual address space of parent.
Shinya Kitaoka 120a6e
The new process is started with a call to func, passing arg to it.
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI T_PID tproc_sproc(void (*func)(void *), void *arg);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
gets pid of current process
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI T_PID tproc_getpid(void);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
Check if process pid is alive or not
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI int tproc_is_process_alive(T_PID pid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
kills process pid (return FALSE if the process is not alive)
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI int tproc_kill_process(T_PID pid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define TPROC_SIGNONE 0x0
Toshihiro Shimizu 890ddd
#define TPROC_SIGABORT 0x2
Toshihiro Shimizu 890ddd
#define TPROC_SIGUSER1 0x4
Toshihiro Shimizu 890ddd
#define TPROC_SIGUSER2 0x8
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
sets the specified callback to be executed when one of the signal
Toshihiro Shimizu 890ddd
into the signal mask (made by ORing the TPROC_SIG) is sent to current process.
Toshihiro Shimizu 890ddd
Warning: only one callback can be assigned to a signal type; for
Toshihiro Shimizu 890ddd
each new assignation the old one is erased.
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI int tproc_set_signals_callback(int signal_mask, void (*signal_cb)(void));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* Note: next function is defined in twin, for it can be used only
Shinya Kitaoka 120a6e
by graphic modules; it is equal to tproc_set_signals_callback(TPROC_SIGCHLD,
Shinya Kitaoka 120a6e
signal_cb);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI int tproc_set_sigchld_signals_callback(void (*signal_cb)(void));
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Shinya Kitaoka 120a6e
erase actions to be executed  for  specified signals:
Toshihiro Shimizu 890ddd
valid only with TPROC_SIGCHILD, TPROC_SIGUSER1, TPROC_SIGUSER2.
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI void tproc_unset_signals_callback(int signal_mask);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
send to process pid one of the user signals.
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI void tproc_send_siguser(T_PID pid, int signal);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
suspend execution of current process  until it receives a user signal.
Toshihiro Shimizu 890ddd
If no user signal was set, it return without waiting.
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI void tproc_wait_for_siguser(void);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Shinya Kitaoka 120a6e
This function create a pipe between two process: a parent that writes
Toshihiro Shimizu 890ddd
messages to a son. For NT only, bytes_dim specifies the buffer size
Shinya Kitaoka 120a6e
for the pipe (if 0, a default value is set).
Shinya Kitaoka 120a6e
It must be executed BEFORE the son process is run with the tproc_run_process.
Shinya Kitaoka 120a6e
To write to the pipe, use tproc_chan_printf.
Toshihiro Shimizu 890ddd
To read from the pipe, use tproc_chan_gets
Toshihiro Shimizu 890ddd
The int argument of this function must be passed from parent to son
Shinya Kitaoka 120a6e
using a program argument (that is, argv). This int argument is
Toshihiro Shimizu 890ddd
retrieved by parent with tproc_get_readpipe_id.
Shinya Kitaoka 120a6e
The son process can have a chan from the int argument with
Toshihiro Shimizu 890ddd
tproc_get_chan_from_pipe_id.
Toshihiro Shimizu 890ddd
 *********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI T_CHAN tproc_create_pipe(int bytes_dim);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Shinya Kitaoka 120a6e
This function set the dimension of the buffer in the pipe;
Toshihiro Shimizu 890ddd
It's needed for NT pipes when reading and writing happens within
Toshihiro Shimizu 890ddd
the same process. On IRIX this function has no effect.
Toshihiro Shimizu 890ddd
 *********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI void tproc_set_pipe_dimension(int bytes_dim);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
This function opens a file for read and/or writing.
Shinya Kitaoka 120a6e
To write into the file, use tproc_chan_printf; to read,
Toshihiro Shimizu 890ddd
tproc_chan_gets.
Toshihiro Shimizu 890ddd
**********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI T_CHAN tproc_open_file(char *filename, int mode_mask);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI int tproc_get_readpipe_id(T_CHAN t_pipe);
Toshihiro Shimizu 890ddd
TNZAPI T_CHAN tproc_get_chan_from_pipe_id(int pipeid);
Toshihiro Shimizu 890ddd
TNZAPI int tproc_chan_printf(T_CHAN chan, char *format, ...);
Toshihiro Shimizu 890ddd
TNZAPI void tproc_chan_flush(T_CHAN chan);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
This function gets a buffer from a stream. The reading stops when a '\n'
Shinya Kitaoka 120a6e
or a '\0' is encountered. NOTICE: the buffer is allocated and
Toshihiro Shimizu 890ddd
owned by the function, which returns pointer to it or NIL if end-of-stream
Toshihiro Shimizu 890ddd
is encountered. The stream can be a pipe too.
Toshihiro Shimizu 890ddd
***********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI char *tproc_chan_gets(T_CHAN chan);
Toshihiro Shimizu 890ddd
TNZAPI int tproc_close_chan(T_CHAN chan);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
This function open a .ddl (for NT) or a .so (for IRIX) returning
Toshihiro Shimizu 890ddd
an identifier to it
Toshihiro Shimizu 890ddd
***********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI TPROC_LIB tproc_open_dll(char *libname);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
This function return  a pointer to the function funcname defined into the
Toshihiro Shimizu 890ddd
previously opened .dll (or .so) lib.
Toshihiro Shimizu 890ddd
***********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI TPROC_FUNC tproc_get_func(TPROC_LIB lib, char *funcname);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**********************************************************************
Toshihiro Shimizu 890ddd
This function returns a unique filename using the string name_seed.
Toshihiro Shimizu 890ddd
It replaces the first '#' character (or append at bottom if absent)
Toshihiro Shimizu 890ddd
with an unique substring. If name_seed has not a path, the path is set
Shinya Kitaoka 120a6e
to TOONZ_TMP. The returned string is owned by function, so must be strsaved.
Toshihiro Shimizu 890ddd
***********************************************************************/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI char *tproc_get_unique_filename(char *name_seed);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif