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