Merged revisions 7797-7917 via svnmerge from
[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 7918 2007-05-20 20:42:18Z michi $
26
27 */
28
29
30 #ifndef _NATIVE_H
31 #define _NATIVE_H
32
33 #include "config.h"
34
35 #if !defined(WITH_STATIC_CLASSPATH)
36 # include <ltdl.h>
37 #endif
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 typedef struct nativeref nativeref;
57 typedef struct nativecompref nativecompref;
58
59
60 #if !defined(WITH_STATIC_CLASSPATH)
61 typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
62 typedef struct hashtable_library_name_entry hashtable_library_name_entry;
63
64
65 /* native_methods_node_t ******************************************************/
66
67 typedef struct native_methods_node_t native_methods_node_t;
68
69 struct native_methods_node_t {
70         utf         *classname;             /* class name                         */
71         utf         *name;                  /* method name                        */
72         utf         *descriptor;            /* descriptor name                    */
73         functionptr  function;              /* pointer to the implementation      */
74 };
75
76
77 /* hashtable_library_loader_entry *********************************************/
78
79 struct hashtable_library_loader_entry {
80         hashtable_classloader_entry    *cle;     /* 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
85
86 /* hashtable_library_name_entry ***********************************************/
87
88 struct hashtable_library_name_entry {
89         utf                          *name;      /* library name                  */
90         lt_dlhandle                   handle;    /* libtool library handle        */
91         hashtable_library_name_entry *hashlink;  /* link for external chaining    */
92 };
93 #endif
94
95
96 struct nativeref {
97         char       *classname;
98         char       *methodname;
99         char       *descriptor;
100         bool        isstatic;
101         functionptr func;
102 };
103
104 /* table for fast string comparison */
105
106 struct nativecompref {
107         utf        *classname;
108         utf        *methodname;
109         utf        *descriptor;
110         bool        isstatic;
111         functionptr func;
112 };
113
114
115 /* function prototypes ********************************************************/
116
117 bool native_init(void);
118
119 void native_method_register(utf *classname, JNINativeMethod *methods, s4 count);
120
121 #if defined(WITH_STATIC_CLASSPATH)
122
123 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
124                                                                 bool isstatic);
125
126 #else /* defined(WITH_STATIC_CLASSPATH) */
127
128 lt_dlhandle native_library_open(utf *filename);
129 void        native_library_add(utf *filename, java_objectheader *loader,
130                                                            lt_dlhandle handle);
131
132 hashtable_library_name_entry *native_library_find(utf *filename,
133                                                                                                   java_objectheader *loader);
134
135 functionptr native_resolve_function(methodinfo *m);
136
137 #endif /* defined(WITH_STATIC_CLASSPATH) */
138
139 java_objectheader *native_new_and_init(classinfo *c);
140
141 java_objectheader *native_new_and_init_string(classinfo *c,
142                                                                                           java_objectheader *s);
143
144 java_objectheader *native_new_and_init_int(classinfo *c, s4 i);
145
146 java_objectheader *native_new_and_init_throwable(classinfo *c,
147                                                                                                  java_objectheader *t);
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  */