opencv/android/service/engine/jni/JNIWrapper/OpenCVEngine_jni.cpp

70 lines
1.6 KiB
C++
Raw Normal View History

2012-06-21 22:50:05 +08:00
#include "OpenCVEngine_jni.h"
#include "EngineCommon.h"
#include "IOpenCVEngine.h"
#include "OpenCVEngine.h"
#include "IPackageManager.h"
#include "JavaBasedPackageManager.h"
#include <utils/Log.h>
#include <android_util_Binder.h>
#undef LOG_TAG
#define LOG_TAG "OpenCVEngine/JNI"
using namespace android;
sp<IBinder> OpenCVEngineBinder = NULL;
IPackageManager* PackageManager = NULL;
JNIEXPORT jobject JNICALL Java_org_opencv_engine_BinderConnector_Connect(JNIEnv* env, jobject)
{
LOGI("Creating new component");
if (NULL != OpenCVEngineBinder.get())
{
LOGI("New component created successfully");
2012-06-21 22:50:05 +08:00
}
else
{
LOGE("OpenCV Engine component was not created!");
2012-06-21 22:50:05 +08:00
}
2012-10-17 07:18:30 +08:00
2012-06-21 22:50:05 +08:00
return javaObjectForIBinder(env, OpenCVEngineBinder);
}
JNIEXPORT jboolean JNICALL Java_org_opencv_engine_BinderConnector_Init(JNIEnv* env, jobject , jobject market)
2012-06-21 22:50:05 +08:00
{
LOGD("Java_org_opencv_engine_BinderConnector_Init");
2012-10-17 07:18:30 +08:00
2012-06-21 22:50:05 +08:00
if (NULL == PackageManager)
{
JavaVM* jvm;
env->GetJavaVM(&jvm);
PackageManager = new JavaBasedPackageManager(jvm, env->NewGlobalRef(market));
2012-06-21 22:50:05 +08:00
}
if (PackageManager)
{
if (!OpenCVEngineBinder.get())
{
OpenCVEngineBinder = new OpenCVEngine(PackageManager);
return (NULL != OpenCVEngineBinder.get());
}
else
{
return true;
}
2012-06-21 22:50:05 +08:00
}
else
{
return false;
2012-06-21 22:50:05 +08:00
}
}
JNIEXPORT void JNICALL Java_org_opencv_engine_BinderConnector_Final(JNIEnv *, jobject)
{
LOGD("Java_org_opencv_engine_BinderConnector_Final");
2012-10-17 07:18:30 +08:00
2012-06-21 22:50:05 +08:00
OpenCVEngineBinder = NULL;
delete PackageManager;
PackageManager = NULL;
}