Project

Profile

Help

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

he / tags / 9.8.0.14 / hec / Saxon.C.API / SaxonCGlue.h @ 02f8308b

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

    
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
#define HANDLE void*
21
#define LoadLibrary(x) dlopen(x, RTLD_LAZY)
22
#define GetProcAddress(x,y) dlsym(x,y)
23
#else
24
#include <windows.h>
25
#endif
26

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

    
35
#ifndef __cplusplus
36
#ifndef _BOOL
37
typedef unsigned char bool;
38
static const bool false = 0;
39
static const bool true = 1;
40
#else
41
static const bool false = 0;
42
static const bool true = 1;
43
#endif
44
#endif
45

    
46
#ifndef __cplusplus 
47
        #if defined(LICENSE)
48
                #define license true;
49
        #else
50
                #define license false
51
        #endif
52
#endif
53

    
54

    
55
//#define DEBUG
56

    
57

    
58
EXTERN_C
59

    
60

    
61

    
62

    
63

    
64

    
65
 
66

    
67
static char tempDllname[] =
68
#if defined (__linux__)
69
        "/libsaxonhec.so";  
70
    #elif  defined (__APPLE__) && defined(__MACH__)
71
        "/libsaxonhec.dylib";
72
    #else
73
         "\\libsaxonhec.dll";
74
    #endif
75

    
76
static char tempResources_dir[] = 
77
     #ifdef __linux__
78
        "/saxon-data";
79
    #elif  defined (__APPLE__) && defined(__MACH__)
80
        "/saxon-data";
81
    #else
82
         "\\saxon-data";
83
    #endif
84

    
85

    
86
static char * dllname;/*[] =
87
    #ifdef __linux__
88
        "/usr/lib/libsaxonhec.so";  //rename according to product edition (hec or pec) Also make change in the c file
89
    #elif  defined (__APPLE__) && defined(__MACH__)
90
        "/usr/lib/libsaxoneec.dylib";
91
    #else
92
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.1\\libsaxonhec.dll";
93
    #endif*/
94

    
95
static char *resources_dir;/*[] = 
96
     #ifdef __linux__
97
        "/usr/lib/saxon-data";
98
    #elif  defined (__APPLE__) && defined(__MACH__)
99
        "/usr/lib/saxon-data";
100
    #else
101
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.1\\saxon-data";
102
    #endif*/
103

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

    
107

    
108
//===============================================================================================//
109
/*! <code>Environment</code>. This struct captures the jni, JVM and handler to the cross compiled Saxon/C library.
110
 * <p/>
111
 */
112
typedef struct {
113
                JNIEnv *env;
114
                HANDLE myDllHandle;
115
                JavaVM *jvm;
116
        } sxnc_environment;
117

    
118

    
119
//===============================================================================================//
120

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

    
129
//===============================================================================================//
130

    
131
/*! <code>sxnc_property</code>. This struct captures details of properties used for the transformation as (string, string) pairs.
132
 * <p/>
133
 */
134
typedef struct {
135
                char * name;
136
                char * value;
137
        } sxnc_property;
138

    
139

    
140

    
141
extern jobject cpp;
142

    
143

    
144

    
145
extern const char * failure;
146

    
147

    
148
/*
149
* Get Dll name.
150
*/
151

    
152
char * getDllname();
153

    
154

    
155
/*
156
* Get Dll name.
157
*/
158

    
159
char * getResourceDirectory();
160

    
161
/*
162
* Set Dll name. Also set the saxon resources directory. 
163
* If the SAXON_HOME environmental variable is set then use that as base.
164
*/
165
void setDllname();
166

    
167
/*
168
 * Load dll using the default setting in Saxon/C
169
 * Recommended method to use to load library
170
 */
171
HANDLE loadDefaultDll();
172

    
173

    
174
/*
175
 * Load dll.
176
 * name - The dll library
177
 */
178
HANDLE loadDll(char* name);
179

    
180

    
181
extern jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
182

    
183
extern jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
184

    
185
/*
186
 * Initialize JET run-time with simplified method. The initJavaRT method will be called 
187
 * with the arguments expanded from environ
188
 * @param environ - the Evironment is passed
189
 */
190
void initDefaultJavaRT(sxnc_environment ** environ);
191

    
192

    
193
/*
194
 * Initialize JET run-time.
195
 */
196
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv);
197

    
198

    
199
/*
200
 * Look for class.
201
 */
202
jclass lookForClass (JNIEnv* penv, const char* name);
203

    
204

    
205
/*
206
 * Create an object and invoke the instance method
207
 */
208
void invokeInstanceMethod (JNIEnv* penv, jclass myClassInDll, char * name, char * arguments);
209

    
210

    
211

    
212

    
213
/*
214
 * Invoke the static method
215
 */
216
void invokeStaticMethod(JNIEnv* penv, jclass myClassInDll, char* name, char* arguments);
217

    
218

    
219
/*
220
 * Find a constructor with a set arguments
221
 */
222
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments);
223

    
224
/*
225
 * Create the Java SaxonProcessor
226
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
227
 */
228
jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean licensei);
229

    
230
/*
231
 * Create the Java SaxonProcessor
232
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
233
 */
234
jobject createSaxonProcessor2 (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1);
235

    
236
/*
237
 * Callback to check for exceptions. When called it returns the exception as a string 
238
 */
239
const char * checkForException(sxnc_environment environ, jclass callingClass,  jobject callingObject);
240

    
241
/*
242
 * Clean up and destroy Java VM to release memory used. 
243
 */
244
void finalizeJavaRT (JavaVM* jvm);
245

    
246

    
247
/*
248
 * Get a parameter from list 
249
 */
250
jobject getParameter(sxnc_parameter *parameters,  int parLen, const char* namespacei, const char * name);
251

    
252
/*
253
 * Get a property from list 
254
 */
255
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name);
256

    
257

    
258
/*
259
 * set a parameter 
260
 */
261
void setParameter(sxnc_parameter **parameters, int *parLen, int *parCap, const char * namespacei, const char * name, jobject value);
262

    
263

    
264
/*
265
 * set a property 
266
 */
267
void setProperty(sxnc_property ** properties, int *propLen, int *propCap, const char* name, const char* value);
268

    
269
/*
270
 * clear parameter 
271
 */
272
void clearSettings(sxnc_parameter **parameters, int *parLen, sxnc_property ** properties, int *propLen);
273

    
274

    
275

    
276
const char * stringValue(sxnc_environment environ, jobject value);
277

    
278
EXTERN_C_END
279

    
280

    
281
#endif //SAXONCGLUE_H
(6-6/45)