Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
DBTNativeDownlink.cxx
Go to the documentation of this file.
1 /*
2  * Author: Sven Gothel <sgothel@jausoft.com>
3  * Copyright (c) 2020 Gothel Software e.K.
4  * Copyright (c) 2020 ZAFENA AB
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 #include "jau_direct_bt_DBTNativeDownlink.h"
27 
28 #include <jau/debug.hpp>
29 
30 #include "helper_base.hpp"
31 #include "helper_dbt.hpp"
32 
33 #include "direct_bt/BTTypes1.hpp"
34 
35 using namespace direct_bt;
36 using namespace jau;
37 
38 void Java_jau_direct_1bt_DBTNativeDownlink_initNativeJavaObject(JNIEnv *env, jobject obj, jlong nativeInstance)
39 {
40  try {
41  JavaUplink *javaUplink = castInstance<JavaUplink>(nativeInstance);
42  jclass javaClazz = search_class(env, obj);
44  if( nullptr == javaClazz ) {
45  throw InternalError("DBTNativeDownlink class not found", E_FILE_LINE);
46  }
47  jmethodID mNotifyDeleted = search_method(env, javaClazz, "notifyDeleted", "()V", false);
49  if( nullptr == mNotifyDeleted ) {
50  throw InternalError("DBTNativeDownlink class has no notifyDeleted() method, for "+javaUplink->toString(), E_FILE_LINE);
51  }
52  javaUplink->setJavaObject( std::shared_ptr<JavaAnon>( new JavaGlobalObj(obj, mNotifyDeleted) ) );
53  JavaGlobalObj::check(javaUplink->getJavaObject(), E_FILE_LINE);
54  DBG_JNI_PRINT("Java_jau_direct_1bt_DBTNativeDownlink_initNativeJavaObject %p -> %s", javaUplink, javaUplink->toString().c_str());
55  } catch(...) {
57  }
58 }
59 
60 void Java_jau_direct_1bt_DBTNativeDownlink_deleteNativeJavaObject(JNIEnv *env, jobject obj, jlong nativeInstance)
61 {
62  (void)obj;
63  try {
64  JavaUplink *javaUplink = castInstance<JavaUplink>(nativeInstance);
65  DBG_JNI_PRINT("Java_jau_direct_1bt_DBTNativeDownlink_deleteNativeJavaObject %p -> %s", javaUplink, javaUplink->toString().c_str());
66  javaUplink->setJavaObject();
67  } catch(...) {
69  }
70 }
71 
helper_dbt.hpp
helper_base.hpp
direct_bt
Definition: ATTPDUTypes.hpp:171
jau::InternalError
Definition: basic_types.hpp:93
BTTypes1.hpp
DBG_JNI_PRINT
#define DBG_JNI_PRINT(...)
Use for environment-variable environment::DEBUG_JNI conditional debug messages, prefix '[elapsed_time...
Definition: debug.hpp:81
jau
Definition: basic_algos.hpp:34
jau::search_class
jclass search_class(JNIEnv *env, const char *clazz_name)
jau::java_exception_check_and_throw
void java_exception_check_and_throw(JNIEnv *env, const char *file, int line)
Throws a C++ exception if a java exception occurred, otherwise do nothing.
E_FILE_LINE
#define E_FILE_LINE
Definition: basic_types.hpp:64
jau::search_method
jmethodID search_method(JNIEnv *env, jclass clazz, const char *method_name, const char *prototype, bool is_static)
debug.hpp
rethrow_and_raise_java_exception
#define rethrow_and_raise_java_exception(E)
Re-throw current exception and raise respective java exception using any matching function above.
Definition: helper_base.hpp:55
jau::JavaGlobalObj
Implementation for JavaAnon, by simply wrapping a JNIGlobalRef instance.
Definition: helper_jni.hpp:136