* src/native/native.c: Moved to .cpp.
[cacao.git] / src / native / native.hpp
1 /* src/native/native.hpp - native library support
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _NATIVE_HPP
27 #define _NATIVE_HPP
28
29 #include <stdint.h>
30
31 #include "native/jni.hpp"
32
33 #include "vm/class.h"
34 #include "vm/global.h"
35 #include "vm/loader.hpp"
36 #include "vm/method.h"
37 #include "vm/os.hpp"
38 #include "vm/utf8.h"
39
40
41 /* defines ********************************************************************/
42
43 #define NATIVE_METHODS_COUNT    sizeof(methods) / sizeof(JNINativeMethod)
44
45
46 #define NATIVE_LIBRARY_PREFIX     "lib"
47
48 #if defined(__DARWIN__)
49 # define NATIVE_LIBRARY_SUFFIX    ".dylib"
50 #else
51 # define NATIVE_LIBRARY_SUFFIX    ".so"
52 #endif
53
54
55 /* native_methods_node_t ******************************************************/
56
57 typedef struct native_methods_node_t native_methods_node_t;
58
59 struct native_methods_node_t {
60         utf         *classname;             /* class name                         */
61         utf         *name;                  /* method name                        */
62         utf         *descriptor;            /* descriptor name                    */
63         functionptr  function;              /* pointer to the implementation      */
64 };
65
66
67 /* hashtable_library_loader_entry *********************************************/
68
69 #if defined(ENABLE_DL)
70 typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
71 typedef struct hashtable_library_name_entry   hashtable_library_name_entry;
72
73 struct hashtable_library_loader_entry {
74         classloader_t                  *loader;  /* class loader                  */
75         hashtable_library_name_entry   *namelink;/* libs loaded by this loader    */
76         hashtable_library_loader_entry *hashlink;/* link for external chaining    */
77 };
78 #endif
79
80
81 /* hashtable_library_name_entry ***********************************************/
82
83 #if defined(ENABLE_DL)
84 struct hashtable_library_name_entry {
85         utf                          *name;      /* library name                  */
86         void*                         handle;    /* libtool library handle        */
87         hashtable_library_name_entry *hashlink;  /* link for external chaining    */
88 };
89 #endif
90
91
92 /* function prototypes ********************************************************/
93
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97
98 bool native_init(void);
99
100 void        native_method_register(utf *classname, const JNINativeMethod *methods, int32_t count);
101 functionptr native_method_resolve(methodinfo *m);
102
103 #if defined(ENABLE_DL)
104 void*       native_library_open(utf *filename);
105 void        native_library_close(void* handle);
106 void        native_library_add(utf *filename, classloader_t *loader, void *handle);
107 hashtable_library_name_entry *native_library_find(utf *filename, classloader_t *loader);
108 int         native_library_load(JNIEnv *env, utf *name, classloader_t *cl);
109 #endif
110
111 java_handle_t *native_new_and_init(classinfo *c);
112 java_handle_t *native_new_and_init_string(classinfo *c, java_handle_t *s);
113
114 #ifdef __cplusplus
115 } // extern "C"
116 #endif
117
118 #endif // _NATIVE_HPP
119
120
121 /*
122  * These are local overrides for various environment variables in Emacs.
123  * Please do not remove this and leave it at the end of the file, where
124  * Emacs will automagically detect them.
125  * ---------------------------------------------------------------------
126  * Local variables:
127  * mode: c++
128  * indent-tabs-mode: t
129  * c-basic-offset: 4
130  * tab-width: 4
131  * End:
132  * vim:noexpandtab:sw=4:ts=4:
133  */