Project

Profile

Help

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

he / latest9.6 / hec / Saxon.C.API / PEC / SaxonCGlue.h @ f62330e8

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 bool;
37
static const bool false = 0;
38
static const bool 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
        "/libsaxonpec.so";  
61
    #elif  defined (__APPLE__) && defined(__MACH__)
62
        "/libsaxonpec.dylib";
63
    #else
64
         "\\libsaxonpec.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
    #ifdef __linux__
79
        "/usr/lib/libsaxonhec.so";  //rename according to product edition (hec or pec) Also make change in the c file
80
    #elif  defined (__APPLE__) && defined(__MACH__)
81
        "/usr/lib/libsaxoneec.dylib";
82
    #else
83
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.1\\libsaxonhec.dll";
84
    #endif*/
85

    
86
static char *resources_dir;/*[] = 
87
     #ifdef __linux__
88
        "/usr/lib/saxon-data";
89
    #elif  defined (__APPLE__) && defined(__MACH__)
90
        "/usr/lib/saxon-data";
91
    #else
92
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.1\\saxon-data";
93
    #endif*/
94

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

    
98

    
99
//===============================================================================================//
100
/*! <code>Environment</code>. This struct captures the jni, JVM and handler to the cross compiled Saxon/C library.
101
 * <p/>
102
 */
103
typedef struct {
104
                JNIEnv *env;
105
                HANDLE myDllHandle;
106
                JavaVM *jvm;
107
        } sxnc_environment;
108

    
109

    
110
//===============================================================================================//
111

    
112
/*! <code>sxnc_parameter</code>. This struct captures details of paramaters used for the transformation as (string, value) pairs.
113
 * <p/>
114
 */
115
typedef struct {
116
                char* name;
117
                jobject value;
118
        } sxnc_parameter;
119

    
120
//===============================================================================================//
121

    
122
/*! <code>sxnc_property</code>. This struct captures details of properties used for the transformation as (string, string) pairs.
123
 * <p/>
124
 */
125
typedef struct {
126
                char * name;
127
                char * value;
128
        } sxnc_property;
129

    
130

    
131

    
132
extern jobject cpp;
133

    
134

    
135

    
136
extern const char * failure;
137

    
138

    
139
/*
140
* Get Dll name.
141
*/
142

    
143
char * getDllname();
144

    
145

    
146
/*
147
* Get Dll name.
148
*/
149

    
150
char * getResourceDirectory();
151

    
152
/*
153
* Set Dll name. Also set the saxon resources directory. 
154
* If the SAXON_HOME environmental variable is set then use that as base.
155
*/
156
void setDllname();
157

    
158
/*
159
 * Load dll using the default setting in Saxon/C
160
 * Recommended method to use to load library
161
 */
162
HANDLE loadDefaultDll();
163

    
164

    
165
/*
166
 * Load dll.
167
 * name - The dll library
168
 */
169
HANDLE loadDll(char* name);
170

    
171

    
172
extern jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
173

    
174
extern jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
175

    
176
/*
177
 * Initialize JET run-time with simplified method. The initJavaRT method will be called 
178
 * with the arguments expanded from environ
179
 * @param environ - the Evironment is passed
180
 */
181
void initDefaultJavaRT(sxnc_environment ** environ);
182

    
183

    
184
/*
185
 * Initialize JET run-time.
186
 */
187
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv);
188

    
189

    
190
/*
191
 * Look for class.
192
 */
193
jclass lookForClass (JNIEnv* penv, const char* name);
194

    
195

    
196
/*
197
 * Create an object and invoke the instance method
198
 */
199
void invokeInstanceMethod (JNIEnv* penv, jclass myClassInDll, char * name, char * arguments);
200

    
201

    
202

    
203

    
204
/*
205
 * Invoke the static method
206
 */
207
void invokeStaticMethod(JNIEnv* penv, jclass myClassInDll, char* name, char* arguments);
208

    
209

    
210
/*
211
 * Find a constructor with a set arguments
212
 */
213
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments);
214

    
215
/*
216
 * Create the Java SaxonProcessor
217
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
218
 */
219
jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean licensei);
220

    
221
/*
222
 * Create the Java SaxonProcessor
223
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
224
 */
225
jobject createSaxonProcessor2 (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1);
226

    
227
/*
228
 * Callback to check for exceptions. When called it returns the exception as a string 
229
 */
230
const char * checkForException(sxnc_environment environ, jclass callingClass,  jobject callingObject);
231

    
232
/*
233
 * Clean up and destroy Java VM to release memory used. 
234
 */
235
void finalizeJavaRT (JavaVM* jvm);
236

    
237

    
238
/*
239
 * Get a parameter from list 
240
 */
241
jobject getParameter(sxnc_parameter *parameters,  int parLen, const char* namespacei, const char * name);
242

    
243
/*
244
 * Get a property from list 
245
 */
246
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name);
247

    
248

    
249
/*
250
 * set a parameter 
251
 */
252
void setParameter(sxnc_parameter **parameters, int *parLen, int *parCap, const char * namespacei, const char * name, jobject value);
253

    
254

    
255
/*
256
 * set a property 
257
 */
258
void setProperty(sxnc_property ** properties, int *propLen, int *propCap, const char* name, const char* value);
259

    
260
/*
261
 * clear parameter 
262
 */
263
void clearSettings(sxnc_parameter **parameters, int *parLen, sxnc_property ** properties, int *propLen);
264

    
265

    
266

    
267
const char * stringValue(sxnc_environment environ, jobject value);
268

    
269
EXTERN_C_END
270

    
271

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