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 mark.hamzy 1.28 Boolean isHttps ();
|
141 schuur 1.1 int port_;
142 String protocol_;
143 String hostName_;
144 String nameSpace_;
|
145 mark.hamzy 1.28 Boolean fHttps;
|
146 schuur 1.1 };
147
|
148 mark.hamzy 1.19 class _dataType {
149 public:
150
151 _dataType (int type,
152 int size,
153 Boolean reference,
154 Boolean null,
155 Boolean array,
156 String& refClass,
157 Boolean fromProperty)
158 : _type(type),
159 _size(size),
160 _reference(reference),
161 _array(array),
162 _refClass(refClass),
163 _fromProperty(fromProperty)
164 {
165 }
166
167 _dataType (int type)
168 : _type(type),
169 mark.hamzy 1.19 _size(1),
170 _reference(false),
171 _array(false),
172 _refClass(String::EMPTY),
173 _fromProperty(false)
174 {
175 }
|
176 schuur 1.1
|
177 mark.hamzy 1.19 _dataType (int type,
178 int size)
179 : _type(type),
180 _size(size),
181 _reference(false),
182 _array(true),
183 _refClass(String::EMPTY),
184 _fromProperty(true)
185 {
186 }
187
188 _dataType (int type,
189 const String ref)
190 : _type(type),
191 _size(0),
192 _reference(true),
193 _array(false),
194 _refClass(ref),
195 _fromProperty(true)
196 {
197 }
|
198 schuur 1.1
|
199 mark.hamzy 1.19 static int convertCTypeToJavaType (CIMType cType, bool *pfSuccess)
200 {
201 static int cTypeToJType[]=
202 /* CIMType.h CIMDataType.java
203 CIMTYPE_BOOLEAN, 0 public static final int BOOLEAN = 10;
204 CIMTYPE_UINT8, 1 public static final int UINT8 = 1;
205 CIMTYPE_SINT8, 2 public static final int SINT8 = 2;
206 CIMTYPE_UINT16, 3 public static final int UINT16 = 3;
207 CIMTYPE_SINT16, 4 public static final int SINT16 = 4;
208 CIMTYPE_UINT32, 5 public static final int UINT32 = 5;
209 CIMTYPE_SINT32, 6 public static final int SINT32 = 6;
210 CIMTYPE_UINT64, 7 public static final int UINT64 = 7;
211 CIMTYPE_SINT64, 8 public static final int SINT64 = 8;
212 CIMTYPE_REAL32, 9 public static final int REAL32 = 11;
213 CIMTYPE_REAL64, 10 public static final int REAL64 = 12;
214 CIMTYPE_CHAR16, 11 public static final int CHAR16 = 14;
215 CIMTYPE_STRING, 12 public static final int STRING = 9;
216 CIMTYPE_DATETIME, 13 public static final int DATETIME = 13;
217 CIMTYPE_REFERENCE, 14 public static final int REFERENCE = 0x20+ 1;
218 CIMTYPE_OBJECT 15 public static final int OBJECT = 15;
219 */
220 mark.hamzy 1.19 // p: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
221 {/* j: */ 10, 1, 2, 3, 4, 5, 6, 7, 8,11,12,14, 9,13,0x20+1,15};
222
223 if ((int)cType < (int)CIMTYPE_BOOLEAN || (int)cType > (int)CIMTYPE_OBJECT)
224 {
225 *pfSuccess = false;
226
227 return cTypeToJType[0];
228 }
229 else
230 {
231 *pfSuccess = true;
232
233 return cTypeToJType[cType];
234 }
235 }
236
237 static CIMType convertJavaTypeToCType (int jType, bool *pfSuccess)
238 {
239 static int jTypeToCType[]=
240 /* CIMDataType.java CIMType.h
241 mark.hamzy 1.19 public static final int UINT8 = 1; CIMTYPE_UINT8, 1
242 public static final int SINT8 = 2; CIMTYPE_SINT8, 2
243 public static final int UINT16 = 3; CIMTYPE_UINT16, 3
244 public static final int SINT16 = 4; CIMTYPE_SINT16, 4
245 public static final int UINT32 = 5; CIMTYPE_UINT32, 5
246 public static final int SINT32 = 6; CIMTYPE_SINT32, 6
247 public static final int UINT64 = 7; CIMTYPE_UINT64, 7
248 public static final int SINT64 = 8; CIMTYPE_SINT64, 8
249 public static final int STRING = 9; CIMTYPE_STRING, 12
250 public static final int BOOLEAN = 10; CIMTYPE_BOOLEAN, 0
251 public static final int REAL32 = 11; CIMTYPE_REAL32, 9
252 public static final int REAL64 = 12; CIMTYPE_REAL64, 10
253 public static final int DATETIME = 13; CIMTYPE_DATETIME, 13
254 public static final int CHAR16 = 14; CIMTYPE_CHAR16, 11
255 public static final int REFERENCE = 0x20+ 1; CIMTYPE_REFERENCE, 14
256 public static final int OBJECT = 15; CIMTYPE_OBJECT 15
257 */
258 // j: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
259 {/* p: */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 0, 9, 10, 13, 11, 15};
260
261 if (jType < 1)
262 mark.hamzy 1.19 {
263 *pfSuccess = false;
264
265 return CIMTYPE_BOOLEAN;
266 }
267 else if (jType <= 15)
268 {
269 *pfSuccess = true;
270
271 return (CIMType)jTypeToCType[jType];
272 }
273 else if (jType == 0x20 + 1) // REFERENCE
274 {
275 *pfSuccess = true;
276
277 return CIMTYPE_REFERENCE;
278 }
279 else
280 {
281 *pfSuccess = false;
282
283 mark.hamzy 1.19 return CIMTYPE_BOOLEAN;
284 }
285 }
286
287 static char *convertJavaTypeToChars (int jType, bool *pfSuccess)
288 {
289 static char *jTypeToChars[]= {
290 /* CIMDataType.java */ NULL,
291 /* public static final int UINT8 = 1; */ "uint8",
292 /* public static final int SINT8 = 2; */ "sint8",
293 /* public static final int UINT16 = 3; */ "uint16",
294 /* public static final int SINT16 = 4; */ "sint16",
295 /* public static final int UINT32 = 5; */ "uint32",
296 /* public static final int SINT32 = 6; */ "sint32",
297 /* public static final int UINT64 = 7; */ "uint64",
298 /* public static final int SINT64 = 8; */ "sint64",
299 /* public static final int STRING = 9; */ "string",
300 /* public static final int BOOLEAN = 10; */ "boolean",
301 /* public static final int REAL32 = 11; */ "real32",
302 /* public static final int REAL64 = 12; */ "real64",
303 /* public static final int DATETIME = 13; */ "datetime",
304 mark.hamzy 1.19 /* public static final int CHAR16 = 14; */ "char16",
305 /* public static final int OBJECT = 15; */ "object"
306 };
307
308 if (jType < 1)
309 {
310 *pfSuccess = false;
311
312 return NULL;
313 }
314 else if (jType <= 15)
315 {
316 *pfSuccess = true;
317
318 return jTypeToChars[jType];
319 }
320 else if (jType == 0x20 + 1) // REFERENCE
321 {
322 *pfSuccess = true;
323
324 return "reference";
325 mark.hamzy 1.19 }
326 else
327 {
328 *pfSuccess = false;
329
330 return NULL;
331 }
332 }
333
334 int _type;
335 int _size;
|
336 schuur 1.1 Boolean _reference;
337 Boolean _null;
338 Boolean _array;
|
339 mark.hamzy 1.19 String _refClass;
|
340 schuur 1.1 Boolean _fromProperty;
341 };
342
|
343 mark.hamzy 1.30 #define VectorClassRef classRefs[0]
344 #define BooleanClassRef classRefs[1]
345 #define ByteClassRef classRefs[2]
346 #define ShortClassRef classRefs[3]
347 #define IntegerClassRef classRefs[4]
348 #define LongClassRef classRefs[5]
349 #define FloatClassRef classRefs[6]
350 #define DoubleClassRef classRefs[7]
351 #define UnsignedInt8ClassRef classRefs[8]
352 #define UnsignedInt16ClassRef classRefs[9]
353 #define UnsignedInt32ClassRef classRefs[10]
354 #define UnsignedInt64ClassRef classRefs[11]
355 #define CIMObjectPathClassRef classRefs[12]
356 #define CIMExceptionClassRef classRefs[13]
357 #define BigIntegerClassRef classRefs[14]
358 #define CIMPropertyClassRef classRefs[15]
359 #define CIMOMHandleClassRef classRefs[16]
360 #define CIMClassClassRef classRefs[17]
361 #define CIMInstanceClassRef classRefs[18]
362 #define CIMValueClassRef classRefs[19]
363 #define ObjectClassRef classRefs[20]
364 mark.hamzy 1.30 #define ThrowableClassRef classRefs[21]
365 #define StringClassRef classRefs[22]
366 #define JarClassLoaderClassRef classRefs[23]
367 #define CIMDateTimeClassRef classRefs[24]
368 #define SelectExpClassRef classRefs[25]
369 #define CIMQualifierClassRef classRefs[26]
370 #define CIMQualifierTypeClassRef classRefs[27]
371 #define CIMFlavorClassRef classRefs[28]
372 #define CIMArgumentClassRef classRefs[29]
373 #define CIMInstanceExceptionClassRef classRefs[30]
374 #define CIMObjectClassRef classRefs[31]
375 #define CharacterClassRef classRefs[32]
376 #define OperationContextClassRef classRefs[33]
377 #define ClassClassRef classRefs[34]
|
378 mark.hamzy 1.29 #define ByteArrayOutputStreamClassRef classRefs[35]
379 #define PrintStreamClassRef classRefs[36]
|
380 mark.hamzy 1.13
|
381 mark.hamzy 1.30 #define BigIntegerValueOf staticMethodIDs[0]
382 #define JarClassLoaderLoad staticMethodIDs[1]
383
384 #define VectorNew instMethodIDs[0]
385 #define VectorAddElement instMethodIDs[15]
386 #define VectorElementAt instMethodIDs[16]
387 #define VectorRemoveElementAt instMethodIDs[30]
388 #define VectorSize instMethodIDs[27]
389 #define BooleanNewZ instMethodIDs[1]
390 #define ByteNewB instMethodIDs[2]
391 #define ShortNewS instMethodIDs[3]
392 #define IntegerNewI instMethodIDs[4]
393 #define LongNewJ instMethodIDs[5]
394 #define FloatNewF instMethodIDs[6]
395 #define DoubleNewD instMethodIDs[7]
396 #define UnsignedInt8NewS instMethodIDs[8]
397 #define UnsignedInt16NewI instMethodIDs[9]
398 #define UnsignedInt32NewJ instMethodIDs[10]
399 #define UnsignedInt64NewBi instMethodIDs[11]
400 #define CIMObjectPathNewJ instMethodIDs[12]
401 #define CIMObjectPathCInst instMethodIDs[21]
402 mark.hamzy 1.30 #define CIMExceptionNewSt instMethodIDs[13]
403 #define CIMExceptionNewISt instMethodIDs[32]
404 #define CIMExceptionNewI instMethodIDs[18]
405 #define CIMExceptionNew instMethodIDs[41]
406 #define CIMExceptionNewStOb instMethodIDs[42]
407 #define CIMExceptionNewStObOb instMethodIDs[43]
408 #define CIMExceptionNewStObObOb instMethodIDs[44]
409 #define CIMExceptionGetCode instMethodIDs[33]
410 #define CIMExceptionGetID instMethodIDs[26]
411 #define CIMPropertyNewJ instMethodIDs[14]
412 #define CIMPropertyCInst instMethodIDs[28]
413 #define CIMOMHandleNewJSt instMethodIDs[17]
414 #define CIMOMHandleGetClass instMethodIDs[29]
415 #define CIMClassNewJ instMethodIDs[19]
416 #define CIMClassCInst instMethodIDs[23]
417 #define CIMInstanceNewJ instMethodIDs[20]
418 #define CIMInstanceCInst instMethodIDs[22]
419 #define CIMValueNewJ instMethodIDs[45]
420 #define CIMValueCInst instMethodIDs[31]
421 #define CIMDateTimeNewJ instMethodIDs[34]
422 #define SelectExpNewJ instMethodIDs[35]
423 mark.hamzy 1.30 #define CIMQualifierNewJ instMethodIDs[36]
424 #define CIMFlavorNewI instMethodIDs[37]
425 #define CIMFlavorGetFlavor instMethodIDs[38]
426 #define CIMArgumentNewJ instMethodIDs[40]
427 #define CIMArgumentCInst instMethodIDs[39]
428 #define ObjectToString instMethodIDs[24]
429 #define ThrowableGetMessage instMethodIDs[25]
430 #define CIMObjectNewJZ instMethodIDs[46]
431 #define CharacterNewC instMethodIDs[47]
432 #define OperationContextNewJ instMethodIDs[48]
433 #define OperationContextUnassociate instMethodIDs[49]
434 #define ClassGetInterfaces instMethodIDs[50]
435 #define ClassGetName instMethodIDs[51]
436 #define UnsignedInt64NewStr instMethodIDs[52]
|
437 mark.hamzy 1.29 #define ByteArrayOutputStreamNew instMethodIDs[53]
438 #define PrintStreamNewOb instMethodIDs[54]
439 #define ThrowablePrintStackTrace instMethodIDs[55]
440 #define ByteArrayOutputStreamToString instMethodIDs[56]
|
441 schuur 1.1
442 //extern "C" JNIEnv* attachThread(JvmVector**);
443 //extern "C" void detachThread();
444 //extern "C" jobject getProvider(JNIEnv*,const char*,jclass*);
445 //extern "C" void checkException(JNIEnv *env);
446
447 typedef JNIEnv* (*JvmAttach)(JvmVector**);
448 typedef void (*JvmDetach)();
449
450 PEGASUS_NAMESPACE_END
451
452 #endif
|