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