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