commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r778792 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/platform/windows/VariantType.java native/Makefile.msc.in native/configure native/os/win32/variant.cpp
Date Tue, 26 May 2009 16:46:21 GMT
Author: mturk
Date: Tue May 26 16:46:20 2009
New Revision: 778792

URL: http://svn.apache.org/viewvc?rev=778792&view=rev
Log:
Add windows VARIANT support skeleton

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/VariantType.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/configure

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/VariantType.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/VariantType.java?rev=778792&r1=778791&r2=778792&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/VariantType.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/VariantType.java
Tue May 26 16:46:20 2009
@@ -16,6 +16,7 @@
 
 package org.apache.commons.runtime.platform.windows;
 
+import java.util.EnumSet;
 
 /**
  * VariantType enumeration.
@@ -75,9 +76,7 @@
     VT_ARRAY            (0x2000),
     VT_BYREF            (0x4000),
     VT_RESERVED         (0x8000),
-    VT_ILLEGAL          (0xffff),
-    VT_ILLEGALMASKED    (0x0fff),
-    VT_TYPEMASK         (0x0fff);
+    VT_ILLEGAL          (0xffff);
 
     private int value;
     private VariantType(int v)
@@ -90,13 +89,47 @@
         return value;
     }
 
-    public static VariantType valueOf(int value)
+    /**
+     * Integer representing the sum of the integer values
+     * of the {@code VariantType} enums.
+     * @param set The {@code EnumSet} which values to get.
+     * @return sum of {@code VariantType} values
+     */
+    public static int bitmapOf(EnumSet<VariantType> set)
     {
+        int bitmap = 0;
+        if (set != null) {
+            for (VariantType v : set)
+                bitmap += v.valueOf();
+        }
+        else {
+            // Use VT_NULL for null set
+            bitmap = 1;
+        }
+        return bitmap;
+    }
+
+    /**
+     * Returns {@code EnumSet} of {@code VariantType} enums
+     * from the integer bitmap value.
+     * @param value Integer used to construct the {@code EnumSet}
+     * with {@code VariantType} values mathching the value flags.
+     * @return set of {@code VariantType} enums.
+     */
+    public static EnumSet<VariantType> valueOf(int value)
+    {
+        EnumSet<VariantType> set = EnumSet.noneOf(VariantType.class);
+        if (value == VT_ILLEGAL.value) {
+            set.add(VT_ILLEGAL);
+            return set;    
+        }
         for (VariantType e : values()) {
-            if (e.value == value)
-                return e;
+            if (e.value  == (value & 0x0fff))
+                set.add(e);
+            if (e.value  == (value & 0xf000))
+                set.add(e);
         }
-        return VT_EMPTY;
+        return set;
     }
 
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=778792&r1=778791&r2=778792&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Tue May 26 16:46:20 2009
@@ -88,6 +88,7 @@
 	$(SRCDIR)/os/win32/group.$(OBJ) \
 	$(SRCDIR)/os/win32/user.$(OBJ) \
 	$(SRCDIR)/os/win32/uuid.$(OBJ) \
+	$(SRCDIR)/os/win32/variant.$(OBJ) \
 	$(SRCDIR)/os/win32/wusec.$(OBJ)
 
 TEST_OBJS= \

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=778792&r1=778791&r2=778792&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Tue May 26 16:46:20 2009
@@ -316,7 +316,7 @@
         varadds ccflags "-nologo -O2 -Ob2 -Oy- -Zi -D_MD -MD -W3"
         varadds cppopts "-DWIN32 -D_WIN32 -D_WINDOWS -D_WINNT -DNDEBUG"
         varadds cppopts "-D_WIN32_WINNT=0x0501 -D_WIN32_IE=0x0600"
-        varadds cxxopts "/TP"
+        varadds cxxopts "-TP"
         varadds ldflags "kernel32.lib advapi32.lib ws2_32.lib mswsock.lib"
         varadds ldflags "ole32.lib shell32.lib rpcrt4.lib user32.lib gdi32.lib"
         varadds ldflags "psapi.lib shlwapi.lib wldap32.lib netapi32.lib iphlpapi.lib"
@@ -326,6 +326,7 @@
         exe=".exe"
         obj="obj"
         nmake=".msc"
