commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r890795 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/platform/windows/RegistryKey.java native/os/win32/registry.c native/os/win32/tfs.c
Date Tue, 15 Dec 2009 13:37:56 GMT
Author: mturk
Date: Tue Dec 15 13:37:56 2009
New Revision: 890795

URL: http://svn.apache.org/viewvc?rev=890795&view=rev
Log:
Start tfs api

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
    commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/tfs.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java?rev=890795&r1=890794&r2=890795&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
Tue Dec 15 13:37:56 2009
@@ -17,11 +17,14 @@
 package org.apache.commons.runtime.platform.windows;
 
 import java.io.Closeable;
+import java.io.Flushable;
 import java.io.IOException;
+import java.io.SyncFailedException;
+import java.util.EnumSet;
 import org.apache.commons.runtime.io.Status;
 
 /**
- * Registry key type.
+ * Registry key class.
  * <p>
  * An application can use handles to these keys as entry points to the
  * registry. These handles are valid for all implementations of the
@@ -31,7 +34,7 @@
  * keys.
  * </p>
  */
-public class RegistryKey implements Closeable
+public class RegistryKey implements Closeable, Flushable
 {
 
     /** Registry entries subordinate to this key define types (or classes)
@@ -48,7 +51,7 @@
      * This handle should not be used in a service or an application that
      * impersonates different users.
      */
-    public static final RegistryKey CLASSES_ROOT       = new RegistryKey(0x80000000L);
+    public static final RegistryKey ClassesRoot     = new RegistryKey(0x80000000L, "HKEY_CLASSES_ROOT");
 
     /** Registry entries subordinate to this key define the preferences of
      * the current user. These preferences include the settings of
@@ -57,7 +60,7 @@
      * easier to establish the current user's settings; the key maps to the
      * current user's branch in {@code HKEY_USERS}.
      */
-    public static final RegistryKey CURRENT_USER       = new RegistryKey(0x80000001L);
+    public static final RegistryKey CurrentUser     = new RegistryKey(0x80000001L, "HKEY_CURRENT_USER");
 
     /** Registry entries subordinate to this key define the physical state
      * of the computer, including data about the bus type, system memory,
@@ -68,20 +71,20 @@
      * security information, software-related information (such as server
      * names and the location of the server), and other system information.
      */
-    public static final RegistryKey LOCAL_MACHINE      = new RegistryKey(0x80000002L);
+    public static final RegistryKey LocalMachine    = new RegistryKey(0x80000002L, "HKEY_LOCAL_MACHINE");
 
     /** Registry entries subordinate to this key define the default user
      * configuration for new users on the local computer and the user
      * configuration for the current user.
      */
-    public static final RegistryKey USERS              = new RegistryKey(0x80000003L);
+    public static final RegistryKey Users           = new RegistryKey(0x80000003L, "HKEY_USERS");
 
     /** Registry entries subordinate to this key allow you to access
      * performance data. The data is not actually stored in the registry;
      * the registry functions cause the system to collect the data from
      * its source.
      */
-    public static final RegistryKey PERFORMANCE_DATA   = new RegistryKey(0x80000004L);
+    public static final RegistryKey PerformanceData = new RegistryKey(0x80000004L, "HKEY_PERFORMANCE_DATA");
 
     /** Contains information about the current hardware profile of the
      * local computer system.
@@ -93,12 +96,15 @@
      * and System keys of {@code HKEY_LOCAL_MACHINE}.
      * </p>
      */
-    public static final RegistryKey CURRENT_CONFIG     = new RegistryKey(0x80000005L);
+    public static final RegistryKey CurrentConfig   = new RegistryKey(0x80000005L, "HKEY_CURRENT_CONFIG");
 
-    private long hKey;
-    private RegistryKey(long v)
+    private String name;
+    private long   hKey;
+
+    private RegistryKey(long v, String n)
     {
         hKey = v;
+        name = n;
     }
 
     public long handle()
@@ -106,6 +112,14 @@
         return hKey;
     }
 
