diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-09-01 20:51:59 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-09-01 20:51:59 (GMT) |
commit | ddd9db10907ee4cee6c44b24b96d81b062521752 (patch) | |
tree | dad93a6003344852c61d5916c8fbc11ab88ad9ed /src | |
parent | fd0778237785840ec754f98e847a524590cbf61c (diff) | |
download | uscxml-ddd9db10907ee4cee6c44b24b96d81b062521752.zip uscxml-ddd9db10907ee4cee6c44b24b96d81b062521752.tar.gz uscxml-ddd9db10907ee4cee6c44b24b96d81b062521752.tar.bz2 |
Added Data::BINARY and compile fixes for non MacOSX platforms
Diffstat (limited to 'src')
7 files changed, 63 insertions, 15 deletions
diff --git a/src/bindings/swig/php/uscxmlNativePHP.php b/src/bindings/swig/php/uscxmlNativePHP.php index 358975a..668e01b 100644 --- a/src/bindings/swig/php/uscxmlNativePHP.php +++ b/src/bindings/swig/php/uscxmlNativePHP.php @@ -2,7 +2,7 @@ /* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.9 + * Version 2.0.7 * * This file is not intended to be easily readable and contains a number of * coding conventions designed to improve portability and efficiency. Do not make @@ -254,6 +254,8 @@ class Data { const INTERPRETED = Data_INTERPRETED; + const BINARY = Data_BINARY; + function __construct($atom__or_dom=null,$type_=null) { if (is_resource($atom__or_dom) && get_resource_type($atom__or_dom) === '_p_uscxml__Data') { $this->_cPtr=$atom__or_dom; diff --git a/src/uscxml/Message.h b/src/uscxml/Message.h index afc536f..0b62a10 100644 --- a/src/uscxml/Message.h +++ b/src/uscxml/Message.h @@ -22,8 +22,9 @@ namespace uscxml { class Data { public: enum Type { - VERBATIM, - INTERPRETED + VERBATIM, + INTERPRETED, + BINARY, }; Data() : type(INTERPRETED) {} diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 173a0ed..f8e0479 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -292,14 +292,32 @@ JSValueRef JSCDataModel::getDataAsValue(const Data& data) { handleException(exception); return value; } - if (data.type == Data::VERBATIM) { - JSStringRef stringRef = JSStringCreateWithUTF8CString(data.atom.c_str()); - JSValueRef value = JSValueMakeString(_ctx, stringRef); - JSStringRelease(stringRef); - return value; - } else { - return evalAsValue(data.atom); + + switch (data.type) { + case Data::VERBATIM: { + JSStringRef stringRef = JSStringCreateWithUTF8CString(data.atom.c_str()); + JSValueRef value = JSValueMakeString(_ctx, stringRef); + JSStringRelease(stringRef); + return value; + break; + } + case Data::INTERPRETED: { + return evalAsValue(data.atom); + break; + } + case Data::BINARY: { + uscxml::ArrayBuffer* localInstance = new uscxml::ArrayBuffer((void*)data.atom.c_str(), data.atom.size()); + + JSClassRef retClass = JSCArrayBuffer::getTmpl(); + struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(_ctx, retClass, retPrivData); + return retObj; + break; + } } + } Data JSCDataModel::getValueAsData(const JSValueRef value) { diff --git a/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp b/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp index b5bb474..b3071ee 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp @@ -45,7 +45,7 @@ std::string Storage::key(unsigned long index) { return ""; std::map<std::string, std::string>::iterator dataIter = _data.begin(); - for (int i = 0; i < index; i++) { + for (unsigned int i = 0; i < index; i++) { dataIter++; } return dataIter->first; diff --git a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp index 98859da..16ee766 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp @@ -34,6 +34,10 @@ ArrayBuffer::ArrayBuffer(unsigned long length) { ArrayBuffer::ArrayBuffer(boost::shared_ptr<ArrayBuffer::Buffer> buffer) : _buffer(buffer) { } +ArrayBuffer::ArrayBuffer(void* data, unsigned int size) { + _buffer = boost::shared_ptr<Buffer>(new Buffer(data, size)); +} + unsigned long ArrayBuffer::getByteLength() { return _buffer->_size; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h index 82da629..229ae70 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h +++ b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h @@ -4,6 +4,9 @@ #include <string> #include <vector> #include <boost/shared_ptr.hpp> +#include <string.h> +#include <inttypes.h> + namespace uscxml { @@ -18,6 +21,7 @@ public: size_t _size; }; + ArrayBuffer(void* data, unsigned int size); ArrayBuffer(unsigned long length); ArrayBuffer(boost::shared_ptr<ArrayBuffer::Buffer>); unsigned long getByteLength(); @@ -48,6 +52,7 @@ public: class ArrayBufferView { public: + virtual ~ArrayBufferView() {} ArrayBuffer getBuffer(); virtual unsigned long getByteOffset() = 0; virtual unsigned long getByteLength() = 0; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index aef41ca..919f4a1 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -350,11 +350,29 @@ v8::Handle<v8::Value> V8DataModel::getDataAsValue(const Data& data) { } return value; } - if (data.type == Data::VERBATIM) { - return v8::String::New(data.atom.c_str()); - } else { - return evalAsValue(data.atom); + switch (data.type) { + case Data::VERBATIM: + return v8::String::New(data.atom.c_str()); + break; + case Data::INTERPRETED: + return evalAsValue(data.atom); + break; + case Data::BINARY: { + uscxml::ArrayBuffer* arrBuffer = new uscxml::ArrayBuffer((void*)data.atom.c_str(), data.atom.size()); + v8::Handle<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate(); + retPrivData->nativeObj = arrBuffer; + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor); + return retObj; + break; + } } + // this will never be reached + return v8::Undefined(); } v8::Handle<v8::Value> V8DataModel::jsPrint(const v8::Arguments& args) { |