a2d355691bd890552cba191cbd52c2756221be6f
[cacao.git] / src / native / native.h
1 /* src/native/native.h - native library support
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _NATIVE_H
27 #define _NATIVE_H
28
29 #include "config.h"
30
31 #include <stdint.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include "native/jni.h"
38
39 #include "vm/class.h"
40 #include "vm/global.h"
41 #include "vm/loader.h"
42 #include "vm/method.h"
43 #include "vm/os.hpp"
44 #include "vm/utf8.h"
45
46
47 /* defines ********************************************************************/
48
49 #define NATIVE_METHODS_COUNT    sizeof(methods) / sizeof(JNINativeMethod)
50
51
52 #define NATIVE_LIBRARY_PREFIX     "lib"
53
54 #if defined(__DARWIN__)
55 # define NATIVE_LIBRARY_SUFFIX    ".dylib"
56 #else
57 # define NATIVE_LIBRARY_SUFFIX    ".so"
58 #endif
59
60
61 /* native_methods_node_t ******************************************************/
62
63 typedef struct native_methods_node_t native_methods_node_t;
64
65 struct native_methods_node_t {
66         utf         *classname;             /* class name                         */
67         utf         *name;                  /* method name                        */
68         utf         *descriptor;            /* descriptor name                    */
69         functionptr  function;              /* pointer to the implementation      */
70 };
71
72
73 /* hashtable_library_loader_entry *********************************************/
74
75 #if defined(ENABLE_DL)
76 typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
77 typedef struct hashtable_library_name_entry   hashtable_library_name_entry;
78
79 struct hashtable_library_loader_entry {
80         classloader_t                  *loader;  /* class loader                  */
81         hashtable_library_name_entry   *namelink;/* libs loaded by this loader    */
82         hashtable_library_loader_entry *hashlink;/* link for external chaining    */
83 };
84 #endif
85
86
87 /* hashtable_library_name_entry ***********************************************/
88
89 #if defined(ENABLE_DL)
90 struct hashtable_library_name_entry {
91         utf                          *name;      /* library name                  */
92         void*                         handle;    /* libtool library handle        */
93         hashtable_library_name_entry *hashlink;  /* link for external chaining    */
94 };
95 #endif
96
97
98 /* function prototypes ********************************************************/
99
100 bool native_init(void);
101
102 void        native_method_register(utf *classname, const JNINativeMethod *methods, int32_t count);
103 functionptr native_method_resolve(methodinfo *m);
104
105 #if defined(ENABLE_DL)
106 void*       native_library_open(utf *filename);
107 void        native_library_close(void* handle);
108 void        native_library_add(utf *filename, classloader_t *loader, void *handle);
109 hashtable_library_name_entry *native_library_find(utf *filename, classloader_t *loader);
110 int         native_library_load(JNIEnv *env, utf *name, classloader_t *cl);
111 #endif
112
113 java_handle_t *native_new_and_init(classinfo *c);
114 java_handle_t *native_new_and_init_string(classinfo *c, java_handle_t *s);
115
116 #ifdef __cplusplus
117 }
118 #endif
119
120 #endif /* _NATIVE_H */
121
122
123 /*
124  * These are local overrides for various environment variables in Emacs.
125  * Please do not remove this and leave it at the end of the file, where
126  * Emacs will automagically detect them.
127  * ---------------------------------------------------------------------
128  * Local variables:
129  * mode: c
130  * indent-tabs-mode: t
131  * c-basic-offset: 4
132  * tab-width: 4
133  * End:
134  * vim:noexpandtab:sw=4:ts=4:
135  */