-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIVirtualMachine.h
175 lines (117 loc) · 4.13 KB
/
IVirtualMachine.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* IVirtualMachine.h
*
* Created on: Feb 4, 2012
* Modified for Cycling '74 October 2015
* Author: Peter J Slack, P.Eng
* Copyright 2012-2015 WaveDNA Ltd. All rights reserved
*
*/
#ifndef IVIRTUALMACHINE_H_
#define IVIRTUALMACHINE_H_
#include <stdio.h>
#include <iostream>
#include <list>
#include <string>
#include <stdlib.h>
//#define LLPLUGDEBUG
#ifdef WIN_VERSION
#include <jni.h>
#include <tchar.h>
#include <Windows.h>
#endif
#ifdef MAC_VERSION
#include "jni.h"
#include <unistd.h>
#include <strings.h>
#endif
using namespace std;
/** a structure to allow us to firewall our c++ code and provide a c API interface */
struct ivirtualmachine{};
//-------------------------------------------------------------------------------------------------
// Class IVirtualMachine
//-------------------------------------------------------------------------------------------------
class IVirtualMachine : public ivirtualmachine
{
public:
//---------------------------------------------------------------------------------------------
// Constructors and destructors
//---------------------------------------------------------------------------------------------
~IVirtualMachine();
//---------------------------------------------------------------------------------------------
// Public interface methods
//---------------------------------------------------------------------------------------------
static IVirtualMachine* getInstance();
static bool exists();
void *launchJVMThread(void * param);
void addLibraryPath(string newPath);
void addClassPath(string newPath);
void addJavaOption(string newOption);
void setStartupClass(string startClass);
void startJava();
void startJVM();
void startJVM(std::string jvmPath, std::string jliPath);
void killJVM();
string findEmbeddedLibrary(string appBase, bool sixtyfourbit);
JavaVM * getJVM(){return jvm;};
JNIEnv * attachJNIThread();
IVirtualMachine(IVirtualMachine const&){};
/** There can only be one mainJVM, this is a singleton class*/
/** depending on which variable is set we will enter development mode */
bool isDevelopmentMode;
/** The constructed option string */
char *libraryPathString;
bool exceptionCheck(JNIEnv * env,int numCleanups,...);
void cleanUpObjects(JNIEnv * env,int numCleanups,...);
static jstring getSystemProperty(string propertyName);
bool is64BitArchitecture();
int majorOSVersion();
protected:
bool launchJVM();
//---------------------------------------------------------------------------------------------
// Class members
//---------------------------------------------------------------------------------------------
// JNI-related variables
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption options[256];
int nbOptions;
jint res;
jclass myStartupJavaClass;
jmethodID constructorID;
jobject JavaGUI;
bool isLaunched;
/** The java home directory as passed in at jvmstartup */
char *javaHomeDirectory;
/** The constructed classpath string */
char *classPathString;
/** An array of additional options to pass along to the jvm */
char *additionalOptions[256];
/** A list of library paths to feed the jvm */
list<string> *libraryPaths;
/** A list of class paths to feed the jvm */
list<string> *classPaths;
/** A list of additional options to feed the jvm */
list<string> *jvmStartupOptions;
/** The class loaded for startup the static main function will be called from the main c thread */
string startUpClass;
//our embedded library paths (future use)
static string * embeddedJavaLibraryPath32;
static string * embeddedJavaLibraryPath64;
/** static instance of our singleton */
static IVirtualMachine *instance;
private:
/** we are a singleton so our cunstructor is private */
IVirtualMachine();
#ifdef WIN32
/** handle to the loaded JVM.DLL */
HMODULE handle;
_TCHAR* findLib();
_TCHAR* checkVMRegistryKey(HKEY jreKey, _TCHAR* subKeyName);
void logLastError(LPTSTR lpszFunction);
#else
void * handle;
#endif
};
#endif /* IVIRTUALMACHINE_H_ */