xref: /illumos-gate/usr/src/lib/libzfs_jni/common/libzfs_jni_util.h (revision a07094369b21309434206d9b3601d162693466fc)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _LIBZFS_JNI_UTIL_H
28 #define	_LIBZFS_JNI_UTIL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <jni.h>
37 #include <regex.h>
38 #include <libnvpair.h>
39 
40 /*
41  * Constants
42  */
43 
44 #define	ZFSJNI_PACKAGE_DATA	"com/sun/zfs/common/model/"
45 
46 /*
47  * Types
48  */
49 
50 typedef struct zjni_Object {
51 	jclass class;
52 	jobject object;
53 	jmethodID constructor;
54 } zjni_Object_t;
55 
56 typedef struct zjni_Collection {
57 	zjni_Object_t super;
58 
59 	jmethodID method_add;
60 	jmethodID method_size;
61 	jmethodID method_toArray;
62 } zjni_Collection_t;
63 
64 typedef struct zjni_ArrayList {
65 	zjni_Collection_t super;
66 } zjni_ArrayList_t;
67 
68 typedef struct zjni_DatasetSet {
69 	zjni_Collection_t super;
70 } zjni_DatasetSet_t;
71 
72 typedef struct zjni_ArrayCallbackData {
73 	JNIEnv *env;
74 	zjni_Collection_t *list;
75 } zjni_ArrayCallbackData_t;
76 
77 typedef struct zjni_field_mapping {
78 	int value;
79 	char *name;
80 } zjni_field_mapping_t;
81 
82 /* Signature for function to free data */
83 typedef void (*zjni_free_f)(void *);
84 
85 /*
86  * Function prototypes
87  */
88 
89 void zjni_free_array(void **array, zjni_free_f);
90 void zjni_throw_exception(JNIEnv *, const char *, ...);
91 jstring zjni_get_matched_string(JNIEnv *, char *, regmatch_t *);
92 void zjni_get_dataset_from_snapshot(const char *, char *, size_t);
93 jobjectArray zjni_Collection_to_array(JNIEnv *, zjni_Collection_t *, char *);
94 void zjni_new_ArrayList(JNIEnv *, zjni_ArrayList_t *);
95 void zjni_new_DatasetSet(JNIEnv *, zjni_DatasetSet_t *);
96 jobject zjni_int_to_boolean(JNIEnv *, uint64_t);
97 jobject zjni_int_to_enum(
98     JNIEnv *, int, char *, char *, zjni_field_mapping_t *);
99 jobject zjni_str_to_long(JNIEnv *, char *);
100 jobject zjni_long_to_Long(JNIEnv *, uint64_t);
101 jobject zjni_str_to_date(JNIEnv *, char *);
102 jobjectArray zjni_c_string_array_to_java(JNIEnv *, char **, int);
103 char **zjni_java_string_array_to_c(JNIEnv *, jobjectArray);
104 int zjni_count_elements(void **);
105 nvpair_t *zjni_nvlist_walk_nvpair(
106 	nvlist_t *, const char *, data_type_t, nvpair_t *);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* _LIBZFS_JNI_UTIL_H */
113