aboutsummaryrefslogtreecommitdiff
path: root/example/HelloWorld.java
blob: 42d755eba00183537c4738de9f3ae2f135077cb1 (plain)
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
class HelloWorld {
    private static native String hello(String input);
    private static native byte[] helloByte(byte[] input);
    private static native void factAndCallMeBack(int n, HelloWorld callback);

    private static native long counterNew(HelloWorld callback);
    private static native void counterIncrement(long counter_ptr);
    private static native void counterDestroy(long counter_ptr);

    private static native void asyncComputation(HelloWorld callback);

    static {
        System.loadLibrary("mylib");
    }

    public static void main(String[] args) {

        String output = HelloWorld.hello("josh");
        System.out.println(output);
        byte[] outputByte = HelloWorld.helloByte("byte".getBytes());
        System.out.println(outputByte);


        HelloWorld.factAndCallMeBack(6, new HelloWorld());

        long counter_ptr = counterNew(new HelloWorld());

        for (int i = 0; i < 5; i++) {
          counterIncrement(counter_ptr);
        }

        counterDestroy(counter_ptr);

        System.out.println("Invoking asyncComputation (thread id = " + Thread.currentThread().getId() + ")");
        asyncComputation(new HelloWorld());
    }

    public void factCallback(int res) {
      System.out.println("factCallback: res = " + res);
    }

    public void counterCallback(int count) {
      System.out.println("counterCallback: count = " + count);
    }

    public void asyncCallback(int progress) {
        System.out.println("asyncCallback: thread id = " + Thread.currentThread().getId() + ", progress = " + progress + "%");
    }
}