2021-07-30 10:27:45 +02:00
|
|
|
//
|
|
|
|
// Created by Marc Rousavy on 25.07.21.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "VisionCameraScheduler.h"
|
|
|
|
#include <fbjni/fbjni.h>
|
|
|
|
|
|
|
|
namespace vision {
|
|
|
|
|
|
|
|
using namespace facebook;
|
|
|
|
using TSelf = jni::local_ref<VisionCameraScheduler::jhybriddata>;
|
|
|
|
|
|
|
|
TSelf VisionCameraScheduler::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
|
|
return makeCxxInstance(jThis);
|
|
|
|
}
|
|
|
|
|
2023-02-13 15:22:45 +01:00
|
|
|
void VisionCameraScheduler::dispatchAsync(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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisionCameraScheduler::scheduleTrigger() {
|
|
|
|
// 2. schedule `triggerUI` to be called on the java thread
|
|
|
|
static auto method = javaPart_->getClass()->getMethod<void()>("scheduleTrigger");
|
|
|
|
method(javaPart_.get());
|
|
|
|
}
|
|
|
|
|
2023-02-13 15:22:45 +01:00
|
|
|
void VisionCameraScheduler::trigger() {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void VisionCameraScheduler::registerNatives() {
|
|
|
|
registerHybrid({
|
|
|
|
makeNativeMethod("initHybrid", VisionCameraScheduler::initHybrid),
|
2023-02-13 15:22:45 +01:00
|
|
|
makeNativeMethod("trigger", VisionCameraScheduler::trigger),
|
2021-07-30 10:27:45 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-02-15 17:24:33 +01:00
|
|
|
} // namespace vision
|