modules/fxpackager/src/main/native/library/common/JavaVirtualMachine.cpp
Print this page
*** 46,55 ****
--- 46,72 ----
#include <map>
#include <list>
+ bool RunVM() {
+ bool result = false;
+ JavaVirtualMachine javavm;
+
+ if (javavm.StartJVM() == true) {
+ result = true;
+ javavm.ShutdownJVM();
+ }
+ else {
+ Platform& platform = Platform::GetInstance();
+ platform.ShowMessage(_T("Failed to launch JVM\n"));
+ }
+
+ return result;
+ }
+
+
// Private typedef for function pointer casting
#ifndef USE_JLI_LAUNCH
#define LAUNCH_FUNC "JNI_CreateJavaVM"
typedef jint (JNICALL *JVM_CREATE)(JavaVM ** jvm, JNIEnv ** env, void *);
#else
*** 198,226 ****
delete[] FOptions;
}
}
- void AppendValue(const TString Key, TString Value) {
- AppendValue(Key, Value, NULL);
- }
-
void AppendValue(const TString Key, TString Value, void* Extra) {
JavaOptionItem item;
item.name = Key;
item.value = Value;
item.extraInfo = Extra;
FItems.push_back(item);
}
! void AppendValues(TOrderedMap Values) {
! std::list<TString> orderedKeys = Helpers::GetOrderedKeysFromMap(Values);
! for (std::list<TString>::const_iterator iterator = orderedKeys.begin(); iterator != orderedKeys.end(); iterator++) {
TString name = *iterator;
! TValueIndex value = Values[name];
! AppendValue(name, value.value);
}
}
void ReplaceValue(const TString Key, TString Value) {
for (std::list<JavaOptionItem>::iterator iterator = FItems.begin();
--- 215,246 ----
delete[] FOptions;
}
}
void AppendValue(const TString Key, TString Value, void* Extra) {
JavaOptionItem item;
item.name = Key;
item.value = Value;
item.extraInfo = Extra;
FItems.push_back(item);
}
! void AppendValue(const TString Key, TString Value) {
! AppendValue(Key, Value, NULL);
! }
!
! void AppendValues(OrderedMap<TString, TString> Values) {
! std::vector<TString> orderedKeys = Values.GetKeys();
! for (std::vector<TString>::const_iterator iterator = orderedKeys.begin(); iterator != orderedKeys.end(); iterator++) {
TString name = *iterator;
! TString value;
!
! if (Values.GetValue(name, value) == true) {
! AppendValue(name, value);
! }
}
}
void ReplaceValue(const TString Key, TString Value) {
for (std::list<JavaOptionItem>::iterator iterator = FItems.begin();
*** 284,321 ****
}
};
// jvmuserargs can have a trailing equals in the key. This needs to be removed to use
// other parts of the launcher.
! TOrderedMap RemoveTrailingEquals(TOrderedMap Map) {
! TOrderedMap result;
! for (TOrderedMap::const_iterator iterator = Map.begin(); iterator != Map.end(); iterator++) {
! TString name = iterator->first;
! TValueIndex value = iterator->second;
// If the last character of the key is an equals, then remove it. If there is no
// equals then combine the two as a key.
TString::iterator i = name.end();
i--;
if (*i == '=') {
name = name.substr(0, name.size() - 1);
}
else {
! i = value.value.begin();
if (*i == '=') {
! value.value = value.value.substr(1, value.value.size() - 1);
}
else {
! name = name + value.value;
! value.value = _T("");
}
}
! result.insert(TOrderedMap::value_type(name, value));
}
return result;
}
--- 304,345 ----
}
};
// jvmuserargs can have a trailing equals in the key. This needs to be removed to use
// other parts of the launcher.
! OrderedMap<TString, TString> RemoveTrailingEquals(OrderedMap<TString, TString> Map) {
! OrderedMap<TString, TString> result;
!
! std::vector<TString> keys = Map.GetKeys();
! for (size_t index = 0; index < keys.size(); index++) {
! TString name = keys[index];
! TString value;
+ if (Map.GetValue(name, value) == true) {
// If the last character of the key is an equals, then remove it. If there is no
// equals then combine the two as a key.
TString::iterator i = name.end();
i--;
if (*i == '=') {
name = name.substr(0, name.size() - 1);
}
else {
! i = value.begin();
if (*i == '=') {
! value = value.substr(1, value.size() - 1);
}
else {
! name = name + value;
! value = _T("");
}
}
! result.Append(name, value);
! }
}
return result;
}
*** 407,417 ****
mainMethod.CallVoidMethod(1, largs.GetData());
return true;
}
catch (JavaException& exception) {
! platform.ShowMessage(PlatformString(exception.what()).toString());
return false;
}
}
return false;
--- 431,441 ----
mainMethod.CallVoidMethod(1, largs.GetData());
return true;
}
catch (JavaException& exception) {
! platform.ShowMessage(exception.GetMessage());
return false;
}
}
return false;
*** 444,454 ****
}
std::list<TString> largs = package.GetArgs();
vmargs.splice(vmargs.end(), largs, largs.begin(), largs.end());
size_t argc = vmargs.size();
! DynamicBuffer<char*> argv(argc+1);
unsigned int index = 0;
for (std::list<TString>::const_iterator iterator = vmargs.begin();
iterator != vmargs.end(); iterator++) {
TString item = *iterator;
--- 468,478 ----
}
std::list<TString> largs = package.GetArgs();
vmargs.splice(vmargs.end(), largs, largs.begin(), largs.end());
size_t argc = vmargs.size();
! DynamicBuffer<char*> argv(argc + 1);
unsigned int index = 0;
for (std::list<TString>::const_iterator iterator = vmargs.begin();
iterator != vmargs.end(); iterator++) {
TString item = *iterator;
*** 461,475 ****
}
argv[argc] = NULL;
// On Mac we can only free the boot fields if the calling thread is not the main thread.
! #ifdef MAC
if (platform.IsMainThread() == false) {
package.FreeBootFields();
}
! #endif //MAC
if (javaLibrary.JavaVMCreate(argc, argv.GetData()) == true) {
return true;
}
--- 485,501 ----
}
argv[argc] = NULL;
// On Mac we can only free the boot fields if the calling thread is not the main thread.
! #ifdef MAC
if (platform.IsMainThread() == false) {
package.FreeBootFields();
}
! #else
! package.FreeBootFields();
! #endif //MAC
if (javaLibrary.JavaVMCreate(argc, argv.GetData()) == true) {
return true;
}