| 17134 |
duncan |
1 |
#ifndef R_CALLBACKS_H
|
|
|
2 |
#define R_CALLBACKS_H
|
|
|
3 |
|
|
|
4 |
/**
|
|
|
5 |
These structures are for C (and R function) top-level task handlers.
|
|
|
6 |
Such routines are called at the end of every (successful) top-level task
|
|
|
7 |
in the regular REPL.
|
|
|
8 |
*/
|
|
|
9 |
|
| 19500 |
hornik |
10 |
#include <Rinternals.h>
|
| 17134 |
duncan |
11 |
/**
|
|
|
12 |
The signature of the C routine that a callback must implement.
|
|
|
13 |
expr - the expression for the top-level task that was evaluated.
|
|
|
14 |
value - the result of the top-level task, i.e. evaluating expr.
|
|
|
15 |
succeeded - a logical value indicating whether the task completed propertly.
|
|
|
16 |
visible - a logical value indicating whether the result was printed to the R ``console''/stdout.
|
|
|
17 |
data - user-level data passed to the registration routine.
|
|
|
18 |
*/
|
|
|
19 |
typedef Rboolean (*R_ToplevelCallback)(SEXP expr, SEXP value, Rboolean succeeded, Rboolean visible, void *);
|
|
|
20 |
|
|
|
21 |
typedef struct _ToplevelCallback R_ToplevelCallbackEl;
|
|
|
22 |
/**
|
|
|
23 |
Linked list element for storing the top-level task callbacks.
|
|
|
24 |
*/
|
|
|
25 |
struct _ToplevelCallback {
|
|
|
26 |
R_ToplevelCallback cb; /* the C routine to call. */
|
|
|
27 |
void *data; /* the user-level data to pass to the call to cb() */
|
|
|
28 |
void (*finalizer)(void *data); /* Called when the callback is removed. */
|
|
|
29 |
|
|
|
30 |
char *name; /* a name by which to identify this element. */
|
|
|
31 |
|
|
|
32 |
R_ToplevelCallbackEl *next; /* the next element in the linked list. */
|
|
|
33 |
};
|
|
|
34 |
|
|
|
35 |
#ifdef __cplusplus
|
|
|
36 |
extern "C" {
|
|
|
37 |
#endif
|
|
|
38 |
|
|
|
39 |
Rboolean Rf_removeTaskCallbackByIndex(int id);
|
|
|
40 |
Rboolean Rf_removeTaskCallbackByName(const char *name);
|
|
|
41 |
SEXP R_removeTaskCallback(SEXP which);
|
|
|
42 |
R_ToplevelCallbackEl* Rf_addTaskCallback(R_ToplevelCallback cb, void *data, void (*finalizer)(void *), const char *name, int *pos);
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
The following definitions are for callbacks to R functions and methods
|
|
|
48 |
related to user-level tables. This is currently implemented in a
|
|
|
49 |
separate package and these declarations allow the package to
|
|
|
50 |
interface to the internal R code.
|
|
|
51 |
|
|
|
52 |
See http://developer.r-project.org/RObjectTables.pdf.
|
|
|
53 |
*/
|
|
|
54 |
|
|
|
55 |
typedef struct _R_ObjectTable R_ObjectTable;
|
|
|
56 |
|
|
|
57 |
/* Do we actually need the exists() since it is never called but R uses get to see if
|
|
|
58 |
the symbol is bound to anything? */
|
|
|
59 |
typedef Rboolean (*Rdb_exists)(const char * const name, Rboolean *canCache, R_ObjectTable *);
|
|
|
60 |
typedef SEXP (*Rdb_get)(const char * const name, Rboolean *canCache, R_ObjectTable *);
|
|
|
61 |
typedef int (*Rdb_remove)(const char * const name, R_ObjectTable *);
|
|
|
62 |
typedef SEXP (*Rdb_assign)(const char * const name, SEXP value, R_ObjectTable *);
|
|
|
63 |
typedef SEXP (*Rdb_objects)(R_ObjectTable *);
|
|
|
64 |
typedef Rboolean (*Rdb_canCache)(const char * const name, R_ObjectTable *);
|
|
|
65 |
|
|
|
66 |
typedef void (*Rdb_onDetach)(R_ObjectTable *);
|
|
|
67 |
typedef void (*Rdb_onAttach)(R_ObjectTable *);
|
|
|
68 |
|
|
|
69 |
struct _R_ObjectTable{
|
|
|
70 |
int type;
|
|
|
71 |
char **cachedNames;
|
|
|
72 |
Rboolean active;
|
|
|
73 |
|
|
|
74 |
Rdb_exists exists;
|
|
|
75 |
Rdb_get get;
|
|
|
76 |
Rdb_remove remove;
|
|
|
77 |
Rdb_assign assign;
|
|
|
78 |
Rdb_objects objects;
|
|
|
79 |
Rdb_canCache canCache;
|
|
|
80 |
|
|
|
81 |
Rdb_onDetach onDetach;
|
|
|
82 |
Rdb_onAttach onAttach;
|
|
|
83 |
|
|
|
84 |
void *privateData;
|
|
|
85 |
};
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
#ifdef __cplusplus
|
|
|
89 |
}
|
|
|
90 |
#endif
|
|
|
91 |
|
|
|
92 |
#endif /* R_CALLBACKS_H */
|