1 karl 1.18 //%2006////////////////////////////////////////////////////////////////////////
|
2 schuur 1.1 //
|
3 karl 1.7 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 schuur 1.1 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.8 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.18 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 schuur 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 mark.hamzy 1.20 //
|
21 schuur 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #ifndef _Provider_JMPIImpl_h
35 #define _Provider_JMPIImpl_h
36
|
37 mark.hamzy 1.24 #include <Pegasus/Common/Config.h>
38
|
39 mark.hamzy 1.10 #include <jni.h>
|
40 mark.hamzy 1.24
41 #ifdef PEGASUS_PLATFORM_LINUX_GENERIC_GNU
42 #if defined (__GNUC__) && GCC_VERSION >= 40000
43 // If gcc is compiled with -fvisibility=hidden then JMPI is broken. This is because
44 // the JNI h file defines JNIEXPORT as empty since the default is visible.
45 #undef JNIEXPORT
46 #define JNIEXPORT __attribute__ ((visibility("default")))
47 #endif
48 #endif
49
|
50 schuur 1.1 #include <stdio.h>
51 #include <stdlib.h>
52 #include <string.h>
53
54 #include <Pegasus/Common/String.h>
55 #include <Pegasus/Common/System.h>
|
56 mark.hamzy 1.11 #include <Pegasus/Common/HashTable.h>
|
57 mark.hamzy 1.19 #include <Pegasus/Common/CIMType.h>
|
58 mark.hamzy 1.17 #include <Pegasus/Common/Mutex.h>
|
59 mark.hamzy 1.26 #include <Pegasus/ProviderManager2/JMPI/Linkage.h>
|
60 schuur 1.1
61 PEGASUS_NAMESPACE_BEGIN
62
63 #define NULL_CHECK0(e) if ((e) == 0) return 0 //added by Andy
64 #define NULL_CHECK(e) if ((e) == 0) return //added by Andy
65
66 #define Catch(jEnv) \
67 catch(CIMException & e) { \
68 JMPIjvm::cacheIDs(jEnv); \
|
69 mark.hamzy 1.15 jobject ev=jEnv->NewObject(JMPIjvm::jv.CIMExceptionClassRef,JMPIjvm::jv.CIMExceptionNewISt,(jint)e.getCode(),jEnv->NewStringUTF(e.getMessage().getCString())); \
|
70 schuur 1.1 jEnv->Throw((jthrowable)ev); \
71 } \
72 catch(Exception & e) { \
73 JMPIjvm::cacheIDs(jEnv);\
|
74 mark.hamzy 1.15 jobject ev=jEnv->NewObject(JMPIjvm::jv.CIMExceptionClassRef,JMPIjvm::jv.CIMExceptionNewISt,(jint)1,jEnv->NewStringUTF(e.getMessage().getCString())); \
|
75 schuur 1.1 jEnv->Throw((jthrowable)ev); \
76 } \
77 catch(...) { \
78 JMPIjvm::cacheIDs(jEnv); \
|
79 mark.hamzy 1.21 jobject ev=jEnv->NewObject(JMPIjvm::jv.CIMExceptionClassRef,JMPIjvm::jv.CIMExceptionNewISt,(jint)1,jEnv->NewStringUTF("Exception: Unknown")); \
|
80 schuur 1.1 jEnv->Throw((jthrowable)ev); \
81 }
82
|
83 mark.hamzy 1.14 typedef struct {
84 int clsIndex;
85 const char *methodName;
86 const char *signature;
87 } METHOD_STRUCT;
88
|
89 schuur 1.1 typedef struct jvmVector {
|
90 mark.hamzy 1.14 int initRc;
91 JavaVM *jvm;
92 JNIEnv *env;
93 jclass *classRefs;
94 jmethodID *instMethodIDs;
95 jmethodID *staticMethodIDs;
96 const METHOD_STRUCT *instanceMethodNames;
|
97 schuur 1.1 } JvmVector;
98
|
99 mark.hamzy 1.26 class PEGASUS_JMPIPM_LINKAGE JMPIjvm {
|
100 schuur 1.1 public:
|
101 schuur 1.2 static int trace;
|
102 schuur 1.1 static JavaVM *jvm;
103 static JvmVector jv;
|
104 mark.hamzy 1.11
|
105 schuur 1.1 JMPIjvm();
106 ~JMPIjvm();
|
107 schuur 1.2
|
108 schuur 1.1 static JNIEnv* attachThread(JvmVector **jvp);
109 static void detachThread();
110 static jobject getProvider(JNIEnv *env, const char *cn, jclass *cls) ;
|
111 konrad.r 1.6 static jobject getProvider(JNIEnv *env, String jar, String cln, const char *cn, jclass *cls) ;
|
112 schuur 1.1 static void checkException(JNIEnv *env);
113 static jstring NewPlatformString(JNIEnv *env,char *s);
114 static jobjectArray NewPlatformStringArray(JNIEnv *env,char **strv, int strc);
115 static int cacheIDs(JNIEnv *env);
|
116 schuur 1.3 static int destroyJVM();
|
117 mark.hamzy 1.11
|
118 schuur 1.1 private:
119 static jclass getGlobalClassRef(JNIEnv *env, const char* name);
120 static int initJVM();
|
121 mark.hamzy 1.11
122 typedef HashTable<String,jclass,EqualFunc<String>,HashFunc<String> > ClassTable;
123 typedef HashTable<String,jobject,EqualFunc<String>,HashFunc<String> > ObjectTable;
124
125 static ClassTable _classTable;
126 static ObjectTable _objectTable;
|
127 mark.hamzy 1.16
128 static Mutex _initMutex;
|
129 schuur 1.1 };
130
131 class _nameSpace {
132 public:
133 _nameSpace();
134 _nameSpace(String hn);
135 _nameSpace(String hn, String ns);
|
136 mark.hamzy 1.10
|
137 schuur 1.1 int port();
138 String hostName();
139 String nameSpace();
140 int port_;
141 String protocol_;
142 String hostName_;
143 String nameSpace_;
144 };
145
|
146 mark.hamzy 1.19 class _dataType {
147 public:
148
149 _dataType (int type,
150 int size,
151 Boolean reference,
152 Boolean null,
153 Boolean array,
154 String& refClass,
155 Boolean fromProperty)
156 : _type(type),
157 _size(size),
158 _reference(reference),
159 _array(array),
160 _refClass(refClass),
161 _fromProperty(fromProperty)
162 {
163 }
164
165 _dataType (int type)
166 : _type(type),
167 mark.hamzy 1.19 _size(1),
168 _reference(false),
169 _array(false),
170 _refClass(String::EMPTY),
171 _fromProperty(false)
172 {
173 }
|
174 schuur 1.1
|
175 mark.hamzy 1.19 _dataType (int type,
176 int size)
177 : _type(type),
178 _size(size),
179 _reference(false),
180 _array(true),
181 _refClass(String::EMPTY),
182 _fromProperty(true)
183 {
184 }
185
186 _dataType (int type,
187 const String ref)
188 : _type(type),
189 _size(0),
190 _reference(true),
191 _array(false),
192 _refClass(ref),
193 _fromProperty(true)
194 {
195 }
|
196 schuur 1.1
|
197 mark.hamzy 1.19 static int convertCTypeToJavaType (CIMType cType, bool *pfSuccess)
198 {
199 static int cTypeToJType[]=
200 /* CIMType.h CIMDataType.java
201 CIMTYPE_BOOLEAN, 0 public static final int BOOLEAN = 10;
202 CIMTYPE_UINT8, 1 public static final int UINT8 = 1;
203 CIMTYPE_SINT8, 2 public static final int SINT8 = 2;
204 CIMTYPE_UINT16, 3 public static final int UINT16 = 3;
205 CIMTYPE_SINT16, 4 public static final int SINT16 = 4;
206 CIMTYPE_UINT32, 5 public static final int UINT32 = 5;
207 CIMTYPE_SINT32, 6 public static final int SINT32 = 6;
208 CIMTYPE_UINT64, 7 public static final int UINT64 = 7;
209 CIMTYPE_SINT64, 8 public static final int SINT64 = 8;
210 CIMTYPE_REAL32, 9 public static final int REAL32 = 11;
211 CIMTYPE_REAL64, 10 public static final int REAL64 = 12;
212 CIMTYPE_CHAR16, 11 public static final int CHAR16 = 14;
213 CIMTYPE_STRING, 12 public static final int STRING = 9;
214 CIMTYPE_DATETIME, 13 public static final int DATETIME = 13;
215 CIMTYPE_REFERENCE, 14 public static final int REFERENCE = 0x20+ 1;
216 CIMTYPE_OBJECT 15 public static final int OBJECT = 15;
217 */
218 mark.hamzy 1.19 // p: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
219 {/* j: */ 10, 1, 2, 3, 4, 5, 6, 7, 8,11,12,14, 9,13,0x20+1,15};
220
221 if ((int)cType < (int)CIMTYPE_BOOLEAN || (int)cType > (int)CIMTYPE_OBJECT)
222 {
223 *pfSuccess = false;
224
225 return cTypeToJType[0];
226 }
227 else
228 {
229 *pfSuccess = true;
230
231 return cTypeToJType[cType];
232 }
233 }
234
235 static CIMType convertJavaTypeToCType (int jType, bool *pfSuccess)
236 {
237 static int jTypeToCType[]=
238 /* CIMDataType.java CIMType.h
239 mark.hamzy 1.19 public static final int UINT8 = 1; CIMTYPE_UINT8, 1
240 public static final int SINT8 = 2; CIMTYPE_SINT8, 2
241 public static final int UINT16 = 3; CIMTYPE_UINT16, 3
242 public static final int SINT16 = 4; CIMTYPE_SINT16, 4
243 public static final int UINT32 = 5; CIMTYPE_UINT32, 5
244 public static final int SINT32 = 6; CIMTYPE_SINT32, 6
245 public static final int UINT64 = 7; CIMTYPE_UINT64, 7
246 public static final int SINT64 = 8; CIMTYPE_SINT64, 8
247 public static final int STRING = 9; CIMTYPE_STRING, 12
248 public static final int BOOLEAN = 10; CIMTYPE_BOOLEAN, 0
249 public static final int REAL32 = 11; CIMTYPE_REAL32, 9
250 public static final int REAL64 = 12; CIMTYPE_REAL64, 10
251 public static final int DATETIME = 13; CIMTYPE_DATETIME, 13
252 public static final int CHAR16 = 14; CIMTYPE_CHAR16, 11
253 public static final int REFERENCE = 0x20+ 1; CIMTYPE_REFERENCE, 14
254 public static final int OBJECT = 15; CIMTYPE_OBJECT 15
255 */
256 // j: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
257 {/* p: */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 0, 9, 10, 13, 11, 15};
258
259 if (jType < 1)
260 mark.hamzy 1.19 {
261 *pfSuccess = false;
262
263 return CIMTYPE_BOOLEAN;
264 }
265 else if (jType <= 15)
266 {
267 *pfSuccess = true;
268
269 return (CIMType)jTypeToCType[jType];
270 }
271 else if (jType == 0x20 + 1) // REFERENCE
272 {
273 *pfSuccess = true;
274
275 return CIMTYPE_REFERENCE;
276 }
277 else
278 {
279 *pfSuccess = false;
280
281 mark.hamzy 1.19 return CIMTYPE_BOOLEAN;
282 }
283 }
284
285 static char *convertJavaTypeToChars (int jType, bool *pfSuccess)
286 {
287 static char *jTypeToChars[]= {
288 /* CIMDataType.java */ NULL,
289 /* public static final int UINT8 = 1; */ "uint8",
290 /* public static final int SINT8 = 2; */ "sint8",
291 /* public static final int UINT16 = 3; */ "uint16",
292 /* public static final int SINT16 = 4; */ "sint16",
293 /* public static final int UINT32 = 5; */ "uint32",
294 /* public static final int SINT32 = 6; */ "sint32",
295 /* public static final int UINT64 = 7; */ "uint64",
296 /* public static final int SINT64 = 8; */ "sint64",
297 /* public static final int STRING = 9; */ "string",
298 /* public static final int BOOLEAN = 10; */ "boolean",
299 /* public static final int REAL32 = 11; */ "real32",
300 /* public static final int REAL64 = 12; */ "real64",
301 /* public static final int DATETIME = 13; */ "datetime",
302 mark.hamzy 1.19 /* public static final int CHAR16 = 14; */ "char16",
303 /* public static final int OBJECT = 15; */ "object"
304 };
305
306 if (jType < 1)
307 {
308 *pfSuccess = false;
309
310 return NULL;
311 }
312 else if (jType <= 15)
313 {
314 *pfSuccess = true;
315
316 return jTypeToChars[jType];
317 }
318 else if (jType == 0x20 + 1) // REFERENCE
319 {
320 *pfSuccess = true;
321
322 return "reference";
323 mark.hamzy 1.19 }
324 else
325 {
326 *pfSuccess = false;
327
328 return NULL;
329 }
330 }
331
332 int _type;
333 int _size;
|
334 schuur 1.1 Boolean _reference;
335 Boolean _null;
336 Boolean _array;
|
337 mark.hamzy 1.19 String _refClass;
|
338 schuur 1.1 Boolean _fromProperty;
339 };
340
|
341 mark.hamzy 1.13 #define VectorClassRef classRefs[0]
342 #define BooleanClassRef classRefs[1]
343 #define ByteClassRef classRefs[2]
344 #define ShortClassRef classRefs[3]
345 #define IntegerClassRef classRefs[4]
346 #define LongClassRef classRefs[5]
347 #define FloatClassRef classRefs[6]
348 #define DoubleClassRef classRefs[7]
349 #define UnsignedInt8ClassRef classRefs[8]
350 #define UnsignedInt16ClassRef classRefs[9]
351 #define UnsignedInt32ClassRef classRefs[10]
352 #define UnsignedInt64ClassRef classRefs[11]
353 #define CIMObjectPathClassRef classRefs[12]
354 #define CIMExceptionClassRef classRefs[13]
355 #define BigIntegerClassRef classRefs[14]
356 #define CIMPropertyClassRef classRefs[15]
357 #define CIMOMHandleClassRef classRefs[16]
358 #define CIMClassClassRef classRefs[17]
359 #define CIMInstanceClassRef classRefs[18]
360 #define CIMValueClassRef classRefs[19]
361 #define ObjectClassRef classRefs[20]
362 mark.hamzy 1.13 #define ThrowableClassRef classRefs[21]
363 #define StringClassRef classRefs[22]
364 #define JarClassLoaderClassRef classRefs[23]
365 #define CIMDateTimeClassRef classRefs[24]
366 #define SelectExpClassRef classRefs[25]
367 #define CIMQualifierClassRef classRefs[26]
368 #define CIMQualifierTypeClassRef classRefs[27]
369 #define CIMFlavorClassRef classRefs[28]
370 #define CIMArgumentClassRef classRefs[29]
371 #define CIMInstanceExceptionClassRef classRefs[30]
|
372 mark.hamzy 1.19 #define CIMObjectClassRef classRefs[31]
373 #define CharacterClassRef classRefs[32]
|
374 mark.hamzy 1.20 #define OperationContextClassRef classRefs[33]
375 #define ClassClassRef classRefs[34]
|
376 mark.hamzy 1.13
377 #define BigIntegerValueOf staticMethodIDs[0]
378 #define JarClassLoaderLoad staticMethodIDs[1]
379
380 #define VectorNew instMethodIDs[0]
381 #define VectorAddElement instMethodIDs[15]
382 #define VectorElementAt instMethodIDs[16]
383 #define VectorRemoveElementAt instMethodIDs[30]
384 #define VectorSize instMethodIDs[27]
385 #define BooleanNewZ instMethodIDs[1]
386 #define ByteNewB instMethodIDs[2]
387 #define ShortNewS instMethodIDs[3]
388 #define IntegerNewI instMethodIDs[4]
389 #define LongNewJ instMethodIDs[5]
390 #define FloatNewF instMethodIDs[6]
391 #define DoubleNewD instMethodIDs[7]
392 #define UnsignedInt8NewS instMethodIDs[8]
393 #define UnsignedInt16NewI instMethodIDs[9]
394 #define UnsignedInt32NewJ instMethodIDs[10]
395 #define UnsignedInt64NewBi instMethodIDs[11]
396 #define CIMObjectPathNewI instMethodIDs[12]
397 mark.hamzy 1.13 #define CIMObjectPathCInst instMethodIDs[21]
398 #define CIMExceptionNewSt instMethodIDs[13]
399 #define CIMExceptionNewISt instMethodIDs[32]
400 #define CIMExceptionNewI instMethodIDs[18]
401 #define CIMExceptionNew instMethodIDs[41]
402 #define CIMExceptionNewStOb instMethodIDs[42]
403 #define CIMExceptionNewStObOb instMethodIDs[43]
404 #define CIMExceptionNewStObObOb instMethodIDs[44]
405 #define CIMExceptionGetCode instMethodIDs[33]
406 #define CIMExceptionGetID instMethodIDs[26]
407 #define CIMPropertyNewI instMethodIDs[14]
408 #define CIMPropertyCInst instMethodIDs[28]
409 #define CIMOMHandleNewISt instMethodIDs[17]
410 #define CIMOMHandleGetClass instMethodIDs[29]
411 #define CIMClassNewI instMethodIDs[19]
412 #define CIMClassCInst instMethodIDs[23]
413 #define CIMInstanceNewI instMethodIDs[20]
414 #define CIMInstanceCInst instMethodIDs[22]
415 #define CIMValueNewI instMethodIDs[45]
416 #define CIMValueCInst instMethodIDs[31]
417 #define CIMDateTimeNewI instMethodIDs[34]
418 mark.hamzy 1.13 #define SelectExpNewI instMethodIDs[35]
419 #define CIMQualifierNewI instMethodIDs[36]
420 #define CIMFlavorNewI instMethodIDs[37]
421 #define CIMFlavorGetFlavor instMethodIDs[38]
422 #define CIMArgumentNewI instMethodIDs[40]
423 #define CIMArgumentCInst instMethodIDs[39]
424 #define ObjectToString instMethodIDs[24]
425 #define ThrowableGetMessage instMethodIDs[25]
|
426 mark.hamzy 1.19 #define CIMObjectNewIZ instMethodIDs[46]
427 #define CharacterNewC instMethodIDs[47]
|
428 mark.hamzy 1.20 #define OperationContextNewI instMethodIDs[48]
429 #define OperationContextUnassociate instMethodIDs[49]
430 #define ClassGetInterfaces instMethodIDs[50]
431 #define ClassGetName instMethodIDs[51]
|
432 mark.hamzy 1.22 #define UnsignedInt64NewStr instMethodIDs[52]
|
433 schuur 1.1
434 //extern "C" JNIEnv* attachThread(JvmVector**);
435 //extern "C" void detachThread();
436 //extern "C" jobject getProvider(JNIEnv*,const char*,jclass*);
437 //extern "C" void checkException(JNIEnv *env);
438
439 typedef JNIEnv* (*JvmAttach)(JvmVector**);
440 typedef void (*JvmDetach)();
441
442 PEGASUS_NAMESPACE_END
443
444 #endif
|