(file) Return to JMPIImpl.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / JMPI

  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 marek      1.31 // If gcc is compiled with -fvisibility=hidden then JMPI is broken.
 44                 // This is because the JNI h file defines JNIEXPORT as empty since 
 45                 // the default is visible.
 46 mark.hamzy 1.24 #undef  JNIEXPORT
 47                 #define JNIEXPORT __attribute__ ((visibility("default")))
 48                 #endif
 49                 #endif
 50                 
 51 schuur     1.1  #include <stdio.h>
 52                 #include <stdlib.h>
 53                 #include <string.h>
 54                 
 55                 #include <Pegasus/Common/String.h>
 56                 #include <Pegasus/Common/System.h>
 57 mark.hamzy 1.11 #include <Pegasus/Common/HashTable.h>
 58 mark.hamzy 1.19 #include <Pegasus/Common/CIMType.h>
 59 mark.hamzy 1.17 #include <Pegasus/Common/Mutex.h>
 60 mark.hamzy 1.26 #include <Pegasus/ProviderManager2/JMPI/Linkage.h>
 61 schuur     1.1  
 62                 PEGASUS_NAMESPACE_BEGIN
 63                 
 64                 #define NULL_CHECK0(e) if ((e) == 0) return 0 //added by Andy
 65                 #define NULL_CHECK(e) if ((e) == 0) return //added by Andy
 66                 
 67                 #define Catch(jEnv) \
 68                    catch(CIMException & e) { \
 69                       JMPIjvm::cacheIDs(jEnv); \
 70 marek      1.31       jobject ev=jEnv->NewObject( \
 71                                      JMPIjvm::jv.CIMExceptionClassRef, \
 72                                      JMPIjvm::jv.CIMExceptionNewISt, \
 73                                      (jint)e.getCode(), \
 74                                      jEnv->NewStringUTF(e.getMessage().getCString())); \
 75 schuur     1.1        jEnv->Throw((jthrowable)ev); \
 76                    } \
 77                    catch(Exception & e) { \
 78                       JMPIjvm::cacheIDs(jEnv);\
 79 marek      1.31       jobject ev=jEnv->NewObject( \
 80                                      JMPIjvm::jv.CIMExceptionClassRef, \
 81                                      JMPIjvm::jv.CIMExceptionNewISt, \
 82                                      (jint)1, \
 83                                      jEnv->NewStringUTF(e.getMessage().getCString())); \
 84 schuur     1.1        jEnv->Throw((jthrowable)ev); \
 85                    } \
 86                    catch(...)  { \
 87                       JMPIjvm::cacheIDs(jEnv); \
 88 marek      1.31       jobject ev=jEnv->NewObject( \
 89                                      JMPIjvm::jv.CIMExceptionClassRef, \
 90                                      JMPIjvm::jv.CIMExceptionNewISt, \
 91                                      (jint)1, \
 92                                      jEnv->NewStringUTF("Exception: Unknown")); \
 93 schuur     1.1        jEnv->Throw((jthrowable)ev); \
 94                    }
 95                 
 96 mark.hamzy 1.14 typedef struct {
 97                   int         clsIndex;
 98                   const char *methodName;
 99                   const char *signature;
100                 } METHOD_STRUCT;
101                 
102 schuur     1.1  typedef struct jvmVector {
103 mark.hamzy 1.14    int                  initRc;
104                    JavaVM              *jvm;
105                    JNIEnv              *env;
106                    jclass              *classRefs;
107                    jmethodID           *instMethodIDs;
108                    jmethodID           *staticMethodIDs;
109                    const METHOD_STRUCT *instanceMethodNames;
110 schuur     1.1  } JvmVector;
111                 
112 mark.hamzy 1.26 class PEGASUS_JMPIPM_LINKAGE JMPIjvm {
113 schuur     1.1   public:
114 schuur     1.2     static int trace;
115 schuur     1.1     static JavaVM *jvm;
116                    static JvmVector jv;
117 mark.hamzy 1.11 
118 schuur     1.1     JMPIjvm();
119                   ~JMPIjvm();
120 schuur     1.2  
121 schuur     1.1     static JNIEnv* attachThread(JvmVector **jvp);
122                    static void detachThread();
123                    static jobject getProvider(JNIEnv *env, const char *cn, jclass *cls) ;
124 marek      1.31    static jobject getProvider(
125                                       JNIEnv *env,
126                                       String jar,
127                                       String cln,
128                                       const char *cn,
129                                       jclass *cls) ;
130 schuur     1.1     static void checkException(JNIEnv *env);
131                    static jstring NewPlatformString(JNIEnv *env,char *s);
132 marek      1.31    static jobjectArray NewPlatformStringArray(
133                                            JNIEnv *env,
134                                            char **strv,
135                                            int strc);
136 schuur     1.1     static int cacheIDs(JNIEnv *env);
137 schuur     1.3     static int destroyJVM();
138 mark.hamzy 1.11 
139 schuur     1.1   private:
140                    static jclass getGlobalClassRef(JNIEnv *env, const char* name);
141                    static int initJVM();
142 mark.hamzy 1.11 
143 marek      1.31    typedef HashTable<
144                                String,
145                                jclass,
146                                EqualFunc<String>,
147                                HashFunc<String> >  ClassTable;
148                    typedef HashTable<
149                                String,
150                                jobject,
151                                EqualFunc<String>,
152                                HashFunc<String> > ObjectTable;
153 mark.hamzy 1.11 
154                    static ClassTable  _classTable;
155                    static ObjectTable _objectTable;
156 mark.hamzy 1.16 
157                    static Mutex _initMutex;
158 schuur     1.1  };
159                 
160                 class _nameSpace {
161                  public:
162                    _nameSpace();
163                    _nameSpace(String hn);
164                    _nameSpace(String hn, String ns);
165 mark.hamzy 1.10 
166 schuur     1.1     int port();
167                    String hostName();
168                    String nameSpace();
169 mark.hamzy 1.28    Boolean isHttps ();
170 schuur     1.1     int port_;
171                    String protocol_;
172                    String hostName_;
173                    String nameSpace_;
174 mark.hamzy 1.28    Boolean fHttps;
175 schuur     1.1  };
176                 
177 mark.hamzy 1.19 class _dataType {
178                    public:
179                 
180                    _dataType (int          type,
181                               int          size,
182                               Boolean      reference,
183                               Boolean      null,
184                               Boolean      array,
185                               String&      refClass,
186                               Boolean      fromProperty)
187                       : _type(type),
188                         _size(size),
189                         _reference(reference),
190                         _array(array),
191                         _refClass(refClass),
192                         _fromProperty(fromProperty)
193                    {
194                    }
195                 
196                    _dataType (int          type)
197                       : _type(type),
198 mark.hamzy 1.19         _size(1),
199                         _reference(false),
200                         _array(false),
201                         _refClass(String::EMPTY),
202                         _fromProperty(false)
203                    {
204                    }
205 schuur     1.1  
206 mark.hamzy 1.19    _dataType (int          type,
207                               int          size)
208                       : _type(type),
209                         _size(size),
210                         _reference(false),
211                         _array(true),
212                         _refClass(String::EMPTY),
213                         _fromProperty(true)
214                    {
215                    }
216                 
217                    _dataType (int          type,
218                               const String ref)
219                        : _type(type),
220                          _size(0),
221                          _reference(true),
222                          _array(false),
223                          _refClass(ref),
224                          _fromProperty(true)
225                    {
226                    }
227 schuur     1.1  
228 mark.hamzy 1.19    static int convertCTypeToJavaType (CIMType cType, bool *pfSuccess)
229                    {
230                       static int cTypeToJType[]=
231                       /*  CIMType.h                CIMDataType.java
232                           CIMTYPE_BOOLEAN,     0   public static final int BOOLEAN   =      10;
233                           CIMTYPE_UINT8,       1   public static final int UINT8     =       1;
234                           CIMTYPE_SINT8,       2   public static final int SINT8     =       2;
235                           CIMTYPE_UINT16,      3   public static final int UINT16    =       3;
236                           CIMTYPE_SINT16,      4   public static final int SINT16    =       4;
237                           CIMTYPE_UINT32,      5   public static final int UINT32    =       5;
238                           CIMTYPE_SINT32,      6   public static final int SINT32    =       6;
239                           CIMTYPE_UINT64,      7   public static final int UINT64    =       7;
240                           CIMTYPE_SINT64,      8   public static final int SINT64    =       8;
241                           CIMTYPE_REAL32,      9   public static final int REAL32    =      11;
242                           CIMTYPE_REAL64,     10   public static final int REAL64    =      12;
243                           CIMTYPE_CHAR16,     11   public static final int CHAR16    =      14;
244                           CIMTYPE_STRING,     12   public static final int STRING    =       9;
245                           CIMTYPE_DATETIME,   13   public static final int DATETIME  =      13;
246                           CIMTYPE_REFERENCE,  14   public static final int REFERENCE = 0x20+ 1;
247                           CIMTYPE_OBJECT      15   public static final int OBJECT    =      15;
248                       */
249 mark.hamzy 1.19       //  p:      0  1  2  3  4  5  6  7  8  9 10 11 12 13 14     15
250                       {/* j: */  10, 1, 2, 3, 4, 5, 6, 7, 8,11,12,14, 9,13,0x20+1,15};
251                 
252                       if ((int)cType < (int)CIMTYPE_BOOLEAN || (int)cType > (int)CIMTYPE_OBJECT)
253                       {
254                          *pfSuccess = false;
255                 
256                          return cTypeToJType[0];
257                       }
258                       else
259                       {
260                          *pfSuccess = true;
261                 
262                          return cTypeToJType[cType];
263                       }
264                    }
265                 
266                    static CIMType convertJavaTypeToCType (int jType, bool *pfSuccess)
267                    {
268                       static int jTypeToCType[]=
269                       /*  CIMDataType.java                              CIMType.h
270 mark.hamzy 1.19           public static final int UINT8     =       1;  CIMTYPE_UINT8,       1
271                           public static final int SINT8     =       2;  CIMTYPE_SINT8,       2
272                           public static final int UINT16    =       3;  CIMTYPE_UINT16,      3
273                           public static final int SINT16    =       4;  CIMTYPE_SINT16,      4
274                           public static final int UINT32    =       5;  CIMTYPE_UINT32,      5
275                           public static final int SINT32    =       6;  CIMTYPE_SINT32,      6
276                           public static final int UINT64    =       7;  CIMTYPE_UINT64,      7
277                           public static final int SINT64    =       8;  CIMTYPE_SINT64,      8
278                           public static final int STRING    =       9;  CIMTYPE_STRING,     12
279                           public static final int BOOLEAN   =      10;  CIMTYPE_BOOLEAN,     0
280                           public static final int REAL32    =      11;  CIMTYPE_REAL32,      9
281                           public static final int REAL64    =      12;  CIMTYPE_REAL64,     10
282                           public static final int DATETIME  =      13;  CIMTYPE_DATETIME,   13
283                           public static final int CHAR16    =      14;  CIMTYPE_CHAR16,     11
284                           public static final int REFERENCE = 0x20+ 1;  CIMTYPE_REFERENCE,  14
285                           public static final int OBJECT    =      15;  CIMTYPE_OBJECT      15
286                       */
287                       //  j:      0  1  2  3  4  5  6  7  8   9 10 11  12  13  14  15
288                       {/* p: */   0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 0, 9, 10, 13, 11, 15};
289                 
290                       if (jType < 1)
291 mark.hamzy 1.19       {
292                          *pfSuccess = false;
293                 
294                          return CIMTYPE_BOOLEAN;
295                       }
296                       else if (jType <= 15)
297                       {
298                          *pfSuccess = true;
299                 
300                          return (CIMType)jTypeToCType[jType];
301                       }
302                       else if (jType == 0x20 + 1) // REFERENCE
303                       {
304                          *pfSuccess = true;
305                 
306                          return CIMTYPE_REFERENCE;
307                       }
308                       else
309                       {
310                          *pfSuccess = false;
311                 
312 mark.hamzy 1.19          return CIMTYPE_BOOLEAN;
313                       }
314                    }
315                 
316                    static char *convertJavaTypeToChars (int jType, bool *pfSuccess)
317                    {
318                       static char *jTypeToChars[]= {
319                       /* CIMDataType.java                             */ NULL,
320                       /* public static final int UINT8     =       1; */ "uint8",
321                       /* public static final int SINT8     =       2; */ "sint8",
322                       /* public static final int UINT16    =       3; */ "uint16",
323                       /* public static final int SINT16    =       4; */ "sint16",
324                       /* public static final int UINT32    =       5; */ "uint32",
325                       /* public static final int SINT32    =       6; */ "sint32",
326                       /* public static final int UINT64    =       7; */ "uint64",
327                       /* public static final int SINT64    =       8; */ "sint64",
328                       /* public static final int STRING    =       9; */ "string",
329                       /* public static final int BOOLEAN   =      10; */ "boolean",
330                       /* public static final int REAL32    =      11; */ "real32",
331                       /* public static final int REAL64    =      12; */ "real64",
332                       /* public static final int DATETIME  =      13; */ "datetime",
333 mark.hamzy 1.19       /* public static final int CHAR16    =      14; */ "char16",
334                       /* public static final int OBJECT    =      15; */ "object"
335                       };
336                 
337                       if (jType < 1)
338                       {
339                          *pfSuccess = false;
340                 
341                          return NULL;
342                       }
343                       else if (jType <= 15)
344                       {
345                          *pfSuccess = true;
346                 
347                          return jTypeToChars[jType];
348                       }
349                       else if (jType == 0x20 + 1) // REFERENCE
350                       {
351                          *pfSuccess = true;
352                 
353                          return "reference";
354 mark.hamzy 1.19       }
355                       else
356                       {
357                          *pfSuccess = false;
358                 
359                          return NULL;
360                       }
361                    }
362                 
363                    int     _type;
364                    int     _size;
365 schuur     1.1     Boolean _reference;
366                    Boolean _null;
367                    Boolean _array;
368 mark.hamzy 1.19    String  _refClass;
369 schuur     1.1     Boolean _fromProperty;
370                 };
371                 
372 mark.hamzy 1.30 #define VectorClassRef                 classRefs[0]
373                 #define BooleanClassRef                classRefs[1]
374                 #define ByteClassRef                   classRefs[2]
375                 #define ShortClassRef                  classRefs[3]
376                 #define IntegerClassRef                classRefs[4]
377                 #define LongClassRef                   classRefs[5]
378                 #define FloatClassRef                  classRefs[6]
379                 #define DoubleClassRef                 classRefs[7]
380                 #define UnsignedInt8ClassRef           classRefs[8]
381                 #define UnsignedInt16ClassRef          classRefs[9]
382                 #define UnsignedInt32ClassRef          classRefs[10]
383                 #define UnsignedInt64ClassRef          classRefs[11]
384                 #define CIMObjectPathClassRef          classRefs[12]
385                 #define CIMExceptionClassRef           classRefs[13]
386                 #define BigIntegerClassRef             classRefs[14]
387                 #define CIMPropertyClassRef            classRefs[15]
388                 #define CIMOMHandleClassRef            classRefs[16]
389                 #define CIMClassClassRef               classRefs[17]
390                 #define CIMInstanceClassRef            classRefs[18]
391                 #define CIMValueClassRef               classRefs[19]
392                 #define ObjectClassRef                 classRefs[20]
393 mark.hamzy 1.30 #define ThrowableClassRef              classRefs[21]
394                 #define StringClassRef                 classRefs[22]
395                 #define JarClassLoaderClassRef         classRefs[23]
396                 #define CIMDateTimeClassRef            classRefs[24]
397                 #define SelectExpClassRef              classRefs[25]
398                 #define CIMQualifierClassRef           classRefs[26]
399                 #define CIMQualifierTypeClassRef       classRefs[27]
400                 #define CIMFlavorClassRef              classRefs[28]
401                 #define CIMArgumentClassRef            classRefs[29]
402                 #define CIMInstanceExceptionClassRef   classRefs[30]
403                 #define CIMObjectClassRef              classRefs[31]
404                 #define CharacterClassRef              classRefs[32]
405                 #define OperationContextClassRef       classRefs[33]
406                 #define ClassClassRef                  classRefs[34]
407 mark.hamzy 1.29 #define ByteArrayOutputStreamClassRef  classRefs[35]
408                 #define PrintStreamClassRef            classRefs[36]
409 mark.hamzy 1.13 
410 mark.hamzy 1.30 #define BigIntegerValueOf              staticMethodIDs[0]
411                 #define JarClassLoaderLoad             staticMethodIDs[1]
412                                                       
413                 #define VectorNew                      instMethodIDs[0]
414                 #define VectorAddElement               instMethodIDs[15]
415                 #define VectorElementAt                instMethodIDs[16]
416                 #define VectorRemoveElementAt          instMethodIDs[30]
417                 #define VectorSize                     instMethodIDs[27]
418                 #define BooleanNewZ                    instMethodIDs[1]
419                 #define ByteNewB                       instMethodIDs[2]
420                 #define ShortNewS                      instMethodIDs[3]
421                 #define IntegerNewI                    instMethodIDs[4]
422                 #define LongNewJ                       instMethodIDs[5]
423                 #define FloatNewF                      instMethodIDs[6]
424                 #define DoubleNewD                     instMethodIDs[7]
425                 #define UnsignedInt8NewS               instMethodIDs[8]
426                 #define UnsignedInt16NewI              instMethodIDs[9]
427                 #define UnsignedInt32NewJ              instMethodIDs[10]
428                 #define UnsignedInt64NewBi             instMethodIDs[11]
429                 #define CIMObjectPathNewJ              instMethodIDs[12]
430                 #define CIMObjectPathCInst             instMethodIDs[21]
431 mark.hamzy 1.30 #define CIMExceptionNewSt              instMethodIDs[13]
432                 #define CIMExceptionNewISt             instMethodIDs[32]
433                 #define CIMExceptionNewI               instMethodIDs[18]
434                 #define CIMExceptionNew                instMethodIDs[41]
435                 #define CIMExceptionNewStOb            instMethodIDs[42]
436                 #define CIMExceptionNewStObOb          instMethodIDs[43]
437                 #define CIMExceptionNewStObObOb        instMethodIDs[44]
438                 #define CIMExceptionGetCode            instMethodIDs[33]
439                 #define CIMExceptionGetID              instMethodIDs[26]
440                 #define CIMPropertyNewJ                instMethodIDs[14]
441                 #define CIMPropertyCInst               instMethodIDs[28]
442                 #define CIMOMHandleNewJSt              instMethodIDs[17]
443                 #define CIMOMHandleGetClass            instMethodIDs[29]
444                 #define CIMClassNewJ                   instMethodIDs[19]
445                 #define CIMClassCInst                  instMethodIDs[23]
446                 #define CIMInstanceNewJ                instMethodIDs[20]
447                 #define CIMInstanceCInst               instMethodIDs[22]
448                 #define CIMValueNewJ                   instMethodIDs[45]
449                 #define CIMValueCInst                  instMethodIDs[31]
450                 #define CIMDateTimeNewJ                instMethodIDs[34]
451                 #define SelectExpNewJ                  instMethodIDs[35]
452 mark.hamzy 1.30 #define CIMQualifierNewJ               instMethodIDs[36]
453                 #define CIMFlavorNewI                  instMethodIDs[37]
454                 #define CIMFlavorGetFlavor             instMethodIDs[38]
455                 #define CIMArgumentNewJ                instMethodIDs[40]
456                 #define CIMArgumentCInst               instMethodIDs[39]
457                 #define ObjectToString                 instMethodIDs[24]
458                 #define ThrowableGetMessage            instMethodIDs[25]
459                 #define CIMObjectNewJZ                 instMethodIDs[46]
460                 #define CharacterNewC                  instMethodIDs[47]
461                 #define OperationContextNewJ           instMethodIDs[48]
462                 #define OperationContextUnassociate    instMethodIDs[49]
463                 #define ClassGetInterfaces             instMethodIDs[50]
464                 #define ClassGetName                   instMethodIDs[51]
465                 #define UnsignedInt64NewStr            instMethodIDs[52]
466 mark.hamzy 1.29 #define ByteArrayOutputStreamNew       instMethodIDs[53]
467                 #define PrintStreamNewOb               instMethodIDs[54]
468                 #define ThrowablePrintStackTrace       instMethodIDs[55]
469                 #define ByteArrayOutputStreamToString  instMethodIDs[56]
470 schuur     1.1  
471                 //extern "C" JNIEnv* attachThread(JvmVector**);
472                 //extern "C" void detachThread();
473                 //extern "C" jobject getProvider(JNIEnv*,const char*,jclass*);
474                 //extern "C" void checkException(JNIEnv *env);
475                 
476                 typedef JNIEnv* (*JvmAttach)(JvmVector**);
477                 typedef void (*JvmDetach)();
478                 
479                 PEGASUS_NAMESPACE_END
480                 
481                 #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2