Project

Profile

Help

How to connect?
Download (5.83 KB) Statistics
| Branch: | Tag: | Revision:

he / latest9.6 / hec / Saxon.C.API / 64-bit-code / EEC / SaxonCGlue.h @ fa554ba5

1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// 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.
6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7

    
8
#ifndef SAXONCGLUE_H
9
#define SAXONCGLUE_H
10
#include <jni.h>
11

    
12

    
13
#if defined __linux__ || defined __APPLE__
14
#include <stdlib.h>
15
#include <string.h>
16
#include <dlfcn.h>
17

    
18

    
19
#define HANDLE void*
20
#define LoadLibrary(x) dlopen(x, RTLD_LAZY)
21
#define GetProcAddress(x,y) dlsym(x,y)
22
#else
23
#include <windows.h>
24
#endif
25

    
26
#ifdef __cplusplus
27
#define EXTERN_C extern "C" {
28
#define EXTERN_C_END }
29
#else
30
#define EXTERN_C
31
#define EXTERN_C_END
32
#endif
33

    
34
#ifndef __cplusplus
35
#ifndef _BOOL
36
typedef unsigned char booli;
37
static const booli __false = 0;
38
static const booli __true = 1;
39
#endif
40
#endif
41

    
42
#ifndef __cplusplus
43
#if defined(LICENSE)
44
#define license __true;
45
#else
46
#define license __false
47
#endif
48
#endif
49

    
50

    
51
//#define DEBUG
52

    
53

    
54
EXTERN_C
55

    
56

    
57

    
58
static char tempDllname[] =
59
#if defined (__linux__)
60
"/libsaxoneec.so";
61
#elif  defined (__APPLE__) && defined(__MACH__)
62
"/libsaxoneec.dylib";
63
#else
64
"\\libsaxoneec.dll";
65
#endif
66

    
67
static char tempResources_dir[] =
68
#ifdef __linux__
69
"/saxon-data";
70
#elif  defined (__APPLE__) && defined(__MACH__)
71
"/saxon-data";
72
#else
73
"\\saxon-data";
74
#endif
75

    
76

    
77
static char * dllname;
78

    
79
static char *resources_dir;
80

    
81
// Static variable used to track when jvm has been created. Used to prevent creation more than once.
82
static int jvmCreated =0;
83

    
84

    
85
//===============================================================================================//
86
/*! <code>Environment</code>. This struct captures the jni, JVM and handler to the cross compiled Saxon/C library.
87
 * <p/>
88
 */
89
typedef struct {
90
    JNIEnv *env;
91
    HANDLE myDllHandle;
92
    JavaVM *jvm;
93
} sxnc_environment;
94

    
95

    
96
//===============================================================================================//
97

    
98
/*! <code>sxnc_parameter</code>. This struct captures details of paramaters used for the transformation as (string, value) pairs.
99
 * <p/>
100
 */
101
typedef struct {
102
    char* name;
103
    jobject value;
104
} sxnc_parameter;
105

    
106
//===============================================================================================//
107

    
108
/*! <code>sxnc_property</code>. This struct captures details of properties used for the transformation as (string, string) pairs.
109
 * <p/>
110
 */
111
typedef struct {
112
    char * name;
113
    char * value;
114
} sxnc_property;
115

    
116

    
117

    
118
extern jobject cpp;
119

    
120

    
121

    
122
extern const char * failure;
123

    
124

    
125
/*
126
 * Get Dll name.
127
 */
128

    
129
char * getDllname();
130

    
131

    
132
/*
133
 * Get Dll name.
134
 */
135

    
136
char * getResourceDirectory();
137

    
138
/*
139
 * Set Dll name. Also set the saxon resources directory.
140
 * If the SAXON_HOME environmental variable is set then use that as base.
141
 */
142
void setDllname();
143

    
144
/*
145
 * Load dll using the default setting in Saxon/C
146
 * Recommended method to use to load library
147
 */
148
HANDLE loadDefaultDll();
149

    
150

    
151
/*
152
 * Load dll.
153
 * name - The dll library
154
 */
155
HANDLE loadDll(char* name);
156

    
157

    
158
extern jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
159

    
160
extern jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
161

    
162
/*
163
 * Initialize JET run-time with simplified method. The initJavaRT method will be called
164
 * with the arguments expanded from environ
165
 * @param environ - the Evironment is passed
166
 */
167
void initDefaultJavaRT(sxnc_environment ** environ);
168

    
169

    
170
/*
171
 * Initialize JET run-time.
172
 */
173
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv);
174

    
175

    
176
/*
177
 * Look for class.
178
 */
179
jclass lookForClass (JNIEnv* penv, const char* name);
180

    
181

    
182
/*
183
 * Create an object and invoke the instance method
184
 */
185
void invokeInstanceMethod (JNIEnv* penv, jclass myClassInDll, char * name, char * arguments);
186

    
187

    
188

    
189

    
190
/*
191
 * Invoke the static method
192
 */
193
void invokeStaticMethod(JNIEnv* penv, jclass myClassInDll, char* name, char* arguments);
194

    
195

    
196
/*
197
 * Find a constructor with a set arguments
198
 */
199
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments);
200

    
201
/*
202
 * Create the Java SaxonProcessor
203
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
204
 */
205
jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean licensei);
206

    
207
/*
208
 * Create the Java SaxonProcessor
209
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
210
 */
211
jobject createSaxonProcessor2 (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1);
212

    
213
/*
214
 * Callback to check for exceptions. When called it returns the exception as a string
215
 */
216
const char * checkForException(sxnc_environment environ, jclass callingClass,  jobject callingObject);
217

    
218
/*
219
 * Clean up and destroy Java VM to release memory used.
220
 */
221
void finalizeJavaRT (JavaVM* jvm);
222

    
223

    
224
/*
225
 * Get a parameter from list
226
 */
227
jobject getParameter(sxnc_parameter *parameters,  int parLen, const char* namespacei, const char * name);
228

    
229
/*
230
 * Get a property from list
231
 */
232
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name);
233

    
234

    
235
/*
236
 * set a parameter
237
 */
238
void setParameter(sxnc_parameter **parameters, int *parLen, int *parCap, const char * namespacei, const char * name, jobject value);
239

    
240

    
241
/*
242
 * set a property
243
 */
244
void setProperty(sxnc_property ** properties, int *propLen, int *propCap, const char* name, const char* value);
245

    
246
/*
247
 * clear parameter
248
 */
249
void clearSettings(sxnc_parameter **parameters, int *parLen, sxnc_property ** properties, int *propLen);
250

    
251

    
252

    
253
const char * stringValue(sxnc_environment environ, jobject value);
254

    
255
EXTERN_C_END
256

    
257

    
258
#endif //SAXONCGLUE_H
(2-2/3)