Cipherpack v1.2.0-dirty
A Cryprographic Stream Processor
CPNativeDownlink.cxx
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#include "org_cipherpack_CPNativeDownlink.h"
26
27#include <jau/debug.hpp>
28
29#include "helper_base.hpp"
30
32
33void Java_org_cipherpack_CPNativeDownlink_initNativeJavaObject(JNIEnv *env, jobject obj, jlong nativeInstance)
34{
35 try {
36 jau::jni::shared_ptr_ref<jau::jni::JavaUplink> javaUplink(nativeInstance); // hold copy until done
37 javaUplink.null_check2();
38 jau::jni::JNIGlobalRef global_obj(obj); // lock instance first (global reference), inserted below
39 jclass javaClazz = jau::jni::search_class(env, global_obj.getObject());
40 jau::jni::java_exception_check_and_throw(env, E_FILE_LINE);
41 if( nullptr == javaClazz ) {
42 throw jau::InternalError("CPNativeDownlink class not found", E_FILE_LINE);
43 }
44 jmethodID mNotifyDeleted = jau::jni::search_method(env, javaClazz, "notifyDeleted", "()V", false);
45 jau::jni::java_exception_check_and_throw(env, E_FILE_LINE);
46 if( nullptr == mNotifyDeleted ) {
47 throw jau::InternalError("CPNativeDownlink class has no notifyDeleted() method, for "+javaUplink->toString(), E_FILE_LINE);
48 }
49 javaUplink->setJavaObject( std::make_shared<jau::jni::JavaGlobalObj>( std::move(global_obj), mNotifyDeleted ) );
50 jau::jni::JavaGlobalObj::check(javaUplink->getJavaObject(), E_FILE_LINE);
51 DBG_JNI_PRINT("Java_org_cipherpack_CPNativeDownlink_initNativeJavaObject %p -> %s", javaUplink.shared_ptr().get(), javaUplink->toString().c_str());
52 } catch(...) {
54 }
55}
56
57void Java_org_cipherpack_CPNativeDownlink_deleteNativeJavaObject(JNIEnv *env, jobject obj, jlong nativeInstance)
58{
59 (void)obj;
60 try {
61 jau::jni::shared_ptr_ref<jau::jni::JavaUplink> javaUplink(nativeInstance); // hold copy until done
62 javaUplink.null_check2();
63 DBG_JNI_PRINT("Java_org_cipherpack_CPNativeDownlink_deleteNativeJavaObject %p -> %s", javaUplink.shared_ptr().get(), javaUplink->toString().c_str());
64 javaUplink->setJavaObject();
65 } catch(...) {
67 }
68}
69
#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:45