+        cxx="$cc"
         if [ ".$java_pinc" = . ]; then java_pinc="win32"; fi
         ;;
     *       )

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp?rev=778792&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp Tue May 26 16:46:20
2009
@@ -0,0 +1,225 @@
+/* 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.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_clazz.h"
+#include "acr_error.h"
+#include "acr_memory.h"
+#include "acr_string.h"
+#include "acr_pointer.h"
+
+#define STRSAFE_NO_DEPRECATE
+#include <comdef.h>
+#include <strsafe.h>
+
+/* Pointer object callback function
+ */
+static int variant_callback(void *p)
+{
+    VARIANT *v = (VARIANT *)p;
+    if (v) {
+        VariantClear(v);
+        free(v);
+    }
+    return 0;
+}
+
+extern "C"
+ACR_JNI_PLATFORM_DECLARE(jobject, VARIANT, alloc0)(ACR_JNISTDARGS)
+{
+    VARIANT *v = (VARIANT *)ACR_Calloc(_E, THROW_FMARK, sizeof(VARIANT));
+
+    UNREFERENCED_O;
+    if (!v)
+        return 0;
+    VariantInit(v);
+    return  ACR_PointerCreate(_E, v, 0, variant_callback);
+}
+
+extern "C"
+ACR_JNI_PLATFORM_DECLARE(jint, VARIANT, vtype0)(ACR_JNISTDARGS)
+{
+    VARIANT *v = (VARIANT *)ACR_PointerGet(_E, _O, NULL);
+
+    if (v)
+        return v->vt;
+    else
+        return VT_NULL;
+}
+
+extern "C"
+ACR_JNI_PLATFORM_DECLARE(jint, VARIANT, getiv0)(ACR_JNISTDARGS)
+{
+    VARIANT *v = (VARIANT *)ACR_PointerGet(_E, _O, NULL);
+
+    if (!v)
+        return 0;
+    switch (v->vt) {
+        case VT_BOOL:
+            return v->boolVal;
+        break;
+        case VT_I1:
+        case VT_UI1:
+            return v->bVal;
+        break;
+        case VT_I2:
+            return v->iVal;
+        break;
+        case VT_UI2:
+            return v->uiVal;
+        break;
+        case VT_I4:
+            return v->lVal;
+        break;
+        case VT_UI4:
+            return v->ulVal;
+        break;
+        case VT_INT:
+            return v->intVal;
+        break;
+        case VT_UINT:
+            return v->uintVal;
+        break;
+        case VT_R4:
+            return (int)(v->fltVal);
+        break;
+        case VT_R8:
+            return (int)(v->dblVal);
+        break;
+        case VT_ERROR:
+            return (int)(v->scode);
+        break;
+        case VT_BSTR:
+            return SysStringLen(v->bstrVal);
+        break;
+    }
+    if (v->vt & VT_ARRAY) {
+        SAFEARRAY *sa = v->parray;
+        long lb, ub;
+
+        SafeArrayGetLBound(sa, 1, &lb);
+        SafeArrayGetUBound(sa, 1, &ub);
+        return (ub - lb + 1);
+    }
+    else {
+        return 0;
+    }
+}
+
+extern "C"
+ACR_JNI_PLATFORM_DECLARE(jlong, VARIANT, getjv0)(ACR_JNISTDARGS)
+{
+    VARIANT *v = (VARIANT *)ACR_PointerGet(_E, _O, NULL);
+
+    if (!v)
+        return 0;
+    switch (v->vt) {
+        case VT_BOOL:
+            return v->boolVal;
+        break;
+        case VT_I1:
+        case VT_UI1:
+            return v->bVal;
+        break;
+        case VT_I2:
+            return v->iVal;
+        break;
+        case VT_UI2:
+            return v->uiVal;
+        break;
+        case VT_I4:
+            return v->lVal;
+        break;
+        case VT_UI4:
+            return v->ulVal;
+        break;
+        case VT_I8:
+            return v->llVal;
+        break;
+        case VT_UI8:
+            return v->ullVal;
+        break;
+        case VT_INT:
+            return v->intVal;
+        break;
+        case VT_UINT:
+            return v->uintVal;
+        break;
+        case VT_R4:
+            return (jlong)(v->fltVal);
+        break;
+        case VT_R8:
+            return (jlong)(v->dblVal);
+        break;
+        case VT_CY:
+            return v->cyVal.int64;
+        break;
+        case VT_ERROR:
+            return v->scode;
+        break;
+        case VT_BSTR:
+            return SysStringLen(v->bstrVal);
+        break;
+    }
+    if (v->vt & VT_ARRAY) {
+        SAFEARRAY *sa = v->parray;
+        long lb, ub;
+
+        SafeArrayGetLBound(sa, 1, &lb);
+        SafeArrayGetUBound(sa, 1, &ub);
+        return (ub - lb + 1);
+    }
+    else {
+        return 0;
+    }
+}
+
+extern "C"
+ACR_JNI_PLATFORM_DECLARE(jstring, VARIANT, getsv0)(ACR_JNISTDARGS)
+{
+    jstring s = NULL;
+    HRESULT  r;
+    VARIANT  c;
+    VARIANT *v = (VARIANT *)ACR_PointerGet(_E, _O, NULL);
+
+    if (!v)
+        return 0;
+    switch (v->vt) {
+        case VT_EMPTY:
+            s = _E->NewString(L"", 0);
+        break;
+        case VT_BSTR:
+            s = _E->NewString(v->bstrVal, SysStringLen(v->bstrVal));
+        break;
+        default:
+            VariantInit(&c);
+            r = VariantChangeType(&c, v,
+                                  VARIANT_ALPHABOOL | VARIANT_NOUSEROVERRIDE,
+                                  VT_BSTR);
+            if (SUCCEEDED(r)) {
+                s = _E->NewString(c.bstrVal, SysStringLen(c.bstrVal));
+                VariantClear(&c);
+            }
+            else {
+                /* TODO: Pick Exception to be thrown
+                 */
+            }
+        break;
+    }
+    return s;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/variant.cpp
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message