1111
1212#include < string>
1313#include < optional>
14+ #include < filesystem>
1415
1516std::optional<odr::Html> s_html;
1617
1718JNIEXPORT jobject JNICALL
18- Java_at_tomtasche_reader_background_CoreWrapper_parseNative (JNIEnv *env, jobject instance ,
19+ Java_at_tomtasche_reader_background_CoreWrapper_parseNative (JNIEnv *env, jclass clazz ,
1920 jobject options) {
2021 jboolean isCopy;
2122
@@ -168,7 +169,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject
168169}
169170
170171JNIEXPORT jobject JNICALL
171- Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative (JNIEnv *env, jobject instance ,
172+ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative (JNIEnv *env, jclass clazz ,
172173 jobject options,
173174 jstring htmlDiff) {
174175 jboolean isCopy;
@@ -228,21 +229,28 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env,
228229}
229230
230231JNIEXPORT void JNICALL
231- Java_at_tomtasche_reader_background_CoreWrapper_closeNative (JNIEnv *env, jobject instance ,
232+ Java_at_tomtasche_reader_background_CoreWrapper_closeNative (JNIEnv *env, jclass clazz ,
232233 jobject options) {
233234 s_html.reset ();
234235}
235236
236237std::optional<odr::HttpServer> s_server;
237238
238239JNIEXPORT void JNICALL
239- Java_at_tomtasche_reader_background_CoreWrapper_createServerNative (JNIEnv *env, jobject instance) {
240+ Java_at_tomtasche_reader_background_CoreWrapper_createServerNative (JNIEnv *env, jclass clazz, jstring outputPath) {
241+ const char * outputPathC = env->GetStringUTFChars (outputPath, nullptr );
242+ std::string output_path = outputPathC;
243+ env->ReleaseStringUTFChars (outputPath, outputPathC);
244+
245+ std::filesystem::create_directories (output_path);
246+
240247 odr::HttpServer::Config config;
248+ config.output_path = output_path;
241249 s_server = odr::HttpServer (config);
242250}
243251
244252JNIEXPORT jstring JNICALL
245- Java_at_tomtasche_reader_background_CoreWrapper_hostFileNative (JNIEnv *env, jobject instance , jobject options) {
253+ Java_at_tomtasche_reader_background_CoreWrapper_hostFileNative (JNIEnv *env, jclass clazz , jobject options) {
246254 jboolean isCopy;
247255
248256 jclass optionsClass = env->GetObjectClass (options);
@@ -253,23 +261,29 @@ Java_at_tomtasche_reader_background_CoreWrapper_hostFileNative(JNIEnv *env, jobj
253261 auto inputPathCpp = std::string (inputPathC, env->GetStringUTFLength (inputPath));
254262 env->ReleaseStringUTFChars (inputPath, inputPathC);
255263
256- odr::DecodePreference decode_preference ;
257- decode_preference .engine_priority = {
264+ odr::DecodePreference decodePreference ;
265+ decodePreference .engine_priority = {
258266 odr::DecoderEngine::poppler, odr::DecoderEngine::wvware, odr::DecoderEngine::odr};
259- odr::DecodedFile file = odr::OpenDocumentReader::open (inputPathCpp, decode_preference );
267+ odr::DecodedFile file = odr::OpenDocumentReader::open (inputPathCpp, decodePreference );
260268
261- std::string id = s_server-> host_file ( file);
269+ __android_log_print (ANDROID_LOG_INFO, " smn " , " file type %i " , file. file_type () );
262270
263- return env->NewStringUTF (id.c_str ());
271+ try {
272+ std::string id = s_server->host_file (file);
273+ return env->NewStringUTF (id.c_str ());
274+ } catch (...) {
275+ __android_log_print (ANDROID_LOG_ERROR, " smn" , " error" );
276+ return env->NewStringUTF (" error" );
277+ }
264278}
265279
266280JNIEXPORT void JNICALL
267- Java_at_tomtasche_reader_background_CoreWrapper_listenServerNative (JNIEnv *env, jobject instance ) {
268- s_server->listen (" 0 .0.0.0 " , 8080 );
281+ Java_at_tomtasche_reader_background_CoreWrapper_listenServerNative (JNIEnv *env, jclass clazz ) {
282+ s_server->listen (" 127 .0.0.1 " , 29665 );
269283}
270284
271285JNIEXPORT void JNICALL
272- Java_at_tomtasche_reader_background_CoreWrapper_stopServerNative (JNIEnv *env, jobject instance ) {
286+ Java_at_tomtasche_reader_background_CoreWrapper_stopServerNative (JNIEnv *env, jclass clazz ) {
273287 s_server->stop ();
274288 s_server.reset ();
275- }
289+ }
0 commit comments