2021-07-30 10:27:45 +02:00
|
|
|
//
|
|
|
|
// Created by Marc Rousavy on 25.07.21.
|
|
|
|
//
|
|
|
|
|
2023-07-22 00:15:11 +02:00
|
|
|
#include "JVisionCameraScheduler.h"
|
2021-07-30 10:27:45 +02:00
|
|
|
#include <fbjni/fbjni.h>
|
|
|
|
|
|
|
|
namespace vision {
|
|
|
|
|
|
|
|
using namespace facebook;
|
2023-07-22 00:15:11 +02:00
|
|
|
using TSelf = jni::local_ref<JVisionCameraScheduler::jhybriddata>;
|
2021-07-30 10:27:45 +02:00
|
|
|
|
2023-07-22 00:15:11 +02:00
|
|
|
TSelf JVisionCameraScheduler::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
2021-07-30 10:27:45 +02:00
|
|
|
return makeCxxInstance(jThis);
|
|
|
|
}
|
|
|
|
|
2023-07-22 00:15:11 +02:00
|
|
|
void JVisionCameraScheduler::dispatchAsync(const std::function<void()>& job) {
|
2021-07-30 10:27:45 +02:00
|
|
|
// 1. add job to queue
|
2023-02-13 15:22:45 +01:00
|
|
|
_jobs.push(job);
|
2021-07-30 10:27:45 +02:00
|
|
|
scheduleTrigger();
|
|
|
|
}
|
|
|
|
|
2023-07-22 00:15:11 +02:00
|
|
|
void JVisionCameraScheduler::scheduleTrigger() {
|
2024-01-30 15:39:33 +01:00
|
|
|
// 2.1 Open a JNI Thread scope because this might be called from a C++ background Thread
|
|
|
|
jni::ThreadScope scope;
|
|
|
|
// 2.2 schedule `triggerUI` to be called on the java thread
|
2023-08-29 17:52:03 +02:00
|
|
|
static auto method = _javaPart->getClass()->getMethod<void()>("scheduleTrigger");
|
|
|
|
method(_javaPart.get());
|
2021-07-30 10:27:45 +02:00
|
|
|
}
|
|
|
|
|
2023-07-22 00:15:11 +02:00
|
|
|
void JVisionCameraScheduler::trigger() {
|
2023-02-13 15:22:45 +01:00
|
|
|
std::unique_lock<std::mutex> lock(_mutex);
|
2021-07-30 10:27:45 +02:00
|
|
|
// 3. call job we enqueued in step 1.
|
2023-02-13 15:22:45 +01:00
|
|
|
auto job = _jobs.front();
|
2021-07-30 10:27:45 +02:00
|
|
|
job();
|
2023-02-13 15:22:45 +01:00
|
|
|
_jobs.pop();
|
2021-07-30 10:27:45 +02:00
|
|
|
}
|
|
|
|
|
2023-07-22 00:15:11 +02:00
|
|
|
void JVisionCameraScheduler::registerNatives() {
|
2021-07-30 10:27:45 +02:00
|
|
|
registerHybrid({
|
2023-09-01 12:58:32 +02:00
|
|
|
makeNativeMethod("initHybrid", JVisionCameraScheduler::initHybrid),
|
|
|
|
makeNativeMethod("trigger", JVisionCameraScheduler::trigger),
|
2021-07-30 10:27:45 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-02-15 17:24:33 +01:00
|
|
|
} // namespace vision
|