summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2012-06-01 03:42:15 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2012-06-01 03:42:15 +0000
commit5e04a943ac3b6eef436d1bbdde45b918428d4e63 (patch)
tree5df76c723b1d4004ab2076e360d6686fbbb6a754
parentd8164a0012e17f6a83340ff994566db15f0bf294 (diff)
downloadqpid-python-5e04a943ac3b6eef436d1bbdde45b918428d4e63.tar.gz
QPID-4027 Refactored the swig files to make them more readable. Added
comments to explain the code. Removed the VariantMapWrapper files as they are now added into swig_java_cpp_helper.i classes. If someones wants to use swig to wrap qmfv2 they could now use the type maps defined here. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/address-refactor2@1344979 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/bindings/qpid/java/VaraintMapWrapper.cpp115
-rw-r--r--qpid/cpp/bindings/qpid/java/VaraintMapWrapper.h49
-rw-r--r--qpid/cpp/bindings/qpid/java/java.i6
-rw-r--r--qpid/cpp/bindings/swig_java_cpp_helper.i36
-rw-r--r--qpid/cpp/bindings/swig_java_helper.i149
-rw-r--r--qpid/cpp/bindings/swig_java_typemaps.i230
6 files changed, 243 insertions, 342 deletions
diff --git a/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.cpp b/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.cpp
deleted file mode 100644
index 1f7cc54550..0000000000
--- a/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- *
- * 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 "qpid/types/Variant.h"
-#include "jni.h"
-
-#include <string>
-
-using namespace qpid::types;
-
-VaraintMapWrapper::VaraintMapWrapper(): env(0), varMap(new Variant::Map())
-
-VaraintMapWrapper::VaraintMapWrapper(JNIEnv*& jniEnv, Variant::Map*& map): env(jniEnv), varMap(map)
-{
-}
-
-VaraintMapWrapper::jobject get(const std::string key) const
-{
- jobject result;
- Varient::Map::iterator iter = varMap->find(key);
- if (iter == varMap->end()){
- return NULL;
- }
-
- Variant v = iter->first();
-
- try {
- switch (v->getType()) {
- case VAR_VOID: {
- result = NULL;
- break;
- }
- case VAR_BOOL : {
- result = v->asBool() ? JNI_TRUE : JNI_FALSE;
- break;
- }
- case VAR_UINT8 :
- case VAR_UINT16 :
- case VAR_UINT32 : {
- result = (jnit) v->asUint32();
- break;
- }
- case VAR_UINT64 : {
- result = (jlong) v->asUint64();
- break;
- }
- case VAR_INT8 :
- case VAR_INT16 :
- case VAR_INT32 : {
- result = (jnit) v->asUint32();
- break;
- }
- case VAR_INT64 : {
- result = (jlong) v->asUint64();
- break;
- }
- case VAR_FLOAT : {
- result = (jfloat) v->asFloat();
- break;
- }
- case VAR_DOUBLE : {
- result = (jdouble) v->asDouble();
- break;
- }
- case VAR_STRING : {
- const std::string val(v->asString());
- result = env->NewStringUTF(val.data());
- break;
- }
- }
- } catch (Exception& ex) {
- result = NULL; // need to throw exception
- }
-
- return result;
-}
-
-VaraintMapWrapper::jboolean containsKey (const jstring key) const
-{
- return (jboolean)true;
-}
-
-VaraintMapWrapper::jboolean containsValue (const jobject value) const
-{
- return (jboolean)true;
-}
-
-VaraintMapWrapper::jboolean isEmpty() const
-{
- return (jboolean)true;
-}
-
-/* jstring[] keys() const;
- jobject[] values() const;
- jinit size() const;
-*/
-
diff --git a/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.h b/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.h
deleted file mode 100644
index 6272bbc49b..0000000000
--- a/qpid/cpp/bindings/qpid/java/VaraintMapWrapper.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- *
- * 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 "qpid/types/Variant.h"
-#include "jni.h"
-
-#include <string>
-
-/**
- * Only primitives types are supported as values.
- */
-class VaraintMapWrapper {
-
- public:
- VaraintMapWrapper();
- VaraintMapWrapper(JNIEnv*& jniEnv, qpid::types::Variant::Map*& map);
- jobject get(const std::string key) const;
- jboolean containsKey (const jstring key) const;
- jboolean containsValue (const jobject value) const;
- jboolean isEmpty() const;
- jobjectArray keys() const;
- jobjectArray values() const;
- jint size() const;
-
- private:
- qpid::types::Variant::Map varMap;
- JNIEnv env;
-};
-
-
-
diff --git a/qpid/cpp/bindings/qpid/java/java.i b/qpid/cpp/bindings/qpid/java/java.i
index 1f6006d955..fb5bc6cde7 100644
--- a/qpid/cpp/bindings/qpid/java/java.i
+++ b/qpid/cpp/bindings/qpid/java/java.i
@@ -17,15 +17,9 @@
* under the License.
*/
-%{
-#include "VaraintMapWrapper.h"
-%}
-
%module cqpid
%include "std_string.i"
%include "../../swig_java_typemaps.i"
-%include "VaraintMapWrapper.h"
-
%include "../qpid.i"
diff --git a/qpid/cpp/bindings/swig_java_cpp_helper.i b/qpid/cpp/bindings/swig_java_cpp_helper.i
new file mode 100644
index 0000000000..12cfb0c91f
--- /dev/null
+++ b/qpid/cpp/bindings/swig_java_cpp_helper.i
@@ -0,0 +1,36 @@
+/*
+ * ===================== C++ Helper Methods ==========================
+ * Defines classes and/or helper functions in support of typemaps,
+ * for converting between C++ and Java.
+ * ===================================================================
+ */
+
+%inline %{
+class VaraintMapWrapper {
+
+ public:
+ VaraintMapWrapper();
+ VaraintMapWrapper(JNIEnv*& jniEnv, qpid::types::Variant::Map*& map);
+ jobject get(const std::string key) const;
+ jboolean containsKey (const jstring key) const;
+ jboolean containsValue (const jobject value) const;
+ jboolean isEmpty() const;
+ jobjectArray keys() const;
+ jobjectArray values() const;
+ jint size() const;
+
+ private:
+ qpid::types::Variant::Map varMap;
+ JNIEnv env;
+};
+%}
+
+VaraintMapWrapper::VaraintMapWrapper();
+VaraintMapWrapper::VaraintMapWrapper(JNIEnv*& jniEnv, qpid::types::Variant::Map*& map);
+jobject VaraintMapWrapper::get(const std::string key) const;
+jboolean VaraintMapWrapper::containsKey (const jstring key) const;
+jboolean VaraintMapWrapper::containsValue (const jobject value) const;
+jboolean VaraintMapWrapper::isEmpty() const;
+jobjectArray VaraintMapWrapper::keys() const;
+jobjectArray VaraintMapWrapper::values() const;
+jint VaraintMapWrapper::size() const;
diff --git a/qpid/cpp/bindings/swig_java_helper.i b/qpid/cpp/bindings/swig_java_helper.i
new file mode 100644
index 0000000000..9a78a55712
--- /dev/null
+++ b/qpid/cpp/bindings/swig_java_helper.i
@@ -0,0 +1,149 @@
+/*
+ * ===================== Java Helper Methods ==========================
+ * Defines helper methods in support of typemaps.
+ * These methods are placed in the respective module.
+ * ===================================================================
+ */
+
+%pragma(java) moduleimports=%{
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+%}
+
+%pragma(java) modulecode=%{
+ /** Checks if the buffer passed is a direct buffer
+ * This method could also convert a non direct buffer into a direct buffer.
+ * However the extra copying deafeats the purpose of the binding.
+ */
+ static protected java.nio.ByteBuffer isBufferDirect(java.nio.ByteBuffer buff)
+ {
+ if (buff.isDirect())
+ {
+ return buff;
+ }
+ else
+ {
+ throw new RuntimeException("The ByteBuffer passed is not allocated direct");
+ }
+ }
+
+ /** We don't support setting maps into C++ atm, but adding here to get around swig **/
+ static VaraintMapWrapper getVariantMap(final Map<String,Object> map)
+ {
+ return new VaraintMapWrapper();
+ }
+
+ static Map<String, Object> getJavaMap(final VaraintMapWrapper map)
+ {
+ return new Map<String, Object>()
+ {
+ @Override
+ public int size()
+ {
+ return map.size();
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ return map.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(Object key)
+ {
+ return map.containsKey((String)key);
+ }
+
+ @Override
+ public boolean containsValue(Object value)
+ {
+ return map.containsValue(value);
+ }
+
+ @Override
+ public Object get(Object key)
+ {
+ return map.get((String)key);
+ }
+
+ @Override
+ public Object put(String key, Object value)
+ {
+ throw new UnsupportedOperationException("This map is read-only");
+ }
+
+ @Override
+ public Object remove(Object key)
+ {
+ throw new UnsupportedOperationException("This map is read-only");
+ }
+
+ @Override
+ public void putAll(Map<? extends String, ? extends Object> m)
+ {
+ throw new UnsupportedOperationException("This map is read-only");
+ }
+
+ @Override
+ public void clear()
+ {
+ throw new UnsupportedOperationException("This map is read-only");
+ }
+
+ @Override
+ public Set<String> keySet()
+ {
+ Set<String> keys = new HashSet<String>();
+ for (String key:(String[])map.keys())
+ {
+ keys.add(key);
+ }
+
+ return keys;
+ }
+
+ @Override
+ public Collection<Object> values()
+ {
+ return Arrays.asList(map.values());
+ }
+
+ @Override
+ public Set<Entry<String, Object>> entrySet()
+ {
+ Set<Entry<String, Object>> entries = new HashSet<Entry<String, Object>>();
+ for (final String key: keySet())
+ {
+ final Object value = map.get(key);
+ entries.add(new Entry<String, Object>()
+ {
+ @Override
+ public String getKey()
+ {
+ return key;
+ }
+
+ @Override
+ public Object getValue()
+ {
+ return value;
+ }
+
+ @Override
+ public Object setValue(Object value)
+ {
+ throw new UnsupportedOperationException("This set is read-only");
+ }
+
+ });
+ }
+ return entries;
+ }
+
+ };
+ }
+%}
diff --git a/qpid/cpp/bindings/swig_java_typemaps.i b/qpid/cpp/bindings/swig_java_typemaps.i
index 344247d0d9..037b050169 100644
--- a/qpid/cpp/bindings/swig_java_typemaps.i
+++ b/qpid/cpp/bindings/swig_java_typemaps.i
@@ -17,157 +17,57 @@
* under the License.
*/
-/* Module code used by some of the wrapper classes */
-
-%pragma(java) moduleimports=%{
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+/* ======================== C/C+ Header files ======================== */
+%begin %{
+#include "qpid/types/Variant.h"
+#include "jni.h"
%}
+/* =================================================================== */
-%pragma(java) modulecode=%{
- /** Checks if the buffer passed is a direct buffer
- * This method could also convert a non direct buffer into a direct buffer.
- * However the extra copying deafeats the purpose of the binding.
- */
- static protected java.nio.ByteBuffer isBufferDirect(java.nio.ByteBuffer buff)
- {
- if (buff.isDirect())
- {
- return buff;
- }
- else
- {
- throw new RuntimeException("The ByteBuffer passed is not allocated direct");
- }
- }
-
- /** We don't support setting maps into C++ atm, but adding here to get around swig **/
- static VaraintMapWrapper getVariantMap(final Map<String,Object> map)
- {
- return new VaraintMapWrapper();
- }
-
- static Map<String, Object> getJavaMap(final VaraintMapWrapper map)
- {
- return new Map<String, Object>()
- {
- @Override
- public int size()
- {
- return map.size();
- }
-
- @Override
- public boolean isEmpty()
- {
- return map.isEmpty();
- }
-
- @Override
- public boolean containsKey(Object key)
- {
- return map.containsKey((String)key);
- }
-
- @Override
- public boolean containsValue(Object value)
- {
- return map.containsValue(value);
- }
-
- @Override
- public Object get(Object key)
- {
- return map.get((String)key);
- }
-
- @Override
- public Object put(String key, Object value)
- {
- throw new UnsupportedOperationException("This map is read-only");
- }
-
- @Override
- public Object remove(Object key)
- {
- throw new UnsupportedOperationException("This map is read-only");
- }
-
- @Override
- public void putAll(Map<? extends String, ? extends Object> m)
- {
- throw new UnsupportedOperationException("This map is read-only");
- }
-
- @Override
- public void clear()
- {
- throw new UnsupportedOperationException("This map is read-only");
- }
-
- @Override
- public Set<String> keySet()
- {
- Set<String> keys = new HashSet<String>();
- for (String key:(String[])map.keys())
- {
- keys.add(key);
- }
-
- return keys;
- }
-
- @Override
- public Collection<Object> values()
- {
- return Arrays.asList(map.values());
- }
-
- @Override
- public Set<Entry<String, Object>> entrySet()
- {
- Set<Entry<String, Object>> entries = new HashSet<Entry<String, Object>>();
- for (final String key: keySet())
- {
- final Object value = map.get(key);
- entries.add(new Entry<String, Object>()
- {
- @Override
- public String getKey()
- {
- return key;
- }
-
- @Override
- public Object getValue()
- {
- return value;
- }
-
- @Override
- public Object setValue(Object value)
- {
- throw new UnsupportedOperationException("This set is read-only");
- }
-
- });
- }
- return entries;
- }
-
- };
- }
-%}
+
+/* ======================== swig file includes ======================= */
+%include "swig_java_cpp_helper.i"
+%include "swig_java_helper.i"
+/* =================================================================== */
+
+
+/*
+ * ========================== Type Maps =============================
+ * Defines the mapping between the various C++ and Java types
+ * ===================================================================
+ */
-/* These 3 typemaps tell SWIG what JNI and Java types to use */
+/*
+ * -------------------------------------------------------------------
+ * The "jni" specfies the jni C types to be used in jni code (c++)
+ * The "jtpye" specifies the type mapping between,
+ * the jni native methods and proxy classes (java code).
+ * The "jstype" specifies the types exposed in the proxy classes.
+ * -------------------------------------------------------------------
+*/
%typemap(jni) qpid::messaging::Message::BYTE_BUFFER "jobject"
%typemap(jtype) qpid::messaging::Message::BYTE_BUFFER "java.nio.ByteBuffer"
%typemap(jstype) qpid::messaging::Message::BYTE_BUFFER "java.nio.ByteBuffer"
+%typemap(jni) qpid::types::Variant::Map& "jobject"
+%typemap(jtype) qpid::types::Variant::Map& "VaraintMapWrapper"
+%typemap(jstype) qpid::types::Variant::Map& "java.util.Map"
+
+%typemap(jni) uint8_t "jbyte"
+%typemap(jtype) uint8_t "byte"
+%typemap(jstype) uint8_t "byte"
+
+%typemap(jni) uint32_t "jint"
+%typemap(jtype) uint32_t "int"
+%typemap(jstype) uint32_t "int"
+
+%typemap(jni) uint64_t "jlong"
+%typemap(jtype) uint64_t "long"
+%typemap(jstype) uint64_t "long"
+
+
+/* -- qpid::messaging::Message::BYTE_BUFFER -- */
%typemap(in) (qpid::messaging::Message::BYTE_BUFFER) {
void* start = jenv->GetDirectBufferAddress($input);
long size = (long)(jenv->GetDirectBufferCapacity($input));
@@ -184,9 +84,12 @@ import java.util.Set;
return $jnicall;
}
-%typemap(jni) qpid::types::Variant::Map& "jobject"
-%typemap(jtype) qpid::types::Variant::Map& "VaraintMapWrapper"
-%typemap(jstype) qpid::types::Variant::Map& "java.util.Map"
+/* -- qpid::types::Variant::Map& -- */
+%typemap(in) (qpid::types::Variant::Map&){
+ $1 = new qpid::types::Variant::Map();
+}
+
+%typemap(javain) (qpid::types::Variant::Map&) "$module.getVariantMap($javainput)"
%typemap(out) qpid::types::Variant::Map& {
*(VaraintMapWrapper **)&jresult = new VaraintMapWrapper(jenv,$1);
@@ -196,16 +99,13 @@ import java.util.Set;
return $module.getJavaMap($jnicall);
}
-%typemap(in) (qpid::types::Variant::Map&){
- $1 = new qpid::types::Variant::Map();
-}
-
-%typemap(javain) (qpid::types::Variant::Map&) "$module.getVariantMap($javainput)"
-
+/* -- qpid::types::uint8_t -- */
%typemap(in) uint8_t {
$1 = (uint8_t)$input;
}
+%typemap(javain) uint8_t "$javainput"
+
%typemap(out) uint8_t {
$result = (jbyte)$1;
}
@@ -214,13 +114,13 @@ import java.util.Set;
return $jnicall;
}
-%typemap(javain) uint8_t "$javainput"
-
-
+/* -- qpid::types::uint32_t -- */
%typemap(in) uint32_t {
$1 = (uint32_t)$input;
}
+%typemap(javain) uint32_t "$javainput"
+
%typemap(out) uint32_t {
$result = (jint)$1;
}
@@ -229,12 +129,13 @@ import java.util.Set;
return $jnicall;
}
-%typemap(javain) uint32_t "$javainput"
-
+/* -- qpid::types::uint64_t -- */
%typemap(in) uint64_t {
$1 = (uint64_t)$input;
}
+%typemap(javain) uint64_t "$javainput"
+
%typemap(out) uint64_t {
$result = (jlong)$1;
}
@@ -242,18 +143,3 @@ import java.util.Set;
%typemap(javaout) uint64_t {
return $jnicall;
}
-
-%typemap(javain) uint64_t "$javainput"
-
-%typemap(jni) uint8_t "jbyte"
-%typemap(jtype) uint8_t "byte"
-%typemap(jstype) uint8_t "byte"
-
-%typemap(jni) uint32_t "jint"
-%typemap(jtype) uint32_t "int"
-%typemap(jstype) uint32_t "int"
-
-%typemap(jni) uint64_t "jlong"
-%typemap(jtype) uint64_t "long"
-%typemap(jstype) uint64_t "long"
-