-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxy.java
More file actions
146 lines (110 loc) · 3.11 KB
/
Proxy.java
File metadata and controls
146 lines (110 loc) · 3.11 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright (c) 2019-2020 Nicholas Corgan
// SPDX-License-Identifier: BSL-1.0
package Pothos;
public class Proxy
{
static
{
LoadNative.loadNative();
}
private long nativeHandle;
public Proxy()
{
nativeHandle = allocateJNI();
}
public Proxy(long handle)
{
nativeHandle = handle;
}
public ProxyEnvironment getEnvironment()
{
return new ProxyEnvironment(getEnvironmentJNI(nativeHandle));
}
public Proxy call(String name)
{
return new Proxy(callJNI(nativeHandle, name));
}
public Proxy call(String name, Object param)
{
Object[] params = new Object[1];
params[0] = param;
return this.call(name, params);
}
public Proxy call(String name, Object[] params)
{
return new Proxy(callJNI(nativeHandle, name, params));
}
public Proxy call(String name, Proxy param)
{
Proxy[] params = new Proxy[1];
params[0] = param;
return this.call(name, params);
}
public Proxy call(String name, Proxy[] params)
{
Object[] objectParams = new Object[params.length];
for(int i = 0; i < objectParams.length; ++i)
{
objectParams[i] = params[i].toObject();
}
return call(name, objectParams);
}
public Proxy get(String field)
{
return new Proxy(getJNI(nativeHandle, field));
}
public void set(String field, Object value)
{
setObjectJNI(nativeHandle, field, value);
}
public void set(String field, Proxy value)
{
setProxyJNI(nativeHandle, field, value.nativeHandle);
}
public Object toObject()
{
return toObjectJNI(nativeHandle);
}
public String getClassName()
{
return getClassNameJNI(nativeHandle);
}
@Override
public String toString()
{
return toStringJNI(nativeHandle);
}
@Override
public int hashCode()
{
return hashCodeJNI(nativeHandle);
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
{
return true;
}
else if(!(obj instanceof Proxy))
{
return false;
}
return equalsJNI(nativeHandle, ((Proxy)obj).nativeHandle);
}
//
// JNI below
//
private static native long getEnvironmentJNI(long handle);
private static native long callJNI(long handle, String name);
private static native long callJNI(long handle, String name, Object[] params);
private static native long getJNI(long handle, String field);
private static native void setObjectJNI(long handle, String field, Object value);
private static native void setProxyJNI(long handle, String field, long valueHandle);
private static native Object toObjectJNI(long handle);
private static native String getClassNameJNI(long handle);
private static native String toStringJNI(long handle);
private static native int hashCodeJNI(long handle);
private static native boolean equalsJNI(long handle1, long handle2);
private static native long allocateJNI();
}