You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/14 19:28:39 UTC

svn commit: r1092399 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ java/org/apache/commons/runtime/platform/windows/ native/include/acr/ native/os/win32/

Author: mturk
Date: Thu Apr 14 17:28:39 2011
New Revision: 1092399

URL: http://svn.apache.org/viewvc?rev=1092399&view=rev
Log:
Move windows classes to platform/windows package

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Api.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphore.java
      - copied, changed from r1092393, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphore.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphoreImpl.java
      - copied, changed from r1092393, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphoreImplFactory.java
      - copied, changed from r1092393, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImplFactory.java
Removed:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphore.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImplFactory.java
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImplFactory.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImplFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImplFactory.java?rev=1092399&r1=1092398&r2=1092399&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImplFactory.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImplFactory.java Thu Apr 14 17:28:39 2011
@@ -24,7 +24,7 @@ import java.io.IOException;
  *
  * @since Runtime 1.0
  */
-abstract class SemaphoreImplFactory {
+public abstract class SemaphoreImplFactory {
     /**
      * Creates a new <code>SemaphoreImpl</code> instance.
      *

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Api.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Api.java?rev=1092399&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Api.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Api.java Thu Apr 14 17:28:39 2011
@@ -0,0 +1,60 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.platform.windows;
+
+import org.apache.commons.runtime.Status;
+import org.apache.commons.runtime.exception.AlreadyExistsException;
+import org.apache.commons.runtime.exception.NoSuchObjectException;
+import org.apache.commons.runtime.exception.ClosedDescriptorException;
+import org.apache.commons.runtime.exception.SystemException;
+
+/**
+ * Win32 API class.
+ * <p>
+ * Tries to bring the native Win32 API to Java with as little overhead as possible.
+ * </p>
+ */
+final class Api
+{
+    private Api()
+    {
+        // No instance.
+    }
+
+    public static final int         INFINITE                = 0xFFFFFFFF;
+
+    public static final int         WAIT_FAILED             = 0xFFFFFFFF;
+    public static final int         WAIT_OBJECT_O           = 0;
+    public static final int         WAIT_ABANDONED          = 0x00000080;
+
+    public static final int         SDDL_REVISION_1         = 1;
+
+
+    public static native int        CloseHandle(long handle);
+    public static native int        LocalFree(long ptr);
+
+
+    public static native long       GetCurrentProcessToken()
+        throws SystemException;
+    public static native long       AllocateWellKnownSid(int sidType)
+        throws SystemException;
+    public static native long       ConvertStringSecurityDescriptorToSecurityDescriptor(String securityDescriptor, int revision)
+        throws SystemException;
+    public static native long       GetSaWithNullDacl(boolean inherit)
+        throws SystemException;
+    public static native int        WaitForSingleObject(long handle, int timeout);
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Api.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphore.java (from r1092393, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphore.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphore.java?p2=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphore.java&p1=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphore.java&r1=1092393&r2=1092399&rev=1092399&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphore.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphore.java Thu Apr 14 17:28:39 2011
@@ -13,8 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.runtime;
+package org.apache.commons.runtime.platform.windows;
 
+import org.apache.commons.runtime.Semaphore;
 import org.apache.commons.runtime.exception.AlreadyExistsException;
 import org.apache.commons.runtime.exception.NoSuchObjectException;
 import org.apache.commons.runtime.exception.ClosedDescriptorException;

Copied: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphoreImpl.java (from r1092393, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImpl.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphoreImpl.java?p2=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphoreImpl.java&p1=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImpl.java&r1=1092393&r2=1092399&rev=1092399&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphoreImpl.java Thu Apr 14 17:28:39 2011
@@ -13,8 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.runtime;
+package org.apache.commons.runtime.platform.windows;
 
+import org.apache.commons.runtime.Semaphore;
+import org.apache.commons.runtime.SemaphoreImpl;
 import org.apache.commons.runtime.exception.AlreadyExistsException;
 import org.apache.commons.runtime.exception.NoSuchObjectException;
 import org.apache.commons.runtime.exception.SystemException;

Copied: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphoreImplFactory.java (from r1092393, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImplFactory.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphoreImplFactory.java?p2=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphoreImplFactory.java&p1=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImplFactory.java&r1=1092393&r2=1092399&rev=1092399&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImplFactory.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphoreImplFactory.java Thu Apr 14 17:28:39 2011
@@ -13,7 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.runtime;
+package org.apache.commons.runtime.platform.windows;
+
+import org.apache.commons.runtime.SemaphoreImpl;
+import org.apache.commons.runtime.SemaphoreImplFactory;
 
 import java.io.IOException;
 

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h?rev=1092399&r1=1092398&r2=1092399&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h Thu Apr 14 17:28:39 2011
@@ -29,6 +29,7 @@
 #define ACR_IO_CP               ACR_CLASS_PATH "io/"
 #define ACR_NET_CP              ACR_CLASS_PATH "net/"
 #define ACR_UTIL_CP             ACR_CLASS_PATH "util/"
+#define ACR_WIN_CP              ACR_CLASS_PATH "platform/windows/"
 
 #define ACR_JNI_EXPORT(RT, CL, MN)      \
     ACR_JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_##CL##_##MN

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c?rev=1092399&r1=1092398&r2=1092399&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c Thu Apr 14 17:28:39 2011
@@ -24,7 +24,7 @@ J_DECLARE_CLAZZ = {
     0,
     0,
     0,
-    ACR_CLASS_PATH "WindowsSemaphoreImplFactory"
+    ACR_WIN_CP "WindowsSemaphoreImplFactory"
 };
 
 J_DECLARE_M_ID(0000) = {
@@ -53,7 +53,7 @@ ACR_JNI_EXPORT(jobject, Semaphore, getIm
     return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
 }
 
-ACR_JNI_EXPORT(jlong, WindowsSemaphore, create0)(JNI_STDARGS,
+ACR_WIN_EXPORT(jlong, WindowsSemaphore, create0)(JNI_STDARGS,
                                                  jstring name,
                                                  jint value, jlong sd)
 {
@@ -89,7 +89,7 @@ ACR_JNI_EXPORT(jlong, WindowsSemaphore, 
     return P2J(sp);
 }
 
-ACR_JNI_EXPORT(jlong, WindowsSemaphore, open0)(JNI_STDARGS,
+ACR_WIN_EXPORT(jlong, WindowsSemaphore, open0)(JNI_STDARGS,
                                                jstring name)
 {
     HANDLE sp  = 0;
@@ -113,7 +113,7 @@ ACR_JNI_EXPORT(jlong, WindowsSemaphore, 
     return P2J(sp);
 }
 
-ACR_JNI_EXPORT(jint, WindowsSemaphore, try0)(JNI_STDARGS, jlong sem)
+ACR_WIN_EXPORT(jint, WindowsSemaphore, try0)(JNI_STDARGS, jlong sem)
 {
 
     DWORD ws = WaitForSingleObject(J2P(sem, HANDLE), 0);
@@ -125,7 +125,7 @@ ACR_JNI_EXPORT(jint, WindowsSemaphore, t
         return ACR_GET_OS_ERROR();
 }
 
-ACR_JNI_EXPORT(jint, PosixSemaphore, release0)(JNI_STDARGS, jlong sem)
+ACR_WIN_EXPORT(jint, PosixSemaphore, release0)(JNI_STDARGS, jlong sem)
 {
     if (ReleaseSemaphore(J2P(sem, HANDLE), 1, 0))
         return 0;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c?rev=1092399&r1=1092398&r2=1092399&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/winapi.c Thu Apr 14 17:28:39 2011
@@ -95,8 +95,7 @@ ACR_WIN_EXPORT(jlong, Api, ConvertString
     PSECURITY_DESCRIPTOR pSD = 0;
 
     WITH_WSTR(desc) {
-        if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(J2S(desc),
-                                                    SDDL_REVISION_1, &pSD, 0)) {
+        if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(J2S(desc), rev, &pSD, 0)) {
             ACR_THROW_SYS_ERROR();
         }
     } DONE_WITH_STR(desc);
@@ -155,5 +154,11 @@ ACR_WIN_EXPORT(jlong, Api, AllocateWellK
 
 ACR_WIN_EXPORT(jint, Api, WaitForSingleObject)(JNI_STDARGS, jlong handle, jint timeout)
 {
-    return WaitForSingleObject(J2P(handle, HANDLE), (DWORD)timeout);
+    DWORD ws = WaitForSingleObject(J2P(handle, HANDLE), (DWORD)timeout);
+    if (ws == WAIT_OBJECT_0 || ws == WAIT_ABANDONED)
+        return 0;
+    else if (ws == WAIT_TIMEOUT)
+        return ACR_EBUSY;
+    else
+        return ACR_GET_OS_ERROR();    
 }