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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2