+    public String toString()
+    {
+        if (name == null)
+            return "null";
+        else
+            return name;
+    }
+
     private static native int close0(long key);
     /**
      * Called by the garbage collector when the object is destroyed.
@@ -154,4 +168,93 @@
         }
     }
 
+    private static native int flush0(long key);
+    /**
+     * Flushed the underlying object by writing any buffered data.
+     * <p>
+     * {@code fsync()} transfers  all  modified in-core data of the object
+     * referred to by {@code this} Descriptor to the disk device
+     * (or other permanent storage device)  where  that  object resides.
+     * The call blocks until the device reports that the transfer has
+     * completed.  It also flushes  metadata information associated with
+     * {@code this} Descriptor.
+     * </p>
+     *
+     * @throws SyncFailedException when the object cannot be flushed.
+     * @throws IOException if an I/O error occurs.
+     */
+    public final void flush()
+        throws SyncFailedException, IOException
+    {
+        if (hKey == 0L || hKey == -1L)
+            throw new InvalidHandleException();
+        else {
+            int s = flush0(hKey);
+            if (s != 0) {
+                throw new SyncFailedException(Status.describe(s));
+            }
+        }
+    }
+
+    private static native long open0(long key, String name, int sam)
+        throws IOException, SecurityException;
+    private static native long create0(long key, String name, int sam)
+        throws IOException, SecurityException;
+
+    public RegistryKey open(String name, EnumSet<RegistryKeyAccessRights> mode)
+        throws NullPointerException, IOException, SecurityException
+    {
+        if (name == null || mode == null) {
+            throw new NullPointerException();
+        }
+        if (hKey == 0L || hKey == -1L) {
+            throw new InvalidHandleException();
+        }
+        long sKey = open0(hKey, name, RegistryKeyAccessRights.bitmapOf(mode));
+        if (sKey == 0L || sKey == -1L)
+            return null;
+        else
+            return new RegistryKey(sKey, name);
+    }
+
+    public RegistryKey open(String name, RegistryKeyAccessRights... mode)
+        throws NullPointerException, IOException, SecurityException
+    {
+        return open(name, RegistryKeyAccessRights.of(mode));
+    }
+
+    public RegistryKey open(String name)
+        throws NullPointerException, IOException, SecurityException
+    {
+        return open(name, RegistryKeyAccessRights.READ);
+    }
+
+    public RegistryKey create(String name, EnumSet<RegistryKeyAccessRights> mode)
+        throws NullPointerException, IOException, SecurityException
+    {
+        if (name == null || mode == null) {
+            throw new NullPointerException();
+        }
+        if (hKey == 0L || hKey == -1L) {
+            throw new InvalidHandleException();
+        }
+        long sKey = create0(hKey, name, RegistryKeyAccessRights.bitmapOf(mode));
+        if (sKey == 0L || sKey == -1L)
+            return null;
+        else
+            return new RegistryKey(sKey, name);
+    }
+
+    public RegistryKey create(String name, RegistryKeyAccessRights... mode)
+        throws NullPointerException, IOException, SecurityException
+    {
+        return create(name, RegistryKeyAccessRights.of(mode));
+    }
+
+    public RegistryKey create(String name)
+        throws NullPointerException, IOException, SecurityException
+    {
+        return create(name, RegistryKeyAccessRights.ALL_ACCESS);
+    }
+
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c?rev=890795&r1=890794&r2=890795&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c Tue Dec 15 13:37:56
2009
@@ -399,6 +399,44 @@
     return i;
 }
 
