1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26
27 #include "jni_Refcount.h"
28 #include "jni_ErrorMsg.hpp"
29
30 #include <ngs/itf/Refcount.hpp>
31
32 using namespace ngs;
33
34 inline
Self(size_t jself)35 OpaqueRefcount * Self ( size_t jself )
36 {
37 return reinterpret_cast < OpaqueRefcount* > ( jself );
38 }
39
40 inline
Cast(void * obj)41 jlong Cast ( void * obj )
42 {
43 return ( jlong ) ( size_t ) obj;
44 }
45
46 /*
47 * Class: ngs_itf_Refcount
48 * Method: Duplicate
49 * Signature: (J)J
50 */
Java_ngs_itf_Refcount_Duplicate(JNIEnv * jenv,jobject jthis,jlong jself)51 JNIEXPORT jlong JNICALL Java_ngs_itf_Refcount_Duplicate
52 ( JNIEnv * jenv, jobject jthis, jlong jself )
53 {
54 if ( jself != 0 )
55 {
56 try
57 {
58 OpaqueRefcount * self = Self ( jself );
59 void * val = self -> Duplicate ();
60 return Cast ( val );
61 }
62 catch ( ErrorMsg & x )
63 {
64 ErrorMsgThrow ( jenv, xt_error_msg, x . what () );
65 }
66 catch ( std :: exception & x )
67 {
68 ErrorMsgThrow ( jenv, xt_error_msg, x . what () );
69 }
70 catch ( ... )
71 {
72 ErrorMsgThrow ( jenv, xt_error_msg, "unknown error" );
73 }
74 }
75
76 return 0;
77 }
78
79 /*
80 * Class: ngs_itf_Refcount
81 * Method: Release
82 * Signature: (J)V
83 */
Java_ngs_itf_Refcount_Release(JNIEnv * jenv,jobject jthis,jlong jself)84 JNIEXPORT void JNICALL Java_ngs_itf_Refcount_Release
85 ( JNIEnv * jenv, jobject jthis, jlong jself )
86 {
87 if ( jself != 0 )
88 {
89 try
90 {
91 OpaqueRefcount * self = Self ( jself );
92 self -> Release ();
93 }
94 catch ( ErrorMsg & x )
95 {
96 ErrorMsgThrow ( jenv, xt_error_msg, x . what () );
97 }
98 catch ( std :: exception & x )
99 {
100 ErrorMsgThrow ( jenv, xt_error_msg, x . what () );
101 }
102 catch ( ... )
103 {
104 ErrorMsgThrow ( jenv, xt_error_msg, "unknown error" );
105 }
106 }
107 }
108
109 /*
110 * Class: ngs_itf_Refcount
111 * Method: ReleaseRef
112 * Signature: (J)V
113 */
Java_ngs_itf_Refcount_ReleaseRef(JNIEnv * jenv,jclass jcls,jlong jref)114 JNIEXPORT void JNICALL Java_ngs_itf_Refcount_ReleaseRef
115 ( JNIEnv * jenv, jclass jcls, jlong jref )
116 {
117 if ( jref != 0 )
118 {
119 try
120 {
121 OpaqueRefcount * ref = Self ( jref );
122 ref -> Release ();
123 }
124 catch ( ErrorMsg & x )
125 {
126 ErrorMsgThrow ( jenv, xt_error_msg, x . what () );
127 }
128 catch ( std :: exception & x )
129 {
130 ErrorMsgThrow ( jenv, xt_error_msg, x . what () );
131 }
132 catch ( ... )
133 {
134 ErrorMsgThrow ( jenv, xt_error_msg, "unknown error" );
135 }
136 }
137 }
138