RAPI
|
00001 /* 00002 * R : A Computer Language for Statistical Data Analysis 00003 * Copyright (C) 2000-2007 The R Core Team. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 2.1 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program; if not, a copy is available at 00017 * https://www.R-project.org/Licenses/ 00018 */ 00019 00020 /* 00021 For use by alternative front-ends and packages which need to share 00022 the R event loop (on all platforms). 00023 00024 Not part of the API and subject to change without notice. 00025 */ 00026 00027 #ifndef R_EXT_EVENTLOOP_H 00028 #define R_EXT_EVENTLOOP_H 00029 00030 #ifndef NO_C_HEADERS 00031 # ifdef HAVE_SYS_SELECT_H 00032 # include <sys/select.h> /* for fd_set according to recent POSIX */ 00033 # endif 00034 /* NOTE: Needed at least on FreeBSD so that fd_set is defined. */ 00035 # include <sys/types.h> 00036 #endif 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif 00041 00042 #define XActivity 1 00043 #define StdinActivity 2 00044 00045 typedef void (*InputHandlerProc)(void *userData); 00046 00047 typedef struct _InputHandler { 00048 00049 int activity; 00050 int fileDescriptor; 00051 InputHandlerProc handler; 00052 00053 struct _InputHandler *next; 00054 00055 /* Whether we should be listening to this file descriptor or not. */ 00056 int active; 00057 00058 /* Data that can be passed to the routine as its only argument. 00059 This might be a user-level function or closure when we implement 00060 a callback to R mechanism. 00061 */ 00062 void *userData; 00063 00064 } InputHandler; 00065 00066 00067 extern InputHandler *initStdinHandler(void); 00068 extern void consoleInputHandler(unsigned char *buf, int len); 00069 00070 extern InputHandler *addInputHandler(InputHandler *handlers, int fd, InputHandlerProc handler, int activity); 00071 extern InputHandler *getInputHandler(InputHandler *handlers, int fd); 00072 extern int removeInputHandler(InputHandler **handlers, InputHandler *it); 00073 extern InputHandler *getSelectedHandler(InputHandler *handlers, fd_set *mask); 00074 extern fd_set *R_checkActivity(int usec, int ignore_stdin); 00075 extern fd_set *R_checkActivityEx(int usec, int ignore_stdin, void (*intr)(void)); 00076 extern void R_runHandlers(InputHandler *handlers, fd_set *mask); 00077 00078 extern int R_SelectEx(int n, fd_set *readfds, fd_set *writefds, 00079 fd_set *exceptfds, struct timeval *timeout, 00080 void (*intr)(void)); 00081 00082 #ifdef __SYSTEM__ 00083 #ifndef __cplusplus /* Would get duplicate conflicting symbols*/ 00084 InputHandler *R_InputHandlers; 00085 #endif 00086 #else 00087 extern InputHandler *R_InputHandlers; 00088 #endif 00089 00090 extern void (* R_PolledEvents)(void); 00091 extern int R_wait_usec; 00092 00093 #ifdef __cplusplus 00094 } 00095 #endif 00096 00097 #endif /* R_EXT_EVENTLOOP_H */