diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bindings/swig/csharp/uscxml.i | 35 | ||||
-rw-r--r-- | src/bindings/swig/java/uscxml.i | 26 | ||||
-rw-r--r-- | src/bindings/swig/uscxml_ignores.i | 8 | ||||
-rw-r--r-- | src/uscxml/messages/Blob.cpp | 7 | ||||
-rw-r--r-- | src/uscxml/messages/Blob.h | 27 | ||||
-rw-r--r-- | src/uscxml/messages/Data.cpp | 4 | ||||
-rw-r--r-- | src/uscxml/messages/Data.h | 22 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp | 2 |
8 files changed, 109 insertions, 22 deletions
diff --git a/src/bindings/swig/csharp/uscxml.i b/src/bindings/swig/csharp/uscxml.i index 2a1ac07..bd8c669 100644 --- a/src/bindings/swig/csharp/uscxml.i +++ b/src/bindings/swig/csharp/uscxml.i @@ -157,6 +157,41 @@ WRAP_TO_STRING(uscxml::InvokeRequest); // Beautify important classes //*********************************************** + +// byte[] signature for Blob get/setData +// see http://permalink.gmane.org/gmane.comp.programming.swig/5804 + +%csmethodmodifiers uscxml::Blob::Blob(const char* data, size_t size, const std::string& mimeType) "private"; +%typemap(cscode) uscxml::Blob %{ + public Blob(byte[] data, string mimeType) : this(uscxmlNativeCSharpPINVOKE.new_Blob(data, (uint)data.Length, mimeType), true) { + if (uscxmlNativeCSharpPINVOKE.SWIGPendingException.Pending) throw uscxmlNativeCSharpPINVOKE.SWIGPendingException.Retrieve(); + } +%} + +%typemap(imtype, out="System.IntPtr") const char *data "byte[]" +%typemap(cstype) const char *data "byte[]" +%typemap(in) const char *data %{ $1 = ($1_ltype)$input; %} +%typemap(csin) const char *data "$csinput" + +%typemap(imtype, out="System.IntPtr") char* getData "byte[]" +%typemap(cstype) char* getData "byte[]" + +%typemap(csout) char* getData %{ + { + byte[] ret = new byte[this.getSize()]; + System.IntPtr data = $imcall; + System.Runtime.InteropServices.Marshal.Copy(data, ret, 0, (int)this.getSize()); + return ret; + } +%} + +// make sure we do not get the default with SWIG_csharp_string_callback +%typemap(out) char* getData { + $result = (char *)result; +} + + + %csmethodmodifiers uscxml::Event::getParamMap() "private"; %csmethodmodifiers uscxml::Event::getParamMapKeys() "private"; %csmethodmodifiers uscxml::Event::setParamMap(const std::map<std::string, std::list<uscxml::Data> >&) "private"; diff --git a/src/bindings/swig/java/uscxml.i b/src/bindings/swig/java/uscxml.i index ee95eb0..9610e77 100644 --- a/src/bindings/swig/java/uscxml.i +++ b/src/bindings/swig/java/uscxml.i @@ -112,6 +112,7 @@ WRAP_TO_STRING(uscxml::InvokeRequest); %include "../uscxml_ignores.i" +#if 0 // see http://swig.org/Doc2.0/Java.html#Java_date_marshalling %define BEAUTIFY_NATIVE( MATCH, WRAPPER, NATIVE ) @@ -164,6 +165,24 @@ BEAUTIFY_NATIVE(uscxml::Event, Event, EventNative); BEAUTIFY_NATIVE(uscxml::SendRequest, SendRequest, SendRequestNative); BEAUTIFY_NATIVE(uscxml::InvokeRequest, InvokeRequest, InvokeRequestNative); */ +#endif + +// bytearray for Blob::data +// see: http://stackoverflow.com/questions/9934059/swig-technique-to-wrap-unsigned-binary-data + +%apply (char *STRING, size_t LENGTH) { (const char* data, size_t size) }; + +%typemap(jni) char* getData "jbyteArray" +%typemap(jtype) char* getData "byte[]" +%typemap(jstype) char* getData "byte[]" +%typemap(javaout) char* getData { + return $jnicall; +} + +%typemap(out) char* getData { + $result = JCALL1(NewByteArray, jenv, ((uscxml::Blob const *)arg1)->getSize()); + JCALL4(SetByteArrayRegion, jenv, $result, 0, ((uscxml::Blob const *)arg1)->getSize(), (jbyte *)$1); +} //*********************************************** @@ -180,6 +199,9 @@ BEAUTIFY_NATIVE(uscxml::InvokeRequest, InvokeRequest, InvokeRequestNative); %javamethodmodifiers uscxml::Interpreter::getIOProcessors() "private"; %javamethodmodifiers uscxml::Data::getCompoundKeys() "private"; +%javamethodmodifiers uscxml::Blob::setData(const char* data, size_t length) "private"; +%javamethodmodifiers uscxml::Blob::setMimeType(const std::string& mimeType) "private"; + %include "../uscxml_beautify.i" @@ -231,6 +253,10 @@ import java.util.LinkedList; %} %typemap(javacode) uscxml::Data %{ + public Data(byte[] data, String mimeType) { + + } + public Data(Map<String, Data> compound) { this(uscxmlNativeJavaJNI.new_Data__SWIG_0(), true); setCompound(compound); diff --git a/src/bindings/swig/uscxml_ignores.i b/src/bindings/swig/uscxml_ignores.i index d54dae2..5e99416 100644 --- a/src/bindings/swig/uscxml_ignores.i +++ b/src/bindings/swig/uscxml_ignores.i @@ -189,6 +189,14 @@ %ignore uscxml::Data::toDocument; %ignore uscxml::Data::Data(const Arabica::DOM::Node<std::string>&); +%ignore uscxml::Data::Data(const char* data, size_t size, const std::string& mimeType, bool adopt); +%ignore uscxml::Data::Data(const char* data, size_t size, const std::string& mimeType); + +// Blob + +%ignore uscxml::Blob::Blob(size_t size); +%ignore uscxml::Blob::Blob(const char* data, size_t size, const std::string& mimeType, bool adopt); + %ignore operator!=; %ignore operator<; diff --git a/src/uscxml/messages/Blob.cpp b/src/uscxml/messages/Blob.cpp index 1d07e6a..2e68e98 100644 --- a/src/uscxml/messages/Blob.cpp +++ b/src/uscxml/messages/Blob.cpp @@ -34,16 +34,17 @@ std::string Blob::md5() { Blob* Blob::fromBase64(const std::string base64) { std::string decoded = base64Decode(base64); - return new Blob((void*)decoded.c_str(), decoded.length(), mimeType); + return new Blob(decoded.c_str(), decoded.length(), mimeType); } Blob::Blob(size_t _size) { data = (char*)malloc(_size); memset(data, 0, _size); size = _size; + mimeType = "application/octet-stream"; } -Blob::Blob(void* _data, size_t _size, const std::string& _mimeType, bool adopt) { +Blob::Blob(const char* _data, size_t _size, const std::string& _mimeType, bool adopt) { if (adopt) { data = (char*)_data; } else { @@ -53,7 +54,7 @@ Blob::Blob(void* _data, size_t _size, const std::string& _mimeType, bool adopt) mimeType = _mimeType; size = _size; } - + std::string Blob::base64() { return base64Encode((char* const)data, size); } diff --git a/src/uscxml/messages/Blob.h b/src/uscxml/messages/Blob.h index b4fcd46..b805da1 100644 --- a/src/uscxml/messages/Blob.h +++ b/src/uscxml/messages/Blob.h @@ -30,15 +30,32 @@ class USCXML_API Blob { public: ~Blob(); Blob(size_t size); - Blob(void* data, size_t size, const std::string& mimeType, bool adopt = false); - char* data; - size_t size; - std::string mimeType; + Blob(const char* data, size_t size, const std::string& mimeType, bool adopt = false); std::string base64(); - std::string md5(); Blob* fromBase64(const std::string base64); + + char* getData() const { + return data; + } + + size_t getSize() const { + return size; + } + + std::string getMimeType() const { + return mimeType; + } + +#ifdef SWIGIMPORTED +protected: +#endif + + char* data; + size_t size; + std::string mimeType; + }; diff --git a/src/uscxml/messages/Data.cpp b/src/uscxml/messages/Data.cpp index 6706253..1ee946a 100644 --- a/src/uscxml/messages/Data.cpp +++ b/src/uscxml/messages/Data.cpp @@ -35,8 +35,8 @@ extern "C" { namespace uscxml { -Data::Data(const char* _data, size_t _size, const std::string& mimeType, bool adopt) { - binary = boost::shared_ptr<Blob>(new Blob((void*)_data, _size, mimeType, adopt)); +Data::Data(const char* data, size_t size, const std::string& mimeType, bool adopt) { + binary = boost::shared_ptr<Blob>(new Blob(data, size, mimeType, adopt)); } void Data::merge(const Data& other) { diff --git a/src/uscxml/messages/Data.h b/src/uscxml/messages/Data.h index 9b5bea7..44ce1d7 100644 --- a/src/uscxml/messages/Data.h +++ b/src/uscxml/messages/Data.h @@ -45,26 +45,26 @@ public: Data() : type(INTERPRETED) {} // TODO: default INTERPRETED is unfortunate - Data(const std::string& atom_, Type type_ = INTERPRETED) : atom(atom_), type(type_) {} + Data(const std::string& atom, Type type = INTERPRETED) : atom(atom), type(type) {} Data(const char* data, size_t size, const std::string& mimeType, bool adopt = false); // convenience constructors - Data(short atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(int atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(unsigned int atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(long atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(unsigned long atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(float atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(double atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(bool atom_) : type(INTERPRETED) { - if (atom_) { + Data(short atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(int atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(unsigned int atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(long atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(unsigned long atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(float atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(double atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(bool atom) : type(INTERPRETED) { + if (atom) { atom = "true"; } else { atom = "false"; } } - template <typename T> Data(T value, Type type_) : atom(toStr(value)), type(type_) {} + template <typename T> Data(T value, Type type) : atom(toStr(value)), type(type) {} #if 0 // constructor for arbitrary types, skip if type is subclass though (C++11) diff --git a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp index fd1f936..5b34181 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp @@ -42,7 +42,7 @@ ArrayBuffer::ArrayBuffer(boost::shared_ptr<Blob> buffer) : _buffer(buffer) { } ArrayBuffer::ArrayBuffer(void* data, unsigned int size) { - _buffer = boost::shared_ptr<Blob>(new Blob(data, size, "application/octet-stream")); + _buffer = boost::shared_ptr<Blob>(new Blob((const char*)data, size, "application/octet-stream")); } unsigned long ArrayBuffer::getByteLength() { |