CXXR (C++ R)
eventloop.h
1 /*CXXR $Id: eventloop.h 1348 2013-02-25 17:49:03Z arr $
2  *CXXR
3  *CXXR This file is part of CXXR, a project to refactor the R interpreter
4  *CXXR into C++. It may consist in whole or in part of program code and
5  *CXXR documentation taken from the R project itself, incorporated into
6  *CXXR CXXR (and possibly MODIFIED) under the terms of the GNU General Public
7  *CXXR Licence.
8  *CXXR
9  *CXXR CXXR is Copyright (C) 2008-13 Andrew R. Runnalls, subject to such other
10  *CXXR copyrights and copyright restrictions as may be stated below.
11  *CXXR
12  *CXXR CXXR is not part of the R project, and bugs and other issues should
13  *CXXR not be reported via r-bugs or other R project channels; instead refer
14  *CXXR to the CXXR website.
15  *CXXR */
16 
17 /*
18  * R : A Computer Language for Statistical Data Analysis
19  * Copyright (C) 2000-2007 The R Core Team.
20  *
21  * This program is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU Lesser General Public License as published by
23  * the Free Software Foundation; either version 2.1 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29  * GNU Lesser General Public License for more details.
30  *
31  * You should have received a copy of the GNU Lesser General Public License
32  * along with this program; if not, a copy is available at
33  * http://www.r-project.org/Licenses/
34  */
35 
36 #ifndef R_EXT_EVENTLOOP_H
37 #define R_EXT_EVENTLOOP_H
38 
39 #ifndef NO_C_HEADERS
40 #ifdef HAVE_SYS_SELECT_H
41 # include <sys/select.h> /* for fd_set according to recent POSIX */
42 #endif
43 /* NOTE: Needed at least on FreeBSD so that fd_set is defined. */
44 # include <sys/types.h>
45 #endif
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #define XActivity 1
52 #define StdinActivity 2
53 
54 typedef void (*InputHandlerProc)(void *userData);
55 
56 typedef struct _InputHandler {
57 
58  int activity;
59  int fileDescriptor;
60  InputHandlerProc handler;
61 
62  struct _InputHandler *next;
63 
64  /* Whether we should be listening to this file descriptor or not. */
65  int active;
66 
67  /* Data that can be passed to the routine as its only argument.
68  This might be a user-level function or closure when we implement
69  a callback to R mechanism.
70  */
71  void *userData;
72 
73 } InputHandler;
74 
75 
76 extern InputHandler *initStdinHandler(void);
77 extern void consoleInputHandler(unsigned char *buf, int len);
78 
79 extern InputHandler *addInputHandler(InputHandler *handlers, int fd, InputHandlerProc handler, int activity);
80 extern InputHandler *getInputHandler(InputHandler *handlers, int fd);
81 extern int removeInputHandler(InputHandler **handlers, InputHandler *it);
82 extern InputHandler *getSelectedHandler(InputHandler *handlers, fd_set *mask);
83 extern fd_set *R_checkActivity(int usec, int ignore_stdin);
84 extern fd_set *R_checkActivityEx(int usec, int ignore_stdin, void (*intr)(void));
85 extern void R_runHandlers(InputHandler *handlers, fd_set *mask);
86 
87 extern int R_SelectEx(int n, fd_set *readfds, fd_set *writefds,
88  fd_set *exceptfds, struct timeval *timeout,
89  void (*intr)(void));
90 
91 #ifdef __SYSTEM__
92 #ifndef __cplusplus /* Would get duplicate conflicting symbols*/
93 InputHandler *R_InputHandlers;
94 #endif
95 #else
96 extern InputHandler *R_InputHandlers;
97 #endif
98 
99 extern void (* R_PolledEvents)(void);
100 extern int R_wait_usec;
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif /* R_EXT_EVENTLOOP_H */