* src/vm/signal.c (signal_thread): Restart sigwait if it has been
[cacao.git] / src / native / vm / gnuclasspath / gnu_classpath_VMSystemProperties.cpp
1 /* src/native/vm/gnuclasspath/gnu_classpath_VMSystemProperties.cpp
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 #include "config.h"
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "vm/types.h"
32
33 #include "mm/memory.h"
34
35 #include "native/jni.h"
36 #include "native/native.h"
37
38 #include "native/include/java_util_Properties.h"
39
40 /// FIXME
41 extern "C" {
42 #include "native/include/gnu_classpath_VMSystemProperties.h"
43 }
44
45 #include "vm/exceptions.hpp"
46 #include "vm/properties.h"
47 #include "vm/vm.hpp"
48
49
50 // Native functions are exported as C functions.
51 extern "C" {
52
53 /*
54  * Class:     gnu/classpath/VMSystemProperties
55  * Method:    preInit
56  * Signature: (Ljava/util/Properties;)V
57  */
58 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, java_util_Properties *properties)
59 {
60         java_handle_t *p;
61
62         p = (java_handle_t *) properties;
63
64         if (p == NULL) {
65                 exceptions_throw_nullpointerexception();
66                 return;
67         }
68
69         /* fill the java.util.Properties object */
70
71         properties_system_add_all(p);
72 }
73
74
75 /*
76  * Class:     gnu/classpath/VMSystemProperties
77  * Method:    postInit
78  * Signature: (Ljava/util/Properties;)V
79  */
80 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_postInit(JNIEnv *env, jclass clazz, java_util_Properties *properties)
81 {
82         java_handle_t *p;
83 #if defined(ENABLE_JRE_LAYOUT)
84         const char *java_home;
85         char *path;
86         s4    len;
87 #endif
88
89         p = (java_handle_t *) properties;
90
91         if (p == NULL) {
92                 exceptions_throw_nullpointerexception();
93                 return;
94         }
95
96         /* post-set some properties */
97
98 #if defined(ENABLE_JRE_LAYOUT)
99         /* XXX when we do it that way, we can't set these properties on
100            commandline */
101
102         java_home = properties_get("java.home");
103
104         properties_system_add(p, "gnu.classpath.home", java_home);
105
106         len =
107                 strlen("file://") +
108                 strlen(java_home) +
109                 strlen("/lib") +
110                 strlen("0");
111
112         path = MNEW(char, len);
113
114         strcpy(path, "file://");
115         strcat(path, java_home);
116         strcat(path, "/lib");
117
118         properties_system_add(p, "gnu.classpath.home.url", path);
119
120         MFREE(path, char, len);
121 #endif
122 }
123
124 } // extern "C"
125
126
127 /* native methods implemented by this file ************************************/
128
129 static JNINativeMethod methods[] = {
130         { (char*) "preInit",  (char*) "(Ljava/util/Properties;)V", (void*) (uintptr_t) &Java_gnu_classpath_VMSystemProperties_preInit  },
131         { (char*) "postInit", (char*) "(Ljava/util/Properties;)V", (void*) (uintptr_t) &Java_gnu_classpath_VMSystemProperties_postInit },
132 };
133
134
135 /* _Jv_gnu_classpat_VMSystemProperties_init ************************************
136
137    Register native functions.
138
139 *******************************************************************************/
140
141 // FIXME
142 extern "C" {
143 void _Jv_gnu_classpath_VMSystemProperties_init(void)
144 {
145         utf *u;
146
147         u = utf_new_char("gnu/classpath/VMSystemProperties");
148
149         native_method_register(u, methods, NATIVE_METHODS_COUNT);
150 }
151 }
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  */