| 1 | // gcj/cni.h -*- c++ -*- | 
|---|
| 2 | // This file describes the Cygnus Native Interface, CNI. | 
|---|
| 3 | // It provides a nicer interface to many of the things in gcj/javaprims.h. | 
|---|
| 4 |  | 
|---|
| 5 | /* Copyright (C) 1998, 1999, 2002  Free Software Foundation | 
|---|
| 6 |  | 
|---|
| 7 | This file is part of libgcj. | 
|---|
| 8 |  | 
|---|
| 9 | This software is copyrighted work licensed under the terms of the | 
|---|
| 10 | Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for | 
|---|
| 11 | details.  */ | 
|---|
| 12 |  | 
|---|
| 13 | #ifndef __GCJ_CNI_H__ | 
|---|
| 14 | #define __GCJ_CNI_H__ | 
|---|
| 15 |  | 
|---|
| 16 | #include <java/lang/Object.h> | 
|---|
| 17 | #include <java/lang/Class.h> | 
|---|
| 18 |  | 
|---|
| 19 | #include <gcj/array.h> | 
|---|
| 20 |  | 
|---|
| 21 | #include <string.h> | 
|---|
| 22 |  | 
|---|
| 23 | extern inline jobject | 
|---|
| 24 | JvAllocObject (jclass cls) | 
|---|
| 25 | { | 
|---|
| 26 | return _Jv_AllocObject (cls, cls->size()); | 
|---|
| 27 | } | 
|---|
| 28 |  | 
|---|
| 29 | extern inline jobject | 
|---|
| 30 | JvAllocObject (jclass cls, jsize sz) | 
|---|
| 31 | { | 
|---|
| 32 | return _Jv_AllocObject (cls, sz); | 
|---|
| 33 | } | 
|---|
| 34 |  | 
|---|
| 35 | extern "C" jstring _Jv_NewStringUTF (const char *bytes); | 
|---|
| 36 | extern "C" void _Jv_InitClass (jclass); | 
|---|
| 37 |  | 
|---|
| 38 | extern inline void | 
|---|
| 39 | JvInitClass (jclass cls) | 
|---|
| 40 | { | 
|---|
| 41 | return _Jv_InitClass (cls); | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | extern inline jstring | 
|---|
| 45 | JvAllocString (jsize sz) | 
|---|
| 46 | { | 
|---|
| 47 | return _Jv_AllocString (sz); | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 | extern inline jstring | 
|---|
| 51 | JvNewString (const jchar *chars, jsize len) | 
|---|
| 52 | { | 
|---|
| 53 | return _Jv_NewString (chars, len); | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | extern inline jstring | 
|---|
| 57 | JvNewStringLatin1 (const char *bytes, jsize len) | 
|---|
| 58 | { | 
|---|
| 59 | return _Jv_NewStringLatin1 (bytes, len); | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | extern inline jstring | 
|---|
| 63 | JvNewStringLatin1 (const char *bytes) | 
|---|
| 64 | { | 
|---|
| 65 | return _Jv_NewStringLatin1 (bytes, strlen (bytes)); | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | extern inline jchar * | 
|---|
| 69 | _Jv_GetStringChars (jstring str) | 
|---|
| 70 | { | 
|---|
| 71 | return (jchar*)((char*) str->data + str->boffset); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | extern inline jchar* | 
|---|
| 75 | JvGetStringChars (jstring str) | 
|---|
| 76 | { | 
|---|
| 77 | return _Jv_GetStringChars (str); | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | extern inline jsize | 
|---|
| 81 | JvGetStringUTFLength (jstring string) | 
|---|
| 82 | { | 
|---|
| 83 | return _Jv_GetStringUTFLength (string); | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | extern inline jsize | 
|---|
| 87 | JvGetStringUTFRegion (jstring str, jsize start, jsize len, char *buf) | 
|---|
| 88 | { | 
|---|
| 89 | return _Jv_GetStringUTFRegion (str, start, len, buf); | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | extern inline jstring | 
|---|
| 93 | JvNewStringUTF (const char *bytes) | 
|---|
| 94 | { | 
|---|
| 95 | return _Jv_NewStringUTF (bytes); | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | class JvSynchronize | 
|---|
| 99 | { | 
|---|
| 100 | private: | 
|---|
| 101 | jobject obj; | 
|---|
| 102 | public: | 
|---|
| 103 | JvSynchronize (const jobject &o) : obj (o) | 
|---|
| 104 | { _Jv_MonitorEnter (obj); } | 
|---|
| 105 | ~JvSynchronize () | 
|---|
| 106 | { _Jv_MonitorExit (obj); } | 
|---|
| 107 | }; | 
|---|
| 108 |  | 
|---|
| 109 | /* Call malloc, but throw exception if insufficient memory. */ | 
|---|
| 110 | extern inline void * | 
|---|
| 111 | JvMalloc (jsize size) | 
|---|
| 112 | { | 
|---|
| 113 | return _Jv_Malloc (size); | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | extern inline void | 
|---|
| 117 | JvFree (void *ptr) | 
|---|
| 118 | { | 
|---|
| 119 | return _Jv_Free (ptr); | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | extern inline jint | 
|---|
| 123 | JvCreateJavaVM (void* vm_args) | 
|---|
| 124 | { | 
|---|
| 125 | return _Jv_CreateJavaVM (vm_args); | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | extern inline java::lang::Thread* | 
|---|
| 129 | JvAttachCurrentThread (jstring name, java::lang::ThreadGroup* group) | 
|---|
| 130 | { | 
|---|
| 131 | return _Jv_AttachCurrentThread (name, group); | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | extern inline java::lang::Thread* | 
|---|
| 135 | JvAttachCurrentThreadAsDaemon (jstring name, java::lang::ThreadGroup* group) | 
|---|
| 136 | { | 
|---|
| 137 | return _Jv_AttachCurrentThreadAsDaemon (name, group); | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | extern inline jint | 
|---|
| 141 | JvDetachCurrentThread (void) | 
|---|
| 142 | { | 
|---|
| 143 | return _Jv_DetachCurrentThread (); | 
|---|
| 144 | } | 
|---|
| 145 | #endif /* __GCJ_CNI_H__ */ | 
|---|