source: rrlib_jni/jvm.h @ 24:d13dfecf897b

Last change on this file since 24:d13dfecf897b was 20:c4f1bedb7be9, checked in by Tobias Föhst <foehst@…>, 7 years ago

Added and updated license information

File size: 2.9 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
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 along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    rrlib/jni/jvm.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2013-05-07
27 *
28 * Functions to set/obtain the current Java virtual machnine.
29 *
30 */
31//----------------------------------------------------------------------
32#ifndef __rrlib__jni__jvm_h__
33#define __rrlib__jni__jvm_h__
34
35//----------------------------------------------------------------------
36// External includes (system with <>, local with "")
37//----------------------------------------------------------------------
38#include <jni.h>
39
40//----------------------------------------------------------------------
41// Internal includes with ""
42//----------------------------------------------------------------------
43
44
45//----------------------------------------------------------------------
46// Namespace declaration
47//----------------------------------------------------------------------
48namespace rrlib
49{
50namespace jni
51{
52
53//----------------------------------------------------------------------
54// Forward declarations / typedefs / enums
55//----------------------------------------------------------------------
56
57namespace internal
58{
59
60/*! Pointer to JavaVM. Set at jvm initialization - needs to be done manually if libraries/jni is not used */
61extern JavaVM* jvm;
62
63/*! (Cached) Pointer to JNIEnv of current thread */
64extern __thread JNIEnv* env;
65
66JNIEnv* AttachThread();
67
68}
69
70//----------------------------------------------------------------------
71// Function declarations
72//----------------------------------------------------------------------
73
74/*! Set JVM - once set, may not be changed to a different instance */
75void SetJavaVM(JavaVM* jvm);
76
77/*! Get JVM instance */
78inline JavaVM* GetJavaVM()
79{
80  return internal::jvm;
81}
82
83/*! Get JNI Env for current thread */
84inline JNIEnv* GetEnv()
85{
86  JNIEnv* result = internal::env;
87  if (result != NULL)
88  {
89    return result;
90  }
91  return internal::AttachThread();
92}
93
94//----------------------------------------------------------------------
95// End of namespace declaration
96//----------------------------------------------------------------------
97}
98}
99
100
101#endif
Note: See TracBrowser for help on using the repository browser.