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 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 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