1 #pragma once 2 3 #ifndef _TOONZPROC_H_ 4 #define _TOONZPROC_H_ 5 6 #include "tmacro.h" 7 #include "stdarg.h" 8 9 #undef TNZAPI 10 #ifdef TNZ_IS_COMMONLIB 11 #define TNZAPI TNZ_EXPORT_API 12 #else 13 #define TNZAPI TNZ_IMPORT_API 14 #endif 15 16 #define T_PID int 17 18 typedef struct T_CHAN_REC *T_CHAN; 19 20 #define TPROC_OPEN_READ 0x1 21 #define TPROC_OPEN_WRITE 0x2 22 #define TPROC_OPEN_READ_BINARY 0x4 23 24 #ifdef WIN32 25 #include "windows.h" 26 #define TPROC_LIB HMODULE 27 #define TPROC_FUNC FARPROC 28 #else 29 #define TPROC_LIB void * 30 typedef void (*TPROC_FUNC)(void); 31 32 /*#define TPROC_FUNC void**/ 33 #endif 34 35 /********************************************************************** 36 Runs without sospending executable filename. A set of arguments to be 37 passed can be setted in the NULL-terminated array argv. First argument 38 MUST NOT be executable name. 39 **********************************************************************/ 40 41 TNZAPI T_PID tproc_run_process(char *filename, char *argv[]); 42 43 /********************************************************************** 44 Runs sospending executable filename. A set of arguments to be 45 passed can be setted in the NULL-terminated array argv. First argument 46 MUST NOT be executable name. Returns TRUE if specified process was 47 successfully executed, FALSE otherwise. 48 **********************************************************************/ 49 50 TNZAPI int tproc_run_process_fg(char *filename, char *argv[]); 51 52 /********************************************************************** 53 (IRIX ONLY, on NT is a void function). 54 Suspend execution of process until child process identified with pid 55 exits. 56 **********************************************************************/ 57 58 TNZAPI void tproc_waitpid(T_PID pid); 59 60 /********************************************************************** 61 Creates a new process, sharing the virtual address space of parent. 62 The new process is started with a call to func, passing arg to it. 63 **********************************************************************/ 64 65 TNZAPI T_PID tproc_sproc(void (*func)(void *), void *arg); 66 67 /********************************************************************** 68 gets pid of current process 69 **********************************************************************/ 70 71 TNZAPI T_PID tproc_getpid(void); 72 73 /********************************************************************** 74 Check if process pid is alive or not 75 **********************************************************************/ 76 77 TNZAPI int tproc_is_process_alive(T_PID pid); 78 79 /********************************************************************** 80 kills process pid (return FALSE if the process is not alive) 81 **********************************************************************/ 82 83 TNZAPI int tproc_kill_process(T_PID pid); 84 85 #define TPROC_SIGNONE 0x0 86 #define TPROC_SIGABORT 0x2 87 #define TPROC_SIGUSER1 0x4 88 #define TPROC_SIGUSER2 0x8 89 90 /********************************************************************** 91 sets the specified callback to be executed when one of the signal 92 into the signal mask (made by ORing the TPROC_SIG) is sent to current process. 93 Warning: only one callback can be assigned to a signal type; for 94 each new assignation the old one is erased. 95 **********************************************************************/ 96 97 TNZAPI int tproc_set_signals_callback(int signal_mask, void (*signal_cb)(void)); 98 99 /* Note: next function is defined in twin, for it can be used only 100 by graphic modules; it is equal to tproc_set_signals_callback(TPROC_SIGCHLD, 101 signal_cb); 102 103 TNZAPI int tproc_set_sigchld_signals_callback(void (*signal_cb)(void)); 104 */ 105 106 /********************************************************************** 107 erase actions to be executed for specified signals: 108 valid only with TPROC_SIGCHILD, TPROC_SIGUSER1, TPROC_SIGUSER2. 109 **********************************************************************/ 110 111 TNZAPI void tproc_unset_signals_callback(int signal_mask); 112 113 /********************************************************************** 114 send to process pid one of the user signals. 115 **********************************************************************/ 116 117 TNZAPI void tproc_send_siguser(T_PID pid, int signal); 118 119 /********************************************************************** 120 suspend execution of current process until it receives a user signal. 121 If no user signal was set, it return without waiting. 122 **********************************************************************/ 123 124 TNZAPI void tproc_wait_for_siguser(void); 125 126 /********************************************************************** 127 This function create a pipe between two process: a parent that writes 128 messages to a son. For NT only, bytes_dim specifies the buffer size 129 for the pipe (if 0, a default value is set). 130 It must be executed BEFORE the son process is run with the tproc_run_process. 131 To write to the pipe, use tproc_chan_printf. 132 To read from the pipe, use tproc_chan_gets 133 The int argument of this function must be passed from parent to son 134 using a program argument (that is, argv). This int argument is 135 retrieved by parent with tproc_get_readpipe_id. 136 The son process can have a chan from the int argument with 137 tproc_get_chan_from_pipe_id. 138 *********************************************************************/ 139 140 TNZAPI T_CHAN tproc_create_pipe(int bytes_dim); 141 142 /********************************************************************** 143 This function set the dimension of the buffer in the pipe; 144 It's needed for NT pipes when reading and writing happens within 145 the same process. On IRIX this function has no effect. 146 *********************************************************************/ 147 148 TNZAPI void tproc_set_pipe_dimension(int bytes_dim); 149 150 /********************************************************************** 151 This function opens a file for read and/or writing. 152 To write into the file, use tproc_chan_printf; to read, 153 tproc_chan_gets. 154 **********************************************************************/ 155 156 TNZAPI T_CHAN tproc_open_file(char *filename, int mode_mask); 157 158 TNZAPI int tproc_get_readpipe_id(T_CHAN t_pipe); 159 TNZAPI T_CHAN tproc_get_chan_from_pipe_id(int pipeid); 160 TNZAPI int tproc_chan_printf(T_CHAN chan, char *format, ...); 161 TNZAPI void tproc_chan_flush(T_CHAN chan); 162 163 /********************************************************************** 164 This function gets a buffer from a stream. The reading stops when a '\n' 165 or a '\0' is encountered. NOTICE: the buffer is allocated and 166 owned by the function, which returns pointer to it or NIL if end-of-stream 167 is encountered. The stream can be a pipe too. 168 ***********************************************************************/ 169 170 TNZAPI char *tproc_chan_gets(T_CHAN chan); 171 TNZAPI int tproc_close_chan(T_CHAN chan); 172 173 /********************************************************************** 174 This function open a .ddl (for NT) or a .so (for IRIX) returning 175 an identifier to it 176 ***********************************************************************/ 177 178 TNZAPI TPROC_LIB tproc_open_dll(char *libname); 179 180 /********************************************************************** 181 This function return a pointer to the function funcname defined into the 182 previously opened .dll (or .so) lib. 183 ***********************************************************************/ 184 185 TNZAPI TPROC_FUNC tproc_get_func(TPROC_LIB lib, char *funcname); 186 187 /********************************************************************** 188 This function returns a unique filename using the string name_seed. 189 It replaces the first '#' character (or append at bottom if absent) 190 with an unique substring. If name_seed has not a path, the path is set 191 to TOONZ_TMP. The returned string is owned by function, so must be strsaved. 192 ***********************************************************************/ 193 194 TNZAPI char *tproc_get_unique_filename(char *name_seed); 195 196 #endif 197