|
|
|
#include <jni.h>
|
|
|
|
#include <string>
|
|
|
|
#include <Factory.h>
|
|
|
|
#include <Client/Terminal.h>
|
|
|
|
#include "TerminalDevice.h"
|
|
|
|
#include "PhoneDevice.h"
|
|
|
|
#include "PhoneDevice2.h"
|
|
|
|
#include <camera/NdkCameraCaptureSession.h>
|
|
|
|
#include <camera/NdkCameraDevice.h>
|
|
|
|
#include <camera/NdkCameraError.h>
|
|
|
|
#include <camera/NdkCameraManager.h>
|
|
|
|
|
|
|
|
#include <android/native_window.h>
|
|
|
|
#include <android/native_window_jni.h>
|
|
|
|
|
|
|
|
#include "Camera.h"
|
|
|
|
#include "Camera2Reader.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool GetJniEnv(JavaVM *vm, JNIEnv **env)
|
|
|
|
{
|
|
|
|
bool did_attach_thread = false;
|
|
|
|
*env = nullptr;
|
|
|
|
// Check if the current thread is attached to the VM
|
|
|
|
auto get_env_result = vm->GetEnv((void**)env, JNI_VERSION_1_6);
|
|
|
|
if (get_env_result == JNI_EDETACHED)
|
|
|
|
{
|
|
|
|
if (vm->AttachCurrentThread(env, NULL) == JNI_OK) {
|
|
|
|
did_attach_thread = true;
|
|
|
|
} else {
|
|
|
|
// Failed to attach thread. Throw an exception if you want to.
|
|
|
|
}
|
|
|
|
} else if (get_env_result == JNI_EVERSION)
|
|
|
|
{
|
|
|
|
// Unsupported JNI version. Throw an exception if you want to.
|
|
|
|
}
|
|
|
|
|
|
|
|
return did_attach_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #include "client/linux/handler/exception_handler.h"
|
|
|
|
// #include "client/linux/handler/minidump_descriptor.h"
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jstring JNICALL
|
|
|
|
Java_com_xinyingpower_microphoto_MainActivity_stringFromJNI(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject /* this */) {
|
|
|
|
std::string hello = "Hello from C++";
|
|
|
|
return env->NewStringUTF(hello.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jboolean JNICALL
|
|
|
|
Java_com_xinyingpower_microphoto_MainActivity_takePhoto(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject pThis, jint channel, jint preset, jstring path, jstring fileName) {
|
|
|
|
|
|
|
|
// ANativeWindow *imgReaderAnw = ANativeWindow_fromSurface(env, surface);
|
|
|
|
|
|
|
|
/*
|
|
|
|
CCamera camera;
|
|
|
|
camera.initCamera(imgReaderAnw);
|
|
|
|
if (camera.isCameraReady())
|
|
|
|
{
|
|
|
|
camera.takePicture();
|
|
|
|
}
|
|
|
|
|
|
|
|
camera.closeCamera();
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (channel < 1 || channel > 0xFF)
|
|
|
|
{
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char id = (unsigned char)channel - 1;
|
|
|
|
|
|
|
|
Camera2Reader *camera = new Camera2Reader(id);
|
|
|
|
const char *pathStr = env->GetStringUTFChars(path, 0);
|
|
|
|
const char *fileNameStr = env->GetStringUTFChars(fileName, 0);
|
|
|
|
|
|
|
|
camera->Open(pathStr, fileNameStr);
|
|
|
|
env->ReleaseStringUTFChars(fileName, fileNameStr);
|
|
|
|
env->ReleaseStringUTFChars(path, pathStr);
|
|
|
|
|
|
|
|
camera->start();
|
|
|
|
|
|
|
|
return JNI_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jlong JNICALL
|
|
|
|
Java_com_xinyingpower_microphoto_MicroPhotoService_init(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject pThis, jstring appPath, jstring ip, jint port, jstring cmdid) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
google_breakpad::MinidumpDescriptor descriptor(".");
|
|
|
|
google_breakpad::ExceptionHandler eh(descriptor, NULL, NULL,
|
|
|
|
NULL, true, -1);
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char *appPathStr = env->GetStringUTFChars(appPath, 0);
|
|
|
|
const char *ipStr = env->GetStringUTFChars(ip, 0);
|
|
|
|
const char *cmdidStr = env->GetStringUTFChars(cmdid, 0);
|
|
|
|
|
|
|
|
JavaVM* vm = NULL;
|
|
|
|
jint ret = env->GetJavaVM(&vm);
|
|
|
|
// const string& appPath, const string& termId, const string& server, unsigned short port, const string& bindIp
|
|
|
|
// CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
|
|
|
|
// CTerminalDevice* device = new CTerminalDevice(vm, pThis);
|
|
|
|
// CPhoneDevice2* device = new CPhoneDevice2(vm, pThis);
|
|
|
|
|
|
|
|
CTerminal* pTerminal = NewTerminal(GetCurrentProtocol());
|
|
|
|
|
|
|
|
CPhoneDevice* device = new CPhoneDevice(vm, pThis);
|
|
|
|
device->SetListener(pTerminal);
|
|
|
|
|
|
|
|
pTerminal->InitServerInfo(appPathStr, cmdidStr, ipStr, port);
|
|
|
|
pTerminal->SetPacketSize(1 * 1024); // 1K
|
|
|
|
bool res = pTerminal->Startup(device);
|
|
|
|
|
|
|
|
env->ReleaseStringUTFChars(appPath, appPathStr);
|
|
|
|
env->ReleaseStringUTFChars(ip, ipStr);
|
|
|
|
env->ReleaseStringUTFChars(cmdid, cmdidStr);
|
|
|
|
|
|
|
|
return reinterpret_cast<jlong>(pTerminal);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jboolean JNICALL
|
|
|
|
Java_com_xinyingpower_microphoto_MicroPhotoService_notifyToTakePhoto(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject pThis, jlong handler, jint channel, jint preset, jlong scheduleTime, jstring path, jstring fileName, jboolean sendToCma) {
|
|
|
|
|
|
|
|
if (channel < 1 || channel > 0xFF)
|
|
|
|
{
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
|
|
|
|
if (pTerminal == NULL)
|
|
|
|
{
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pTerminal->RequestCapture((unsigned int)channel, (unsigned int)preset, 0, (unsigned long)scheduleTime);
|
|
|
|
|
|
|
|
return JNI_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jboolean JNICALL
|
|
|
|
Java_com_xinyingpower_microphoto_MicroPhotoService_sendHeartbeat(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject pThis,
|
|
|
|
jlong handler) {
|
|
|
|
|
|
|
|
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
|
|
|
|
if (pTerminal == NULL)
|
|
|
|
{
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pTerminal->SendHeartbeat();
|
|
|
|
|
|
|
|
return JNI_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jboolean JNICALL
|
|
|
|
Java_com_xinyingpower_microphoto_MicroPhotoService_fireTimeout(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject pThis, jlong handler, jlong uid) {
|
|
|
|
|
|
|
|
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
|
|
|
|
IDevice* dev = pTerminal->GetDevice();
|
|
|
|
if (dev == NULL)
|
|
|
|
{
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPhoneDevice* phoneDevice = (CPhoneDevice *)dev;
|
|
|
|
return phoneDevice->FireTimer((IDevice::timer_uid_t)uid) ? JNI_TRUE : JNI_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jboolean JNICALL
|
|
|
|
Java_com_xinyingpower_microphoto_MicroPhotoService_uninit(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject pThis, jlong handler) {
|
|
|
|
|
|
|
|
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
|
|
|
|
if (pTerminal == NULL)
|
|
|
|
{
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pTerminal->SignalExit();
|
|
|
|
pTerminal->Shutdown();
|
|
|
|
|
|
|
|
delete pTerminal;
|
|
|
|
|
|
|
|
return JNI_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jlong JNICALL
|
|
|
|
Java_com_xinyingpower_microphoto_MicroPhotoService_getHeartbeatDuration(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject pThis, jlong handler) {
|
|
|
|
|
|
|
|
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
|
|
|
|
if (pTerminal == NULL)
|
|
|
|
{
|
|
|
|
return DEFAULT_HEARTBEAT_DURATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pTerminal->GetHeartbeatDuration();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jlongArray JNICALL
|
|
|
|
Java_com_xinyingpower_microphoto_MicroPhotoService_getPhotoTimeData(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject pThis, jlong handler) {
|
|
|
|
|
|
|
|
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
|
|
|
|
if (pTerminal == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
map<unsigned char, vector<unsigned int>> photoTime;
|
|
|
|
if (!pTerminal->GetPhotoTime(photoTime) || photoTime.empty())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t numberOfData = photoTime.size() * photoTime.begin()->second.size();
|
|
|
|
if (numberOfData == 0)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<jlong> dataArray;
|
|
|
|
dataArray.reserve(numberOfData);
|
|
|
|
|
|
|
|
unsigned long val = 0;
|
|
|
|
jint channel = 0;
|
|
|
|
for (map<unsigned char, vector<unsigned int>>::const_iterator it = photoTime.cbegin(); it != photoTime.cend(); ++it)
|
|
|
|
{
|
|
|
|
if (it->second.empty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = (jint)((unsigned short)it->first);
|
|
|
|
// dataArray.push_back(channel);
|
|
|
|
|
|
|
|
// val = (jint)it->second.size();
|
|
|
|
// dataArray.push_back(val);
|
|
|
|
for (vector<unsigned int>::const_iterator it2 = it->second.cbegin(); it2 != it->second.cend(); ++it2)
|
|
|
|
{
|
|
|
|
// time
|
|
|
|
val = ((unsigned long)((*it2) & 0xFFFFFF00)) << 24;
|
|
|
|
// channel
|
|
|
|
val |= ((unsigned long)channel) << 16;
|
|
|
|
// preset
|
|
|
|
val |= ((unsigned long)((*it2) & 0xFF)) << 8;
|
|
|
|
|
|
|
|
dataArray.push_back((jlong)val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(dataArray.begin(), dataArray.end());
|
|
|
|
|
|
|
|
jlongArray data = env->NewLongArray(dataArray.size());
|
|
|
|
if (data == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->SetLongArrayRegion(data, 0, dataArray.size(), &dataArray[0]);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
extern "C" JNIEXPORT jlongArray JNICALL
|
|
|
|
Java_com_xinyingpower_microphoto_MicroPhotoService_getNextScheduleItem(
|
|
|
|
JNIEnv* env,
|
|
|
|
jobject pThis, jlong handler) {
|
|
|
|
|
|
|
|
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
|
|
|
|
if (pTerminal == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
map<unsigned char, vector<unsigned int>> photoTime;
|
|
|
|
if (!pTerminal->GetPhotoTime(photoTime) || photoTime.empty())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t numberOfData = photoTime.size() * photoTime.begin()->second.size();
|
|
|
|
if (numberOfData == 0)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<jlong> dataArray;
|
|
|
|
dataArray.reserve(numberOfData);
|
|
|
|
|
|
|
|
unsigned long val = 0;
|
|
|
|
jint channel = 0;
|
|
|
|
for (map<unsigned char, vector<unsigned int>>::const_iterator it = photoTime.cbegin(); it != photoTime.cend(); ++it)
|
|
|
|
{
|
|
|
|
if (it->second.empty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = (jint)((unsigned short)it->first);
|
|
|
|
// dataArray.push_back(channel);
|
|
|
|
|
|
|
|
// val = (jint)it->second.size();
|
|
|
|
// dataArray.push_back(val);
|
|
|
|
for (vector<unsigned int>::const_iterator it2 = it->second.cbegin(); it2 != it->second.cend(); ++it2)
|
|
|
|
{
|
|
|
|
// time
|
|
|
|
val = ((unsigned long)((*it2) & 0xFFFFFF00)) << 24;
|
|
|
|
// channel
|
|
|
|
val |= ((unsigned long)channel) << 16;
|
|
|
|
// preset
|
|
|
|
val |= ((unsigned long)((*it2) & 0xFF)) << 8;
|
|
|
|
|
|
|
|
dataArray.push_back((jlong)val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(dataArray.begin(), dataArray.end());
|
|
|
|
|
|
|
|
jlongArray data = env->NewLongArray(dataArray.size());
|
|
|
|
if (data == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->SetLongArrayRegion(data, 0, dataArray.size(), &dataArray[0]);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
*/
|