-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathjnaexample_NativeClient_Setup.m
100 lines (88 loc) · 2.94 KB
/
jnaexample_NativeClient_Setup.m
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
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jnaexample_NativeClient_Setup.h>
#include <WLJavaProxy.h>
#include "JavaUtil.h"
void exceptionHandler(NSException *exception)
{
NSLog(@"%@",[exception name]);
NSLog(@"%@",[exception reason]);
NSLog(@"%@",[exception userInfo]);
NSLog(@"%@",[exception callStackSymbols]);
NSLog(@"%@",[exception callStackReturnAddresses]);
}
JNIEXPORT void JNICALL Java_ca_weblite_objc_RuntimeUtils_init
(JNIEnv *env, jclass cls)
{
// enable better error logging?
NSSetUncaughtExceptionHandler(&exceptionHandler);
@try {
JavaVM *jvm;
(*env)->GetJavaVM(env, &jvm);
[WLJavaProxy setJVM:jvm];
} @catch (NSException *e) {
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
NSLog(@"Exception: %@", e);
}
}
#ifndef ptr_to_jlong
#define ptr_to_jlong(a) ((jlong)(uintptr_t)(a))
#endif
/*
* Class: jnaexample_NativeClient_Setup
* Method: createProxy
* Signature: (Ljnaexample/NativeClient;)J
*/
JNIEXPORT jlong JNICALL Java_ca_weblite_objc_RuntimeUtils_createProxy
(JNIEnv *env, jclass jcls, jobject jclient)
{
@try {
return ptr_to_jlong([[WLJavaProxy alloc] init:jclient]);
} @catch (NSException *e) {
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
NSLog(@"Exception: %@", e);
}
}
/*
* Class: jnaexample_NativeClient_Setup
* Method: getJavaPeer
* Signature: (Ljnaexample/NativeClient;)J
*/
JNIEXPORT jobject JNICALL Java_ca_weblite_objc_RuntimeUtils_getJavaPeer
(JNIEnv *env, jclass jcls, jlong nsObject)
{
@try {
NSObject* proxy = (NSObject*)nsObject;
if ( [proxy respondsToSelector:@selector(javaPeer)] ){
WLJavaProxy* proxy2 = (WLJavaProxy*)proxy;
return [proxy2 javaPeer];
} else {
return NULL;
}
} @catch (NSException *e) {
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
NSLog(@"Exception: %@", e);
}
}
JNIEXPORT void JNICALL Java_ca_weblite_objc_RuntimeUtils_setDebugMode
(JNIEnv *env, jclass cls, jboolean debugMode)
{
[WLJavaProxy setDebugMode:debugMode];
}
/*
JNIEXPORT jobject JNICALL Java_ca_weblite_objc_RuntimeUtils_invokeWithSelfAndTarget
(JNIEnv *env, jclass jcls, jlong selfPtr, jlong target, jlong invocation)
{
id selfO = (id)selfPtr;
id targetO = (id)target;
NSInvocation* inv = (NSInvocation*)invocation;
NSMethodSignature *sig = [inv methodSignature];
NSUInteger numArgs = [sig numberOfArguments];
const char* returnType = [sig methodReturnType];
// OK If anyone knows how to call a function with a variable number of
// arguments, Please correct this, but I don't know how!! So I'm just
// going to use a Switch statement and cover most of the reasonable
// cases
IMP impl = [targetO methodForSelector:[inv selector]];
impl(selfO, [inv selector], [inv ])
}
*/