ACT-CV - Machine Vision for Cognitive Modeling
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
general
java
JVM.h
Go to the documentation of this file.
1
// -*- mode: c++; indent-tabs-mode: nil; c-basic-offset: 4; coding: iso-8859-1; -*-
2
3
/*
4
ACT-CV - Machine Vision for Cognitive Modeling
5
Copyright (c) 2008 Marc Halbruegge
6
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
32
#ifndef JVM_H_
33
#define JVM_H_
34
35
#include <jni.h>
36
#include <map>
37
38
#if HAVE_CONFIG_H
39
#include <
config.h
>
40
#endif
41
42
#ifdef __GNUC__
43
#ifdef __APPLE__
44
// os x specific stuff
45
#include <sys/types.h>
46
#include <unistd.h>
47
#include <unistd.h>
48
#include <errno.h>
49
#include <sys/syscall.h>
50
51
#else
52
// linux specific stuff
53
#include <sys/types.h>
54
#include <unistd.h>
55
#include <linux/unistd.h>
56
#include <errno.h>
57
#include <sys/syscall.h>
58
#endif
59
#endif
60
61
#ifdef _WINDOWS
62
# include <windows.h>
63
#else
64
// linux
65
# include <dlfcn.h>
66
# define __stdcall
67
#endif
68
70
class
JVM
{
71
JavaVMInitArgs
vm_args
;
72
JavaVMOption
options
[3];
73
75
std::map<int,JNIEnv*>
threadSpecificEnvs
;
76
81
bool
mustDestroyVM
;
82
83
#ifdef _WINDOWS
84
HINSTANCE
jvmInstance
;
85
#else
86
void
*
jvmInstance
;
87
#endif
88
89
jint
(
__stdcall
*jniCreateJavaVM)(JavaVM **,
void
**,
void
*);
90
91
jint
(
__stdcall
*jniGetCreatedJavaVMs)(JavaVM **,
jsize
,
jsize
*);
92
93
void
LoadJvmLib
();
94
95
protected
:
97
JavaVM *
jvm
;
98
106
JNIEnv*
GetEnv
() {
107
std::map<int,JNIEnv*>::const_iterator i
108
=
threadSpecificEnvs
.find(
GetThreadId
());
109
if
(i==
threadSpecificEnvs
.end()) {
110
AttachCurrentThread
();
111
}
112
return
threadSpecificEnvs
[
GetThreadId
()];
113
}
114
115
void
CreateJVM
(
const
char
*classpath);
116
117
jobject
CreateGlobalRef
(jobject obj);
118
jclass
CreateGlobalRef
(jclass obj);
119
120
void
AttachCurrentThread
();
121
void
DetachCurrentThread
();
122
124
int
GetThreadId
() {
125
#ifdef __GNUC__
126
return
syscall(SYS_gettid);
127
#else
128
return
0;
129
#endif
130
}
131
133
JavaVM*
GetCreatedJavaVM
();
134
135
public
:
136
JVM
();
137
JVM
(
const
char
*cp);
138
139
~JVM
();
140
};
141
142
#endif
/*JVM_H_*/
ACT-CV - Machine Vision for Cognitive Modeling
© 2015
Marc Halbruegge
(actcvlibrary@googlemail.com)