Mercurial > cgi-bin > hgweb.cgi > JpegWasher
annotate src/name/blackcap/exifwasher/exiv2/native.cpp @ 1:42277ce58ace
Improve exception handling; always use absolute paths on libs.
author | David Barts <n5jrn@me.com> |
---|---|
date | Tue, 31 Mar 2020 15:38:25 -0700 |
parents | db63d01a23c6 |
children | efd9fe2d70d7 |
rev | line source |
---|---|
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
1 #include <jni.h> |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
2 #include <exiv2/exiv2.hpp> |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
3 #include <iostream> |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
4 #include <iomanip> |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
5 #include <cassert> |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
6 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
7 /* Functions for class name_blackcap_exifwasher_exiv2_Image */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
8 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
9 #ifndef _Included_name_blackcap_exifwasher_exiv2_Image |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
10 #define _Included_name_blackcap_exifwasher_exiv2_Image |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
11 #ifdef __cplusplus |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
12 extern "C" { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
13 #endif |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
14 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
15 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
16 * Utility function to get pointer field. |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
17 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
18 jlong getPointer(JNIEnv *jEnv, jobject jThis) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
19 return jEnv->GetLongField(jThis, jEnv->GetFieldID(jEnv->GetObjectClass(jThis), "pointer", "J")); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
20 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
21 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
22 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
23 * Class: name_blackcap_exifwasher_exiv2_Image |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
24 * Method: _ctor |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
25 * Signature: (Ljava/lang/String;)J |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
26 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
27 JNIEXPORT jlong JNICALL Java_name_blackcap_exifwasher_exiv2_Image__1ctor |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
28 (JNIEnv *jEnv, jobject jThis, jstring path) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
29 const char *cPath = jEnv->GetStringUTFChars(path, NULL); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
30 jlong ret = 0; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
31 try { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
32 ret = reinterpret_cast<jlong> (Exiv2::ImageFactory::open(cPath).release()); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
33 } catch (...) { |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
34 jEnv->ExceptionClear(); |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
35 jclass ex = jEnv->FindClass("name/blackcap/exifwasher/exiv2/Exiv2Exception"); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
36 const char *pfx = "unable to open "; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
37 char *message = (char *) malloc(strlen(cPath) + strlen(pfx) + 1); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
38 strcpy(message, pfx); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
39 strcat(message, cPath); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
40 jEnv->ThrowNew(ex, message); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
41 free(message); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
42 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
43 jEnv->ReleaseStringUTFChars(path, cPath); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
44 return ret; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
45 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
46 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
47 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
48 * Class: name_blackcap_exifwasher_exiv2_Image |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
49 * Method: _writeMetadata |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
50 * Signature: ()V |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
51 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
52 JNIEXPORT void JNICALL Java_name_blackcap_exifwasher_exiv2_Image__1writeMetadata |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
53 (JNIEnv *jEnv, jobject jThis) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
54 Exiv2::Image *image = reinterpret_cast<Exiv2::Image *> (getPointer(jEnv, jThis)); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
55 if (jEnv->ExceptionCheck()) return; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
56 try { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
57 image->writeMetadata(); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
58 } catch (...) { |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
59 jEnv->ExceptionClear(); |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
60 jclass ex = jEnv->FindClass("name/blackcap/exifwasher/exiv2/Exiv2Exception"); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
61 jEnv->ThrowNew(ex, "unable to write metadata"); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
62 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
63 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
64 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
65 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
66 * Class: name_blackcap_exifwasher_exiv2_Image |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
67 * Method: _getMetadata |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
68 * Signature: ()J |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
69 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
70 JNIEXPORT jlong JNICALL Java_name_blackcap_exifwasher_exiv2_Image__1getMetadata |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
71 (JNIEnv *jEnv, jobject jThis) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
72 Exiv2::Image *image = reinterpret_cast<Exiv2::Image *> (getPointer(jEnv, jThis)); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
73 if (jEnv->ExceptionCheck()) return 0; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
74 try { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
75 image->readMetadata(); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
76 } catch (...) { |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
77 jEnv->ExceptionClear(); |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
78 jclass ex = jEnv->FindClass("name/blackcap/exifwasher/exiv2/Exiv2Exception"); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
79 jEnv->ThrowNew(ex, "unable to read metadata"); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
80 return 0; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
81 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
82 return reinterpret_cast<jlong> (&(image->exifData())); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
83 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
84 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
85 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
86 * Class: name_blackcap_exifwasher_exiv2_Image |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
87 * Method: _dtor |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
88 * Signature: ()V |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
89 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
90 JNIEXPORT void JNICALL Java_name_blackcap_exifwasher_exiv2_Image__1dtor |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
91 (JNIEnv *jEnv, jobject jThis) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
92 Exiv2::Image *image = reinterpret_cast<Exiv2::Image *> (getPointer(jEnv, jThis)); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
93 if (jEnv->ExceptionCheck()) return; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
94 delete image; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
95 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
96 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
97 #ifdef __cplusplus |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
98 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
99 #endif |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
100 #endif |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
101 /* Header for class name_blackcap_exifwasher_exiv2_ExifData */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
102 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
103 #ifndef _Included_name_blackcap_exifwasher_exiv2_ExifData |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
104 #define _Included_name_blackcap_exifwasher_exiv2_ExifData |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
105 #ifdef __cplusplus |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
106 extern "C" { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
107 #endif |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
108 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
109 * Class: name_blackcap_exifwasher_exiv2_ExifData |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
110 * Method: _erase |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
111 * Signature: (Ljava/lang/String;)V |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
112 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
113 JNIEXPORT void JNICALL Java_name_blackcap_exifwasher_exiv2_ExifData__1erase |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
114 (JNIEnv *jEnv, jobject jThis, jstring key) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
115 Exiv2::ExifData *data = reinterpret_cast<Exiv2::ExifData *> (getPointer(jEnv, jThis)); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
116 if (jEnv->ExceptionCheck()) return; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
117 const char *cKey = jEnv->GetStringUTFChars(key, NULL); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
118 Exiv2::ExifData::iterator found = data->findKey(Exiv2::ExifKey(std::string(cKey))); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
119 try { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
120 data->erase(found); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
121 } catch (...) { |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
122 jEnv->ExceptionClear(); |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
123 jclass ex = jEnv->FindClass("name/blackcap/exifwasher/exiv2/Exiv2Exception"); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
124 const char *pfx = "unable to delete "; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
125 char *message = (char *) malloc(strlen(cKey) + strlen(pfx) + 1); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
126 strcpy(message, pfx); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
127 strcat(message, cKey); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
128 jEnv->ThrowNew(ex, message); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
129 free(message); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
130 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
131 jEnv->ReleaseStringUTFChars(key, cKey); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
132 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
133 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
134 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
135 * Class: name_blackcap_exifwasher_exiv2_ExifData |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
136 * Method: _value |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
137 * Signature: (Ljava/lang/String;)Lname/blackcap/exifwasher/exiv2/ExifData/Value; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
138 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
139 JNIEXPORT jobject JNICALL Java_name_blackcap_exifwasher_exiv2_ExifData__1value |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
140 (JNIEnv *jEnv, jobject jThis, jstring key) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
141 Exiv2::ExifData *data = reinterpret_cast<Exiv2::ExifData *> (getPointer(jEnv, jThis)); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
142 if (jEnv->ExceptionCheck()) return NULL; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
143 const char *cKey = jEnv->GetStringUTFChars(key, NULL); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
144 Exiv2::ExifData::const_iterator found = data->findKey(Exiv2::ExifKey(std::string(cKey))); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
145 jEnv->ReleaseStringUTFChars(key, cKey); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
146 if (found == data->end()) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
147 return NULL; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
148 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
149 jclass klass = jEnv->FindClass("name/blackcap/exifwasher/exiv2/ExifData$Value"); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
150 if (jEnv->ExceptionCheck()) return NULL; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
151 jstring type = jEnv->NewStringUTF(found->typeName()); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
152 jstring value = jEnv->NewStringUTF(found->toString().c_str()); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
153 jmethodID method = jEnv->GetMethodID(klass, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V"); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
154 if (jEnv->ExceptionCheck()) return NULL; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
155 return jEnv->NewObject(klass, method, type, value); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
156 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
157 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
158 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
159 * Class: name_blackcap_exifwasher_exiv2_ExifData |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
160 * Method: _keys |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
161 * Signature: ()[Ljava/lang/String; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
162 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
163 JNIEXPORT jobjectArray JNICALL Java_name_blackcap_exifwasher_exiv2_ExifData__1keys |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
164 (JNIEnv *jEnv, jobject jThis) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
165 Exiv2::ExifData *data = reinterpret_cast<Exiv2::ExifData *> (getPointer(jEnv, jThis)); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
166 if (jEnv->ExceptionCheck()) return NULL; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
167 jclass klass = jEnv->FindClass("java/lang/String"); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
168 if (jEnv->ExceptionCheck()) return NULL; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
169 jobjectArray ret = jEnv->NewObjectArray(data->count(), klass, NULL); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
170 if (jEnv->ExceptionCheck()) return NULL; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
171 Exiv2::ExifData::const_iterator end = data->end(); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
172 jsize j = 0; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
173 for (Exiv2::ExifData::const_iterator i = data->begin(); i != end; ++i) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
174 jEnv->SetObjectArrayElement(ret, j++, jEnv->NewStringUTF(i->key().c_str())); |
1
42277ce58ace
Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
175 if (jEnv->ExceptionCheck()) break; |
0
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
176 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
177 return ret; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
178 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
179 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
180 #ifdef __cplusplus |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
181 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
182 #endif |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
183 #endif |