Changeset 14:42254b90cc4b in rrlib_jni


Ignore:
Timestamp:
07.05.2013 17:51:34 (7 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Moved from rrlib_finroc_core_utils_jni. Tidied code up.

Files:
5 added
2 deleted
1 edited
2 moved

Legend:

Unmodified
Added
Removed
  • java_native_utility_functions_jni.cpp

    r12 r14  
    1 //This is a generated JNI wrapper file 
     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 
     8// modify it under the terms of the GNU General Public License 
     9// as published by the Free Software Foundation; either version 2 
     10// of the License, or (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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
     20// 
     21//---------------------------------------------------------------------- 
     22/*!\file    rrlib/jni/java_native_utility_functions_jni.cpp 
     23 * 
     24 * \author  Max Reichardt 
     25 * 
     26 * \date    2013-05-07 
     27 * 
     28 * Native utility functions for java code (e.g. get Pointers to native byte buffers) 
     29 */ 
     30//---------------------------------------------------------------------- 
    231 
    3 /** 
    4  * You received this file as part of an advanced experimental 
    5  * robotics framework prototype ('finroc') 
    6  * 
    7  * Copyright (C) 2007-2010 Max Reichardt, 
    8  *   Robotics Research Lab, University of Kaiserslautern 
    9  * 
    10  * This program is free software; you can redistribute it and/or 
    11  * modify it under the terms of the GNU General Public License 
    12  * as published by the Free Software Foundation; either version 2 
    13  * of the License, or (at your option) any later version. 
    14  * 
    15  * This program is distributed in the hope that it will be useful, 
    16  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    18  * GNU General Public License for more details. 
    19  * 
    20  * You should have received a copy of the GNU General Public License 
    21  * along with this program; if not, write to the Free Software 
    22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
    23  */ 
    24 #include "rrlib/finroc_core_utils_jni/tJNIConvert.h" 
    25 #include "rrlib/finroc_core_utils_jni/tJNIHelper.h" 
     32//---------------------------------------------------------------------- 
     33// External includes (system with <>, local with "") 
     34//---------------------------------------------------------------------- 
     35#include <jni.h> 
     36#include <cstring> 
    2637 
    27 #include <cstring> 
     38//---------------------------------------------------------------------- 
     39// Internal includes with "" 
     40//---------------------------------------------------------------------- 
     41#include "rrlib/jni/tJNIWrappable.h" 
     42 
     43//---------------------------------------------------------------------- 
     44// Debugging 
     45//---------------------------------------------------------------------- 
     46#include <cassert> 
     47 
     48//---------------------------------------------------------------------- 
     49// Namespace usage 
     50//---------------------------------------------------------------------- 
     51 
     52//---------------------------------------------------------------------- 
     53// Namespace declaration 
     54//---------------------------------------------------------------------- 
     55namespace rrlib 
     56{ 
     57namespace jni 
     58{ 
     59 
     60//---------------------------------------------------------------------- 
     61// Forward declarations / typedefs / enums 
     62//---------------------------------------------------------------------- 
     63 
     64//---------------------------------------------------------------------- 
     65// Const values 
     66//---------------------------------------------------------------------- 
     67 
     68//---------------------------------------------------------------------- 
     69// Implementation 
     70//---------------------------------------------------------------------- 
    2871 
    2972extern "C" 
     
    3174  JNIEXPORT void JNICALL Java_org_rrlib_finroc_1core_1utils_jc_jni_JNICalls_deleteJNIWrappable(JNIEnv* env, jclass class_, jlong pointer) 
    3275  { 
    33     finroc::util::tJNIWrappable* obj = (finroc::util::tJNIWrappable*)pointer; 
     76    rrlib::jni::tJNIWrappable* obj = (rrlib::jni::tJNIWrappable*)pointer; 
    3477    obj->SetJavaWrapper(NULL, false); // avoids that Java "destructor" is invoked (again) 
    3578    delete obj; 
     
    63106  JNIEXPORT jlong JNICALL Java_org_rrlib_finroc_1core_1utils_jc_jni_JNICalls_getJavaVM(JNIEnv* env, jclass class_) 
    64107  { 
    65     JavaVM* jvm = finroc::util::tJNIHelper::GetJavaVM(); 
     108    JavaVM* jvm = rrlib::jni::GetJavaVM(); 
    66109    if (jvm != NULL) 
    67110    { 
     
    70113    env->GetJavaVM(&jvm); 
    71114    assert(jvm != NULL && "Error initializing JavaVM pointer"); 
    72     finroc::util::tJNIHelper::SetJavaVM(jvm); 
     115    rrlib::jni::SetJavaVM(jvm); 
    73116    return (jlong)jvm; 
    74117  } 
     
    108151  JNIEXPORT void JNICALL Java_org_rrlib_finroc_1core_1utils_jc_jni_JNICalls_setJavaObject(JNIEnv* env, jclass class_, jlong pointer, jobject object, jboolean java_responsible) 
    109152  { 
    110     finroc::util::tJNIWrappable* obj = (finroc::util::tJNIWrappable*)pointer; 
     153    rrlib::jni::tJNIWrappable* obj = (rrlib::jni::tJNIWrappable*)pointer; 
    111154    obj->SetJavaWrapper(object, !java_responsible); 
    112155  } 
     
    141184} // extern C 
    142185 
     186//---------------------------------------------------------------------- 
     187// End of namespace declaration 
     188//---------------------------------------------------------------------- 
     189} 
     190} 
  • make.xml

    r13 r14  
    11<targets> 
    2   <rrlib name="finroc_core_utils_jni_base" libs="jni"> 
    3     <sources>tJNICalls_JNI.cpp tJNIHelper.cpp tJNIConvert.h</sources> 
     2  <rrlib name="jni" libs="jni"> 
     3    <sources>**</sources> 
    44  </rrlib> 
    55</targets> 
  • type_conversion.h

    r13 r14  
    1 /** 
    2  * You received this file as part of an advanced experimental 
    3  * robotics framework prototype ('finroc') 
    4  * 
    5  * Copyright (C) 2007-2010 Max Reichardt, 
    6  *   Robotics Research Lab, University of Kaiserslautern 
    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 
    10  * as published by the Free Software Foundation; either version 2 
    11  * of the License, or (at your option) any later version. 
    12  * 
    13  * This program is distributed in the hope that it will be useful, 
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    16  * GNU 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
     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 
     8// modify it under the terms of the GNU General Public License 
     9// as published by the Free Software Foundation; either version 2 
     10// of the License, or (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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
     20// 
     21//---------------------------------------------------------------------- 
     22/*!\file    rrlib/jni/type_conversion.h 
     23 * 
     24 * \author  Max Reichardt 
     25 * 
     26 * \date    2013-05-07 
     27 * 
     28 * Functions that convert native C++ types to JNI types and vice versa. 
     29 * 
    2130 */ 
    22 #ifndef rrlib__finroc_core_utils_jni__tJNIConvert_h__ 
    23 #define rrlib__finroc_core_utils_jni__tJNIConvert_h__ 
    24  
    25 #include "rrlib/finroc_core_utils_jni/tJNIHelper.h" 
     31//---------------------------------------------------------------------- 
     32#ifndef __rrlib__jni__jni_type_conversion_h__ 
     33#define __rrlib__jni__jni_type_conversion_h__ 
     34 
     35//---------------------------------------------------------------------- 
     36// External includes (system with <>, local with "") 
     37//---------------------------------------------------------------------- 
    2638#include <jni.h> 
    2739 
    28 //#ifdef __JC_CREATE_JNI_WRAPPERS__ 
    29  
    30 namespace finroc 
    31 { 
    32 namespace util 
     40//---------------------------------------------------------------------- 
     41// Internal includes with "" 
     42//---------------------------------------------------------------------- 
     43#include "rrlib/jni/jvm.h" 
     44#include "rrlib/jni/tJNIWrappable.h" 
     45 
     46//---------------------------------------------------------------------- 
     47// Namespace declaration 
     48//---------------------------------------------------------------------- 
     49namespace rrlib 
    3350{ 
    3451namespace jni 
    3552{ 
    3653 
     54//---------------------------------------------------------------------- 
     55// Forward declarations / typedefs / enums 
     56//---------------------------------------------------------------------- 
     57 
     58//---------------------------------------------------------------------- 
     59// Function declarations 
     60//---------------------------------------------------------------------- 
     61 
    3762/////////////////////////////////////////////////////////////////////////////// 
    3863// conversion methods C++ to Java 
     
    4065 
    4166template <typename T> 
    42 jbyte ToJbyte(T v) 
     67inline jbyte ToJbyte(T v) 
    4368{ 
    4469  return static_cast<jbyte>(v); 
     
    4671 
    4772template <typename T> 
    48 jshort ToJshort(T v) 
     73inline jshort ToJshort(T v) 
    4974{ 
    5075  return static_cast<jshort>(v); 
     
    5277 
    5378template <typename T> 
    54 jint ToJint(T v) 
     79inline jint ToJint(T v) 
    5580{ 
    5681  return static_cast<jint>(v); 
    5782} 
    5883 
    59 jlong ToJlong(int64_t v) 
     84inline jlong ToJlong(int64_t v) 
    6085{ 
    6186  return static_cast<jlong>(v); 
    6287} 
    63 jlong ToJlong(float v) 
     88inline jlong ToJlong(float v) 
    6489{ 
    6590  return static_cast<jlong>(v); 
    6691} 
    67 jlong ToJlong(double v) 
     92inline jlong ToJlong(double v) 
    6893{ 
    6994  return static_cast<jlong>(v); 
    7095} 
    71 jlong ToJlong(tJNIWrappable* v) 
     96inline jlong ToJlong(tJNIWrappable* v) 
    7297{ 
    7398  return (jlong)v;  // Pointer conversion 
    7499} 
    75 jlong ToJlong(const tJNIWrappable& v) 
     100inline jlong ToJlong(const tJNIWrappable& v) 
    76101{ 
    77102  return (jlong)&v;  // Pointer conversion 
     
    79104 
    80105template <typename T> 
    81 jchar ToJchar(T v) 
     106inline jchar ToJchar(T v) 
    82107{ 
    83108  return static_cast<jchar>(v); 
     
    85110 
    86111template <typename T> 
    87 jfloat ToJfloat(T v) 
     112inline jfloat ToJfloat(T v) 
    88113{ 
    89114  return static_cast<jfloat>(v); 
     
    91116 
    92117template <typename T> 
    93 jdouble ToJdouble(T v) 
     118inline jdouble ToJdouble(T v) 
    94119{ 
    95120  return static_cast<jdouble>(v); 
    96121} 
    97122 
    98 jstring ToJstring(const char* c) 
    99 { 
    100   jstring js = tJNIHelper::GetEnv()->NewStringUTF(c); 
     123inline jstring ToJstring(const char* c) 
     124{ 
     125  jstring js = GetEnv()->NewStringUTF(c); 
    101126  return js; 
    102127} 
    103 jstring ToJstring(const std::string& d) 
     128inline jstring ToJstring(const std::string& d) 
    104129{ 
    105130  return ToJstring(d.c_str()); 
    106131} 
    107132 
    108 jobject ToJobject(tJNIWrappable* ptr) 
    109 { 
    110   return ptr->GetJavaWrapper(); 
    111 } 
    112 jobject ToJobject(tJNIWrappable& ref) 
     133//inline jobject ToJobject(tJNIWrappable* ptr) 
     134//{ 
     135//  return ptr->GetJavaWrapper(); 
     136//} 
     137inline jobject ToJobject(tJNIWrappable& ref) 
    113138{ 
    114139  return ref.GetJavaWrapper(); 
    115140} 
    116 template<typename T> 
    117 jobject ToJobject(T* ptr) 
    118 { 
    119   return tCastCache::DynamicCast<tJNIWrappable>(ptr)->GetJavaWrapper(); 
    120 } 
    121 template<typename T> 
    122 jobject ToJobject(T& ref) 
    123 { 
    124   return tCastCache::DynamicCast<tJNIWrappable>(&ref)->GetJavaWrapper(); 
    125 } 
     141//template<typename T> 
     142//inline jobject ToJobject(T& ref) 
     143//{ 
     144//  return dynamic_cast<tJNIWrappable&>(ref)->GetJavaWrapper(); 
     145//} 
    126146 
    127147 
     
    130150/////////////////////////////////////////////////////////////////////////////// 
    131151 
    132 int ToInt(jint v) 
    133 { 
    134   return static_cast<int>(v); 
    135 } 
    136 int ToInt(jlong v) 
    137 { 
    138   return static_cast<int>(v); 
    139 } 
    140 int ToInt(jbyte v) 
    141 { 
    142   return static_cast<int>(v); 
    143 } 
    144 int ToInt(jshort v) 
    145 { 
    146   return static_cast<int>(v); 
    147 } 
    148  
    149 int16_t ToInt16(jint v) 
    150 { 
    151   return static_cast<int16_t>(v); 
    152 } 
    153 int16_t ToInt16(jlong v) 
    154 { 
    155   return static_cast<int16_t>(v); 
    156 } 
    157 int16_t ToInt16(jbyte v) 
    158 { 
    159   return static_cast<int16_t>(v); 
    160 } 
    161 int16_t ToInt16(jshort v) 
    162 { 
    163   return static_cast<int16_t>(v); 
    164 } 
    165  
    166 int8_t ToInt8(jint v) 
    167 { 
    168   return static_cast<int8_t>(v); 
    169 } 
    170 int8_t ToInt8(jlong v) 
    171 { 
    172   return static_cast<int8_t>(v); 
    173 } 
    174 int8_t ToInt8(jbyte v) 
    175 { 
    176   return static_cast<int8_t>(v); 
    177 } 
    178 int8_t ToInt8(jshort v) 
    179 { 
    180   return static_cast<int8_t>(v); 
    181 } 
    182  
    183 int64_t ToInt64(jint v) 
    184 { 
    185   return static_cast<int64_t>(v); 
    186 } 
    187 int64_t ToInt64(jlong v) 
    188 { 
    189   return static_cast<int64_t>(v); 
    190 } 
    191 int64_t ToInt64(jbyte v) 
    192 { 
    193   return static_cast<int64_t>(v); 
    194 } 
    195 int64_t ToInt64(jshort v) 
    196 { 
    197   return static_cast<int64_t>(v); 
    198 } 
    199  
    200 double ToDouble(jdouble v) 
     152inline int ToInt(jint v) 
     153{ 
     154  return static_cast<int>(v); 
     155} 
     156inline int ToInt(jlong v) 
     157{ 
     158  return static_cast<int>(v); 
     159} 
     160inline int ToInt(jbyte v) 
     161{ 
     162  return static_cast<int>(v); 
     163} 
     164inline int ToInt(jshort v) 
     165{ 
     166  return static_cast<int>(v); 
     167} 
     168 
     169inline int16_t ToInt16(jint v) 
     170{ 
     171  return static_cast<int16_t>(v); 
     172} 
     173inline int16_t ToInt16(jlong v) 
     174{ 
     175  return static_cast<int16_t>(v); 
     176} 
     177inline int16_t ToInt16(jbyte v) 
     178{ 
     179  return static_cast<int16_t>(v); 
     180} 
     181inline int16_t ToInt16(jshort v) 
     182{ 
     183  return static_cast<int16_t>(v); 
     184} 
     185 
     186inline int8_t ToInt8(jint v) 
     187{ 
     188  return static_cast<int8_t>(v); 
     189} 
     190inline int8_t ToInt8(jlong v) 
     191{ 
     192  return static_cast<int8_t>(v); 
     193} 
     194inline int8_t ToInt8(jbyte v) 
     195{ 
     196  return static_cast<int8_t>(v); 
     197} 
     198inline int8_t ToInt8(jshort v) 
     199{ 
     200  return static_cast<int8_t>(v); 
     201} 
     202 
     203inline int64_t ToInt64(jint v) 
     204{ 
     205  return static_cast<int64_t>(v); 
     206} 
     207inline int64_t ToInt64(jlong v) 
     208{ 
     209  return static_cast<int64_t>(v); 
     210} 
     211inline int64_t ToInt64(jbyte v) 
     212{ 
     213  return static_cast<int64_t>(v); 
     214} 
     215inline int64_t ToInt64(jshort v) 
     216{ 
     217  return static_cast<int64_t>(v); 
     218} 
     219 
     220inline double ToDouble(jdouble v) 
    201221{ 
    202222  return static_cast<jdouble>(v); 
    203223} 
    204 float ToFloat(jfloat v) 
     224inline float ToFloat(jfloat v) 
    205225{ 
    206226  return static_cast<jfloat>(v); 
    207227} 
    208228 
    209 std::string ToString(jstring js) 
    210 { 
    211   const jchar* str = tJNIHelper::GetEnv()->GetStringUTFChars(js, NULL); 
     229inline std::string ToString(jstring js) 
     230{ 
     231  const char* str = GetEnv()->GetStringUTFChars(js, NULL); 
    212232  assert(str != NULL && "OutOfMemoryError"); 
    213233  std::string s(str); 
    214   tJNIHelper::GetEnv()->ReleaseStringUTFChars(js, str); 
     234  GetEnv()->ReleaseStringUTFChars(js, str); 
    215235  return s; 
    216236} 
    217237 
    218238template <typename T> 
    219 T* StaticCast(jlong ptr) 
     239inline T* StaticCast(jlong ptr) 
    220240{ 
    221241  tJNIWrappable* jw = (tJNIWrappable*)ptr; 
     
    223243} 
    224244 
    225 template <typename T> 
    226 T* DynamicCast(jlong ptr) 
    227 { 
    228   tJNIWrappable* jw = (tJNIWrappable*)ptr; 
    229   return tCastCache::DynamicCast<T>(jw); 
    230 } 
    231  
    232 } // namespace jni 
    233 } // namespace util 
    234 } // namespace finroc 
    235  
    236 //#endif 
    237  
    238 #endif // rrlib__finroc_core_utils_jni__tJNIConvert_h__ 
     245//template <typename T> 
     246//inline T* DynamicCast(jlong ptr) 
     247//{ 
     248//  tJNIWrappable* jw = (tJNIWrappable*)ptr; 
     249//  return tCastCache::DynamicCast<T>(jw); 
     250//} 
     251 
     252//---------------------------------------------------------------------- 
     253// End of namespace declaration 
     254//---------------------------------------------------------------------- 
     255} 
     256} 
     257 
     258 
     259#endif 
Note: See TracChangeset for help on using the changeset viewer.