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 #include <jni.h>
31 #include <regex.h>
32 #include <libnvpair.h>
33 #include <libzfs.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Constants
41  */
42 
43 #define	ZFSJNI_PACKAGE_DATA	"com/sun/zfs/common/model/"
44 
45 /*
46  * Types
47  */
48 
49 typedef struct zjni_Object {
50 	jclass class;
51 	jobject object;
52 	jmethodID constructor;
53 } zjni_Object_t;
54 
55 typedef struct zjni_Collection {
56 	zjni_Object_t super;
57 
58 	jmethodID method_add;
59 	jmethodID method_size;
60 	jmethodID method_toArray;
61 } zjni_Collection_t;
62 
63 typedef struct zjni_ArrayList {
64 	zjni_Collection_t super;
65 } zjni_ArrayList_t;
66 
67 typedef struct zjni_DatasetSet {
68 	zjni_Collection_t super;
69 } zjni_DatasetSet_t;
70 
71 typedef struct zjni_ArrayCallbackData {
72 	JNIEnv *env;
73 	zjni_Collection_t *list;
74 } zjni_ArrayCallbackData_t;
75 
76 typedef struct zjni_field_mapping {
77 	int value;
78 	char *name;
79 } zjni_field_mapping_t;
80 
81 /* Signature for function to free data */
82 typedef void (*zjni_free_f)(void *);
83 
84 /*
85  * Function prototypes
86  */
87 
88 void zjni_free_array(void **array, zjni_free_f);
89 void zjni_throw_exception(JNIEnv *, const char *, ...);
90 jstring zjni_get_matched_string(JNIEnv *, char *, regmatch_t *);
91 void zjni_get_dataset_from_snapshot(const char *, char *, size_t);
92 jobjectArray zjni_Collection_to_array(JNIEnv *, zjni_Collection_t *, char *);
93 void zjni_new_ArrayList(JNIEnv *, zjni_ArrayList_t *);
94 void zjni_new_DatasetSet(JNIEnv *, zjni_DatasetSet_t *);
95 jobject zjni_int_to_boolean(JNIEnv *, uint64_t);
96 jobject zjni_int_to_enum(
97     JNIEnv *, int, char *, char *, zjni_field_mapping_t *);
98 jobject zjni_str_to_long(JNIEnv *, char *);
99 jobject zjni_long_to_Long(JNIEnv *, uint64_t);
100 jobject zjni_str_to_date(JNIEnv *, char *);
101 jobjectArray zjni_c_string_array_to_java(JNIEnv *, char **, int);
102 char **zjni_java_string_array_to_c(JNIEnv *, jobjectArray);
103 int zjni_count_elements(void **);
104 nvpair_t *zjni_nvlist_walk_nvpair(
105 	nvlist_t *, const char *, data_type_t, nvpair_t *);
106 
107 extern libzfs_handle_t *g_zfs;
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* _LIBZFS_JNI_UTIL_H */
114