source: main/trunk/greenstone2/common-src/indexers/mgpp/jni/MGPPPassesWrapperImpl.cpp@ 26660

Last change on this file since 26660 was 26660, checked in by davidb, 9 years ago

Support for cross-compilation added. This particular set of changes focus on flags that assist cross-compilation with JNI

  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/*
2 * MGPassesWrapperImpl.c
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21#include <jni.h>
22
23#ifdef __MINGW32__
24
25/* Cross compiling for Windows
26 Want the type definitions in *win32* version of jni_md.h but
27 this then leads to C-mangled style functions which we *don't*
28 want. The following achieves this */
29
30#undef JNIEXPORT
31#undef JNIIMPORT
32#undef JNICALL
33
34#define JNIEXPORT
35#define JNIIMPORT
36#define JNICALL
37#endif
38
39#include <assert.h>
40#include "sysfuncs.h"
41#include "org_greenstone_mgpp_MGPPPassesWrapper.h"
42
43#include "mgpp_passes_4jni.h"
44#include "mg_files.h"
45
46/* if we need to use java objects, we should initialise their field ids here*/
47JNIEXPORT void JNICALL
48Java_org_greenstone_mgpp_MGPPPassesWrapper_initIDs(JNIEnv *j_env, jclass j_cls)
49{
50 return;
51}
52
53JNIEXPORT jboolean JNICALL
54Java_org_greenstone_mgpp_MGPPPassesWrapper_initCSide(JNIEnv *j_env, jobject j_obj)
55{
56 clear_variables();
57 return true;
58}
59
60/* add a pass type T1, T2, I1, I2, S */
61JNIEXPORT void JNICALL
62Java_org_greenstone_mgpp_MGPPPassesWrapper_addPass(JNIEnv *j_env,
63 jobject j_obj,
64 jchar j_pass_type,
65 jchar j_pass_num)
66{
67 /* get the level as a c char */
68 const char pass_type = j_pass_type;
69 const char pass_num = j_pass_num;
70 add_pass(pass_type, pass_num);
71
72}
73
74/* Set the filename */
75JNIEXPORT void JNICALL
76Java_org_greenstone_mgpp_MGPPPassesWrapper_setFileName(JNIEnv *j_env,
77 jobject j_obj,
78 jstring j_filename)
79{
80 /* Get the filename as a C string */
81 const char* filename = j_env->GetStringUTFChars(j_filename, NULL);
82
83 assert(filename != NULL);
84 set_filename(filename);
85
86 /* Release the string */
87 j_env->ReleaseStringUTFChars(j_filename, filename);
88
89}
90
91/* Set the base path */
92JNIEXPORT void JNICALL
93Java_org_greenstone_mgpp_MGPPPassesWrapper_setBasePath(JNIEnv *j_env,
94 jobject j_obj,
95 jstring j_basepath)
96{
97 /* Get the base_path as a C string */
98 const char* basepath = j_env->GetStringUTFChars(j_basepath, NULL);
99 assert(basepath != NULL);
100
101 set_basepath(basepath);
102
103 /* Release the string */
104 j_env->ReleaseStringUTFChars(j_basepath, basepath);
105
106}
107
108/* set the Document tag */
109JNIEXPORT void JNICALL
110Java_org_greenstone_mgpp_MGPPPassesWrapper_setDocumentTag(JNIEnv *j_env,
111 jobject j_obj,
112 jstring j_tag)
113{
114 const char* tag = j_env->GetStringUTFChars(j_tag, NULL);
115
116 set_document_tag(tag);
117 /* Release the string */
118 j_env->ReleaseStringUTFChars(j_tag, tag);
119
120
121}
122
123/* add a level tag */
124JNIEXPORT void JNICALL
125Java_org_greenstone_mgpp_MGPPPassesWrapper_addLevelTag(JNIEnv *j_env,
126 jobject j_obj,
127 jstring j_tag)
128{
129 const char* tag = j_env->GetStringUTFChars(j_tag, NULL);
130 add_level_tag(tag);
131
132 /* Release the string */
133 j_env->ReleaseStringUTFChars(j_tag, tag);
134
135}
136
137/* set the index level (default word level) */
138JNIEXPORT void JNICALL
139Java_org_greenstone_mgpp_MGPPPassesWrapper_setIndexLevel(JNIEnv *j_env,
140 jobject j_obj,
141 jstring j_tag)
142{
143 const char* tag = j_env->GetStringUTFChars(j_tag, NULL);
144 set_index_level(tag);
145
146 /* Release the string */
147 j_env->ReleaseStringUTFChars(j_tag, tag);
148
149
150}
151
152
153/** Maximum amount of memory to use for the index pass-2 file
154 inversion in megabytes.
155*/
156JNIEXPORT void JNICALL
157Java_org_greenstone_mgpp_MGPPPassesWrapper_setInversionMemLimit(JNIEnv *j_env,
158 jobject j_obj,
159 jint j_limit) {
160 int limit = j_limit;
161 set_inversion_limit(limit);
162}
163
164
165/* initialise the pass through the documents. must be called after all
166 the set methods
167*/
168JNIEXPORT jboolean JNICALL
169Java_org_greenstone_mgpp_MGPPPassesWrapper_init(JNIEnv *j_env,
170 jobject j_obj) {
171
172 init_driver();
173 return true;
174}
175
176
177/* process one or more documents */
178JNIEXPORT jboolean JNICALL
179Java_org_greenstone_mgpp_MGPPPassesWrapper_processMGPPDocument(JNIEnv *j_env,
180 jobject j_obj,
181 jbyteArray j_doc_text) {
182 /* Get the text as a C string */
183 int length = j_env->GetArrayLength(j_doc_text);
184 u_char * text_buffer = (u_char *)j_env->GetByteArrayElements(j_doc_text, NULL);
185 process_document(text_buffer, length);
186 /* Release the string */
187 // why doesn't this work in c++ when it works in C?????
188 //j_env->ReleaseByteArrayElements(j_doc_text, text_buffer, 0);
189 return true;
190}
191
192/* finalise the pass through the documents */
193JNIEXPORT jboolean JNICALL
194Java_org_greenstone_mgpp_MGPPPassesWrapper_finish(JNIEnv *j_env,
195 jobject j_obj) {
196
197 finalise_driver();
198 return true;
199}
200
201/** get the exit value once finished */
202JNIEXPORT jint JNICALL
203Java_org_greenstone_mgpp_MGPPPassesWrapper_exitValue(JNIEnv *j_env,
204 jobject j_obj) {
205
206 return get_exit_value();
207}
Note: See TracBrowser for help on using the repository browser.