+static REGSAM _regsam_translate(int nsam)
+{
+    REGSAM rsam = 0;
+    if (nsam & ACR_KEY_ALL_ACCESS)
+        rsam |= KEY_ALL_ACCESS;
+    if (nsam & ACR_KEY_CREATE_LINK)
+        rsam |= KEY_CREATE_LINK;
+    if (nsam & ACR_KEY_CREATE_SUB_KEY)
+        rsam |= KEY_CREATE_SUB_KEY;
+    if (nsam & ACR_KEY_ENUMERATE_SUB_KEYS)
+        rsam |= KEY_ENUMERATE_SUB_KEYS;
+    if (nsam & ACR_KEY_EXECUTE)
+        rsam |= KEY_EXECUTE;
+    if (nsam & ACR_KEY_NOTIFY)
+        rsam |= KEY_NOTIFY;
+    if (nsam & ACR_KEY_QUERY_VALUE)
+        rsam |= KEY_QUERY_VALUE;
+    if (nsam & ACR_KEY_READ)
+        rsam |= KEY_READ;
+    if (nsam & ACR_KEY_SET_VALUE)
+        rsam |= KEY_SET_VALUE;
+    if (nsam & ACR_KEY_WOW64_64KEY)
+        rsam |= KEY_WOW64_64KEY;
+    if (nsam & ACR_KEY_WOW64_32KEY)
+        rsam |= KEY_WOW64_32KEY;
+    if (nsam & ACR_KEY_WRITE)
+        rsam |= KEY_WRITE;
+    return rsam;
+}
+
+static __inline void FS2BS(wchar_t *s)
+{
+    for (; *s; s++) {
+        if (*s == L'/')
+            *s = L'\\';
+    }
+}
+
 ACR_JNI_PLATFORM_DECLARE(jint, RegistryKey, close0)(ACR_JNISTDARGS,
                                                     jlong key)
 {
@@ -419,3 +457,64 @@
     return rc;
 }
 
