diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-07-22 12:38:43 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-07-22 12:38:43 (GMT) |
commit | f2d8c967076e5d8ebd3ca718e14edef8acb5f87c (patch) | |
tree | 0bed80b7ff8081a6108e7c847a4489de272679c8 /src/uscxml/plugins/datamodel | |
parent | 7bd0256239f247ed01ee6c673e31283c794bb3d0 (diff) | |
download | uscxml-f2d8c967076e5d8ebd3ca718e14edef8acb5f87c.zip uscxml-f2d8c967076e5d8ebd3ca718e14edef8acb5f87c.tar.gz uscxml-f2d8c967076e5d8ebd3ca718e14edef8acb5f87c.tar.bz2 |
Removed iOS project again
Diffstat (limited to 'src/uscxml/plugins/datamodel')
3 files changed, 108 insertions, 15 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 8feb73a..47ec21d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -24,10 +24,37 @@ bool connect(pluma::Host& host) { JSCDataModel::JSCDataModel() { } +#if 0 +typedef struct { + int version; /* current (and only) version is 0 */ + JSClassAttributes attributes; + + const char* className; + JSClassRef parentClass; + + const JSStaticValue* staticValues; + const JSStaticFunction* staticFunctions; + + JSObjectInitializeCallback initialize; + JSObjectFinalizeCallback finalize; + JSObjectHasPropertyCallback hasProperty; + JSObjectGetPropertyCallback getProperty; + JSObjectSetPropertyCallback setProperty; + JSObjectDeletePropertyCallback deleteProperty; + JSObjectGetPropertyNamesCallback getPropertyNames; + JSObjectCallAsFunctionCallback callAsFunction; + JSObjectCallAsConstructorCallback callAsConstructor; + JSObjectHasInstanceCallback hasInstance; + JSObjectConvertToTypeCallback convertToType; +} JSClassDefinition; +#endif + // functions need to be objects to hold private data in JSC JSClassDefinition JSCDataModel::jsInClassDef = { 0, 0, "In", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, jsIn, 0, 0, 0 }; JSClassDefinition JSCDataModel::jsPrintClassDef = { 0, 0, "print", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, jsPrint, 0, 0, 0 }; +JSClassDefinition JSCDataModel::jsIOProcessorsClassDef = { 0, 0, "ioProcessors", 0, 0, 0, 0, 0, jsIOProcessorHasProp, jsIOProcessorGetProp, 0, 0, jsIOProcessorListProps, 0, 0, 0, 0 }; + boost::shared_ptr<DataModelImpl> JSCDataModel::create(InterpreterImpl* interpreter) { boost::shared_ptr<JSCDataModel> dm = boost::shared_ptr<JSCDataModel>(new JSCDataModel()); @@ -51,15 +78,33 @@ boost::shared_ptr<DataModelImpl> JSCDataModel::create(InterpreterImpl* interpret JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), printName, jsPrint, kJSPropertyAttributeNone, NULL); JSStringRelease(inName); - dm->eval("_ioprocessors = {};"); + JSClassRef jsIOProcClassRef = JSClassCreate(&jsIOProcessorsClassDef); + JSObjectRef jsIOProc = JSObjectMake(dm->_ctx, jsIOProcClassRef, dm.get()); + JSStringRef ioProcName = JSStringCreateWithUTF8CString("_ioprocessors"); + JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), ioProcName, jsIOProc, kJSPropertyAttributeNone, NULL); + JSStringRelease(ioProcName); + + JSStringRef nameName = JSStringCreateWithUTF8CString("_name"); + JSStringRef name = JSStringCreateWithUTF8CString(dm->_interpreter->getName().c_str()); + JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), nameName, JSValueMakeString(dm->_ctx, name), kJSPropertyAttributeNone, NULL); + JSStringRelease(nameName); + JSStringRelease(name); + + JSStringRef sessionIdName = JSStringCreateWithUTF8CString("_sessionid"); + JSStringRef sessionId = JSStringCreateWithUTF8CString(dm->_interpreter->getSessionId().c_str()); + JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), sessionIdName, JSValueMakeString(dm->_ctx, sessionId), kJSPropertyAttributeNone, NULL); + JSStringRelease(sessionIdName); + JSStringRelease(sessionId); Arabica::DOM::JSCDocument::JSCDocumentPrivate* privData = new Arabica::DOM::JSCDocument::JSCDocumentPrivate(); - privData->nativeObj = new Arabica::DOM::Document<std::string>(interpreter->getDocument()); - privData->dom = dm->_dom; + if (interpreter) { + privData->nativeObj = new Arabica::DOM::Document<std::string>(interpreter->getDocument()); + privData->dom = dm->_dom; - JSObjectRef documentObject = JSObjectMake(dm->_ctx, Arabica::DOM::JSCDocument::getTmpl(), privData); - JSObjectRef globalObject = JSContextGetGlobalObject(dm->_ctx); - JSObjectSetProperty(dm->_ctx, globalObject, JSStringCreateWithUTF8CString("document"), documentObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL); + JSObjectRef documentObject = JSObjectMake(dm->_ctx, Arabica::DOM::JSCDocument::getTmpl(), privData); + JSObjectRef globalObject = JSContextGetGlobalObject(dm->_ctx); + JSObjectSetProperty(dm->_ctx, globalObject, JSStringCreateWithUTF8CString("document"), documentObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL); + } dm->eval("_invokers = {};"); dm->eval("_x = {};"); @@ -202,10 +247,9 @@ Data JSCDataModel::getValueAsData(const JSValueRef value) { JSValueRef exception = NULL; switch(JSValueGetType(_ctx, value)) { case kJSTypeUndefined: - LOG(ERROR) << "IsUndefined is unimplemented"; - break; case kJSTypeNull: - LOG(ERROR) << "IsNull is unimplemented"; + data.atom = "null"; + data.type = Data::INTERPRETED; break; case kJSTypeBoolean: data.atom = (JSValueToBoolean(_ctx, value) ? "true" : "false"); @@ -225,6 +269,7 @@ Data JSCDataModel::getValueAsData(const JSValueRef value) { JSStringGetUTF8CString(stringValue, buf, maxSize); data.atom = std::string(buf); + data.type = Data::VERBATIM; JSStringRelease(stringValue); free(buf); break; @@ -488,4 +533,43 @@ JSValueRef JSCDataModel::jsIn(JSContextRef ctx, JSObjectRef function, JSObjectRe } +bool JSCDataModel::jsIOProcessorHasProp(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSCDataModel* INSTANCE = (JSCDataModel*)JSObjectGetPrivate(object); + std::map<std::string, IOProcessor> ioProcessors = INSTANCE->_interpreter->getIOProcessors(); + + size_t maxSize = JSStringGetMaximumUTF8CStringSize(propertyName); + char buffer[maxSize]; + JSStringGetUTF8CString(propertyName, buffer, maxSize); + std::string prop(buffer); + + return ioProcessors.find(prop) != ioProcessors.end(); +} + +JSValueRef JSCDataModel::jsIOProcessorGetProp(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSCDataModel* INSTANCE = (JSCDataModel*)JSObjectGetPrivate(object); + std::map<std::string, IOProcessor> ioProcessors = INSTANCE->_interpreter->getIOProcessors(); + + size_t maxSize = JSStringGetMaximumUTF8CStringSize(propertyName); + char buffer[maxSize]; + JSStringGetUTF8CString(propertyName, buffer, maxSize); + std::string prop(buffer); + + if (ioProcessors.find(prop) != ioProcessors.end()) { + return INSTANCE->getDataAsValue(ioProcessors.find(prop)->second.getDataModelVariables()); + } + return JSValueMakeUndefined(ctx); +} + +void JSCDataModel::jsIOProcessorListProps(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames) { + JSCDataModel* INSTANCE = (JSCDataModel*)JSObjectGetPrivate(object); + std::map<std::string, IOProcessor> ioProcessors = INSTANCE->_interpreter->getIOProcessors(); + + std::map<std::string, IOProcessor>::const_iterator ioProcIter = ioProcessors.begin(); + while(ioProcIter != ioProcessors.end()) { + JSStringRef ioProcName = JSStringCreateWithUTF8CString(ioProcIter->first.c_str()); + JSPropertyNameAccumulatorAddName(propertyNames, ioProcName); + ioProcIter++; + } +} + }
\ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index 28a313e..36765c2 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -66,6 +66,11 @@ protected: static JSClassDefinition jsPrintClassDef; static JSValueRef jsPrint(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); + static JSClassDefinition jsIOProcessorsClassDef; + static bool jsIOProcessorHasProp(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); + static JSValueRef jsIOProcessorGetProp(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); + static void jsIOProcessorListProps(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames); + JSValueRef getDocumentAsValue(const Arabica::DOM::Document<std::string>& doc); JSValueRef getDataAsValue(const Data& data); Data getValueAsData(const JSValueRef value); diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index c92274c..2e37b29 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -264,13 +264,17 @@ void SWIDataModel::eval(const std::string& expr) { } bool SWIDataModel::evalAsBool(const std::string& expr) { - PlCompound compound(expr.c_str()); - PlTermv termv(compound.arity()); - for (int i = 0; i < compound.arity(); i++) { - termv[i] = compound[i + 1]; + try { + PlCompound compound(expr.c_str()); + PlTermv termv(compound.arity()); + for (int i = 0; i < compound.arity(); i++) { + termv[i] = compound[i + 1]; + } + PlQuery query(compound.name(), termv); + return query.next_solution() > 0; + } catch(...) { + return false; } - PlQuery query(compound.name(), termv); - return query.next_solution() > 0; } std::string SWIDataModel::evalAsString(const std::string& expr) { |