adding runtime Android logging in Debug

pull/13383/head
Andrey Pavlenko 14 years ago
parent 7159845021
commit bc9a9b714c
  1. 29
      modules/java/gen_java.py

@ -318,11 +318,12 @@ class JavaWrapperGenerator(object):
//
#include <jni.h>
/*
#ifdef DEBUG
#include <android/log.h>
#define MODULE_LOG_TAG "OpenCV.%s"
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__))
*/
#endif // DEBUG
""" % module)
self.cpp_code.write( "\n".join(['#include "opencv2/%s/%s"' % (module, os.path.basename(f)) \
@ -503,14 +504,14 @@ class JavaWrapperGenerator(object):
# jni_func(..) { return cv_func(..); }
ret = "return "
ext = ""
default = "return 0"
default = "return 0;"
if fi.ctype == "void":
ret = ""
default = ""
elif fi.ctype == "string":
ret = "return env->NewStringUTF"
ext = ".c_str()"
default = 'return env->NewStringUTF("")'
default = 'return env->NewStringUTF("");'
elif fi.ctype in self.classes: # wrapped class:
ret = "return (jlong) new " + self.classes[fi.ctype].jname
@ -541,20 +542,26 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_$fname
($args)
{
try {
//LOGD("$module::$fname()");
#ifdef DEBUG
LOGD("$module::$fname()");
#endif // DEBUG
$j2cv
$ret( $cvname( $cvargs )$ext );
} catch(cv::Exception e) {
//LOGD("$module::$fname() catched cv::Exception: %s", e.what());
#ifdef DEBUG
LOGD("$module::$fname() catched cv::Exception: %s", e.what());
#endif // DEBUG
jclass je = env->FindClass("org/opencv/CvException");
if(!je) je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, e.what());
$default;
$default
} catch (...) {
//LOGD("$module::$fname() catched ...");
#ifdef DEBUG
LOGD("$module::$fname() catched unknown exception (...)");
#endif // DEBUG
jclass je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, "Unknown exception in JNI code {$module::$fname()}");
$default;
$default
}
}
@ -601,8 +608,8 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_$fname
if name == "Mat":
continue
self.java_code.write( "\n\n" + indent + "// C++: class %s" % (ci.cname) + "\n" )
self.java_code.write( indent + "//javadoc: " + name + "\n" ) #java doc comment
self.java_code.write( indent + "public static class %s {\n\n" % (ci.jname) )
# self
self.java_code.write( indent_m + "protected final long nativeObj;\n" )
self.java_code.write( indent_m + "protected %s(long addr) { nativeObj = addr; }\n\n" \
@ -689,5 +696,3 @@ if __name__ == "__main__":
generator = JavaWrapperGenerator()
generator.gen(srcfiles, module, dstdir)

Loading…
Cancel
Save