-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathrjava.c
More file actions
55 lines (46 loc) · 1.24 KB
/
rjava.c
File metadata and controls
55 lines (46 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "rjava.h"
#include <unistd.h>
#ifdef _WIN64
typedef long long ptrlong;
#else
typedef long ptrlong;
#endif
int ipcout;
int resin;
int *rjctrl = 0;
typedef void(callbackfn)(void *);
int RJava_request_lock() {
ptrlong buf[4];
int n;
if (rjctrl && *rjctrl) return 2;
buf[0] = IPCC_LOCK_REQUEST;
if (write(ipcout, buf, sizeof(ptrlong)) < sizeof(ptrlong)) return 0;
n = read(resin, buf, sizeof(ptrlong));
return (n == sizeof(ptrlong) && buf[0] == IPCC_LOCK_GRANTED) ? 1 : 0;
}
int RJava_clear_lock() {
ptrlong buf[4];
buf[0] = IPCC_CLEAR_LOCK;
return (write(ipcout, buf, sizeof(ptrlong)) == sizeof(ptrlong)) ? 1 : 0;
}
int RJava_request_callback(callbackfn *fn, void *data) {
ptrlong buf[4];
buf[0] = IPCC_CALL_REQUEST;
buf[1] = (ptrlong) fn;
buf[2] = (ptrlong) data;
return (write(ipcout, buf, sizeof(ptrlong) * 3) == sizeof(ptrlong) * 3) ? 1 : 0;
}
void RJava_setup(int _in, int _out) {
/* ptrlong buf[4]; */
ipcout = _out;
resin = _in;
}
void RJava_init_ctrl() {
ptrlong buf[4];
buf[0] = IPCC_CONTROL_ADDR;
if (write(ipcout, buf, sizeof(ptrlong)) == sizeof(ptrlong) &&
read(resin, buf, sizeof(ptrlong) * 2) == sizeof(ptrlong) * 2 &&
buf[0] == IPCC_CONTROL_ADDR) {
rjctrl= (int*) buf[1];
}
}