source: rrlib_jni/tJNIWrappable.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: 4.1 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/tJNIWrappable.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2013-05-07
27 *
28 * \brief   Contains tJNIWrappable
29 *
30 * \b tJNIWrappable
31 *
32 * Base class for classes that can be wrapped from a Java VM via JNI.
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __rrlib__jni__tJNIWrappable_h__
37#define __rrlib__jni__tJNIWrappable_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42#include "rrlib/thread/tMutex.h"
43
44//----------------------------------------------------------------------
45// Internal includes with ""
46//----------------------------------------------------------------------
47#include "rrlib/jni/tJavaObjectReference.h"
48
49//----------------------------------------------------------------------
50// Namespace declaration
51//----------------------------------------------------------------------
52namespace rrlib
53{
54namespace jni
55{
56
57//----------------------------------------------------------------------
58// Forward declarations / typedefs / enums
59//----------------------------------------------------------------------
60
61//----------------------------------------------------------------------
62// Class declaration
63//----------------------------------------------------------------------
64//! Can be wrapped as Java object
65/*!
66 * Base class for classes that can be wrapped from a Java VM via JNI.
67 */
68class tJNIWrappable : private rrlib::util::tNoncopyable
69{
70
71//----------------------------------------------------------------------
72// Public methods and typedefs
73//----------------------------------------------------------------------
74public:
75
76  tJNIWrappable();
77
78  virtual ~tJNIWrappable();
79
80  /*! Get Java Wrapper for this object */
81  jobject GetJavaWrapper()
82  {
83    jobject obj = java_wrapper_object.Get();
84    if (obj != NULL)
85    {
86      return obj;
87    }
88    return CreateJavaWrapper();
89  }
90
91  /*! Set Java Wrapper for this object - once set, may not be changed to a different instance */
92  void SetJavaWrapper(jobject obj, bool cpp_responsible_);
93
94//----------------------------------------------------------------------
95// Protected methods (TODO: can they be private?)
96//----------------------------------------------------------------------
97protected:
98
99  /*! Returns fully-qualified name of Java-(Wrapper)-Class name */
100  virtual const char* GetJavaClassName() const;
101
102  /** Creates Java Wrapper object from c++ side */
103  virtual jobject CreateJavaWrapper();
104
105//----------------------------------------------------------------------
106// Private fields and methods
107//----------------------------------------------------------------------
108private:
109
110  /*! Java Object that wraps this object. Null, if there isn't any wrapper (yet) */
111  tJavaObjectReference java_wrapper_object;
112
113  /*! Mutex for creating Java objects - non-static would be faster at creation, but would consume more memory */
114  static rrlib::thread::tMutex create_mutex;
115
116};
117
118//----------------------------------------------------------------------
119// End of namespace declaration
120//----------------------------------------------------------------------
121}
122}
123
124
125#endif
Note: See TracBrowser for help on using the repository browser.