Saxon/C  1.1.2
Saxon Processor library for C/C++/PHP
 All Classes Functions Variables
SaxonCGlue.h
1 // Copyright (c) 2016 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
7 
8 
9 #ifndef SAXONCGLUE_H
10 #define SAXONCGLUE_H
11 #include <jni.h>
12 
13 
14 #if defined __linux__ || defined __APPLE__
15 #include <stdlib.h>
16 #include <string.h>
17 #include <dlfcn.h>
18 #include <stdio.h>
19 
20 
21 #define HANDLE void*
22 #define LoadLibrary(x) dlopen(x, RTLD_LAZY)
23 #define GetProcAddress(x,y) dlsym(x,y)
24 #else
25 #include <windows.h>
26 #endif
27 
28 #ifdef __cplusplus
29 #define EXTERN_SAXONC extern "C" {
30 #define EXTERN_SAXONC_END }
31 #else
32 #define EXTERN_SAXONC
33 #define EXTERN_SAXONC_END
34 #endif
35 
36 
37 #ifndef __cplusplus
38 #ifndef _BOOL
39 #include <stdbool.h>
40 /*typedef unsigned char sxn_bool;
41 static const sxn_bool sxn_false = 0;
42 static const sxn_bool sxn_true = 1;*/
43 
44 #else
45 //typedef bool sxn_bool;
46 static const bool false = 0;
47 static const bool true = 1;
48 #endif
49 #endif
50 
51 
52 
53 #ifndef __cplusplus
54  #if defined(LICENSE)
55  #define sxn_license 1
56  #else
57  #define sxn_license 0
58  #endif
59 #endif
60 
61 
62 //#define DEBUG
63 
64 
65 EXTERN_SAXONC
66 
67 
68 extern char * dllname;
69 
70 extern char * resources_dir;
71 
72 // Static variable used to track when jvm has been created. Used to prevent creation more than once.
73 extern int jvmCreated;
74 
75 
76 //===============================================================================================//
80 typedef struct {
81  JNIEnv *env;
82  HANDLE myDllHandle;
83  JavaVM *jvm;
85 
86 
87 //===============================================================================================//
88 
92 typedef struct {
93  char* name;
94  jobject value;
95  char * namespacei; //not used yet
97 
98 //===============================================================================================//
99 
103 typedef struct {
104  char * name;
105  char * value;
106  } sxnc_property;
107 
108 
109 
110 extern jobject cpp;
111 
112 
113 
114 extern const char * failure;
115 
116 
117 /*
118 * Get Dll name.
119 */
120 
121 char * getDllname();
122 
123 
124 /*
125 * Get resources directory.
126 */
127 
128 char * getResourceDirectory();
129 
130 /*
131 * Get resources directory. This is to replace getResourceDirectory().
132 */
133 
134 char * _getResourceDirectory();
135 
136 /*
137 * Set Dll name. Also set the saxon resources directory.
138 * If the SAXON_HOME environmental variable is set then use that as base.
139 */
140 void setDllname();
141 
142 /*
143  * Load dll using the default setting in Saxon/C
144  * Recommended method to use to load library
145  */
146 HANDLE loadDefaultDll();
147 
148 
149 /*
150  * Load dll.
151  * name - The dll library
152  */
153 HANDLE loadDll(char* name);
154 
155 
156 extern jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
157 
158 extern jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
159 
160 /*
161  * Initialize JET run-time with simplified method. The initJavaRT method will be called
162  * with the arguments expanded from environ
163  * @param environ - the Evironment is passed
164  */
165 void initDefaultJavaRT(sxnc_environment ** environ);
166 
167 
168 /*
169  * Initialize JET run-time.
170  */
171 void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv);
172 
173 
174 /*
175  * Look for class.
176  */
177 jclass lookForClass (JNIEnv* penv, const char* name);
178 
179 
180 /*
181  * Create an object and invoke the instance method
182  */
183 void invokeInstanceMethod (JNIEnv* penv, jclass myClassInDll, char * name, char * arguments);
184 
185 
186 
187 
188 /*
189  * Invoke the static method
190  */
191 void invokeStaticMethod(JNIEnv* penv, jclass myClassInDll, char* name, char* arguments);
192 
193 
194 /*
195  * Find a constructor with a set arguments
196  */
197 jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments);
198 
199 /*
200  * Create the Java SaxonProcessor
201  * This can be used to pass the sub-classes of SaxonAPI, there the argument1 should can be null or Processor object
202  */
203 jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean licensei);
204 
205 /*
206  * Create the Java SaxonProcessor
207  * This can be used to pass the sub-classes of SaxonAPI, there the argument1 should can be null or Processor object
208  */
209 jobject createSaxonProcessor2 (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1);
210 
211 /*
212  * Callback to check for exceptions. When called it returns the exception as a string
213  */
214 const char * checkForException(sxnc_environment environ, jobject callingObject);
215 
216 /*
217  * Clean up and destroy Java VM to release memory used.
218  */
219 void finalizeJavaRT (JavaVM* jvm);
220 
221 
222 /*
223  * Get a parameter from list
224  */
225 jobject getParameter(sxnc_parameter *parameters, int parLen, const char* namespacei, const char * name);
226 
227 /*
228  * Get a property from list
229  */
230 char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name);
231 
232 
233 /*
234  * set a parameter
235  */
236 void setParameter(sxnc_parameter **parameters, int *parLen, int *parCap, const char * namespacei, const char * name, jobject value);
237 
238 
239 /*
240  * set a property
241  */
242 void setProperty(sxnc_property ** properties, int *propLen, int *propCap, const char* name, const char* value);
243 
244 /*
245  * clear parameter
246  */
247 void clearSettings(sxnc_parameter **parameters, int *parLen, sxnc_property ** properties, int *propLen);
248 
249 
250 
251 const char * stringValue(sxnc_environment environ, jobject value);
252 
253 EXTERN_SAXONC_END
254 
255 
256 #endif //SAXONCGLUE_H
Definition: SaxonCGlue.h:80
Definition: SaxonCGlue.h:103
Definition: SaxonCGlue.h:92