+ACR_JNI_PLATFORM_DECLARE(jint, RegistryKey, flush0)(ACR_JNISTDARGS,
+                                                    jlong key)
+{
+    return (int)RegFlushKey(J2P(key, HKEY));
+}
+
+ACR_JNI_PLATFORM_DECLARE(jint, RegistryKey, open0)(ACR_JNISTDARGS,
+                                                   jlong key,
+                                                   jstring name,
+                                                   jint sam)
+{
+    int  rc     = ACR_EINVAL;
+    HKEY skey   = NULL;
+    HKEY hkey   = J2P(key, HKEY);
+    REGSAM rsam = _regsam_translate(sam);
+
+    WITH_WSTR(name) {
+        FS2BS(J2W(name));
+        rc = RegOpenKeyExW(hkey,
+                           J2W(name),
+                           0,
+                           rsam,
+                           &skey);
+    } END_WITH_WSTR(name);
+
+    if (rc) {
+        skey = NULL;
+        ACR_THROW_IO_IF_ERR(rc);
+    }
+    return P2J(skey);
+}
+
+ACR_JNI_PLATFORM_DECLARE(jint, RegistryKey, create0)(ACR_JNISTDARGS,
+                                                     jlong key,
+                                                     jstring name,
+                                                     jint sam)
+{
+    int  rc     = ACR_EINVAL;
+    HKEY skey   = NULL;
+    HKEY hkey   = J2P(key, HKEY);
+    REGSAM rsam = _regsam_translate(sam);
+
+    WITH_WSTR(name) {
+        FS2BS(J2W(name));
+        rc = RegCreateKeyExW(hkey,
+                             J2W(name),
+                             0,
+                             NULL,
+                             0,
+                             rsam,
+                             NULL,
+                             &skey,
+                             NULL);
+    } END_WITH_WSTR(name);
+
+    if (rc) {
+        skey = NULL;
+        ACR_THROW_IO_IF_ERR(rc);
+    }
+    return P2J(skey);
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/tfs.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/tfs.c?rev=890795&r1=890794&r2=890795&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/tfs.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/tfs.c Tue Dec 15 13:37:56 2009
@@ -25,7 +25,112 @@
 #include "acr_file.h"
 #include "acr_port.h"
 
+#ifndef TRANSACTION_DO_NOT_PROMOTE
+#define TRANSACTION_DO_NOT_PROMOTE        0x00000001
+#endif
+
 /**
- * Transactional NTFS functions
+ * Transactional NTOS functions
  *
  */
+
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KTMW32, HANDLE, INVALID_HANDLE_VALUE,
+                          WINAPI, CreateTransaction, 0, (
+    IN LPSECURITY_ATTRIBUTES lpTransactionAttributes,
+    IN LPGUID UOW,
+    IN DWORD CreateOptions,
+    IN DWORD IsolationLevel,
+    IN DWORD IsolationFlags,
+    IN DWORD Timeout,
+    IN LPWSTR Description),
+    (lpTransactionAttributes, UOW, CreateOptions, IsolationLevel, IsolationFlags, Timeout,
Description));
+#undef  CreateTransaction
+#define CreateTransaction acr_winapi_CreateTransaction
+
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KTMW32, BOOL, FALSE,
+                          WINAPI, CommitTransaction, 0, (
+    IN HANDLE TransactionHandle),
+    (TransactionHandle));
+#undef  CommitTransaction
+#define CommitTransaction acr_winapi_CommitTransaction
+
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KTMW32, BOOL, FALSE,
+                          WINAPI, RollbackTransaction, 0, (
+    IN HANDLE TransactionHandle),
+    (TransactionHandle));
+#undef  RollbackTransaction
+#define RollbackTransaction acr_winapi_RollbackTransaction
+
+ACR_JNI_PLATFORM_DECLARE(jlong, Transaction, create0)(ACR_JNISTDARGS,
+                                                      jstring desc,
+                                                      jint timeout,
+                                                      jboolean distributed)
+{
+    int  rc   = ACR_EINVAL;
+    HANDLE ht = NULL;
+
+    WITH_ZWSTR(desc) {
+        ht = CreateTransaction(NULL,
+                               NULL,
+                               0,
+                               0,
+                               distributed ? 0 : TRANSACTION_DO_NOT_PROMOTE,
+                               (DWORD)timeout,
+                               J2W(desc));
+        if (IS_INVALID_HANDLE(ht))
+            rc = ACR_GET_OS_ERROR();
+        else
+            rc = 0;
+    } END_WITH_WSTR(desc);
+
+    if (rc) {
+        ht = NULL;
+        ACR_THROW_IO_IF_ERR(rc);
+    }
+    return P2J(ht);
+}
+
+ACR_JNI_PLATFORM_DECLARE(jint, Transaction, close0)(ACR_JNISTDARGS,
+                                                    jlong th)
+{
+    int    rc = ACR_EBADF;
+    HANDLE ht = J2P(th, HKEY);
+
+    if (IS_VALID_HANDLE(ht)) {
+        if (CloseHandle(ht))
+            rc = 0;
+        else
+            rc = ACR_GET_OS_ERROR();
+    }
+    return rc;
+}
+
+ACR_JNI_PLATFORM_DECLARE(jint, Transaction, commit0)(ACR_JNISTDARGS,
+                                                     jlong th)
+{
+    int    rc = ACR_EBADF;
+    HANDLE ht = J2P(th, HKEY);
+
+    if (IS_VALID_HANDLE(ht)) {
+        if (CommitTransaction(ht))
+            rc = 0;
+        else
+            rc = ACR_GET_OS_ERROR();
+    }
+    return rc;
+}
+
+ACR_JNI_PLATFORM_DECLARE(jint, Transaction, rollback0)(ACR_JNISTDARGS,
+                                                       jlong th)
+{
+    int    rc = ACR_EBADF;
+    HANDLE ht = J2P(th, HKEY);
+
+    if (IS_VALID_HANDLE(ht)) {
+        if (RollbackTransaction(ht))
+            rc = 0;
+        else
+            rc = ACR_GET_OS_ERROR();
+    }
+    return rc;
+}



Mime
View raw message