From bf07b44ed6a8958dd321cc4c08fd2bdd08299611 Mon Sep 17 00:00:00 2001
From: Michael Bien <mbien@fh-landshut.de>
Date: Mon, 12 Apr 2010 22:18:39 +0200
Subject: renamed package com.mbien.* in com.jogamp.* JOCL is now officially a
 JogAmp team player ;).

---
 src/com/jogamp/opencl/CLInfoAccessor.java | 62 +++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 src/com/jogamp/opencl/CLInfoAccessor.java

(limited to 'src/com/jogamp/opencl/CLInfoAccessor.java')

diff --git a/src/com/jogamp/opencl/CLInfoAccessor.java b/src/com/jogamp/opencl/CLInfoAccessor.java
new file mode 100644
index 00000000..56f2318d
--- /dev/null
+++ b/src/com/jogamp/opencl/CLInfoAccessor.java
@@ -0,0 +1,62 @@
+package com.jogamp.opencl;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.common.nio.Int64Buffer;
+import com.jogamp.opencl.util.CLUtil;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+
+import static com.jogamp.opencl.CLException.*;
+
+/**
+ * Internal utility for common OpenCL clGetFooInfo calls.
+ * Threadsafe.
+ * @author Michael Bien
+ */
+abstract class CLInfoAccessor {
+
+    protected final static ThreadLocal<ByteBuffer> localBB = new ThreadLocal<ByteBuffer>() {
+
+        @Override
+        protected ByteBuffer initialValue() {
+            return Buffers.newDirectByteBuffer(512);
+        }
+
+    };
+    protected final static ThreadLocal<Int64Buffer> localPB = new ThreadLocal<Int64Buffer>() {
+
+        @Override
+        protected Int64Buffer initialValue() {
+            return Int64Buffer.allocateDirect(1);
+        }
+
+    };
+
+    public final long getLong(int key) {
+
+        ByteBuffer buffer = localBB.get();
+        int ret = getInfo(key, 8, buffer, null);
+        checkForError(ret, "error while asking for info value");
+
+        return buffer.getLong(0);
+    }
+
+    public final String getString(int key) {
+        
+        ByteBuffer buffer = localBB.get();
+        Int64Buffer sizeBuffer = localPB.get();
+        int ret = getInfo(key, buffer.capacity(), buffer, sizeBuffer);
+        checkForError(ret, "error while asking for info string");
+
+        int clSize = (int)sizeBuffer.get(0);
+        byte[] array = new byte[clSize-1]; // last char is always null
+        buffer.get(array).rewind();
+
+        return CLUtil.clString2JavaString(array, clSize);
+
+    }
+
+    protected abstract int getInfo(int name, long valueSize, Buffer value, Int64Buffer valueSizeRet);
+
+
+}
-- 
cgit v1.2.3