-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathjsyphon_JSyphonClient.m
More file actions
232 lines (162 loc) · 7.04 KB
/
jsyphon_JSyphonClient.m
File metadata and controls
232 lines (162 loc) · 7.04 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#import "jsyphon_imports.h"
#import <SyphonNameboundClient.h>
// pass options in case they are needed in the future...
JNIEXPORT jlong JNICALL Java_jsyphon_JSyphonClient_init(JNIEnv * env, jobject jobj, jobject options)
{
jlong ptr = 0;
JNF_COCOA_ENTER(env);
CGLContextObj cgl_ctx = CGLGetCurrentContext();
if (cgl_ctx)
{
SyphonNameboundClient* client = [[SyphonNameboundClient alloc] initWithContext:cgl_ctx];
ptr = ptr_to_jlong(client);
}
JNF_COCOA_EXIT(env);
return ptr;
}
JNIEXPORT void JNICALL Java_jsyphon_JSyphonClient_setApplicationName(JNIEnv * env, jobject jobj, jlong ptr, jstring appName)
{
JNF_COCOA_ENTER(env);
NSString* name = JNFJavaToNSString(env, appName);
SyphonNameboundClient* client = jlong_to_ptr(ptr);
[client setAppName:name];
JNF_COCOA_EXIT(env);
}
JNIEXPORT void JNICALL Java_jsyphon_JSyphonClient_setServerName(JNIEnv * env, jobject jobj, jlong ptr, jstring serverName)
{
JNF_COCOA_ENTER(env);
NSString* name = JNFJavaToNSString(env, serverName);
if([name length] == 0)
name = nil;
SyphonNameboundClient* client = jlong_to_ptr(ptr);
[client setName:name];
JNF_COCOA_EXIT(env);
}
JNIEXPORT jboolean JNICALL Java_jsyphon_JSyphonClient_isValid(JNIEnv * env, jobject jobj, jlong ptr)
{
jboolean val = JNI_FALSE;
JNF_COCOA_ENTER(env);
SyphonNameboundClient* boundClient = jlong_to_ptr(ptr);
[boundClient lockClient];
SyphonClient *client = [boundClient client];
if([client isValid])
val = JNI_TRUE;
[boundClient unlockClient];
JNF_COCOA_EXIT(env);
return val;
}
JNIEXPORT jobject JNICALL Java_jsyphon_JSyphonClient_serverDescription(JNIEnv * env, jobject jobj, jlong ptr)
{
jobject serverdesc = nil;
// This methods returns a ArrayList<String>:
// (realm kdc* null) null (mapping-domain mapping-realm)*
jclass jc_arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
CHECK_NULL_RETURN(jc_arrayListClass, NULL);
jmethodID jm_arrayListCons = (*env)->GetMethodID(env, jc_arrayListClass, "<init>", "()V");
CHECK_NULL_RETURN(jm_arrayListCons, NULL);
jmethodID jm_listAdd = (*env)->GetMethodID(env, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z");
CHECK_NULL_RETURN(jm_listAdd, NULL);
serverdesc = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons);
CHECK_NULL_RETURN(serverdesc, NULL);
SyphonNameboundClient* boundClient = jlong_to_ptr(ptr);
[boundClient lockClient];
SyphonClient *client = [(SyphonNameboundClient*)boundClient client];
ADD(serverdesc, client);
ADDNULL(serverdesc);
[boundClient unlockClient];
return serverdesc;
/*
JNF_COCOA_ENTER(env);
SyphonNameboundClient* boundClient = jlong_to_ptr(ptr);
[boundClient lockClient];
SyphonClient *client = [(SyphonNameboundClient*)boundClient client];
NSDictionary* desc = [client serverDescription];
JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
[JNFDefaultCoercions addMapCoercionTo:coecer];
serverdesc = [coecer coerceNSObject:desc withEnv:env];
[boundClient unlockClient];
JNF_COCOA_EXIT(env);
return serverdesc;
*/
}
JNIEXPORT jboolean JNICALL Java_jsyphon_JSyphonClient_hasNewFrame(JNIEnv * env, jobject jobj, jlong ptr)
{
jboolean val = JNI_FALSE;
JNF_COCOA_ENTER(env);
SyphonNameboundClient* boundClient = jlong_to_ptr(ptr);
[boundClient lockClient];
SyphonClient *client = [(SyphonNameboundClient*)boundClient client];
if([client hasNewFrame])
val = JNI_TRUE;
[boundClient unlockClient];
JNF_COCOA_EXIT(env);
return val;
}
JNIEXPORT jobject JNICALL Java_jsyphon_JSyphonClient_newFrameDataForContext(JNIEnv * env, jobject jobj, jlong ptr)
{
jobject imgdata = nil;
//JNF_COCOA_ENTER(env);
SyphonNameboundClient* boundClient = jlong_to_ptr(ptr);
[boundClient lockClient];
SyphonClient *client = [(SyphonNameboundClient*)boundClient client];
SyphonImage* img = [client newFrameImage];
NSSize texSize = [img textureSize];
NSNumber *name = [NSNumber numberWithInt:[img textureName]];
NSNumber *width = [NSNumber numberWithFloat:texSize.width];
NSNumber *height = [NSNumber numberWithFloat:texSize.height];
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:
name, @"name",
width, @"width",
height, @"height",
nil];
jclass jc_arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
CHECK_NULL_RETURN(jc_arrayListClass, NULL);
jmethodID jm_arrayListCons = (*env)->GetMethodID(env, jc_arrayListClass, "<init>", "()V");
CHECK_NULL_RETURN(jm_arrayListCons, NULL);
jmethodID jm_listAdd = (*env)->GetMethodID(env, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z");
CHECK_NULL_RETURN(jm_listAdd, NULL);
imgdata = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons);
CHECK_NULL_RETURN(imgdata, NULL);
//JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
//[JNFDefaultCoercions addMapCoercionTo:coecer];
ADD(imgdata, dic);
ADDNULL(imgdata);
//imgdata = [coecer coerceNSObject:dic withEnv:env];
[img release];
[boundClient unlockClient];
//JNF_COCOA_EXIT(env);
return imgdata;
}
JNIEXPORT void JNICALL Java_jsyphon_JSyphonClient_stop(JNIEnv * env, jobject jobj, jlong ptr)
{
JNF_COCOA_ENTER(env);
SyphonNameboundClient* boundClient = jlong_to_ptr(ptr);
[boundClient lockClient];
SyphonClient *client = [(SyphonNameboundClient*)boundClient client];
[client stop];
[boundClient unlockClient];
JNF_COCOA_EXIT(env);
}
// Commented out until we figure out how to properly coerce arbitrary objects from Objective-C to Java
/*
JNIEXPORT jobject JNICALL Java_jsyphon_JSyphonClient_newFrameImageForContext(JNIEnv * env, jobject jobj)
{
jobject frameimg = nil;
JNF_COCOA_ENTER(env);
[(SyphonNameboundClient*)mClient lockClient];
SyphonClient *client = [(SyphonNameboundClient*)mClient client];
SyphonImage* img = [client newFrameImageForContext:CGLGetCurrentContext()];
JNFTypeCoercer *coercer = [[[JNFTypeCoercer alloc] init] autorelease];
// TODO: we need to implement a coercion between SyphonImage and JSyphonImage:
// https://developer.apple.com/library/mac/#documentation/CrossPlatform/Reference/JNFTypeCoercer_Class/Reference/JNFTypeCoercer.html
// https://developer.apple.com/library/mac/#documentation/CrossPlatform/Reference/JNFTypeCoercion_Protocol/Reference/NSView.html
// https://developer.apple.com/library/mac/#documentation/CrossPlatform/Reference/JNFDefaultCoercions_Class/Reference/JNFDefaultCoercions.html
// http://cr.openjdk.java.net/~michaelm/7113349/1/jdk/new/src/macosx/native/apple/applescript/NS_Java_ConversionUtils.m.html
//[coercer addCoercion:[[[JNFVectorCoercion alloc] init] autorelease] forNSClass:[SyphonImage class] javaClass:@"jsyphon/JSyphonImage"];
//frameimg = [coecer coerceNSObject:img withEnv:env];
[(SyphonImage*)img release];
[(SyphonNameboundClient*)mClient unlockClient];
JNF_COCOA_EXIT(env);
return frameimg;
}
*/