Back to index

radiance  4R0+20100331
rtprocess.h
Go to the documentation of this file.
00001 /* RCSid $Id: rtprocess.h,v 3.11 2004/10/23 18:55:52 schorsch Exp $ */
00002 /*
00003  *   rtprocess.h 
00004  *   Routines to communicate with separate process via dual pipes
00005  *
00006  *   WARNING: On Windows, there's a system header named <process.h>.
00007  */
00008 #ifndef _RAD_PROCESS_H_
00009 #define _RAD_PROCESS_H_
00010 
00011 #include  <errno.h>
00012 #ifdef _WIN32
00013   #include <windows.h> /* DWORD etc. */
00014   #include <stdio.h>
00015   typedef DWORD RT_PID;
00016   #include <process.h> /* getpid() and others */
00017   #define nice(inc) win_nice(inc)
00018 
00019   #ifdef __cplusplus
00020   extern "C" {
00021   #endif
00022   extern FILE *win_popen(char *command, char *type);
00023   extern int win_pclose(FILE *p);
00024   int win_kill(RT_PID pid, int sig /* ignored */);
00025   #define kill(pid,sig) win_kill(pid,sig)
00026   #ifdef __cplusplus
00027   }
00028   #endif
00029 
00030   #define popen(cmd,mode) win_popen(cmd,mode)
00031   #define pclose(p) win_pclose(p)
00032 #else
00033   #include <stdio.h>
00034   #include <sys/param.h>
00035   #include <sys/types.h>
00036   typedef pid_t RT_PID;
00037 #endif
00038 
00039 #include "paths.h"
00040 
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044 
00045 /* On Windows, a process ID is a DWORD. That might actually be the
00046    same thing as an int, but it's better not to assume anything.
00047 
00048    This means that we shouldn't rely on PIDs and file descriptors
00049    being the same type, so we have to describe processes with a struct,
00050    instead of the original int[3]. For that purpose, we typedef a
00051    platform independent RT_PID.
00052 */
00053 
00054 
00055 #ifndef PIPE_BUF
00056   #ifdef PIPSIZ
00057     #define PIPE_BUF PIPSIZ
00058   #else
00059     #ifdef PIPE_MAX
00060       #define PIPE_BUF      PIPE_MAX
00061     #else
00062       #define PIPE_BUF      512           /* hyperconservative */
00063     #endif
00064   #endif
00065 #endif
00066 
00067 typedef struct {
00068        int r; /* read handle */
00069        int w; /* write handle */
00070        int running; /* doing something */
00071        RT_PID pid; /* process ID */
00072 } SUBPROC;
00073 
00074 #define SP_INACTIVE {-1,-1,0,0} /* for static initializations */
00075 
00076 extern int open_process(SUBPROC *pd, char *av[]);
00077 extern int close_process(SUBPROC *pd);
00078 extern int process(SUBPROC *pd, char *recvbuf, char *sendbuf, int nbr, int nbs);
00079 extern int readbuf(int fd, char *bpos, int siz);
00080 extern int writebuf(int fd, char *bpos, int siz);
00081 
00082 #ifdef _WIN32
00083 /* any non-negative increment will send the process to IDLE_PRIORITY_CLASS. */
00084 extern int win_nice(int inc);
00085 #endif
00086 
00087 
00088 #ifdef __cplusplus
00089 }
00090 #endif
00091 #endif /* _RAD_PROCESS_H_ */
00092