ThinConsole& ThinConsole::WriteToConsole(string_type const& outputString, console_location_type const& location, console_color_type const& foreground, console_color_type const& background) { assert(outputHandle != NULL && "Output Handle Not Initialized"); std::vector<console_attribute_type> outputAttributes(outputString.size(), foregroundColorMap[foreground] | backgroundColorMap[background]); console_information_type charsWritten; ExceptionCheck(WriteConsoleOutputCharacter(outputHandle, std::wstring(outputString.begin(), outputString.end()).c_str(), outputString.size(), location, &charsWritten), __FUNCTION__, __LINE__); ExceptionCheck(WriteConsoleOutputAttribute(outputHandle, outputAttributes.data(), outputAttributes.size(), location, &charsWritten), __FUNCTION__, __LINE__); return *this; }
ThinConsole& ThinConsole::SetBufferSize(console_length_type const& columns, console_length_type const& rows) { assert(outputHandle != NULL && "Output Handle Not Initialized"); console_location_type bufferSize; bufferSize.X = columns; bufferSize.Y = rows; ExceptionCheck(SetConsoleScreenBufferSize(outputHandle, bufferSize), __FUNCTION__, __LINE__); return *this; }
ThinConsole::input_events ThinConsole::GetInputEvents(size_t const& numToCapture) { assert(inputHandle != NULL && "Input Handle Not Initialized"); input_events capturedEvents(numToCapture); console_information_type eventsCaptured; ExceptionCheck(ReadConsoleInput(inputHandle, capturedEvents.data(), static_cast<console_information_type>(capturedEvents.size()), &eventsCaptured), __FUNCTION__, __LINE__); capturedEvents.resize(eventsCaptured); return capturedEvents; }
ThinConsole& ThinConsole::SetWindowSize(console_length_type const& columns, console_length_type const& rows) { assert(outputHandle != NULL && "Output Handle Not Initialized"); console_window_type window{ 0 }; window.Right = columns; window.Bottom = rows; ExceptionCheck(SetConsoleWindowInfo(outputHandle, true, &window), __FUNCTION__, __LINE__); return *this; }
ThinConsole& ThinConsole::SetupCursorInfo(BOOL const& isVisible, console_information_type const& cursorSize) { assert(outputHandle != NULL && "Output Handle Not Initialized"); console_cursor_type cursor; cursor.bVisible = isVisible; cursor.dwSize = cursorSize; ExceptionCheck(SetConsoleCursorInfo(outputHandle, &cursor), __FUNCTION__, __LINE__); return *this; }
void generateJavaLangClassInstances() { // Allocate Class[] containing only those classes that are referenced: javaLangClassArray = NewObjectArray((jint) numberOfAllClassInstanceInfo, CLASS_ID_java_lang_Class, NULL); if (javaLangClassArray != NULL) { // Don't GC our array of classes: heapProtect(javaLangClassArray, TRUE); int i; for (i = 0; i < numberOfAllClassInstanceInfo; i++) { // Simulate: Class cl = new Class(); // TODO NewObject !!! // TODO Lazy load? u2 size; getClassSize(CLASS_ID_java_lang_Class, &size); jobject jc = heapAllocObjectByStackableSize(size, CLASS_ID_java_lang_Class); SetIntField(jc, LINK_ID_java_lang_Class_aClassId_I, i); if (ExceptionCheck()) { break; } SetObjectArrayElement(javaLangClassArray, i, jc); if (ExceptionCheck()) { break; } } // Set the aAllClasses in java.lang.Class: jclass classInstance = getJavaLangClass(CLASS_ID_java_lang_Class); SetStaticObjectField(classInstance, LINK_ID_java_lang_Class_aAllClasses__Ljava_lang_Class_, javaLangClassArray); // No need of protection: heapProtect(javaLangClassArray, FALSE); } // consout("class init done\n"); }
void JniFirebase::SetJson(const char *value) { auto env = getEnv(); if (s_objectMapperInstance == NULL) { lock<std::mutex> lock(s_objectMapperLock); if (s_objectMapperInstance == NULL) { if (!GetClass(env, "java/util/HashMap", &s_objectClass)) { return; } if (!GetClass(env, s_objectMapperClassName, &s_objectMapperClass)) { return; } jmethodID ctor = NULL; if (!GetMethod(env, s_objectMapperClass, "<init>", "()V", &ctor)) { return; } if (!GetMethod(env, s_objectMapperClass, s_objectMapperReadValueName, s_objectMapperReadValueSig, &s_objectMapperReadValue)) { return; } JOBJECT localRef = JOBJECT(env, env->NewObject(s_objectMapperClass, ctor)); s_objectMapperInstance = env->NewGlobalRef(localRef); } } JOBJECT localValue = JOBJECT(env, env->CallObjectMethod(s_objectMapperInstance, s_objectMapperReadValue, (jstring)JSTRING(env, env->NewStringUTF(value)), s_objectClass)); if (env->ExceptionCheck() == JNI_TRUE) { SetString(GetJNIExceptionDescription(env, env->ExceptionOccurred())); return; } if (!GetMethod(env, s_firebaseClass, s_firebaseSetValueName, s_firebaseSetValueSig, &s_firebaseSetValue)) { return; } env->CallVoidMethod(m_firebase, s_firebaseSetValue, (jobject)localValue); }
jobject JPJavaEnv::NewObject(jclass a0, jmethodID a1) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->AllocObject(env, a0); JAVA_CHECK("NewObject"); env->functions->CallVoidMethod(env, res, a1); if (ExceptionCheck()) { DeleteLocalRef(res); } JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("NewObject"); return res; }
ThinConsole& ThinConsole::SetInputTypes(console_information_type const& consoleMode) { assert(inputHandle != NULL && "Input Handle Not Initialized"); ExceptionCheck(SetConsoleMode(inputHandle, consoleMode), __FUNCTION__, __LINE__); return *this; }
ThinConsole::list_buffer_data ThinConsole::GetBufferData(console_buffer_type const& buffer, console_window_type& window, console_location_type const& coords) const { assert(outputHandle != NULL && "Output Handle Not Initialized"); list_buffer_data bufferData(buffer.dwSize.X * buffer.dwSize.Y); ExceptionCheck(ReadConsoleOutput(outputHandle, bufferData.data(), buffer.dwSize, { 0 }, &window), __FUNCTION__, __LINE__); return std::move(bufferData); }
void ThinConsole::SetWindowInformation(console_window_type const& window) { assert(outputHandle != NULL && "Output Handle Not Initialized"); ExceptionCheck(SetConsoleWindowInfo(outputHandle, TRUE, &window), __FUNCTION__, __LINE__); }
ThinConsole::console_information_type ThinConsole::GetConsoleInputType() const { assert(inputHandle != NULL && "Input Handle Not Initialized"); console_information_type consoleMode; ExceptionCheck(GetConsoleMode(inputHandle, &consoleMode), __FUNCTION__, __LINE__); return consoleMode; }
ThinConsole::string_type ThinConsole::GetWindowTitle() const { wchar_t charArray[25]; ExceptionCheck(GetConsoleTitle(charArray, 25), __FUNCTION__, __LINE__); return string_type(charArray); }
ThinConsole::console_buffer_type ThinConsole::GetConsoleBuffer() const { assert(outputHandle != NULL && "Output Handle Not Initialized"); console_buffer_type oldBuffer; ExceptionCheck(GetConsoleScreenBufferInfo(outputHandle, &oldBuffer), __FUNCTION__, __LINE__); return oldBuffer; }
ThinConsole::console_cursor_type ThinConsole::GetConsoleCursor() const { assert(outputHandle != NULL && "Output Handle Not Initialized"); console_cursor_type oldCursor; ExceptionCheck(GetConsoleCursorInfo(outputHandle, &oldCursor), __FUNCTION__, __LINE__); return oldCursor; }
void ThinConsole::SetWindowTitle(string_type const& title) { ExceptionCheck(SetConsoleTitle(title.c_str()), __FUNCTION__, __LINE__); }
void ThinConsole::SetCursorPosition(console_location_type const& cursorLocation) { assert(outputHandle != NULL && "Output Handle Not Initialized"); ExceptionCheck(SetConsoleCursorPosition(outputHandle, cursorLocation), __FUNCTION__, __LINE__); }
void ThinConsole::SetBufferData(list_buffer_data const& bufferData, console_location_type const& windowSize, console_window_type window, console_location_type const& coords) { assert(outputHandle != NULL && "Output Handle Not Initialized"); ExceptionCheck(WriteConsoleOutput(outputHandle, bufferData.data(), windowSize, coords, &window), __FUNCTION__, __LINE__); }
ThinConsole& ThinConsole::SetCtrlHandler() { ExceptionCheck(SetConsoleCtrlHandler((PHANDLER_ROUTINE)(CtrlHandler), TRUE), __FUNCTION__, __LINE__); return *this; }
ThinConsole::~ThinConsole() { ExceptionCheck(CloseHandle(inputHandle), __FUNCTION__ ,__LINE__); ExceptionCheck(CloseHandle(outputHandle), __FUNCTION__ ,__LINE__); }
void deprecated_generateJavaLangClassInstances() { int i; int j; int arrayLength = 0; // Calculate the length of the Class[] to generate: for (i = 0; i < numberOfAllClassReferences; i++) { // The candidate for java.lang.Class generation: u2 classId = allClassReferences[i].targetClassId; // Verify that it hasn't been generated before: BOOL found = FALSE; for (j = 0; j < i - 1 && !found; j++) { found = allClassReferences[j].targetClassId == classId; } if (!found) { arrayLength++; } } consoutli("arrayLength: %d\n", arrayLength); // Allocate Class[] containing only those classes that are referenced: javaLangClassArray = NewObjectArray((jint) arrayLength, CLASS_ID_java_lang_Class, NULL); if (javaLangClassArray != NULL) { // Don't GC our array of classes: heapProtect(javaLangClassArray, TRUE); int arrayIndex = 0; u2 aClassIdLinkId = LINK_ID_java_lang_Class_aClassId_I; jclass classInstance = NULL; for (i = 0; i < numberOfAllClassReferences; i++) { // The candidate for java.lang.Class generation: u2 classId = allClassReferences[i].targetClassId; // Verify that it hasn't been generated before: BOOL found = FALSE; for (j = 0; j < i - 1 && !found; j++) { found = allClassReferences[j].targetClassId == classId; } if (!found) { // The class instance does not exist yet: // Simulate: Class cl = new Class(); u2 size; getClassSize(CLASS_ID_java_lang_Class, &size); jobject jc = heapAllocObjectByStackableSize(size, CLASS_ID_java_lang_Class); SetIntField(jc, aClassIdLinkId, classId); if (ExceptionCheck()) { break; } consoutli("class id: %d\n", classId); if (classId == CLASS_ID_java_lang_Class) { classInstance = jc; consoutli("class: \n"); } SetObjectArrayElement(javaLangClassArray, arrayIndex, jc); arrayIndex++; } } // Set the aAllClasses in java.lang.Class: SetStaticObjectField(classInstance, LINK_ID_java_lang_Class_aAllClasses__Ljava_lang_Class_, javaLangClassArray); } // consout("class init done\n"); }
void ThinConsole::SetConsoleCursor(ThinConsole::console_cursor_type const& cursor) { assert(outputHandle != NULL && "Output Handle Not Initialized"); ExceptionCheck(SetConsoleCursorInfo(outputHandle, &cursor), __FUNCTION__, __LINE__); }