* Merged with default branch at rev 16f3633aaa5a.
[cacao.git] / src / native / native.h
1 /* src/native/native.h - table of native functions
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifndef _NATIVE_H
29 #define _NATIVE_H
30
31 #include "config.h"
32
33 #if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
34 # include <ltdl.h>
35 #endif
36
37 #include <stdint.h>
38
39 #include "native/jni.h"
40
41 #include "vm/global.h"
42
43 #include "vmcore/class.h"
44 #include "vmcore/loader.h"
45 #include "vmcore/method.h"
46 #include "vmcore/utf8.h"
47
48
49 /* defines ********************************************************************/
50
51 #define NATIVE_METHODS_COUNT    sizeof(methods) / sizeof(JNINativeMethod)
52
53
54 /* table for locating native methods */
55
56 #if defined(WITH_STATIC_CLASSPATH)
57 typedef struct nativeref nativeref;
58 typedef struct nativecompref nativecompref;
59 #endif
60
61
62 /* native_methods_node_t ******************************************************/
63
64 typedef struct native_methods_node_t native_methods_node_t;
65
66 struct native_methods_node_t {
67         utf         *classname;             /* class name                         */
68         utf         *name;                  /* method name                        */
69         utf         *descriptor;            /* descriptor name                    */
70         functionptr  function;              /* pointer to the implementation      */
71 };
72
73
74 /* hashtable_library_loader_entry *********************************************/
75
76 #if defined(ENABLE_LTDL)
77 typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
78 typedef struct hashtable_library_name_entry   hashtable_library_name_entry;
79
80 struct hashtable_library_loader_entry {
81         classloader                    *loader;  /* class loader                  */
82         hashtable_library_name_entry   *namelink;/* libs loaded by this loader    */
83         hashtable_library_loader_entry *hashlink;/* link for external chaining    */
84 };
85 #endif
86
87
88 /* hashtable_library_name_entry ***********************************************/
89
90 #if defined(ENABLE_LTDL)
91 struct hashtable_library_name_entry {
92         utf                          *name;      /* library name                  */
93         lt_dlhandle                   handle;    /* libtool library handle        */
94         hashtable_library_name_entry *hashlink;  /* link for external chaining    */
95 };
96 #endif
97
98
99 struct nativeref {
100         char       *classname;
101         char       *methodname;
102         char       *descriptor;
103         bool        isstatic;
104         functionptr func;
105 };
106
107 /* table for fast string comparison */
108
109 struct nativecompref {
110         utf        *classname;
111         utf        *methodname;
112         utf        *descriptor;
113         bool        isstatic;
114         functionptr func;
115 };
116
117
118 /* function prototypes ********************************************************/
119
120 bool native_init(void);
121
122 void native_method_register(utf *classname, const JNINativeMethod *methods,
123                                                         int32_t count);
124
125 #if defined(WITH_STATIC_CLASSPATH)
126
127 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
128                                                                 bool isstatic);
129
130 #else /* defined(WITH_STATIC_CLASSPATH) */
131
132 # if defined(ENABLE_LTDL)
133 lt_dlhandle native_library_open(utf *filename);
134 void        native_library_add(utf *filename, classloader *loader,
135                                                            lt_dlhandle handle);
136 hashtable_library_name_entry *native_library_find(utf *filename,
137                                                                                                   classloader *loader);
138 # endif
139
140 functionptr native_resolve_function(methodinfo *m);
141
142 #endif /* defined(WITH_STATIC_CLASSPATH) */
143
144 java_handle_t *native_new_and_init(classinfo *c);
145
146 java_handle_t *native_new_and_init_string(classinfo *c, java_handle_t *s);
147
148 #endif /* _NATIVE_H */
149
150
151 /*
152  * These are local overrides for various environment variables in Emacs.
153  * Please do not remove this and leave it at the end of the file, where
154  * Emacs will automagically detect them.
155  * ---------------------------------------------------------------------
156  * Local variables:
157  * mode: c
158  * indent-tabs-mode: t
159  * c-basic-offset: 4
160  * tab-width: 4
161  * End:
162  * vim:noexpandtab:sw=4:ts=4:
163  */