8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / pools / poold / libjpool / jpool.c
blobd2ca2f556ae66e32c683fc3e882e692e6b13664b
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <errno.h>
30 #include <jni.h>
31 #include <pool.h>
32 #include <stdlib.h>
33 #include <string.h>
35 #include <sys/time.h>
37 #include "jpool.h"
39 struct pool_callback {
40 jobject pc_user;
41 jobject pc_handler;
42 jobject pc_elem;
43 JNIEnv *pc_env;
46 static void throwException(JNIEnv *, const char *, const char *);
47 static void throw_pe(JNIEnv *);
48 static jobject makeUnsignedInt64(JNIEnv *, uint64_t);
49 static int pool_property_walker(pool_conf_t *, pool_elem_t *p, const char *,
50 pool_value_t *, void *);
51 static jobject copyArray(JNIEnv *, void **);
54 * Cached class, method, and field IDs.
56 static jclass ui64class;
57 static jmethodID ui64cons_mid;
60 * Throw an exception of the specified class with the specified message.
62 void
63 throwException(JNIEnv *env, const char *class, const char *msg)
65 jclass clazz;
67 clazz = (*env)->FindClass(env, class);
69 (*env)->ThrowNew(env, clazz, msg);
73 * Throw a PoolsException.
75 void
76 throw_pe(JNIEnv *jenv)
78 jclass clazz;
79 jmethodID mid;
80 jthrowable throwObj;
82 clazz = (*jenv)->FindClass(jenv,
83 "com/sun/solaris/service/pools/PoolsException");
84 mid = (*jenv)->GetMethodID(jenv, clazz, "<init>", "()V");
85 throwObj = (*jenv)->NewObject(jenv, clazz, mid);
86 (*jenv)->Throw(jenv, throwObj);
90 * Return an instance of an UnsignedInt64 class which encapsulates the
91 * supplied value.
93 jobject
94 makeUnsignedInt64(JNIEnv *env, uint64_t value)
96 jobject valueObj;
97 jobject byteArray;
98 jbyte *bytes;
99 int i;
101 if (!(byteArray = (*env)->NewByteArray(env, 9)))
102 return (NULL); /* OutOfMemoryError thrown */
103 if (!(bytes = (*env)->GetByteArrayElements(env, byteArray, NULL)))
104 return (NULL); /* OutOfMemoryError thrown */
107 * Interpret the uint64_t as a 9-byte big-endian signed quantity
108 * suitable for constructing an UnsignedInt64 or BigInteger.
110 for (i = 8; i >= 1; i--) {
111 bytes[i] = value & 0xff;
112 value >>= 8;
114 bytes[0] = 0;
115 (*env)->ReleaseByteArrayElements(env, byteArray, bytes, 0);
117 if (!(valueObj = (*env)->NewObject(env, ui64class, ui64cons_mid,
118 byteArray)))
119 return (NULL); /* exception thrown */
121 return (valueObj);
125 * Create an array list and then copy the native array into it
127 jobject
128 copyArray(JNIEnv *jenv, void **nativeArray)
130 int i;
131 jobject jresult = NULL;
133 if (nativeArray != NULL) {
134 jclass ALclazz;
135 jmethodID ALinit, ALadd;
136 jclass Lclazz;
137 jmethodID Linit;
139 ALclazz = (*jenv)->FindClass(jenv,
140 "java/util/ArrayList");
141 ALinit = (*jenv)->GetMethodID(jenv,
142 ALclazz, "<init>", "()V");
143 ALadd = (*jenv)->GetMethodID(jenv,
144 ALclazz, "add", "(Ljava/lang/Object;)Z");
145 jresult = (*jenv)->NewObject(jenv, ALclazz, ALinit);
146 Lclazz = (*jenv)->FindClass(jenv, "java/lang/Long");
147 Linit = (*jenv)->GetMethodID(jenv,
148 Lclazz, "<init>", "(J)V");
149 for (i = 0; nativeArray[i] != NULL; i++) {
150 jobject L;
151 /* Build longs and add them */
152 L = (*jenv)->NewObject(jenv,
153 Lclazz, Linit, (jlong)(uintptr_t)nativeArray[i]);
154 (*jenv)->CallBooleanMethod(jenv,
155 jresult, ALadd, L);
157 free(nativeArray);
159 return (jresult);
163 * pool_version(3pool) wrapper
165 /*ARGSUSED*/
166 JNIEXPORT jlong JNICALL
167 Java_com_sun_solaris_service_pools_PoolInternal_pool_1version(JNIEnv *jenv,
168 jclass jcls, jlong jver) {
169 return ((jlong)pool_version((uint_t)jver));
173 * native constant accessor
175 /*ARGSUSED*/
176 JNIEXPORT jint JNICALL
177 Java_com_sun_solaris_service_pools_PoolInternal_get_1POX_1NATIVE(JNIEnv *jenv,
178 jclass jcls) {
179 return ((jint)POX_NATIVE);
183 * native constant accessor
185 /*ARGSUSED*/
186 JNIEXPORT jint JNICALL
187 Java_com_sun_solaris_service_pools_PoolInternal_get_1POX_1TEXT(JNIEnv *jenv,
188 jclass jcls) {
189 return ((jint)POX_TEXT);
193 * native constant accessor
195 /*ARGSUSED*/
196 JNIEXPORT jint JNICALL
197 Java_com_sun_solaris_service_pools_PoolInternal_get_1POC_1INVAL(JNIEnv *jenv,
198 jclass jcls) {
199 return ((jint)POC_INVAL);
203 * native constant accessor
205 /*ARGSUSED*/
206 JNIEXPORT jint JNICALL
207 Java_com_sun_solaris_service_pools_PoolInternal_get_1POC_1UINT(JNIEnv *jenv,
208 jclass jcls) {
209 return ((jint)POC_UINT);
213 * native constant accessor
215 /*ARGSUSED*/
216 JNIEXPORT jint JNICALL
217 Java_com_sun_solaris_service_pools_PoolInternal_get_1POC_1INT(JNIEnv *jenv,
218 jclass jcls) {
219 return ((jint)POC_INT);
223 * native constant accessor
225 /*ARGSUSED*/
226 JNIEXPORT jint JNICALL
227 Java_com_sun_solaris_service_pools_PoolInternal_get_1POC_1DOUBLE(JNIEnv *jenv,
228 jclass jcls) {
229 return ((jint)POC_DOUBLE);
233 * native constant accessor
235 /*ARGSUSED*/
236 JNIEXPORT jint JNICALL
237 Java_com_sun_solaris_service_pools_PoolInternal_get_1POC_1BOOL(JNIEnv *jenv,
238 jclass jcls) {
239 return ((jint)POC_BOOL);
243 * native constant accessor
245 /*ARGSUSED*/
246 JNIEXPORT jint JNICALL
247 Java_com_sun_solaris_service_pools_PoolInternal_get_1POC_1STRING(JNIEnv *jenv,
248 jclass jcls) {
249 return ((jint)POC_STRING);
253 * native constant accessor
255 /*ARGSUSED*/
256 JNIEXPORT jint JNICALL
257 Java_com_sun_solaris_service_pools_PoolInternal_get_1POV_1NONE(JNIEnv *jenv,
258 jclass jcls) {
259 return ((jint)POV_NONE);
263 * native constant accessor
265 /*ARGSUSED*/
266 JNIEXPORT jint JNICALL
267 Java_com_sun_solaris_service_pools_PoolInternal_get_1POV_1LOOSE(JNIEnv *jenv,
268 jclass jcls) {
269 return ((jint)POV_LOOSE);
273 * native constant accessor
275 /*ARGSUSED*/
276 JNIEXPORT jint JNICALL
277 Java_com_sun_solaris_service_pools_PoolInternal_get_1POV_1STRICT(JNIEnv *jenv,
278 jclass jcls) {
279 return ((jint)POV_STRICT);
283 * native constant accessor
285 /*ARGSUSED*/
286 JNIEXPORT jint JNICALL
287 Java_com_sun_solaris_service_pools_PoolInternal_get_1POV_1RUNTIME(JNIEnv *jenv,
288 jclass jcls) {
289 return ((jint)POV_RUNTIME);
293 * native constant accessor
295 /*ARGSUSED*/
296 JNIEXPORT jint JNICALL
297 Java_com_sun_solaris_service_pools_PoolInternal_get_1POF_1INVALID(JNIEnv *jenv,
298 jclass jcls) {
299 return ((jint)POF_INVALID);
303 * native constant accessor
305 /*ARGSUSED*/
306 JNIEXPORT jint JNICALL
307 Java_com_sun_solaris_service_pools_PoolInternal_get_1POF_1VALID(JNIEnv *jenv,
308 jclass jcls) {
309 return ((jint)POF_VALID);
313 * native constant accessor
315 /*ARGSUSED*/
316 JNIEXPORT jint JNICALL
317 Java_com_sun_solaris_service_pools_PoolInternal_get_1POF_1DESTROY(JNIEnv *jenv,
318 jclass jcls) {
319 return ((jint)POF_DESTROY);
323 * pool_error(3pool) wrapper
325 /*ARGSUSED*/
326 JNIEXPORT jint JNICALL
327 Java_com_sun_solaris_service_pools_PoolInternal_pool_1error(JNIEnv *jenv,
328 jclass jcls) {
329 return ((jint)pool_error());
333 * pool_strerror(3pool) wrapper
335 /*ARGSUSED*/
336 JNIEXPORT jstring JNICALL
337 Java_com_sun_solaris_service_pools_PoolInternal_pool_1strerror(JNIEnv *jenv,
338 jclass jcls, jint jperr) {
339 jstring jresult = NULL;
340 char *result;
342 result = (char *)pool_strerror((int)jperr);
344 if (result)
345 jresult = (*jenv)->NewStringUTF(jenv, result);
346 return (jresult);
350 * strerror(3c) wrapper
352 /*ARGSUSED*/
353 JNIEXPORT jstring JNICALL
354 Java_com_sun_solaris_service_pools_PoolInternal_pool_1strerror_1sys(JNIEnv *
355 jenv, jclass jcls) {
356 jstring jresult = NULL;
357 char *result;
359 result = (char *)strerror(errno);
361 if (result)
362 jresult = (*jenv)->NewStringUTF(jenv, result);
363 return (jresult);
367 * errno(3c) accessor
369 /*ARGSUSED*/
370 JNIEXPORT jint JNICALL
371 Java_com_sun_solaris_service_pools_PoolsException_getErrno(JNIEnv *jenv,
372 jclass jcls) {
373 return ((jint)errno);
377 * pool_resource_type_list(3pool) wrapper
379 /*ARGSUSED*/
380 JNIEXPORT jint JNICALL
381 Java_com_sun_solaris_service_pools_PoolInternal_pool_1resource_1type_1list(
382 JNIEnv *jenv, jclass jcls, jlong jreslist, jlong jnumres) {
383 char **reslist = (char **)(uintptr_t)jreslist;
384 uint_t *numres = (uint_t *)(uintptr_t)jnumres;
386 return ((jint)pool_resource_type_list((char const **)reslist, numres));
390 * pool_get_status(3pool) wrapper
392 /*ARGSUSED*/
393 JNIEXPORT jint JNICALL
394 Java_com_sun_solaris_service_pools_PoolInternal_pool_1get_1status(JNIEnv *jenv,
395 jclass jcls) {
396 int status;
397 int err;
399 err = pool_get_status(&status);
400 if (err == -1)
401 return ((jint)PO_FAIL);
402 else
403 return ((jint)status);
407 * pool_set_status(3pool) wrapper
409 /*ARGSUSED*/
410 JNIEXPORT jint JNICALL
411 Java_com_sun_solaris_service_pools_PoolInternal_pool_1set_1status(JNIEnv *jenv,
412 jclass jcls, jint jstate) {
413 return ((jint)pool_set_status((int)jstate));
417 * pool_conf_alloc(3pool) wrapper
419 /*ARGSUSED*/
420 JNIEXPORT jlong JNICALL
421 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1alloc(JNIEnv *jenv,
422 jclass jcls) {
423 return ((jlong)(uintptr_t)pool_conf_alloc());
427 * pool_conf_free(3pool) wrapper
429 /*ARGSUSED*/
430 JNIEXPORT void JNICALL
431 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1free(JNIEnv *jenv,
432 jclass jcls, jlong jconf) {
433 pool_conf_free((pool_conf_t *)(uintptr_t)jconf);
437 * pool_conf_status(3pool) wrapper
439 /*ARGSUSED*/
440 JNIEXPORT jint JNICALL
441 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1status(JNIEnv *jenv,
442 jclass jcls, jlong jconf) {
443 return ((jint)pool_conf_status((pool_conf_t *)(uintptr_t)jconf));
447 * pool_conf_close(3pool) wrapper
449 /*ARGSUSED*/
450 JNIEXPORT jint JNICALL
451 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1close(JNIEnv *jenv,
452 jclass jcls, jlong jconf) {
453 return ((jint)pool_conf_close((pool_conf_t *)(uintptr_t)jconf));
457 * pool_conf_remove(3pool) wrapper
459 /*ARGSUSED*/
460 JNIEXPORT jint JNICALL
461 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1remove(JNIEnv *jenv,
462 jclass jcls, jlong jconf) {
463 return ((jint)pool_conf_remove((pool_conf_t *)(uintptr_t)jconf));
467 * pool_conf_open(3pool) wrapper
469 /*ARGSUSED*/
470 JNIEXPORT jint JNICALL
471 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1open(JNIEnv *jenv,
472 jclass jcls, jlong jconf, jstring jlocation, jint jflags) {
473 const char *location;
474 int result;
476 location = (jlocation) ? (*jenv)->GetStringUTFChars(jenv,
477 jlocation, 0) : NULL;
478 result = (int)pool_conf_open((pool_conf_t *)(uintptr_t)jconf, location,
479 (int)jflags);
481 if (location)
482 (*jenv)->ReleaseStringUTFChars(jenv, jlocation, location);
483 return ((jint)result);
487 * pool_conf_rollback(3pool) wrapper
489 /*ARGSUSED*/
490 JNIEXPORT jint JNICALL
491 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1rollback(
492 JNIEnv *jenv, jclass jcls, jlong jconf) {
493 return ((jint)pool_conf_rollback((pool_conf_t *)(uintptr_t)jconf));
497 * pool_conf_commit(3pool) wrapper
499 /*ARGSUSED*/
500 JNIEXPORT jint JNICALL
501 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1commit(JNIEnv *jenv,
502 jclass jcls, jlong jconf, jint jactive) {
503 return ((jint)pool_conf_commit(
504 (pool_conf_t *)(uintptr_t)jconf, (int)jactive));
508 * pool_conf_export(3pool) wrapper
510 /*ARGSUSED*/
511 JNIEXPORT jint JNICALL
512 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1export(JNIEnv *jenv,
513 jclass jcls, jlong jconf, jstring jlocation, jint jformat) {
514 const char *location;
515 int result;
517 location = (jlocation) ? (*jenv)->GetStringUTFChars(jenv,
518 jlocation, 0) : NULL;
519 result = (int)pool_conf_export((pool_conf_t *)(uintptr_t)jconf,
520 location, (pool_export_format_t)jformat);
522 if (location)
523 (*jenv)->ReleaseStringUTFChars(jenv, jlocation, location);
524 return ((jint)result);
528 * pool_conf_validate(3pool) wrapper
530 /*ARGSUSED*/
531 JNIEXPORT jint JNICALL
532 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1validate(
533 JNIEnv *jenv, jclass jcls, jlong jconf, jint jlevel) {
534 return ((jint)pool_conf_validate((pool_conf_t *)(uintptr_t)jconf,
535 (pool_valid_level_t)jlevel));
539 * pool_conf_update(3pool) wrapper
541 /*ARGSUSED*/
542 JNIEXPORT jint JNICALL
543 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1update(JNIEnv *jenv,
544 jclass jcls, jlong jconf) {
545 int changed;
546 int result;
548 result = pool_conf_update((pool_conf_t *)(uintptr_t)jconf, &changed);
550 if (result != PO_SUCCESS) {
551 throw_pe(jenv);
554 return ((jint)changed);
558 * pool_get_pool(3pool) wrapper
560 /*ARGSUSED*/
561 JNIEXPORT jlong JNICALL
562 Java_com_sun_solaris_service_pools_PoolInternal_pool_1get_1pool(JNIEnv *jenv,
563 jclass jcls, jlong jconf, jstring jname) {
564 const char *name;
565 pool_t *result;
567 name = (jname) ? (*jenv)->GetStringUTFChars(jenv, jname, 0) :
568 NULL;
569 result = (pool_t *)pool_get_pool((pool_conf_t *)(uintptr_t)jconf, name);
571 if (name)
572 (*jenv)->ReleaseStringUTFChars(jenv, jname, name);
573 return ((jlong)(uintptr_t)result);
577 * pool_query_pools(3pool) wrapper
579 /*ARGSUSED*/
580 JNIEXPORT jobject JNICALL
581 Java_com_sun_solaris_service_pools_PoolInternal_pool_1query_1pools(JNIEnv *jenv,
582 jclass jcls, jlong jconf, jobject jprops) {
583 pool_value_t **props;
584 pool_t **result;
585 jclass Lclazz;
586 jmethodID Lsize;
587 jint size;
588 uint_t nelem;
589 int i;
593 * Initialize the target parameter for case when input is null
595 props = NULL;
596 if (jprops != NULL) {
597 Lclazz = (*jenv)->GetObjectClass(jenv, jprops);
598 Lsize = (*jenv)->GetMethodID(jenv, Lclazz, "size", "()I");
599 size = (*jenv)->CallIntMethod(jenv, jprops, Lsize);
601 if (size != 0) {
602 jmethodID Lget;
604 Lget = (*jenv)->GetMethodID(jenv, Lclazz, "get",
605 "(I)Ljava/lang/Object;");
607 * Allocate space for the props array
610 if ((props = calloc(size + 1, sizeof (pool_value_t *)))
611 == NULL) {
612 throwException(jenv, "java/lang/Exception",
613 "Could not allocate props array");
614 return (NULL);
617 * Copy in the array
619 for (i = 0; i < size; i++) {
620 jobject aVal;
621 jclass Vclazz;
622 jfieldID Vthis;
623 jlong this;
625 aVal = (*jenv)->CallObjectMethod(jenv, jprops,
626 Lget, (jint) i);
627 Vclazz = (*jenv)->GetObjectClass(jenv, aVal);
628 Vthis = (*jenv)->GetFieldID(jenv, Vclazz,
629 "_this", "J");
630 this = (*jenv)->GetLongField(jenv, aVal, Vthis);
631 props[i] = (pool_value_t *)(uintptr_t)this;
635 result = pool_query_pools((pool_conf_t *)(uintptr_t)jconf, &nelem,
636 props);
637 free(props);
638 return (copyArray(jenv, (void **)result));
642 * pool_get_resource(3pool) wrapper
644 /*ARGSUSED*/
645 JNIEXPORT jlong JNICALL
646 Java_com_sun_solaris_service_pools_PoolInternal_pool_1get_1resource(
647 JNIEnv *jenv, jclass jcls, jlong jconf, jstring jtype, jstring jname) {
648 const char *type;
649 const char *name;
650 pool_resource_t *result;
652 type = (jtype) ? (*jenv)->GetStringUTFChars(jenv, jtype, 0) :
653 NULL;
654 name = (jname) ? (*jenv)->GetStringUTFChars(jenv, jname, 0) :
655 NULL;
656 result = pool_get_resource((pool_conf_t *)(uintptr_t)jconf, type, name);
658 if (type)
659 (*jenv)->ReleaseStringUTFChars(jenv, jtype, type);
660 if (name)
661 (*jenv)->ReleaseStringUTFChars(jenv, jname, name);
662 return ((jlong)(uintptr_t)result);
666 * pool_query_resources(3pool) wrapper
668 /*ARGSUSED*/
669 JNIEXPORT jobject JNICALL
670 Java_com_sun_solaris_service_pools_PoolInternal_pool_1query_1resources(
671 JNIEnv *jenv, jclass jcls, jlong jconf, jobject jprops) {
672 pool_value_t **props;
673 pool_resource_t **result;
674 jclass Lclazz;
675 jmethodID Lsize;
676 jint size;
677 uint_t nelem;
678 int i;
681 * Initialize the target parameter for case when input is null
683 props = NULL;
684 if (jprops != NULL) {
685 Lclazz = (*jenv)->GetObjectClass(jenv, jprops);
686 Lsize = (*jenv)->GetMethodID(jenv, Lclazz, "size", "()I");
687 size = (*jenv)->CallIntMethod(jenv, jprops, Lsize);
689 if (size != 0) {
690 jmethodID Lget;
692 Lget = (*jenv)->GetMethodID(jenv, Lclazz, "get",
693 "(I)Ljava/lang/Object;");
695 * Allocate space for the props array
697 if ((props = calloc(size + 1, sizeof (pool_value_t *)))
698 == NULL) {
699 throwException(jenv, "java/lang/Exception",
700 "Could not allocate props array");
701 return (NULL);
704 * Copy in the array
706 for (i = 0; i < size; i++) {
707 jobject aVal;
708 jclass Vclazz;
709 jfieldID Vthis;
710 jlong this;
713 aVal = (*jenv)->CallObjectMethod(jenv, jprops,
714 Lget, (jint) i);
715 Vclazz = (*jenv)->GetObjectClass(jenv, aVal);
716 Vthis = (*jenv)->GetFieldID(jenv, Vclazz,
717 "_this", "J");
718 this = (*jenv)->GetLongField(jenv, aVal, Vthis);
719 props[i] = (pool_value_t *)(uintptr_t)this;
723 result = pool_query_resources((pool_conf_t *)(uintptr_t)jconf, &nelem,
724 props);
725 free(props);
726 return (copyArray(jenv, (void *)result));
730 * pool_query_components(3pool) wrapper
732 /*ARGSUSED*/
733 JNIEXPORT jobject JNICALL
734 Java_com_sun_solaris_service_pools_PoolInternal_pool_1query_1components(
735 JNIEnv *jenv, jclass jcls, jlong jconf, jobject jprops) {
736 pool_value_t **props;
737 pool_component_t **result;
738 jclass Lclazz;
739 jmethodID Lsize;
740 jint size;
741 uint_t nelem;
742 int i;
745 * Initialize the target parameter for case when input is null
747 props = NULL;
748 if (jprops != NULL) {
749 Lclazz = (*jenv)->GetObjectClass(jenv, jprops);
750 Lsize = (*jenv)->GetMethodID(jenv, Lclazz, "size", "()I");
751 size = (*jenv)->CallIntMethod(jenv, jprops, Lsize);
753 if (size != 0) {
754 jmethodID Lget;
756 Lget = (*jenv)->GetMethodID(jenv, Lclazz, "get",
757 "(I)Ljava/lang/Object;");
759 * Allocate space for the props array
762 if ((props = calloc(size + 1, sizeof (pool_value_t *)))
763 == NULL) {
764 throwException(jenv, "java/lang/Exception",
765 "Could not allocate props array");
766 return (NULL);
769 * Copy in the array
771 for (i = 0; i < size; i++) {
772 jobject aVal;
773 jclass Vclazz;
774 jfieldID Vthis;
775 jlong this;
777 aVal = (*jenv)->CallObjectMethod(jenv, jprops,
778 Lget, (jint) i);
779 Vclazz = (*jenv)->GetObjectClass(jenv, aVal);
780 Vthis = (*jenv)->GetFieldID(jenv, Vclazz,
781 "_this", "J");
782 this = (*jenv)->GetLongField(jenv, aVal, Vthis);
783 props[i] = (pool_value_t *)(uintptr_t)this;
787 result = pool_query_components((pool_conf_t *)(uintptr_t)jconf, &nelem,
788 props);
789 free(props);
790 return (copyArray(jenv, (void **)result));
794 * pool_conf_location(3pool) wrapper
796 /*ARGSUSED*/
797 JNIEXPORT jstring JNICALL
798 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1location(
799 JNIEnv *jenv, jclass jcls, jlong jconf) {
800 jstring jresult = NULL;
801 const char *result;
803 result = pool_conf_location((pool_conf_t *)(uintptr_t)jconf);
805 if (result)
806 jresult = (*jenv)->NewStringUTF(jenv, result);
807 return (jresult);
811 * pool_conf_info(3pool) wrapper
813 /*ARGSUSED*/
814 JNIEXPORT jstring JNICALL
815 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1info(JNIEnv *jenv,
816 jclass jcls, jlong jconf, jint jflags) {
817 jstring jresult = NULL;
818 const char *result;
820 result = pool_conf_info((pool_conf_t *)(uintptr_t)jconf, (int)jflags);
822 if (result)
823 jresult = (*jenv)->NewStringUTF(jenv, result);
824 free((void *)result);
825 return (jresult);
829 * pool_resource_create(3pool) wrapper
831 /*ARGSUSED*/
832 JNIEXPORT jlong JNICALL
833 Java_com_sun_solaris_service_pools_PoolInternal_pool_1resource_1create(
834 JNIEnv *jenv, jclass jcls, jlong jconf, jstring jtype, jstring jname) {
835 const char *type;
836 const char *name;
837 pool_resource_t *result;
839 type = (jtype) ? (*jenv)->GetStringUTFChars(jenv, jtype, 0) :
840 NULL;
841 name = (jname) ? (*jenv)->GetStringUTFChars(jenv, jname, 0) :
842 NULL;
843 result =
844 pool_resource_create((pool_conf_t *)(uintptr_t)jconf, type, name);
846 if (type)
847 (*jenv)->ReleaseStringUTFChars(jenv, jtype, type);
848 if (name)
849 (*jenv)->ReleaseStringUTFChars(jenv, jname, name);
850 return ((jlong)(uintptr_t)result);
854 * pool_resource_destroy(3pool) wrapper
856 /*ARGSUSED*/
857 JNIEXPORT jint JNICALL
858 Java_com_sun_solaris_service_pools_PoolInternal_pool_1resource_1destroy(
859 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jresource) {
860 return ((jint)pool_resource_destroy((pool_conf_t *)(uintptr_t)jconf,
861 (pool_resource_t *)(uintptr_t)jresource));
865 * pool_resource_transfer(3pool) wrapper
867 /*ARGSUSED*/
868 JNIEXPORT jint JNICALL
869 Java_com_sun_solaris_service_pools_PoolInternal_pool_1resource_1transfer(
870 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jsource, jlong jtarget,
871 jlong jsize) {
872 return (pool_resource_transfer((pool_conf_t *)(uintptr_t)jconf,
873 (pool_resource_t *)(uintptr_t)jsource,
874 (pool_resource_t *)(uintptr_t)jtarget,
875 (uint64_t)jsize));
879 * pool_resource_xtransfer(3pool) wrapper
881 /*ARGSUSED*/
882 JNIEXPORT jint JNICALL
883 Java_com_sun_solaris_service_pools_PoolInternal_pool_1resource_1xtransfer(
884 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jsource, jlong jtarget,
885 jobject jcomponents) {
886 pool_component_t **components;
887 int result;
888 jclass Lclazz;
889 jmethodID Lsize;
890 jint size;
893 * Initialize the target parameter for case when input is null
895 components = NULL;
896 if (jcomponents != NULL) {
897 Lclazz = (*jenv)->GetObjectClass(jenv, jcomponents);
898 Lsize = (*jenv)->GetMethodID(jenv, Lclazz, "size", "()I");
899 size = (*jenv)->CallIntMethod(jenv, jcomponents, Lsize);
901 if (size != 0) {
902 jmethodID Lget;
903 int i;
905 Lget = (*jenv)->GetMethodID(jenv,
906 Lclazz, "get", "(I)Ljava/lang/Object;");
907 /* Allocate space for the components array */
909 if ((components = calloc(size + 1,
910 sizeof (pool_component_t *))) == NULL) {
911 throwException(jenv, "java/lang/Exception",
912 "Could not allocate component array");
913 return (NULL);
916 * Copy in the array
918 for (i = 0; i < size; i++) {
919 jobject aVal;
920 jclass Vclazz;
921 jlong this;
922 jmethodID Vthis;
924 aVal = (*jenv)->CallObjectMethod(jenv,
925 jcomponents, Lget, (jint) i);
926 Vclazz = (*jenv)->GetObjectClass(jenv,
927 aVal);
928 Vthis = (*jenv)->GetMethodID(jenv,
929 Vclazz, "getComponent", "()J");
930 this = (*jenv)->CallLongMethod(jenv,
931 aVal, Vthis);
932 components[i] =
933 (pool_component_t *)(uintptr_t)this;
937 result = (int)pool_resource_xtransfer((pool_conf_t *)(uintptr_t)jconf,
938 (pool_resource_t *)(uintptr_t)jsource,
939 (pool_resource_t *)(uintptr_t)jtarget,
940 components);
941 free(components);
943 return ((jint)result);
947 * pool_query_resource_components(3pool) wrapper
949 /*ARGSUSED*/
950 JNIEXPORT jobject JNICALL
951 Java_com_sun_solaris_service_pools_PoolInternal_pool_1query_1resource_\
952 1components(JNIEnv *jenv, jclass jcls, jlong jconf, jlong jresource,
953 jobject jprops) {
954 pool_value_t **props;
955 pool_component_t **result;
956 jclass Lclazz;
957 jmethodID Lsize;
958 uint_t nelem;
959 jint size;
962 * Initialize the target parameter for case when input is null
964 props = NULL;
965 if (jprops != NULL) {
966 Lclazz = (*jenv)->GetObjectClass(jenv, jprops);
967 Lsize = (*jenv)->GetMethodID(jenv, Lclazz, "size", "()I");
968 size = (*jenv)->CallIntMethod(jenv, jprops, Lsize);
970 if (size != 0) {
971 jmethodID Lget;
972 int i;
974 Lget = (*jenv)->GetMethodID(jenv, Lclazz, "get",
975 "(I)Ljava/lang/Object;");
977 * Allocate space for the props array
979 if ((props = calloc(size + 1, sizeof (pool_value_t *)))
980 == NULL) {
981 throwException(jenv, "java/lang/Exception",
982 "Could not allocate props array");
983 return (NULL);
986 * Copy in the array
988 for (i = 0; i < size; i++) {
989 jobject aVal;
990 jclass Vclazz;
991 jfieldID Vthis;
992 jlong this;
994 aVal = (*jenv)->CallObjectMethod(jenv, jprops,
995 Lget, (jint) i);
996 Vclazz = (*jenv)->GetObjectClass(jenv, aVal);
997 Vthis = (*jenv)->GetFieldID(jenv, Vclazz,
998 "_this", "J");
999 this = (*jenv)->GetLongField(jenv, aVal, Vthis);
1000 props[i] = (pool_value_t *)(uintptr_t)this;
1004 result = pool_query_resource_components(
1005 (pool_conf_t *)(uintptr_t)jconf,
1006 (pool_resource_t *)(uintptr_t)jresource, &nelem, props);
1007 free(props);
1008 return (copyArray(jenv, (void **)result));
1012 * pool_resource_info(3pool) wrapper
1014 /*ARGSUSED*/
1015 JNIEXPORT jstring JNICALL
1016 Java_com_sun_solaris_service_pools_PoolInternal_pool_1resource_1info(
1017 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jresource, jint jflags) {
1018 jstring jresult = NULL;
1019 const char *result;
1021 result = pool_resource_info((pool_conf_t *)(uintptr_t)jconf,
1022 (pool_resource_t *)(uintptr_t)jresource, (int)jflags);
1024 if (result)
1025 jresult = (*jenv)->NewStringUTF(jenv, result);
1026 free((void *)result);
1027 return (jresult);
1031 * pool_create(3pool) wrapper
1033 /*ARGSUSED*/
1034 JNIEXPORT jlong JNICALL
1035 Java_com_sun_solaris_service_pools_PoolInternal_pool_1create(JNIEnv *jenv,
1036 jclass jcls, jlong jconf, jstring jname) {
1037 const char *name;
1038 pool_t *result;
1040 name = (jname) ? (*jenv)->GetStringUTFChars(jenv, jname, 0) :
1041 NULL;
1042 result = pool_create((pool_conf_t *)(uintptr_t)jconf, name);
1044 if (name)
1045 (*jenv)->ReleaseStringUTFChars(jenv, jname, name);
1046 return ((jlong)(uintptr_t)result);
1050 * pool_destroy(3pool) wrapper
1052 /*ARGSUSED*/
1053 JNIEXPORT jint JNICALL
1054 Java_com_sun_solaris_service_pools_PoolInternal_pool_1destroy(JNIEnv *jenv,
1055 jclass jcls, jlong jconf, jlong jpool) {
1056 return ((jint)pool_destroy((pool_conf_t *)(uintptr_t)jconf,
1057 (pool_t *)(uintptr_t)jpool));
1061 * pool_associate(3pool) wrapper
1063 /*ARGSUSED*/
1064 JNIEXPORT jint JNICALL
1065 Java_com_sun_solaris_service_pools_PoolInternal_pool_1associate(JNIEnv *jenv,
1066 jclass jcls, jlong jconf, jlong jpool, jlong jresource) {
1067 return ((jint)pool_associate((pool_conf_t *)(uintptr_t)jconf,
1068 (pool_t *)(uintptr_t)jpool,
1069 (pool_resource_t *)(uintptr_t)jresource));
1073 * pool_dissociate(3pool) wrapper
1075 /*ARGSUSED*/
1076 JNIEXPORT jint JNICALL
1077 Java_com_sun_solaris_service_pools_PoolInternal_pool_1dissociate(JNIEnv *jenv,
1078 jclass jcls, jlong jconf, jlong jpool, jlong jresource) {
1079 return ((jint)pool_dissociate((pool_conf_t *)(uintptr_t)jconf,
1080 (pool_t *)(uintptr_t)jpool,
1081 (pool_resource_t *)(uintptr_t)jresource));
1085 * pool_info(3pool) wrapper
1087 /*ARGSUSED*/
1088 JNIEXPORT jstring JNICALL
1089 Java_com_sun_solaris_service_pools_PoolInternal_pool_1info(JNIEnv *jenv,
1090 jclass jcls, jlong jconf, jlong jpool, jint jflags) {
1091 jstring jresult = NULL;
1092 const char *result;
1094 result = pool_info((pool_conf_t *)(uintptr_t)jconf,
1095 (pool_t *)(uintptr_t)jpool, (int)jflags);
1097 if (result)
1098 jresult = (*jenv)->NewStringUTF(jenv, result);
1099 free((void *)result);
1100 return (jresult);
1104 * pool_query_pool_resources(3pool) wrapper
1106 /*ARGSUSED*/
1107 JNIEXPORT jobject JNICALL
1108 Java_com_sun_solaris_service_pools_PoolInternal_pool_1query_1pool_1resources(
1109 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jpool, jobject jprops) {
1110 pool_value_t **props;
1111 pool_resource_t **result;
1112 jclass Lclazz;
1113 jmethodID Lsize;
1114 uint_t nelem;
1115 jint size;
1118 * Initialize the target parameter for case when input is null
1120 props = NULL;
1121 if (jprops != NULL) {
1122 Lclazz = (*jenv)->GetObjectClass(jenv, jprops);
1123 Lsize = (*jenv)->GetMethodID(jenv, Lclazz, "size", "()I");
1124 size = (*jenv)->CallIntMethod(jenv, jprops, Lsize);
1126 if (size != 0) {
1127 jmethodID Lget;
1128 int i;
1130 Lget = (*jenv)->GetMethodID(jenv,
1131 Lclazz, "get", "(I)Ljava/lang/Object;");
1133 * Allocate space for the props array
1136 if ((props = calloc(size + 1, sizeof (pool_value_t *)))
1137 == NULL) {
1138 throwException(jenv, "java/lang/Exception",
1139 "Could not allocate props array");
1140 return (NULL);
1143 * Copy in the array
1145 for (i = 0; i < size; i++) {
1146 jobject aVal;
1147 jclass Vclazz;
1148 jfieldID Vthis;
1149 jlong this;
1151 aVal = (*jenv)->CallObjectMethod(jenv, jprops,
1152 Lget, (jint) i);
1153 Vclazz = (*jenv)->GetObjectClass(jenv, aVal);
1154 Vthis = (*jenv)->GetFieldID(jenv, Vclazz,
1155 "_this", "J");
1156 this = (*jenv)->GetLongField(jenv, aVal, Vthis);
1157 props[i] = (pool_value_t *)(uintptr_t)this;
1161 result = pool_query_pool_resources((pool_conf_t *)(uintptr_t)jconf,
1162 (pool_t *)(uintptr_t)jpool, &nelem, props);
1163 free(props);
1164 return (copyArray(jenv, (void **)result));
1168 * pool_get_owning_resource(3pool) wrapper
1170 /*ARGSUSED*/
1171 JNIEXPORT jlong JNICALL
1172 Java_com_sun_solaris_service_pools_PoolInternal_pool_1get_1owning_1resource(
1173 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jcomponent) {
1174 return ((jlong)(uintptr_t)pool_get_owning_resource(
1175 (pool_conf_t *)(uintptr_t)jconf,
1176 (pool_component_t *)(uintptr_t)jcomponent));
1180 * pool_component_info(3pool) wrapper
1182 /*ARGSUSED*/
1183 JNIEXPORT jstring JNICALL
1184 Java_com_sun_solaris_service_pools_PoolInternal_pool_1component_1info(
1185 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jcomponent, jint jflags) {
1186 jstring jresult = NULL;
1187 const char *result;
1189 result = pool_component_info((pool_conf_t *)(uintptr_t)jconf,
1190 (pool_component_t *)(uintptr_t)jcomponent, (int)jflags);
1192 if (result)
1193 jresult = (*jenv)->NewStringUTF(jenv, result);
1194 free((void *)result);
1195 return (jresult);
1199 * pool_get_property(3pool) wrapper
1201 /*ARGSUSED*/
1202 JNIEXPORT jint JNICALL
1203 Java_com_sun_solaris_service_pools_PoolInternal_pool_1get_1property(
1204 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jelem, jstring jname,
1205 jlong jproperty) {
1206 const char *name;
1207 int result;
1209 name = (jname) ? (*jenv)->GetStringUTFChars(jenv, jname, 0) :
1210 NULL;
1211 result = pool_get_property((pool_conf_t *)(uintptr_t)jconf,
1212 (pool_elem_t *)(uintptr_t)jelem, name,
1213 (pool_value_t *)(uintptr_t)jproperty);
1215 if (name)
1216 (*jenv)->ReleaseStringUTFChars(jenv, jname, name);
1217 return ((jint)result);
1221 * pool_put_property(3pool) wrapper
1223 /*ARGSUSED*/
1224 JNIEXPORT jint JNICALL
1225 Java_com_sun_solaris_service_pools_PoolInternal_pool_1put_1property(
1226 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jelem, jstring jname,
1227 jlong jvalue) {
1228 const char *name;
1229 int result;
1231 name = (jname) ? (*jenv)->GetStringUTFChars(jenv, jname, 0) : NULL;
1232 result = (int)pool_put_property((pool_conf_t *)(uintptr_t)jconf,
1233 (pool_elem_t *)(uintptr_t)jelem, name,
1234 (pool_value_t *)(uintptr_t)jvalue);
1236 if (name)
1237 (*jenv)->ReleaseStringUTFChars(jenv, jname, name);
1238 return ((jint)result);
1242 * pool_rm_property(3pool) wrapper
1244 /*ARGSUSED*/
1245 JNIEXPORT jint JNICALL
1246 Java_com_sun_solaris_service_pools_PoolInternal_pool_1rm_1property(JNIEnv *jenv,
1247 jclass jcls, jlong jconf, jlong jelem, jstring jname) {
1248 const char *name;
1249 int result;
1251 name = (jname) ? (*jenv)->GetStringUTFChars(jenv, jname, 0) : NULL;
1252 result = pool_rm_property((pool_conf_t *)(uintptr_t)jconf,
1253 (pool_elem_t *)(uintptr_t)jelem, name);
1255 if (name)
1256 (*jenv)->ReleaseStringUTFChars(jenv, jname, name);
1257 return ((jint)result);
1261 * pool_walk_properties(3pool) wrapper
1263 /*ARGSUSED*/
1264 JNIEXPORT jint JNICALL
1265 Java_com_sun_solaris_service_pools_PoolInternal_pool_1walk_1properties(
1266 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jelem, jlong jarg,
1267 jlong jcallback) {
1268 int result;
1270 result = (int)pool_walk_properties((pool_conf_t *)(uintptr_t)jconf,
1271 (pool_elem_t *)(uintptr_t)jelem, (void *)(uintptr_t)jarg,
1272 (int (*)(pool_conf_t *, pool_elem_t *, char const *,
1273 pool_value_t *, void *))(uintptr_t)jcallback);
1275 return ((jint)result);
1279 * pool_conf_to_elem(3pool) wrapper
1281 /*ARGSUSED*/
1282 JNIEXPORT jlong JNICALL
1283 Java_com_sun_solaris_service_pools_PoolInternal_pool_1conf_1to_1elem(
1284 JNIEnv *jenv, jclass jcls, jlong jconf) {
1285 return ((jlong)(uintptr_t)pool_conf_to_elem(
1286 (pool_conf_t *)(uintptr_t)jconf));
1290 * pool_to_elem(3pool) wrapper
1292 /*ARGSUSED*/
1293 JNIEXPORT jlong JNICALL
1294 Java_com_sun_solaris_service_pools_PoolInternal_pool_1to_1elem(JNIEnv *jenv,
1295 jclass jcls, jlong jconf, jlong jpool) {
1296 return ((jlong)(uintptr_t)pool_to_elem((pool_conf_t *)(uintptr_t)jconf,
1297 (pool_t *)(uintptr_t)jpool));
1301 * pool_resource_to_elem(3pool) wrapper
1303 /*ARGSUSED*/
1304 JNIEXPORT jlong JNICALL
1305 Java_com_sun_solaris_service_pools_PoolInternal_pool_1resource_1to_1elem(
1306 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jresource) {
1307 return ((jlong)(uintptr_t)pool_resource_to_elem(
1308 (pool_conf_t *)(uintptr_t)jconf,
1309 (pool_resource_t *)(uintptr_t)jresource));
1313 * pool_component_to_elem(3pool) wrapper
1315 /*ARGSUSED*/
1316 JNIEXPORT jlong JNICALL
1317 Java_com_sun_solaris_service_pools_PoolInternal_pool_1component_1to_1elem(
1318 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jcomponent) {
1319 return ((jlong)(uintptr_t)pool_component_to_elem(
1320 (pool_conf_t *)(uintptr_t)jconf,
1321 (pool_component_t *)(uintptr_t)jcomponent));
1325 * pool_value_get_type(3pool) wrapper
1327 /*ARGSUSED*/
1328 JNIEXPORT jint JNICALL
1329 Java_com_sun_solaris_service_pools_PoolInternal_pool_1value_1get_1type(
1330 JNIEnv *jenv, jclass jcls, jlong jvalue) {
1331 return ((jint)pool_value_get_type((pool_value_t *)(uintptr_t)jvalue));
1335 * pool_value_set_uint64(3pool) wrapper
1337 /*ARGSUSED*/
1338 JNIEXPORT void JNICALL
1339 Java_com_sun_solaris_service_pools_PoolInternal_pool_1value_1set_1uint64(
1340 JNIEnv *jenv, jclass jcls, jlong jvalue, jlong jui64) {
1341 pool_value_set_uint64(
1342 (pool_value_t *)(uintptr_t)jvalue, (uint64_t)jui64);
1346 * pool_value_set_int64(3pool) wrapper
1348 /*ARGSUSED*/
1349 JNIEXPORT void JNICALL
1350 Java_com_sun_solaris_service_pools_PoolInternal_pool_1value_1set_1int64(
1351 JNIEnv *jenv, jclass jcls, jlong jvalue, jlong ji64) {
1352 pool_value_set_int64((pool_value_t *)(uintptr_t)jvalue, (int64_t)ji64);
1356 * pool_value_set_double(3pool) wrapper
1358 /*ARGSUSED*/
1359 JNIEXPORT void JNICALL
1360 Java_com_sun_solaris_service_pools_PoolInternal_pool_1value_1set_1double(
1361 JNIEnv *jenv, jclass jcls, jlong jvalue, jdouble jd) {
1362 pool_value_set_double((pool_value_t *)(uintptr_t)jvalue, (double)jd);
1366 * pool_value_set_bool(3pool) wrapper
1368 /*ARGSUSED*/
1369 JNIEXPORT void JNICALL
1370 Java_com_sun_solaris_service_pools_PoolInternal_pool_1value_1set_1bool(
1371 JNIEnv *jenv, jclass jcls, jlong jvalue, jshort jb) {
1372 pool_value_set_bool((pool_value_t *)(uintptr_t)jvalue, (uchar_t)jb);
1376 * pool_value_set_string(3pool) wrapper
1378 /*ARGSUSED*/
1379 JNIEXPORT jint JNICALL
1380 Java_com_sun_solaris_service_pools_PoolInternal_pool_1value_1set_1string(
1381 JNIEnv * jenv, jclass jcls, jlong jvalue, jstring jstr) {
1382 const char *str;
1383 int result;
1385 str = (jstr) ? (*jenv)->GetStringUTFChars(jenv, jstr, 0) : NULL;
1386 result = pool_value_set_string((pool_value_t *)(uintptr_t)jvalue, str);
1388 if (str)
1389 (*jenv)->ReleaseStringUTFChars(jenv, jstr, str);
1390 return ((jint)result);
1394 * pool_value_get_name(3pool) wrapper
1396 /*ARGSUSED*/
1397 JNIEXPORT jstring JNICALL
1398 Java_com_sun_solaris_service_pools_PoolInternal_pool_1value_1get_1name(
1399 JNIEnv *jenv, jclass jcls, jlong jvalue) {
1400 jstring jresult = NULL;
1401 const char *result;
1403 result = pool_value_get_name((pool_value_t *)(uintptr_t)jvalue);
1405 if (result)
1406 jresult = (*jenv)->NewStringUTF(jenv, result);
1407 return (jresult);
1411 * pool_value_set_name(3pool) wrapper
1413 /*ARGSUSED*/
1414 JNIEXPORT jint JNICALL
1415 Java_com_sun_solaris_service_pools_PoolInternal_pool_1value_1set_1name(
1416 JNIEnv *jenv, jclass jcls, jlong jvalue, jstring jname) {
1417 const char *name;
1418 int result;
1420 name = (jname) ? (*jenv)->GetStringUTFChars(jenv, jname, 0) : NULL;
1421 result = pool_value_set_name((pool_value_t *)(uintptr_t)jvalue, name);
1423 if (name)
1424 (*jenv)->ReleaseStringUTFChars(jenv, jname, name);
1425 return ((jint)result);
1429 * pool_value_alloc(3pool) wrapper
1431 /*ARGSUSED*/
1432 JNIEXPORT jlong JNICALL
1433 Java_com_sun_solaris_service_pools_PoolInternal_pool_1value_1alloc(JNIEnv *jenv,
1434 jclass jcls) {
1435 return ((jlong)(uintptr_t)pool_value_alloc());
1439 * pool_value_free(3pool) wrapper
1441 /*ARGSUSED*/
1442 JNIEXPORT void JNICALL
1443 Java_com_sun_solaris_service_pools_PoolInternal_pool_1value_1free(JNIEnv *jenv,
1444 jclass jcls, jlong jvalue) {
1445 pool_value_free((pool_value_t *)(uintptr_t)jvalue);
1449 * pool_static_location(3pool) wrapper
1451 /*ARGSUSED*/
1452 JNIEXPORT jstring JNICALL
1453 Java_com_sun_solaris_service_pools_PoolInternal_pool_1static_1location(
1454 JNIEnv *jenv, jclass jcls) {
1455 jstring jresult = NULL;
1456 const char *result;
1458 result = pool_static_location();
1460 if (result)
1461 jresult = (*jenv)->NewStringUTF(jenv, result);
1462 return (jresult);
1466 * pool_dynamic_location(3pool) wrapper
1468 /*ARGSUSED*/
1469 JNIEXPORT jstring JNICALL
1470 Java_com_sun_solaris_service_pools_PoolInternal_pool_1dynamic_1location(JNIEnv *
1471 jenv, jclass jcls) {
1472 jstring jresult = NULL;
1473 const char *result;
1475 result = pool_dynamic_location();
1477 if (result)
1478 jresult = (*jenv)->NewStringUTF(jenv, result);
1479 return (jresult);
1483 * pool_set_binding(3pool) wrapper
1485 /*ARGSUSED*/
1486 JNIEXPORT jint JNICALL
1487 Java_com_sun_solaris_service_pools_PoolInternal_pool_1set_1binding(JNIEnv *jenv,
1488 jclass jcls, jstring jpool, jint jidtype, jint jpid) {
1489 const char *pool;
1490 int result;
1492 pool = (jpool) ? (*jenv)->GetStringUTFChars(jenv, jpool, 0) : NULL;
1493 result = (int)pool_set_binding(pool, (idtype_t)jidtype, (id_t)jpid);
1495 if (pool)
1496 (*jenv)->ReleaseStringUTFChars(jenv, jpool, pool);
1497 return ((jint)result);
1501 * pool_get_binding(3pool) wrapper
1503 /*ARGSUSED*/
1504 JNIEXPORT jstring JNICALL
1505 Java_com_sun_solaris_service_pools_PoolInternal_pool_1get_1binding(JNIEnv *jenv,
1506 jclass jcls, jint jpid) {
1507 jstring jresult = NULL;
1508 const char *result;
1510 result = pool_get_binding((pid_t)jpid);
1512 if (result)
1513 jresult = (*jenv)->NewStringUTF(jenv, result);
1514 free((void *)result);
1515 return (jresult);
1519 * pool_get_resource_binding(3pool) wrapper
1521 /*ARGSUSED*/
1522 JNIEXPORT jstring JNICALL
1523 Java_com_sun_solaris_service_pools_PoolInternal_pool_1get_1resource_1binding(
1524 JNIEnv *jenv, jclass jcls, jstring jtype, jint jpid) {
1525 jstring jresult = NULL;
1526 const char *type;
1527 const char *result;
1529 type = (jtype) ? (*jenv)->GetStringUTFChars(jenv, jtype, 0) : NULL;
1530 result = pool_get_resource_binding(type, (pid_t)jpid);
1532 if (result)
1533 jresult = (*jenv)->NewStringUTF(jenv, result);
1534 free((void *)result);
1535 if (type)
1536 (*jenv)->ReleaseStringUTFChars(jenv, jtype, type);
1537 return (jresult);
1541 * pool_walk_pools(3pool) wrapper
1543 /*ARGSUSED*/
1544 JNIEXPORT jint JNICALL
1545 Java_com_sun_solaris_service_pools_PoolInternal_pool_1walk_1pools(JNIEnv *jenv,
1546 jclass jcls, jlong jconf, jlong jarg, jlong jcallback) {
1547 int result;
1549 result = pool_walk_pools((pool_conf_t *)(uintptr_t)jconf,
1550 (void *)(uintptr_t)jarg,
1551 (int (*)(pool_conf_t *, pool_t *, void *))(uintptr_t)jcallback);
1552 return ((jint)result);
1556 * pool_walk_resources(3pool) wrapper
1558 /*ARGSUSED*/
1559 JNIEXPORT jint JNICALL
1560 Java_com_sun_solaris_service_pools_PoolInternal_pool_1walk_1resources(
1561 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jpool, jlong jarg,
1562 jlong jcallback) {
1563 int result;
1565 result = pool_walk_resources((pool_conf_t *)(uintptr_t)jconf,
1566 (pool_t *)(uintptr_t)jpool, (void *)(uintptr_t)jarg,
1567 (int (*)(pool_conf_t *, pool_resource_t *, void *))
1568 (uintptr_t)jcallback);
1569 return ((jint)result);
1573 * pool_walk_components(3pool) wrapper
1575 /*ARGSUSED*/
1576 JNIEXPORT jint JNICALL
1577 Java_com_sun_solaris_service_pools_PoolInternal_pool_1walk_1components(
1578 JNIEnv *jenv, jclass jcls, jlong jconf, jlong jresource, jlong jarg,
1579 jlong jcallback) {
1580 int result;
1582 result = pool_walk_components((pool_conf_t *)(uintptr_t)jconf,
1583 (pool_resource_t *)(uintptr_t)jresource, (void *)(uintptr_t)jarg,
1584 (int (*)(pool_conf_t *, pool_component_t *, void *))
1585 (uintptr_t)jcallback);
1586 return ((jint)result);
1589 /*ARGSUSED*/
1590 JNIEXPORT jint JNICALL
1591 Java_com_sun_solaris_service_pools_Element_walkProps(JNIEnv *env,
1592 jobject obj, jlong conf, jlong elem, jobject handler, jobject userobj)
1594 struct pool_callback pc;
1596 pc.pc_user = userobj;
1597 pc.pc_handler = handler;
1598 pc.pc_elem = obj;
1599 pc.pc_env = env;
1600 return (pool_walk_properties((pool_conf_t *)*(void**)&conf,
1601 (pool_elem_t *)*(void**)&elem, (void *)&pc, pool_property_walker));
1604 /*ARGSUSED*/
1605 static int
1606 pool_property_walker(pool_conf_t *conf, pool_elem_t *pe, const char *name,
1607 pool_value_t *pv, void *user)
1609 jclass clazz, vclazz;
1610 jmethodID mgetwalk, mvcon;
1611 struct pool_callback *pc = (struct pool_callback *)user;
1612 jobject valueObj;
1613 pool_value_t *pv_new;
1614 uint64_t uval;
1615 int64_t ival;
1616 double dval;
1617 uchar_t bval;
1618 const char *sval;
1621 * Since we intend to embed our value into a Java Value object
1622 * and then reclaim the value when the object is garbage
1623 * collected we must create a new pool value and then pass this
1624 * to the constructor. We must not use the pool value which is
1625 * passed to us.
1628 if ((pv_new = pool_value_alloc()) == NULL)
1629 return (PO_FAIL);
1630 switch (pool_value_get_type(pv)) {
1631 case POC_UINT:
1632 (void) pool_value_get_uint64(pv, &uval);
1633 (void) pool_value_set_uint64(pv_new, uval);
1634 break;
1635 case POC_INT:
1636 (void) pool_value_get_int64(pv, &ival);
1637 (void) pool_value_set_int64(pv_new, ival);
1638 break;
1639 case POC_DOUBLE:
1640 (void) pool_value_get_double(pv, &dval);
1641 (void) pool_value_set_double(pv_new, dval);
1642 break;
1643 case POC_BOOL:
1644 (void) pool_value_get_bool(pv, &bval);
1645 (void) pool_value_set_bool(pv_new, bval);
1646 break;
1647 case POC_STRING:
1648 (void) pool_value_get_string(pv, &sval);
1649 (void) pool_value_set_string(pv_new, sval);
1650 break;
1651 default:
1652 pool_value_free(pv_new);
1653 return (PO_FAIL);
1655 if (pool_value_set_name(pv_new, name) != PO_SUCCESS ||
1656 (vclazz = (*pc->pc_env)->FindClass(pc->pc_env,
1657 "com/sun/solaris/service/pools/Value")) == NULL ||
1658 (mvcon = (*pc->pc_env)->GetMethodID(pc->pc_env, vclazz,
1659 "<init>", "(J)V")) == NULL ||
1660 (valueObj = (*pc->pc_env)->NewObject(pc->pc_env, vclazz, mvcon,
1661 pv_new)) == NULL ||
1662 (clazz = (*pc->pc_env)->GetObjectClass(pc->pc_env, pc->pc_handler))
1663 == NULL ||
1664 (mgetwalk = (*pc->pc_env)->GetMethodID(pc->pc_env,
1665 clazz, "walk",
1666 "(Lcom/sun/solaris/service/pools/Element;Lcom/sun/solaris/"
1667 "service/pools/Value;Ljava/lang/Object;)I")) == NULL)
1668 return (PO_FAIL);
1669 return ((*pc->pc_env)->CallIntMethod(pc->pc_env,
1670 pc->pc_handler, mgetwalk, pc->pc_elem, valueObj, pc->pc_user));
1673 /*ARGSUSED*/
1674 JNIEXPORT jlong JNICALL
1675 Java_com_sun_solaris_service_pools_Value_getLongValue(JNIEnv *jenv,
1676 jclass class, jlong pointer)
1678 int64_t arg2;
1679 int result;
1681 result =
1682 pool_value_get_int64((pool_value_t *)(uintptr_t)pointer, &arg2);
1684 if (result != PO_SUCCESS) { /* it could be a uint64 */
1685 result =
1686 pool_value_get_uint64((pool_value_t *)(uintptr_t)pointer,
1687 (uint64_t *)&arg2);
1688 if (result != PO_SUCCESS) {
1689 throw_pe(jenv);
1692 * Unfortunately, Java has no unsigned types, so we lose some
1693 * precision by forcing the top bit clear
1695 arg2 &= 0x7fffffffffffffffULL;
1697 return ((jlong)arg2);
1700 /*ARGSUSED*/
1701 JNIEXPORT jstring JNICALL
1702 Java_com_sun_solaris_service_pools_Value_getStringValue(JNIEnv *jenv,
1703 jclass class, jlong pointer)
1705 const char *arg2;
1706 int result;
1708 result =
1709 pool_value_get_string((pool_value_t *)(uintptr_t)pointer, &arg2);
1710 if (result != PO_SUCCESS)
1711 throw_pe(jenv);
1712 return ((*jenv)->NewStringUTF(jenv, arg2));
1715 /*ARGSUSED*/
1716 JNIEXPORT jboolean JNICALL
1717 Java_com_sun_solaris_service_pools_Value_getBoolValue(JNIEnv *jenv,
1718 jclass class, jlong pointer)
1720 uchar_t arg2;
1721 int result;
1723 result = pool_value_get_bool((pool_value_t *)(uintptr_t)pointer, &arg2);
1725 if (result != PO_SUCCESS) {
1726 throw_pe(jenv);
1728 if (arg2 == PO_TRUE)
1729 return (JNI_TRUE);
1730 else
1731 return (JNI_FALSE);
1734 /*ARGSUSED*/
1735 JNIEXPORT jdouble JNICALL
1736 Java_com_sun_solaris_service_pools_Value_getDoubleValue(JNIEnv *jenv,
1737 jclass class, jlong pointer)
1739 double arg2;
1740 int result;
1742 result =
1743 pool_value_get_double((pool_value_t *)(uintptr_t)pointer, &arg2);
1745 if (result != PO_SUCCESS) {
1746 throw_pe(jenv);
1748 return ((jdouble)arg2);
1751 /*ARGSUSED*/
1752 JNIEXPORT jobject JNICALL
1753 Java_com_sun_solaris_service_pools_Value_getUnsignedInt64Value(JNIEnv *jenv,
1754 jclass class, jlong pointer)
1756 uint64_t arg2;
1757 int result;
1759 result =
1760 pool_value_get_uint64((pool_value_t *)(uintptr_t)pointer, &arg2);
1762 if (result != PO_SUCCESS) {
1763 throw_pe(jenv);
1765 return (makeUnsignedInt64(jenv, arg2));
1768 /*ARGSUSED*/
1769 JNIEXPORT jobject JNICALL
1770 Java_com_sun_solaris_service_pools_HRTime_timestamp(JNIEnv *env, jobject obj)
1772 return (makeUnsignedInt64(env, gethrtime()));
1776 * Cache class, method, and field IDs.
1778 /*ARGSUSED*/
1779 JNIEXPORT void JNICALL
1780 Java_com_sun_solaris_service_pools_PoolInternal_init(JNIEnv *env, jclass clazz)
1782 jclass ui64class_lref;
1784 if (!(ui64class_lref = (*env)->FindClass(env,
1785 "com/sun/solaris/service/pools/UnsignedInt64")))
1786 return; /* exception thrown */
1787 if (!(ui64class = (*env)->NewGlobalRef(env, ui64class_lref)))
1788 return; /* exception thrown */
1789 ui64cons_mid = (*env)->GetMethodID(env, ui64class, "<init>", "([B)V");