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

71 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())
{
2012-10-17 15:12:04 +08:00
LOGI("New component created successfully");
2012-06-21 22:50:05 +08:00
}
else
{
2012-10-17 15:12:04 +08:00
LOGE("OpenCV Engine component was not created!");
2012-06-21 22:50:05 +08:00
}
2012-10-17 15:12:04 +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 thiz, jobject market)
{
LOGD("Java_org_opencv_engine_BinderConnector_Init");
2012-10-17 15:12:04 +08:00
2012-06-21 22:50:05 +08:00
if (NULL == PackageManager)
{
2012-10-17 15:12:04 +08:00
JavaVM* jvm;
env->GetJavaVM(&jvm);
PackageManager = new JavaBasedPackageManager(jvm, env->NewGlobalRef(market));
2012-06-21 22:50:05 +08:00
}
if (PackageManager)
{
2012-10-17 15:12:04 +08:00
if (!OpenCVEngineBinder.get())
{
OpenCVEngineBinder = new OpenCVEngine(PackageManager);
return (NULL != OpenCVEngineBinder.get());
}
else
{
return true;
}
2012-06-21 22:50:05 +08:00
}
else
{
2012-10-17 15:12:04 +08:00
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 15:12:04 +08:00
2012-06-21 22:50:05 +08:00
OpenCVEngineBinder = NULL;
delete PackageManager;
PackageManager = NULL;
}