Mercurial > cgi-bin > hgweb.cgi > JpegWasher
annotate src/name/blackcap/exifwasher/exiv2/native.cpp @ 0:db63d01a23c6
JNI calls and test case (finally!) seem to work.
author | David Barts <n5jrn@me.com> |
---|---|
date | Tue, 31 Mar 2020 13:24:48 -0700 |
parents | |
children | 42277ce58ace |
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 (...) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
34 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
|
35 const char *pfx = "unable to open "; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
36 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
|
37 strcpy(message, pfx); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
38 strcat(message, cPath); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
39 jEnv->ThrowNew(ex, message); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
40 free(message); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
41 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
42 jEnv->ReleaseStringUTFChars(path, cPath); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
43 return ret; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
44 } |
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 * Class: name_blackcap_exifwasher_exiv2_Image |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
48 * Method: _writeMetadata |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
49 * Signature: ()V |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
50 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
51 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
|
52 (JNIEnv *jEnv, jobject jThis) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
53 Exiv2::Image *image = reinterpret_cast<Exiv2::Image *> (getPointer(jEnv, jThis)); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
54 try { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
55 image->writeMetadata(); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
56 } catch (...) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
57 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
|
58 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
|
59 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
60 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
61 |
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 * Class: name_blackcap_exifwasher_exiv2_Image |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
64 * Method: _getMetadata |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
65 * Signature: ()J |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
66 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
67 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
|
68 (JNIEnv *jEnv, jobject jThis) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
69 Exiv2::Image *image = reinterpret_cast<Exiv2::Image *> (getPointer(jEnv, jThis)); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
70 try { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
71 image->readMetadata(); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
72 } catch (...) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
73 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
|
74 jEnv->ThrowNew(ex, "unable to read metadata"); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
75 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
76 return reinterpret_cast<jlong> (&(image->exifData())); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
77 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
78 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
79 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
80 * Class: name_blackcap_exifwasher_exiv2_Image |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
81 * Method: _dtor |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
82 * Signature: ()V |
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 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
|
85 (JNIEnv *jEnv, jobject jThis) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
86 Exiv2::Image *image = reinterpret_cast<Exiv2::Image *> (getPointer(jEnv, jThis)); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
87 delete image; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
88 } |
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 #ifdef __cplusplus |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
91 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
92 #endif |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
93 #endif |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
94 /* 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
|
95 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
96 #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
|
97 #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
|
98 #ifdef __cplusplus |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
99 extern "C" { |
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 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
102 * Class: name_blackcap_exifwasher_exiv2_ExifData |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
103 * Method: _erase |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
104 * Signature: (Ljava/lang/String;)V |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
105 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
106 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
|
107 (JNIEnv *jEnv, jobject jThis, jstring key) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
108 Exiv2::ExifData *data = reinterpret_cast<Exiv2::ExifData *> (getPointer(jEnv, jThis)); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
109 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
|
110 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
|
111 try { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
112 data->erase(found); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
113 } catch (...) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
114 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
|
115 const char *pfx = "unable to delete "; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
116 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
|
117 strcpy(message, pfx); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
118 strcat(message, cKey); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
119 jEnv->ThrowNew(ex, message); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
120 free(message); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
121 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
122 jEnv->ReleaseStringUTFChars(key, cKey); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
123 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
124 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
125 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
126 * Class: name_blackcap_exifwasher_exiv2_ExifData |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
127 * Method: _value |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
128 * 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
|
129 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
130 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
|
131 (JNIEnv *jEnv, jobject jThis, jstring key) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
132 Exiv2::ExifData *data = reinterpret_cast<Exiv2::ExifData *> (getPointer(jEnv, jThis)); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
133 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
|
134 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
|
135 jEnv->ReleaseStringUTFChars(key, cKey); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
136 if (found == data->end()) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
137 return NULL; |
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 jclass klass = jEnv->FindClass("name/blackcap/exifwasher/exiv2/ExifData$Value"); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
140 jstring type = jEnv->NewStringUTF(found->typeName()); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
141 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
|
142 jmethodID method = jEnv->GetMethodID(klass, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V"); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
143 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
|
144 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
145 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
146 /* |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
147 * Class: name_blackcap_exifwasher_exiv2_ExifData |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
148 * Method: _keys |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
149 * Signature: ()[Ljava/lang/String; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
150 */ |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
151 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
|
152 (JNIEnv *jEnv, jobject jThis) { |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
153 Exiv2::ExifData *data = reinterpret_cast<Exiv2::ExifData *> (getPointer(jEnv, jThis)); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
154 jclass klass = jEnv->FindClass("java/lang/String"); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
155 jobjectArray ret = jEnv->NewObjectArray(data->count(), klass, NULL); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
156 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
|
157 jsize j = 0; |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
158 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
|
159 jEnv->SetObjectArrayElement(ret, j++, jEnv->NewStringUTF(i->key().c_str())); |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
160 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
161 return ret; |
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 |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
164 #ifdef __cplusplus |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
165 } |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
166 #endif |
db63d01a23c6
JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
167 #endif |