1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*
15  *  For details of the HDF libraries, see the HDF Documentation at:
16  *    http://hdfgroup.org/HDF5/doc/
17  *
18  */
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
23 
24 #include <stdlib.h>
25 #include "hdf5.h"
26 #include "h5jni.h"
27 #include "h5pLAPLImp.h"
28 
29 /*
30  * Pointer to the JNI's Virtual Machine; used for callback functions.
31  */
32 /* extern JavaVM *jvm; */
33 
34 /*
35  * Class:     hdf_hdf5lib_H5
36  * Method:    H5Pset_nlinks
37  * Signature: (JJ)I
38  */
39 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Pset_1nlinks(JNIEnv * env,jclass clss,jlong lapl_id,jlong nlinks)40 Java_hdf_hdf5lib_H5_H5Pset_1nlinks
41     (JNIEnv *env, jclass clss, jlong lapl_id, jlong nlinks)
42 {
43     herr_t retVal = FAIL;
44 
45     UNUSED(clss);
46 
47     if (nlinks <= 0)
48         H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Pset_nlinks: nlinks <= 0");
49 
50     if ((retVal = H5Pset_nlinks((hid_t)lapl_id, (size_t)nlinks)) < 0)
51         H5_LIBRARY_ERROR(ENVONLY);
52 
53 done:
54     return (jint)retVal;
55 } /* end Java_hdf_hdf5lib_H5_H5Pset_1nlinks */
56 
57 /*
58  * Class:     hdf_hdf5lib_H5
59  * Method:    H5Pget_nlinks
60  * Signature: (J)J
61  */
62 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5_H5Pget_1nlinks(JNIEnv * env,jclass clss,jlong lapl_id)63 Java_hdf_hdf5lib_H5_H5Pget_1nlinks
64     (JNIEnv *env, jclass clss, jlong lapl_id)
65 {
66     size_t nlinks = 0;
67 
68     UNUSED(clss);
69 
70     if (H5Pget_nlinks((hid_t)lapl_id, &nlinks) < 0)
71         H5_LIBRARY_ERROR(ENVONLY);
72 
73 done:
74     return (jlong) nlinks;
75 } /* end Java_hdf_hdf5lib_H5_H5Pget_1nlinks */
76 
77 /*
78  * TODO: H5Pset_elink_cb
79  */
80 
81 /*
82  * TODO: H5Pget_elink_cb
83  */
84 
85 /*
86  * Class:     hdf_hdf5lib_H5
87  * Method:    H5Pset_elink_prefix
88  * Signature: (JLjava/lang/String;)I
89  */
90 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix(JNIEnv * env,jclass clss,jlong lapl_id,jstring prefix)91 Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix
92     (JNIEnv *env, jclass clss, jlong lapl_id, jstring prefix)
93 {
94     const char *linkPrefix = NULL;
95     herr_t      retVal = FAIL;
96 
97     UNUSED(clss);
98 
99     if (NULL == prefix)
100         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pset_elink_prefix: prefix is NULL");
101 
102     PIN_JAVA_STRING(ENVONLY, prefix, linkPrefix, NULL, "H5Pset_elink_prefix: link prefix not pinned");
103 
104     if ((retVal = H5Pset_elink_prefix((hid_t)lapl_id, linkPrefix)) < 0)
105         H5_LIBRARY_ERROR(ENVONLY);
106 
107 done:
108     if (linkPrefix)
109         UNPIN_JAVA_STRING(ENVONLY, prefix, linkPrefix);
110 
111     return (jint)retVal;
112 } /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix */
113 
114 /*
115  * Class:     hdf_hdf5lib_H5
116  * Method:    H5Pget_elink_prefix
117  * Signature: (J[Ljava/lang/String;)J
118  */
119 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix(JNIEnv * env,jclass clss,jlong lapl_id,jobjectArray prefix)120 Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix
121     (JNIEnv *env, jclass clss, jlong lapl_id, jobjectArray prefix)
122 {
123     ssize_t  prefix_size = -1;
124     size_t   size = 0;
125     char    *pre = NULL;
126     jstring  str = NULL;
127 
128     UNUSED(clss);
129 
130     if (NULL == prefix)
131         H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_elink_prefix: prefix is NULL");
132 
133     if ((prefix_size = H5Pget_elink_prefix((hid_t)lapl_id, (char *)NULL, size)) < 0)
134         H5_LIBRARY_ERROR(ENVONLY);
135 
136     if (NULL == (pre = (char *) HDmalloc(sizeof(char) * (size_t) prefix_size + 1)))
137         H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_elink_prefix: memory allocation failed");
138 
139     if (H5Pget_elink_prefix((hid_t)lapl_id, (char *)pre, (size_t) prefix_size + 1) < 0)
140         H5_LIBRARY_ERROR(ENVONLY);
141     pre[prefix_size] = '\0';
142 
143     if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, pre))) {
144         CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
145         H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_elink_prefix: out of memory - unable to construct string from UTF characters");
146     }
147 
148     ENVPTR->SetObjectArrayElement(ENVONLY, prefix, 0, str);
149     CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
150 
151 done:
152     if (pre)
153         HDfree(pre);
154 
155     return (jlong)prefix_size;
156 } /* end Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix */
157 
158 /*
159  * Class:     hdf_hdf5lib_H5
160  * Method:    H5Pset_elink_fapl
161  * Signature: (JJ)I
162  */
163 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Pset_1elink_1fapl(JNIEnv * env,jclass clss,jlong lapl_id,jlong fapl_id)164 Java_hdf_hdf5lib_H5_H5Pset_1elink_1fapl
165     (JNIEnv *env, jclass clss, jlong lapl_id, jlong fapl_id)
166 {
167     herr_t retVal = FAIL;
168 
169     UNUSED(clss);
170 
171     if ((retVal = H5Pset_elink_fapl((hid_t)lapl_id, (hid_t)fapl_id)) < 0)
172         H5_LIBRARY_ERROR(ENVONLY);
173 
174 done:
175     return (jint)retVal;
176 } /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1fapl */
177 
178 /*
179  * Class:     hdf_hdf5lib_H5
180  * Method:    _H5Pget_elink_fapl
181  * Signature: (J)J
182  */
183 JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Pget_1elink_1fapl(JNIEnv * env,jclass clss,jlong lapl_id)184 Java_hdf_hdf5lib_H5__1H5Pget_1elink_1fapl
185     (JNIEnv *env, jclass clss, jlong lapl_id)
186 {
187     hid_t retVal = H5I_INVALID_HID;
188 
189     UNUSED(clss);
190 
191     if ((retVal = H5Pget_elink_fapl((hid_t)lapl_id)) < 0)
192         H5_LIBRARY_ERROR(ENVONLY);
193 
194 done:
195     return (jlong)retVal;
196 } /* end Java_hdf_hdf5lib_H5__1H5Pget_1elink_1fapl */
197 
198 /*
199  * Class:     hdf_hdf5lib_H5
200  * Method:    H5Pset_elink_acc_flags
201  * Signature: (JI)I
202  */
203 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Pset_1elink_1acc_1flags(JNIEnv * env,jclass clss,jlong lapl_id,jint flags)204 Java_hdf_hdf5lib_H5_H5Pset_1elink_1acc_1flags
205     (JNIEnv *env, jclass clss, jlong lapl_id, jint flags)
206 {
207     herr_t retVal = FAIL;
208 
209     UNUSED(clss);
210 
211     if ((retVal = H5Pset_elink_acc_flags((hid_t)lapl_id, (unsigned)flags)) < 0)
212         H5_LIBRARY_ERROR(ENVONLY);
213 
214 done:
215     return (jint) retVal;
216 } /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1acc_1flags */
217 
218 /*
219  * Class:     hdf_hdf5lib_H5
220  * Method:    H5Pget_elink_acc_flags
221  * Signature: (J)I
222  */
223 JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Pget_1elink_1acc_1flags(JNIEnv * env,jclass clss,jlong lapl_id)224 Java_hdf_hdf5lib_H5_H5Pget_1elink_1acc_1flags
225     (JNIEnv *env, jclass clss, jlong lapl_id)
226 {
227     unsigned flags;
228 
229     UNUSED(clss);
230 
231     if (H5Pget_elink_acc_flags((hid_t)lapl_id, &flags) < 0)
232         H5_LIBRARY_ERROR(ENVONLY);
233 
234 done:
235     return (jint)flags;
236 } /* end Java_hdf_hdf5lib_H5_H5Pget_1elink_1acc_1flags */
237 
238 #ifdef __cplusplus
239 } /* end extern "C" */
240 #endif /* __cplusplus */
241