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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2