forked from bitter/android-jni-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Proxy.h
57 lines (44 loc) · 1.71 KB
/
Proxy.h
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
#pragma once
#include "API.h"
namespace jni
{
class ProxyObject : public virtual ProxyInvoker
{
// Dispatch invoke calls
public:
virtual jobject __Invoke(jclass clazz, jmethodID mid, jobjectArray args);
// These functions are special and always forwarded
protected:
virtual ::jint HashCode() const;
virtual ::jboolean Equals(const ::jobject arg0) const;
virtual java::lang::String ToString() const;
bool __TryInvoke(jclass clazz, jmethodID methodID, jobjectArray args, bool* success, jobject* result);
virtual bool __InvokeInternal(jclass clazz, jmethodID mid, jobjectArray args, jobject* result) = 0;
// Factory stuff
protected:
static jobject NewInstance(void* nativePtr, const jobject* interfaces, size_t interfaces_len);
static void DisableInstance(jobject proxy);
};
template <class RefAllocator, class ...TX>
class ProxyGenerator : public ProxyObject, public TX::__Proxy...
{
protected:
ProxyGenerator() : m_ProxyObject(NewInstance(this, (jobject[]){TX::__CLASS...}, sizeof...(TX))) { }
virtual ~ProxyGenerator()
{
DisableInstance(__ProxyObject());
}
virtual ::jobject __ProxyObject() const { return m_ProxyObject; }
private:
template<typename... Args> inline void DummyInvoke(Args&&...) {}
virtual bool __InvokeInternal(jclass clazz, jmethodID mid, jobjectArray args, jobject* result)
{
bool success = false;
DummyInvoke(ProxyObject::__TryInvoke(clazz, mid, args, &success, result), TX::__Proxy::__TryInvoke(clazz, mid, args, &success, result)...);
return success;
}
Ref<RefAllocator, jobject> m_ProxyObject;
};
template <class ...TX> class Proxy : public ProxyGenerator<GlobalRefAllocator, TX...> {};
template <class ...TX> class WeakProxy : public ProxyGenerator<WeakGlobalRefAllocator, TX...> {};
}