The R Project SVN R

Rev

Rev 71371 | Rev 89135 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
12778 pd 1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
71027 ripley 3
 *  Copyright (C) 2000-2016 The R Core Team.
12778 pd 4
 *
71657 plummer 5
 *  This header file is free software; you can redistribute it and/or modify
12778 pd 6
 *  it under the terms of the GNU Lesser General Public License as published by
7
 *  the Free Software Foundation; either version 2.1 of the License, or
8
 *  (at your option) any later version.
9
 *
71657 plummer 10
 *  This file is part of R. R is distributed under the terms of the
11
 *  GNU General Public License, either Version 2, June 1991 or Version 3,
12
 *  June 2007. See doc/COPYRIGHTS for details of the copyright status of R.
13
 *
12778 pd 14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Lesser General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Lesser General Public License
42308 ripley 20
 *  along with this program; if not, a copy is available at
68949 ripley 21
 *  https://www.R-project.org/Licenses/
12778 pd 22
 */
23
 
60255 ripley 24
/* 
25
   For use by alternative front-ends and packages which need to share
71071 ripley 26
   the R event loop (on Unix-alikes).
60255 ripley 27
 
28
   Not part of the API and subject to change without notice.
71071 ripley 29
 
30
   NB: HAVE_SYS_SELECT_H should be checked and defined before this is
71371 ripley 31
   included.
60255 ripley 32
 */
33
 
11211 ripley 34
#ifndef R_EXT_EVENTLOOP_H
35
#define R_EXT_EVENTLOOP_H
8902 duncan 36
 
71371 ripley 37
#ifdef HAVE_SYS_SELECT_H
38
# include <sys/select.h> /* for fd_set, select according to POSIX 2004 */
39
#endif
40
#ifdef HAVE_SYS_TIME_H
41
# include <sys/time.h>	 /* ... according to earlier POSIX and perhaps HP-UX */
42
#endif
71071 ripley 43
/* NOTE: At one time needed on FreeBSD so that fd_set is defined. */
71371 ripley 44
#include <sys/types.h>
19423 hornik 45
 
11211 ripley 46
#ifdef  __cplusplus
47
extern "C" {
48
#endif
8902 duncan 49
 
50
#define XActivity 1
51
#define StdinActivity 2
52
 
53
typedef void (*InputHandlerProc)(void *userData); 
54
 
55
typedef struct _InputHandler {
56
 
57
  int activity;
58
  int fileDescriptor;
59
  InputHandlerProc handler;
60
 
61
  struct _InputHandler *next;
62
 
63
    /* Whether we should be listening to this file descriptor or not. */
64
  int active;
65
 
66
    /* Data that can be passed to the routine as its only argument.
67
       This might be a user-level function or closure when we implement
68
       a callback to R mechanism. 
69
     */
70
  void *userData;
71
 
72
} InputHandler;
73
 
74
 
75
extern InputHandler *initStdinHandler(void);
76
extern void consoleInputHandler(unsigned char *buf, int len);
77
 
78
extern InputHandler *addInputHandler(InputHandler *handlers, int fd, InputHandlerProc handler, int activity);
79
extern InputHandler *getInputHandler(InputHandler *handlers, int fd);
80
extern int           removeInputHandler(InputHandler **handlers, InputHandler *it);
81
extern InputHandler *getSelectedHandler(InputHandler *handlers, fd_set *mask);
21006 pd 82
extern fd_set *R_checkActivity(int usec, int ignore_stdin);
25220 luke 83
extern fd_set *R_checkActivityEx(int usec, int ignore_stdin, void (*intr)(void));
21006 pd 84
extern void R_runHandlers(InputHandler *handlers, fd_set *mask);
8902 duncan 85
 
25220 luke 86
extern int R_SelectEx(int  n,  fd_set  *readfds,  fd_set  *writefds,
87
		      fd_set *exceptfds, struct timeval *timeout,
88
		      void (*intr)(void));
89
 
8973 ripley 90
#ifdef __SYSTEM__
39864 duncan 91
#ifndef __cplusplus   /* Would get duplicate conflicting symbols*/
8973 ripley 92
InputHandler *R_InputHandlers;
39864 duncan 93
#endif
8973 ripley 94
#else
95
extern InputHandler *R_InputHandlers;
96
#endif
8902 duncan 97
 
9242 pd 98
extern void (* R_PolledEvents)(void);
99
extern int R_wait_usec;
100
 
11211 ripley 101
#ifdef  __cplusplus
102
}
8902 duncan 103
#endif
11211 ripley 104
 
105
#endif /* R_EXT_EVENTLOOP_H */