Project

Profile

Help

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

he / latest9.6 / hec / Saxon.C.API / EEC / SaxonCGlue.h @ 0e42f323

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

    
59
static char dllname[] =
60
    #ifdef __linux__
61
        "/usr/lib/libsaxoneec.so";  //rename according to product edition (hec or pec) Also make change in the c file
62
    #elif  defined (__APPLE__) && defined(__MACH__)
63
        "/usr/lib/libsaxoneec.dylib";
64
    #else
65
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.1\\libsaxoneec.dll";
66
    #endif
67

    
68
static char resources_dir[] = 
69
     #ifdef __linux__
70
        "/usr/lib/saxon-data";
71
    #elif  defined (__APPLE__) && defined(__MACH__)
72
        "/usr/lib/saxon-data";
73
    #else
74
         "C:\\Program Files\\Saxonica\\SaxonHEC1.0.1\\saxon-data";
75
    #endif
76

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

    
80

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

    
91

    
92
//===============================================================================================//
93

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

    
102
//===============================================================================================//
103

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

    
112

    
113

    
114
extern jobject cpp;
115

    
116

    
117

    
118
extern const char * failure;
119

    
120

    
121
/*
122
* Get Dll name.
123
*/
124

    
125
char * getDllname();
126

    
127

    
128
/*
129
* Set Dll name. Also set the saxon resources directory. 
130
* If the SAXON_HOME environmental variable is set then use that as base.
131
*/
132
void setDllname();
133

    
134
/*
135
 * Load dll using the default setting in Saxon/C
136
 * Recommended method to use to load library
137
 */
138
HANDLE loadDefaultDll();
139

    
140

    
141
/*
142
 * Load dll.
143
 * name - The dll library
144
 */
145
HANDLE loadDll(char* name);
146

    
147

    
148
extern jint (JNICALL * JNI_GetDefaultJavaVMInitArgs_func) (void *args);
149

    
150
extern jint (JNICALL * JNI_CreateJavaVM_func) (JavaVM **pvm, void **penv, void *args);
151

    
152
/*
153
 * Initialize JET run-time with simplified method. The initJavaRT method will be called 
154
 * with the arguments expanded from environ
155
 * @param environ - the Evironment is passed
156
 */
157
void initDefaultJavaRT(sxnc_environment ** environ);
158

    
159

    
160
/*
161
 * Initialize JET run-time.
162
 */
163
void initJavaRT(HANDLE myDllHandle, JavaVM** pjvm, JNIEnv** penv);
164

    
165

    
166
/*
167
 * Look for class.
168
 */
169
jclass lookForClass (JNIEnv* penv, const char* name);
170

    
171

    
172
/*
173
 * Create an object and invoke the instance method
174
 */
175
void invokeInstanceMethod (JNIEnv* penv, jclass myClassInDll, char * name, char * arguments);
176

    
177

    
178

    
179

    
180
/*
181
 * Invoke the static method
182
 */
183
void invokeStaticMethod(JNIEnv* penv, jclass myClassInDll, char* name, char* arguments);
184

    
185

    
186
/*
187
 * Find a constructor with a set arguments
188
 */
189
jmethodID findConstructor (JNIEnv* penv, jclass myClassInDll, char* arguments);
190

    
191
/*
192
 * Create the Java SaxonProcessor
193
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
194
 */
195
jobject createSaxonProcessor (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1, jboolean licensei);
196

    
197
/*
198
 * Create the Java SaxonProcessor
199
 * This can be used to pass the sub-classes of SaxonAPI, there the argument1  should can be null or Processor object
200
 */
201
jobject createSaxonProcessor2 (JNIEnv* penv, jclass myClassInDll, const char * arguments, jobject argument1);
202

    
203
/*
204
 * Callback to check for exceptions. When called it returns the exception as a string 
205
 */
206
const char * checkForException(sxnc_environment environ, jclass callingClass,  jobject callingObject);
207

    
208
/*
209
 * Clean up and destroy Java VM to release memory used. 
210
 */
211
void finalizeJavaRT (JavaVM* jvm);
212

    
213

    
214
/*
215
 * Get a parameter from list 
216
 */
217
jobject getParameter(sxnc_parameter *parameters,  int parLen, const char* namespacei, const char * name);
218

    
219
/*
220
 * Get a property from list 
221
 */
222
char* getProperty(sxnc_property * properties, int propLen, const char* namespacei, const char * name);
223

    
224

    
225
/*
226
 * set a parameter 
227
 */
228
void setParameter(sxnc_parameter **parameters, int *parLen, int *parCap, const char * namespacei, const char * name, jobject value);
229

    
230

    
231
/*
232
 * set a property 
233
 */
234
void setProperty(sxnc_property ** properties, int *propLen, int *propCap, const char* name, const char* value);
235

    
236
/*
237
 * clear parameter 
238
 */
239
void clearSettings(sxnc_parameter **parameters, int *parLen, sxnc_property ** properties, int *propLen);
240

    
241

    
242

    
243
const char * stringValue(sxnc_environment environ, jobject value);
244

    
245
EXTERN_C_END
246

    
247

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