File: rjava.c

package info (click to toggle)
rjava 0.9-3-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,196 kB
  • sloc: java: 7,733; ansic: 4,947; sh: 2,878; makefile: 137; perl: 33
file content (56 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (2)
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
56
#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;
  write(ipcout, buf, sizeof(ptrlong));
  n = read(resin, buf, sizeof(ptrlong));
  return (buf[0] == IPCC_LOCK_GRANTED)?1:0;
}

int RJava_clear_lock() {
  ptrlong buf[4];
  buf[0] = IPCC_CLEAR_LOCK;
  write(ipcout, buf, sizeof(ptrlong));
  return 1;
}

void RJava_request_callback(callbackfn *fn, void *data) {
  ptrlong buf[4];
  buf[0] = IPCC_CALL_REQUEST;
  buf[1] = (ptrlong) fn;
  buf[2] = (ptrlong) data;
  write(ipcout, buf, sizeof(ptrlong) * 3);
}

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;
  write(ipcout, buf, sizeof(ptrlong));
  read(resin, buf, sizeof(ptrlong) * 2);
  if (buf[0] == IPCC_CONTROL_ADDR) {
    rjctrl= (int*) buf[1];
  }
}