893N/A/*
2362N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
893N/A *
893N/A * This code is free software; you can redistribute it and/or modify it
893N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
893N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
893N/A *
893N/A * This code is distributed in the hope that it will be useful, but WITHOUT
893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
893N/A * version 2 for more details (a copy is included in the LICENSE file that
893N/A * accompanied this code).
893N/A *
893N/A * You should have received a copy of the GNU General Public License version
893N/A * 2 along with this work; if not, write to the Free Software Foundation,
893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
893N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
893N/A */
893N/A
893N/A#include "jni.h"
893N/A#include "jni_util.h"
893N/A#include "jvm.h"
893N/A#include "jlong.h"
893N/A
893N/A#include <stdlib.h>
893N/A#include <dlfcn.h>
893N/A#include <sys/types.h>
893N/A#include <port.h> // Solaris 10
893N/A
893N/A#include "sun_nio_fs_SolarisWatchService.h"
893N/A
893N/Astatic void throwUnixException(JNIEnv* env, int errnum) {
893N/A jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
893N/A "(I)V", errnum);
893N/A if (x != NULL) {
893N/A (*env)->Throw(env, x);
893N/A }
893N/A}
893N/A
893N/AJNIEXPORT void JNICALL
893N/AJava_sun_nio_fs_SolarisWatchService_init(JNIEnv *env, jclass clazz)
893N/A{
893N/A}
893N/A
893N/AJNIEXPORT jint JNICALL
893N/AJava_sun_nio_fs_SolarisWatchService_portCreate
893N/A (JNIEnv* env, jclass clazz)
893N/A{
893N/A int port = port_create();
893N/A if (port == -1) {
893N/A throwUnixException(env, errno);
893N/A }
893N/A return (jint)port;
893N/A}
893N/A
893N/AJNIEXPORT void JNICALL
893N/AJava_sun_nio_fs_SolarisWatchService_portAssociate
893N/A (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events)
893N/A{
893N/A uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);
893N/A
893N/A if (port_associate((int)port, (int)source, object, (int)events, NULL) == -1) {
893N/A throwUnixException(env, errno);
893N/A }
893N/A}
893N/A
893N/AJNIEXPORT void JNICALL
893N/AJava_sun_nio_fs_SolarisWatchService_portDissociate
893N/A (JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress)
893N/A{
893N/A uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);
893N/A
893N/A if (port_dissociate((int)port, (int)source, object) == -1) {
893N/A throwUnixException(env, errno);
893N/A }
893N/A}
893N/A
893N/AJNIEXPORT void JNICALL
893N/AJava_sun_nio_fs_SolarisWatchService_portSend(JNIEnv* env, jclass clazz,
893N/A jint port, jint events)
893N/A{
893N/A if (port_send((int)port, (int)events, NULL) == -1) {
893N/A throwUnixException(env, errno);
893N/A }
893N/A}
893N/A
893N/AJNIEXPORT jint JNICALL
893N/AJava_sun_nio_fs_SolarisWatchService_portGetn(JNIEnv* env, jclass clazz,
893N/A jint port, jlong arrayAddress, jint max)
893N/A{
893N/A uint_t n = 1;
893N/A port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress);
893N/A
893N/A if (port_getn((int)port, list, (uint_t)max, &n, NULL) == -1) {
893N/A throwUnixException(env, errno);
893N/A }
893N/A return (jint)n;
893N/A}