b88668af0eef4a9530548c9f0a1b25b6eca39cca
[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    $Id: native.h 8179 2007-07-05 11:21:08Z michi $
26
27 */
28
29
30 #ifndef _NATIVE_H
31 #define _NATIVE_H
32
33 #include "config.h"
34
35 #if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
36 # include <ltdl.h>
37 #endif
38
39 #include <stdint.h>
40
41 #include "native/jni.h"
42
43 #include "vm/global.h"
44
45 #include "vmcore/class.h"
46 #include "vmcore/loader.h"
47 #include "vmcore/method.h"
48 #include "vmcore/utf8.h"
49
50
51 /* defines ********************************************************************/
52
53 #define NATIVE_METHODS_COUNT    sizeof(methods) / sizeof(JNINativeMethod)
54
55
56 /* table for locating native methods */
57
58 #if defined(WITH_STATIC_CLASSPATH)
59 typedef struct nativeref nativeref;
60 typedef struct nativecompref nativecompref;
61 #endif
62
63
64 /* native_methods_node_t ******************************************************/
65
66 typedef struct native_methods_node_t native_methods_node_t;
67
68 struct native_methods_node_t {
69         utf         *classname;             /* class name                         */
70         utf         *name;                  /* method name                        */
71         utf         *descriptor;            /* descriptor name                    */
72         functionptr  function;              /* pointer to the implementation      */
73 };
74
75
76 /* hashtable_library_loader_entry *********************************************/
77
78 #if defined(ENABLE_LTDL)
79 typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
80 typedef struct hashtable_library_name_entry   hashtable_library_name_entry;
81
82 struct hashtable_library_loader_entry {
83         hashtable_classloader_entry    *cle;     /* class loader                  */
84         hashtable_library_name_entry   *namelink;/* libs loaded by this loader    */
85         hashtable_library_loader_entry *hashlink;/* link for external chaining    */
86 };
87 #endif
88
89
90 /* hashtable_library_name_entry ***********************************************/
91
92 #if defined(ENABLE_LTDL)
93 struct hashtable_library_name_entry {
94         utf                          *name;      /* library name                  */
95         lt_dlhandle                   handle;    /* libtool library handle        */
96         hashtable_library_name_entry *hashlink;  /* link for external chaining    */
97 };
98 #endif
99
100
101 struct nativeref {
102         char       *classname;
103         char       *methodname;
104         char       *descriptor;
105         bool        isstatic;
106         functionptr func;
107 };
108
109 /* table for fast string comparison */
110
111 struct nativecompref {
112         utf        *classname;
113         utf        *methodname;
114         utf        *descriptor;
115         bool        isstatic;
116         functionptr func;
117 };
118
119
120 /* function prototypes ********************************************************/
121
122 bool native_init(void);
123
124 void native_method_register(utf *classname, const JNINativeMethod *methods,
125                                                         int32_t count);
126
127 #if defined(WITH_STATIC_CLASSPATH)
128
129 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
130                                                                 bool isstatic);
131
132 #else /* defined(WITH_STATIC_CLASSPATH) */
133
134 # if defined(ENABLE_LTDL)
135 lt_dlhandle native_library_open(utf *filename);
136 void        native_library_add(utf *filename, java_objectheader *loader,
137                                                            lt_dlhandle handle);
138 hashtable_library_name_entry *native_library_find(utf *filename,
139                                                                                                   java_objectheader *loader);
140 # endif
141
142 functionptr native_resolve_function(methodinfo *m);
143
144 #endif /* defined(WITH_STATIC_CLASSPATH) */
145
146 java_objectheader *native_new_and_init(classinfo *c);
147
148 java_objectheader *native_new_and_init_string(classinfo *c,
149                                                                                           java_objectheader *s);
150
151 #endif /* _NATIVE_H */
152
153
154 /*
155  * These are local overrides for various environment variables in Emacs.
156  * Please do not remove this and leave it at the end of the file, where
157  * Emacs will automagically detect them.
158  * ---------------------------------------------------------------------
159  * Local variables:
160  * mode: c
161  * indent-tabs-mode: t
162  * c-basic-offset: 4
163  * tab-width: 4
164  * End:
165  */