This commit is contained in:
2025-06-25 08:09:19 +02:00
parent 53ba9dc12e
commit f3a6650cb7
10 changed files with 136 additions and 2 deletions

View File

@@ -28,5 +28,6 @@ if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
add_link_options(-O3)
endif ()
add_subdirectory(libjvm_wrapper)
add_subdirectory(backend)
add_subdirectory(gui)
add_subdirectory(backend)

View File

@@ -5,3 +5,5 @@ add_library(backend
target_include_directories(backend PRIVATE include)
target_include_directories(backend PUBLIC include_public)
target_link_libraries(backend PUBLIC libjvm_wrapper)

View File

@@ -5,12 +5,31 @@
#ifndef DHFSINSTANCE_HPP
#define DHFSINSTANCE_HPP
#include <jni.h>
enum class DhfsInstanceState {
RUNNING,
STOPPED,
};
class DhfsInstance {
public:
DhfsInstance();
~DhfsInstance();
DhfsInstanceState state();
void start();
void stop();
private:
DhfsInstanceState _state = DhfsInstanceState::STOPPED;
JavaVM* _jvm = nullptr;
JNIEnv *_env = nullptr;
};
#endif //DHFSINSTANCE_HPP

View File

@@ -3,3 +3,48 @@
//
#include "DhfsInstance.hpp"
#include <stdexcept>
#include <vector>
#include "LibjvmWrapper.hpp"
DhfsInstance::DhfsInstance() {
}
DhfsInstance::~DhfsInstance() {
}
DhfsInstanceState DhfsInstance::state() {
}
void DhfsInstance::start() {
switch (_state) {
case DhfsInstanceState::RUNNING:
return;
case DhfsInstanceState::STOPPED:
break;
default:
throw std::runtime_error("Unknown DhfsInstanceState");
}
JavaVMInitArgs args;
std::vector<JavaVMOption> options;
args.version = JNI_VERSION_21;
args.nOptions = 0;
args.options = options.data();
args.ignoreUnrecognized = false;
LibjvmWrapper::instance().JNI_CreateJavaVM(&_jvm, (void**) &_env, &args);
}
void DhfsInstance::stop() {
switch (_state) {
case DhfsInstanceState::RUNNING:
break;
case DhfsInstanceState::STOPPED:
return;
default:
throw std::runtime_error("Unknown DhfsInstanceState");
}
}

View File

@@ -11,3 +11,4 @@ add_executable(launcher
)
target_link_libraries(launcher ${wxWidgets_LIBRARIES})
target_link_libraries(launcher backend)

View File

@@ -8,5 +8,6 @@ LauncherAppMainFrame::LauncherAppMainFrame(wxWindow* parent)
void LauncherAppMainFrame::OnStartStopButtonClick(wxCommandEvent& event) {
std::cout << "Hi!" << std::endl;
_dhfsInstance.start();
// TODO: Implement OnStartStopButtonClick
}

View File

@@ -10,6 +10,8 @@ Subclass of MainFrame, which is generated by wxFormBuilder.
//// end generated include
#include "DhfsInstance.hpp"
/** Implementing MainFrame */
class LauncherAppMainFrame : public MainFrame {
protected:
@@ -21,6 +23,9 @@ public:
LauncherAppMainFrame(wxWindow* parent);
//// end generated class members
private:
DhfsInstance _dhfsInstance;
};
#endif // __LauncherAppMainFrame__

View File

@@ -0,0 +1,10 @@
add_library(libjvm_wrapper
src/LibjvmWrapper.cpp
include_public/LibjvmWrapper.hpp
)
target_include_directories(libjvm_wrapper PRIVATE include)
target_include_directories(libjvm_wrapper PUBLIC include_public)
find_package(JNI REQUIRED)
target_include_directories(libjvm_wrapper PUBLIC ${JNI_INCLUDE_DIRS})

View File

@@ -0,0 +1,25 @@
//
// Created by Stepan Usatiuk on 24.06.2025.
//
#ifndef LIBJVMWRAPPER_HPP
#define LIBJVMWRAPPER_HPP
#include <jni.h>
class LibjvmWrapper {
public:
static LibjvmWrapper& instance();
decltype(JNI_CreateJavaVM)* JNI_CreateJavaVM;
private:
LibjvmWrapper();
~LibjvmWrapper();
void* _lib_handle;
};
#endif //LIBJVMWRAPPER_HPP

View File

@@ -0,0 +1,25 @@
//
// Created by Stepan Usatiuk on 24.06.2025.
//
#include "LibjvmWrapper.hpp"
#include <dlfcn.h>
#include <jni.h>
static constexpr auto LIBJVM_PATH =
"/Library/Java/JavaVirtualMachines/zulu-21.jdk/Contents/Home/lib/server/libjvm.dylib";
LibjvmWrapper& LibjvmWrapper::instance() {
static LibjvmWrapper instance;
return instance;
}
LibjvmWrapper::LibjvmWrapper() {
_lib_handle = dlopen(LIBJVM_PATH, RTLD_NOW | RTLD_GLOBAL);
JNI_CreateJavaVM = reinterpret_cast<decltype(JNI_CreateJavaVM)>(
dlsym(_lib_handle, "JNI_CreateJavaVM"));
}
LibjvmWrapper::~LibjvmWrapper() {
dlclose(_lib_handle);
}