-
Notifications
You must be signed in to change notification settings - Fork 10
/
JVMLauncher.h
155 lines (133 loc) · 5.28 KB
/
JVMLauncher.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
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
#ifndef __JVMLAUNCHER_H__
#define __JVMLAUNCHER_H__
#include "ComponentBase.h"
#include "AddInDefBase.h"
#include "IMemoryManager.h"
#include <string>
#include <vector>
#include <map>
#include <include/jni.h>
#include "Utils.h"
#include <optional>
#define BEGIN_JAVA { JNIEnv* env = this->m_JVMEnv; this->m_JVMEnv = nullptr;
#define END_JAVA this->m_JVMEnv = env; }
#define BEGIN_CALL \
BEGIN_JAVA
#define END_CALL \
hasError = this->endCall(env); }
#define JVM_LAUNCHER L"JVMLauncher"
typedef jint(JNICALL *CreateJavaVM)(JavaVM **pvm, void **penv, void *args);
typedef jint(JNICALL * GetCreatedJavaVMs)(JavaVM**, jsize, jsize*);
typedef std::pair<jclass, jmethodID> jclassMethodHolder;
static IAddInDefBase *gAsyncEvent;
class JVMLauncher : public IComponentBase {
public:
JavaVM *m_RunningJVMInstance;
JNIEnv *m_JVMEnv;
enum Props
{
ePropIsEnabled = 0,
ePropJavaHome,
ePropLibraryDir,
ePropLast // Always last
};
enum Methods
{
eCallAsProcedure = 0,
eCallAsProcedureP,
eCallAsProcedurePP,
eCallAsFuncB,
eCallAsFuncBP,
eCallAsFuncBPP,
eCallAsFunc,
eCallAsFuncP,
eCallAsFuncPP,
eCallAsFuncPPP,
eCallAsFuncPPPP,
eClassFunctionCall,
eClassFunctionCallP,
eClassFunctionCallPP,
eClassProcedureCall,
eClassProcedureCallP,
eClassProcedureCallPP,
eMethDisable,
eMethAddJar,
eMethLast // Always last
};
JVMLauncher(void);
~JVMLauncher() override {};
// IInitDoneBase
bool ADDIN_API Init(void*) override;
bool ADDIN_API setMemManager(void* mem) override;
long ADDIN_API GetInfo() override { return 2000; }
void ADDIN_API Done() override {};
// ILanguageExtenderBase
bool ADDIN_API RegisterExtensionAs(WCHAR_T**) override;
long ADDIN_API GetNProps() override;
long ADDIN_API FindProp(const WCHAR_T* wsPropName) override;
const WCHAR_T* ADDIN_API GetPropName(long lPropNum, long lPropAlias) override;
bool ADDIN_API GetPropVal(const long lPropNum, tVariant* pvarPropVal) override;
bool ADDIN_API SetPropVal(const long lPropNum, tVariant* varPropVal) override;
bool ADDIN_API IsPropReadable(const long lPropNum) override;
bool ADDIN_API IsPropWritable(const long lPropNum) override;
long ADDIN_API GetNMethods() override;
long ADDIN_API FindMethod(const WCHAR_T* wsMethodName) override;
const WCHAR_T* ADDIN_API GetMethodName(const long lMethodNum,
const long lMethodAlias) override;
long ADDIN_API GetNParams(const long lMethodNum) override;
bool ADDIN_API GetParamDefValue(const long lMethodNum, const long lParamNum,
tVariant *pvarParamDefValue) override {
return false;
};
bool ADDIN_API HasRetVal(const long lMethodNum) override;
bool ADDIN_API CallAsProc(const long lMethodNum,
tVariant* paParams, const long lSizeArray) override;
bool ADDIN_API CallAsFunc(const long lMethodNum,
tVariant* pvarRetValue, tVariant* paParams, const long lSizeArray) override;
// LocaleBase
void ADDIN_API SetLocale(const WCHAR_T* loc) override {};
private:
// Attributes
IAddInDefBase *pAsyncEvent = nullptr;
IMemoryManager *m_iMemory;
bool m_boolEnabled = false;
bool valid = true;
HINSTANCE m_hDllInstance = nullptr;
std::string m_JavaHome;
std::string m_ProductLibDir;
std::string m_JvmDllLocation;
CreateJavaVM m_JVMInstance = nullptr;
GetCreatedJavaVMs m_GetCreatedJavaVMs = nullptr;
std::vector<std::string> m_listOfJars;
std::vector<std::string> m_listOfClasses;
std::map<std::string, jclass> m_cachedClasses;
std::map<jclass, jmethodID> m_cachedMethod;
std::map<std::string, jclassMethodHolder> m_cachedClassesMethod;
void LaunchJVM();
bool verify();
jint JNI_destroyVM();
bool validateCall();
std::string buildSignature(JNIEnv * env, tVariant * paParams, int start, int end, TYPEVAR returnType);
jclass findClassForCall(std::string className);
jmethodID findMethodForCall(jclass findedclass, bool& hasError);
jmethodID HasMethodInCache(jclass findedclass);
std::optional<jclassMethodHolder> HasClassAndMethodInCache(std::string classFunctionName);
long findName(wchar_t* names[], const wchar_t* name, const uint32_t size) const;
void addError(uint32_t wcode, const wchar_t* source,
const wchar_t* descriptor, long code);
void addJar(const char* jarname);
jclass JNI_findClass(const char* className);
void JNI_callStaticVoidMethod(jclass clazz, jmethodID methodID, bool& hasError, ...);
jobjectArray JNI_newObjectArray(jsize length, jclass elementClass, jobject initialElement, bool& hasError);
void JNI_callStaticVoidMethodA(jclass clazz, jmethodID methodID, jvalue* args, bool& hasError);
jobject JNI_callStaticObjectMethodA(jclass clazz, jmethodID methodID, jvalue* args, bool& hasError);
jboolean JNI_callStaticBooleanMethodA(jclass clazz, jmethodID methodID, jvalue* args, bool& hasError);
jint JNI_callStaticIntMethodA(jclass clazz, jmethodID methodID, jvalue* args, bool& hasError);
jfloat JNI_callStaticFloatMethodA(jclass clazz, jmethodID methodID, jvalue* args, bool& hasError);
jdouble JNI_callStaticDoubleMethodA(jclass clazz, jmethodID methodID, jvalue* args, bool& hasError);
void JNI_callStaticVoidMethodV(jclass clazz, jmethodID methodID, va_list args, bool& hasError);
jmethodID JNI_getStaticMethodID(jclass clazz, const char* name, const char* sig, bool& hasError);
bool endCall(JNIEnv* env);
protected:
};
#endif //__JVMLAUNCHER_H__