From bd45c688b3d3aad5d62b85457ce943eaadf989ae Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Wed, 21 Aug 2013 17:16:52 +0200 Subject: Added WebStorage object to document Some refinements to DotWriter --- CMakeLists.txt | 32 +- apps/uscxml-browser.cpp | 54 +-- contrib/dom/idl/Document.idl | 2 + contrib/dom/idl/Storage.idl | 8 + contrib/dom/scripts/CodeGeneratorArabicaJSC.pm | 3 +- contrib/dom/scripts/CodeGeneratorArabicaV8.pm | 3 +- contrib/java/.classpath | 2 + contrib/java/.project | 5 + src/bindings/swig/php/uscxmlNativePHP.php | 2 +- src/uscxml/CMakeLists.txt | 8 + src/uscxml/Interpreter.cpp | 4 +- src/uscxml/Interpreter.h | 2 + src/uscxml/URL.cpp | 43 ++ src/uscxml/URL.h | 2 + src/uscxml/URL.mm | 28 ++ src/uscxml/debug/SCXMLDotWriter.cpp | 464 +++++++++++++++++++++ src/uscxml/debug/SCXMLDotWriter.cpp.old | 359 ---------------- src/uscxml/debug/SCXMLDotWriter.h | 57 ++- src/uscxml/interpreter/InterpreterDraft6.cpp | 29 +- src/uscxml/plugins/datamodel/CMakeLists.txt | 4 + .../datamodel/ecmascript/JavaScriptCore/JSCDOM.cpp | 19 + .../datamodel/ecmascript/JavaScriptCore/JSCDOM.h | 39 ++ .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 4 +- .../ecmascript/JavaScriptCore/JSCDataModel.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCAttr.h | 2 +- .../JavaScriptCore/dom/JSCCDATASection.h | 2 +- .../JavaScriptCore/dom/JSCCharacterData.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCComment.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCDOM.cpp | 16 - .../ecmascript/JavaScriptCore/dom/JSCDOM.h | 38 -- .../JavaScriptCore/dom/JSCDOMImplementation.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCDocument.cpp | 1 + .../ecmascript/JavaScriptCore/dom/JSCDocument.h | 3 +- .../JavaScriptCore/dom/JSCDocumentCustom.cpp | 18 + .../JavaScriptCore/dom/JSCDocumentFragment.h | 2 +- .../JavaScriptCore/dom/JSCDocumentType.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCElement.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCEntity.h | 2 +- .../JavaScriptCore/dom/JSCEntityReference.h | 2 +- .../JavaScriptCore/dom/JSCNamedNodeMap.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCNode.cpp.old | 60 --- .../ecmascript/JavaScriptCore/dom/JSCNode.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCNode.h.old | 223 ---------- .../JavaScriptCore/dom/JSCNodeCustom.cpp | 23 +- .../ecmascript/JavaScriptCore/dom/JSCNodeList.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCNodeSet.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCNotation.h | 2 +- .../JavaScriptCore/dom/JSCProcessingInstruction.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCStorage.cpp | 155 +++++++ .../ecmascript/JavaScriptCore/dom/JSCStorage.h | 73 ++++ .../ecmascript/JavaScriptCore/dom/JSCText.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCXPathResult.h | 2 +- .../plugins/datamodel/ecmascript/Storage.cpp | 74 ++++ src/uscxml/plugins/datamodel/ecmascript/Storage.h | 30 ++ .../plugins/datamodel/ecmascript/v8/V8DOM.cpp | 17 + src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h | 83 ++++ .../datamodel/ecmascript/v8/V8DataModel.cpp | 20 +- .../plugins/datamodel/ecmascript/v8/V8DataModel.h | 2 +- .../plugins/datamodel/ecmascript/v8/dom/V8Attr.h | 2 +- .../datamodel/ecmascript/v8/dom/V8CDATASection.h | 2 +- .../datamodel/ecmascript/v8/dom/V8CharacterData.h | 2 +- .../datamodel/ecmascript/v8/dom/V8Comment.h | 2 +- .../plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp | 11 - .../plugins/datamodel/ecmascript/v8/dom/V8DOM.h | 81 ---- .../ecmascript/v8/dom/V8DOMImplementation.h | 2 +- .../datamodel/ecmascript/v8/dom/V8Document.h | 5 +- .../ecmascript/v8/dom/V8DocumentCustom.cpp | 19 + .../ecmascript/v8/dom/V8DocumentFragment.h | 2 +- .../datamodel/ecmascript/v8/dom/V8DocumentType.h | 2 +- .../datamodel/ecmascript/v8/dom/V8Element.h | 2 +- .../plugins/datamodel/ecmascript/v8/dom/V8Entity.h | 2 +- .../ecmascript/v8/dom/V8EntityReference.h | 2 +- .../datamodel/ecmascript/v8/dom/V8NamedNodeMap.h | 2 +- .../plugins/datamodel/ecmascript/v8/dom/V8Node.h | 2 +- .../datamodel/ecmascript/v8/dom/V8NodeList.h | 2 +- .../datamodel/ecmascript/v8/dom/V8NodeSet.h | 2 +- .../datamodel/ecmascript/v8/dom/V8Notation.h | 2 +- .../ecmascript/v8/dom/V8ProcessingInstruction.h | 2 +- .../datamodel/ecmascript/v8/dom/V8SCXMLEvent.h | 2 +- .../datamodel/ecmascript/v8/dom/V8Storage.cpp | 83 ++++ .../datamodel/ecmascript/v8/dom/V8Storage.h | 90 ++++ .../plugins/datamodel/ecmascript/v8/dom/V8Text.h | 2 +- .../datamodel/ecmascript/v8/dom/V8XPathResult.h | 2 +- .../plugins/datamodel/prolog/swi/SWIDataModel.cpp | 3 +- src/uscxml/plugins/invoker/audio/AudioToolbox.mm | 18 +- src/uscxml/plugins/invoker/audio/OpenALInvoker.cpp | 13 + src/uscxml/plugins/invoker/audio/OpenALInvoker.h | 1 + src/uscxml/plugins/invoker/audio/OpenALPlayer.h | 2 +- src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp | 3 + .../uscxml/applications/SpatialMapTicker.java | 12 +- .../uscxml/applications/spoken-map-ticker.scxml | 7 +- .../uscxml/applications/spoken-map-ticker.xhtml | 2 +- test/samples/uscxml/test-ecmascript.scxml | 6 +- test/samples/uscxml/test-scenegraph.scxml | 6 +- test/src/test-arabica-xpath.cpp | 2 +- 96 files changed, 1528 insertions(+), 923 deletions(-) create mode 100644 contrib/dom/idl/Storage.idl create mode 100644 src/uscxml/URL.mm create mode 100644 src/uscxml/debug/SCXMLDotWriter.cpp delete mode 100644 src/uscxml/debug/SCXMLDotWriter.cpp.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h delete mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp delete mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h delete mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp.old delete mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/Storage.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/Storage.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h delete mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp delete mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c256caa..11feca6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -461,25 +461,27 @@ list (APPEND USCXML_CORE_LIBS ${EVENT_LIBRARY}) ################################################# # Optional libraries -if (OFF AND (APPLE OR IOS)) +if (APPLE OR IOS) find_library(AUDIOTOOLBOX AudioToolbox REQUIRED) - list (APPEND USCXML_OPT_LIBS ${AUDIOTOOLBOX}) - + list (APPEND USCXML_OPT_LIBS ${AUDIOTOOLBOX}/AudioToolbox) + set(AUDIOTOOLBOX_FOUND ON) + find_library(FOUNDATION_LIBRARY Foundation) list (APPEND USCXML_OPT_LIBS ${FOUNDATION_LIBRARY}/Foundation) - - find_library(JSC_LIBRARY JavaScriptCore) + if (IOS) find_library(WTF_LIBRARY WTF) find_library(ICU_LIBRARY icucore REQUIRED) - list (APPEND USCXML_OPT_LIBS ${JSC_LIBRARY}) list (APPEND USCXML_OPT_LIBS ${WTF_LIBRARY}) list (APPEND USCXML_OPT_LIBS ${ICU_LIBRARY}) - else() - list (APPEND USCXML_OPT_LIBS ${JSC_LIBRARY}) endif() + +endif() + +if (APPLE OR IOS) + find_library(JSC_LIBRARY JavaScriptCore) + list (APPEND USCXML_OPT_LIBS ${JSC_LIBRARY}) set(JSC_FOUND ON) - set(AUDIOTOOLBOX_FOUND ON) else() find_package(V8) if (V8_FOUND) @@ -559,7 +561,11 @@ set(CMAKE_FIND_FRAMEWORK "FIRST") find_package(OpenAL) if (OPENAL_FOUND) list (APPEND USCXML_INCLUDE_DIRS ${OPENAL_INCLUDE_DIR}) - list (APPEND USCXML_OPT_LIBS ${OPENAL_LIBRARY}) + if (APPLE OR IOS) + list (APPEND USCXML_OPT_LIBS ${OPENAL_LIBRARY}/OpenAL) + else() + list (APPEND USCXML_OPT_LIBS ${OPENAL_LIBRARY}) + endif() else() find_package(OpenALKCAT) if (OPENAL_FOUND) @@ -626,7 +632,11 @@ foreach( FILE ${USCXML_FILES} ) if (${PATH} MATCHES ".*datamodel\\/ecmascript.*") STRING(REGEX MATCH "[^\\/]*$" COMP_NAME ${PATH}) - source_group("Datamodel\\EcmaScript\\${COMP_NAME}" FILES ${FILE}) + if (COMP_NAME STREQUAL "ecmascript") + source_group("Datamodel\\EcmaScript" FILES ${FILE}) + else() + source_group("Datamodel\\EcmaScript\\${COMP_NAME}" FILES ${FILE}) + endif() elseif (${PATH} MATCHES ".*datamodel\\/prolog.*") STRING(REGEX MATCH "[^\\/]*$" COMP_NAME ${PATH}) source_group("Datamodel\\Prolog\\${COMP_NAME}" FILES ${FILE}) diff --git a/apps/uscxml-browser.cpp b/apps/uscxml-browser.cpp index 70fb540..34cf47a 100644 --- a/apps/uscxml-browser.cpp +++ b/apps/uscxml-browser.cpp @@ -1,5 +1,6 @@ #include "uscxml/config.h" #include "uscxml/Interpreter.h" +#include "uscxml/debug/SCXMLDotWriter.h" #include #ifdef HAS_SIGNAL_H @@ -76,20 +77,18 @@ void __cxa_throw (void *thrown_exception, void *pvtinfo, void (*dest)(void *)) { // see http://stackoverflow.com/questions/2443135/how-do-i-find-where-an-exception-was-thrown-in-c void customTerminate() { static bool tried_throw = false; + try { // try once to re-throw currently active exception if (!tried_throw) { - throw; tried_throw = true; + throw; } else { tried_throw = false; - }; + } } catch (const std::exception &e) { std::cerr << __FUNCTION__ << " caught unhandled exception. what(): " << e.what() << std::endl; - } catch (const std::runtime_error &e) { - std::cerr << __FUNCTION__ << " caught unhandled exception. what(): " - << e.what() << std::endl; } catch (const uscxml::Event &e) { std::cerr << __FUNCTION__ << " caught unhandled exception. Event: " << e << std::endl; @@ -112,13 +111,14 @@ void printUsageAndExit() { printf("Usage\n"); printf("\tuscxml-browser"); #ifdef BUILD_AS_PLUGINS - printf(" [-d pluginPath]"); + printf(" [-e pluginPath]"); #endif - printf(" URL\n"); + printf("[-v] [-pN] URL\n"); printf("\n"); printf("Options\n"); printf("\t-v : be verbose\n"); printf("\t-pN : port for HTTP server\n"); + printf("\t-d : write each configuration as a dot file\n"); printf("\n"); exit(1); } @@ -137,6 +137,7 @@ int main(int argc, char** argv) { } bool verbose = false; + bool useDot = false; size_t port = 8080; google::InitGoogleLogging(argv[0]); google::LogToStderr(); @@ -145,14 +146,17 @@ int main(int argc, char** argv) { opterr = 0; #endif int option; - while ((option = getopt(argc, argv, "vl:d:p:")) != -1) { + while ((option = getopt(argc, argv, "dvl:e:p:")) != -1) { switch(option) { case 'l': google::InitGoogleLogging(optarg); break; - case 'd': + case 'e': uscxml::Factory::pluginPath = optarg; break; + case 'd': + useDot = true; + break; case 'p': port = strTo(optarg); break; @@ -174,22 +178,24 @@ int main(int argc, char** argv) { // intialize http server on given port HTTPServer::getInstance(port); - while(true) { - LOG(INFO) << "Processing " << argv[optind]; - Interpreter interpreter = Interpreter::fromURI(argv[optind]); - if (interpreter) { - interpreter.setCmdLineOptions(argc, argv); - // interpreter->setCapabilities(Interpreter::CAN_NOTHING); - // interpreter->setCapabilities(Interpreter::CAN_BASIC_HTTP | Interpreter::CAN_GENERIC_HTTP); - - if (verbose) { - VerboseMonitor* vm = new VerboseMonitor(); - interpreter.addMonitor(vm); - } - - interpreter.start(); - while(interpreter.runOnMainThread(25)); + LOG(INFO) << "Processing " << argv[optind]; + Interpreter interpreter = Interpreter::fromURI(argv[optind]); + if (interpreter) { + interpreter.setCmdLineOptions(argc, argv); + // interpreter->setCapabilities(Interpreter::CAN_NOTHING); + // interpreter->setCapabilities(Interpreter::CAN_BASIC_HTTP | Interpreter::CAN_GENERIC_HTTP); + + if (verbose) { + VerboseMonitor* vm = new VerboseMonitor(); + interpreter.addMonitor(vm); + } + if (useDot) { + SCXMLDotWriter* dotWriter = new SCXMLDotWriter(); + interpreter.addMonitor(dotWriter); } + + interpreter.start(); + while(interpreter.runOnMainThread(25)); } return EXIT_SUCCESS; } \ No newline at end of file diff --git a/contrib/dom/idl/Document.idl b/contrib/dom/idl/Document.idl index 7399921..56035b0 100644 --- a/contrib/dom/idl/Document.idl +++ b/contrib/dom/idl/Document.idl @@ -46,4 +46,6 @@ interface Document : Node { // in unsigned short type, // in XPathResult inResult) raises(DOMException); + [CustomGetter] readonly attribute Storage localStorage; + }; diff --git a/contrib/dom/idl/Storage.idl b/contrib/dom/idl/Storage.idl new file mode 100644 index 0000000..e709184 --- /dev/null +++ b/contrib/dom/idl/Storage.idl @@ -0,0 +1,8 @@ +[DontDestroyWrapped] interface Storage { + readonly attribute unsigned long length; + DOMString key(unsigned long index); + getter DOMString getItem(DOMString key); + setter creator void setItem(DOMString key, DOMString value); + deleter void removeItem(DOMString key); + void clear(); +}; diff --git a/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm b/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm index 87ca6a9..1546ea6 100644 --- a/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm +++ b/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm @@ -137,7 +137,7 @@ sub GenerateHeader # - Add default header template push(@headerContent, GenerateHeaderContentHeader($interface)); - $headerIncludes{"uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h"} = 1; + $headerIncludes{"uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h"} = 1; $headerIncludes{"DOM/Node.hpp"} = 1; $headerIncludes{"JavaScriptCore/JavaScriptCore.h"} = 1; @@ -668,6 +668,7 @@ sub IdlToWrapperType return "Arabica::DOM::Node" if ($idlType eq "Node"); return "Arabica::DOM::Element" if ($idlType eq "Element"); return "uscxml::Event" if ($idlType eq "SCXMLEvent"); + return "uscxml::Storage" if ($idlType eq "Storage"); return "Arabica::DOM::${idlType}"; } diff --git a/contrib/dom/scripts/CodeGeneratorArabicaV8.pm b/contrib/dom/scripts/CodeGeneratorArabicaV8.pm index 17c83f5..7befef9 100644 --- a/contrib/dom/scripts/CodeGeneratorArabicaV8.pm +++ b/contrib/dom/scripts/CodeGeneratorArabicaV8.pm @@ -138,7 +138,7 @@ sub GenerateHeader push(@headerContent, GenerateHeaderContentHeader($interface)); $headerIncludes{"string"} = 1; - $headerIncludes{"uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h"} = 1; + $headerIncludes{"uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h"} = 1; $headerIncludes{"DOM/Node.hpp"} = 1; $headerIncludes{"v8.h"} = 1; @@ -634,6 +634,7 @@ sub IdlToWrapperType return "Arabica::DOM::Node" if ($idlType eq "Node"); return "Arabica::DOM::Element" if ($idlType eq "Element"); return "uscxml::Event" if ($idlType eq "SCXMLEvent"); + return "uscxml::Storage" if ($idlType eq "Storage"); return "Arabica::DOM::${idlType}"; } diff --git a/contrib/java/.classpath b/contrib/java/.classpath index 96001cb..6034288 100644 --- a/contrib/java/.classpath +++ b/contrib/java/.classpath @@ -3,6 +3,8 @@ + + diff --git a/contrib/java/.project b/contrib/java/.project index fda3442..260e80f 100644 --- a/contrib/java/.project +++ b/contrib/java/.project @@ -16,6 +16,11 @@ + applications + 2 + /Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/applications + + bindings 2 /Users/sradomski/Documents/TK/Code/uscxml/src/bindings/swig/java diff --git a/src/bindings/swig/php/uscxmlNativePHP.php b/src/bindings/swig/php/uscxmlNativePHP.php index ce52045..6e4823a 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 diff --git a/src/uscxml/CMakeLists.txt b/src/uscxml/CMakeLists.txt index d96895e..391b498 100644 --- a/src/uscxml/CMakeLists.txt +++ b/src/uscxml/CMakeLists.txt @@ -30,6 +30,14 @@ file(GLOB_RECURSE USCXML_INTERPRETERS source_group("Interpreter" FILES ${USCXML_INTERPRETERS}) list (APPEND USCXML_FILES ${USCXML_INTERPRETERS}) +if(APPLE OR IOS) + file(GLOB_RECURSE USCXML_APPLE + *.mm + ) + source_group("Interpreter" FILES ${USCXML_APPLE}) + list (APPEND USCXML_FILES ${USCXML_APPLE}) +endif() + file(GLOB USCXML_CORE ${CMAKE_SOURCE_DIR}/contrib/src/jsmn/jsmn.c *.cpp diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index a58de6b..6b17d94 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -108,11 +108,13 @@ Interpreter Interpreter::fromURI(const std::string& uri) { Arabica::SAX::InputSource inputSource; inputSource.setSystemId(absUrl.asString()); interpreter = fromInputSource(inputSource); +#if 0 } else if (boost::iequals(absUrl.scheme(), "http")) { - // handle http per arabica + // handle http per arabica - this will not follow redirects Arabica::SAX::InputSource inputSource; inputSource.setSystemId(absUrl.asString()); interpreter = fromInputSource(inputSource); +#endif } else { // use curl for everything else std::stringstream ss; diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index f7ce708..f8cf823 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -65,6 +65,8 @@ enum Capabilities { class InterpreterImpl : public boost::enable_shared_from_this { public: + typedef std::set::iterator monIter_t; + enum Binding { EARLY = 0, LATE = 1 diff --git a/src/uscxml/URL.cpp b/src/uscxml/URL.cpp index a58818a..4d60999 100644 --- a/src/uscxml/URL.cpp +++ b/src/uscxml/URL.cpp @@ -14,6 +14,8 @@ #define getcwd _getcwd #else #include +#include +#include #endif #include // mkstemp @@ -49,6 +51,42 @@ std::string URL::tmpDir() { return tmpl; } +#if (!defined APPLE && !defined IOS) +std::string URL::getResourceDir() { +#ifdef _WIN32 + TCHAR szPath[MAX_PATH]; + if (SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, szPath)) { + return szPath; + } else { + return getenv("APPDATA"); + } +#else + struct passwd* pw = getpwuid(getuid()); + std::string homedir(pw->pw_dir); + struct stat dirStat; + int err = 0; + + err = stat(std::string(homedir + PATH_SEPERATOR + ".config").c_str(), &dirStat); + if (err == ENOENT) { + err = mkdir(std::string(homedir + PATH_SEPERATOR + ".config").c_str(), S_IWUSR | S_IRUSR | S_IROTH); + } + + err = stat(std::string(homedir + PATH_SEPERATOR + ".config" + PATH_SEPERATOR + "uscxml").c_str(), &dirStat); + if (err != 0) { + std::cout << std::string(homedir + PATH_SEPERATOR + ".config" + PATH_SEPERATOR + "uscxml") << std::endl; + err = mkdir(std::string(homedir + PATH_SEPERATOR + ".config" + PATH_SEPERATOR + "uscxml").c_str(), + S_IWUSR | S_IRUSR | S_IROTH | S_IRGRP | S_IXUSR | S_IXOTH | S_IXGRP); + } + + err = stat(std::string(homedir + PATH_SEPERATOR + ".config" + PATH_SEPERATOR + "uscxml").c_str(), &dirStat); + if (err == 0) { + return homedir + PATH_SEPERATOR + ".config" + PATH_SEPERATOR + "uscxml"; + } + return ""; +#endif +} +#endif + URLImpl::URLImpl(const std::string& url) : _handle(NULL), _uri(url), _isDownloaded(false), _hasFailed(false) { std::stringstream ss(_uri.path()); std::string item; @@ -461,6 +499,11 @@ void URLFetcher::fetchURL(URL& url) { (curlError = curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, false)) == CURLE_OK || LOG(ERROR) << "Cannot forfeit peer verification: " << curl_easy_strerror(curlError); + (curlError = curl_easy_setopt(handle, CURLOPT_USERAGENT, "curl/7.31.0")) == CURLE_OK || + LOG(ERROR) << "Cannot set our user agent string: " << curl_easy_strerror(curlError); + + (curlError = curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, true)) == CURLE_OK || + LOG(ERROR) << "Cannot enable follow redirects: " << curl_easy_strerror(curlError); if (boost::iequals(url._impl->_requestType, "post")) { diff --git a/src/uscxml/URL.h b/src/uscxml/URL.h index b6d8a86..3acd462 100644 --- a/src/uscxml/URL.h +++ b/src/uscxml/URL.h @@ -204,6 +204,8 @@ public: static URL asBaseURL(const URL& url); static void toBaseURL(URL& uri); + static std::string getResourceDir(); + static URL toLocalFile(const std::string& content, const std::string& suffix) { boost::shared_ptr impl = URLImpl::toLocalFile(content, suffix); return URL(impl); diff --git a/src/uscxml/URL.mm b/src/uscxml/URL.mm new file mode 100644 index 0000000..46975a0 --- /dev/null +++ b/src/uscxml/URL.mm @@ -0,0 +1,28 @@ +#include "URL.h" +#include "Foundation/Foundation.h" + +#ifdef __has_feature +# if __has_feature(objc_arc) +# define(HAS_AUTORELEASE_POOL) +# endif +#endif + +namespace uscxml { + +std::string URL::getResourceDir() { +#if HAS_AUTORELEASE_POOL + @autoreleasepool { +#else + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif + NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; + return [resourcePath cStringUsingEncoding:NSUTF8StringEncoding]; + +#if HAS_AUTORELEASE_POOL + } +#else + [pool drain]; +#endif +} + +} diff --git a/src/uscxml/debug/SCXMLDotWriter.cpp b/src/uscxml/debug/SCXMLDotWriter.cpp new file mode 100644 index 0000000..d6a9a49 --- /dev/null +++ b/src/uscxml/debug/SCXMLDotWriter.cpp @@ -0,0 +1,464 @@ +#include "uscxml/Common.h" +#include "SCXMLDotWriter.h" +#include // replace_all +#include + +namespace uscxml { + +using namespace Arabica::DOM; + +SCXMLDotWriter::SCXMLDotWriter() { + _iteration = 0; + _indentation = 0; +} + +SCXMLDotWriter::SCXMLDotWriter(Interpreter interpreter, const Arabica::XPath::NodeSet& transitions) { + _interpreter = interpreter; + _transitions = transitions; + _iteration = 0; + _indentation = 0; +} + +SCXMLDotWriter::~SCXMLDotWriter() { + +} + +void SCXMLDotWriter::onStableConfiguration(Interpreter interpreter) { + std::ostringstream fileSS; + fileSS << interpreter.getName() << "." << std::setw(6) << std::setfill('0') << _iteration++ << ".dot"; + toDot(fileSS.str(), interpreter); +} + +void SCXMLDotWriter::afterCompletion(Interpreter interpreter) { + std::ostringstream fileSS; + fileSS << interpreter.getName() << "." << std::setw(6) << std::setfill('0') << _iteration++ << ".dot"; + toDot(fileSS.str(), interpreter); +} + +void SCXMLDotWriter::beforeMicroStep(Interpreter interpreter) { +// std::ostringstream fileSS; +// fileSS << interpreter.getName() << "." << std::setw(6) << std::setfill('0') << _iteration++ << ".dot"; +// toDot(fileSS.str(), interpreter); +} + +void SCXMLDotWriter::beforeTakingTransitions(Interpreter interpreter, const Arabica::XPath::NodeSet& transitions) { + std::ostringstream fileSS; + fileSS << interpreter.getName() << "." << std::setw(6) << std::setfill('0') << _iteration++ << ".dot"; + toDot(fileSS.str(), interpreter, transitions); +} + +std::string SCXMLDotWriter::getPrefix() { + std::string prefix = ""; + for (int i = 0; i < _indentation; i++) + prefix += " "; + return prefix; +} + +void SCXMLDotWriter::toDot(const std::string& filename, Interpreter interpreter, const Arabica::XPath::NodeSet& transitions) { + std::ofstream outfile(filename.c_str()); + NodeList scxmlElems = interpreter.getDocument().getElementsByTagName("scxml"); + SCXMLDotWriter writer(interpreter, transitions); + if (scxmlElems.getLength() > 0) { + writer._indentation++; + outfile << "digraph {" << std::endl; + outfile << "rankdir=TB; fontsize=10;" << std::endl; + writer.writeSCXMLElement(outfile, (Arabica::DOM::Element)scxmlElems.item(0)); + writer._indentation--; + outfile << "}" << std::endl; + } + +} + +void SCXMLDotWriter::writeSCXMLElement(std::ostream& os, const Arabica::DOM::Element& elem) { + writeStateElement(os, elem); + +// std::string elemId = idForNode(elem); +// os << getPrefix() << "subgraph \"cluster" << elemId.substr(1, elemId.length() - 1) << " {" << std::endl; +// _indentation++; +// os << getPrefix() << "label=\"" << nameForNode(elem) << "\"" << std::endl; +// writeStateElement(os, (Arabica::DOM::Element)_interpreter->getInitialState()); +// os << getPrefix() << "} " << std::endl; + +} + +void SCXMLDotWriter::writeStateElement(std::ostream& os, const Arabica::DOM::Element& elem) { + + std::string elemId = idForNode(elem); + NodeList childElems = elem.getChildNodes(); + + if (_knownIds.find(elemId) != _knownIds.end()) + return; + _knownIds.insert(elemId); + + bool subgraph = Interpreter::isCompound(elem) || Interpreter::isParallel(elem); + if (subgraph) { + _indentation++; + os << getPrefix() << "subgraph \"cluster_" << elemId << "\" {" << std::endl; + os << getPrefix() << "label=\"" << nameForNode(elem) << "\\l\"" << std::endl; + } + + os << getPrefix() << "\"" << elemId << "\"["; + os << "fontsize=10,"; + os << "label=<State
" << nameForNode(elem) << ">,"; + + // is the state initial? + if (_interpreter.isInitial(elem)) + os << "style=filled, fillcolor=lightgrey, "; + + // is this state final? + if (_interpreter.isFinal(elem)) + os << "shape=doublecircle,"; + + // is the current state in the basic configuration? + if (_interpreter.isMember(elem, _interpreter.getBasicConfiguration())) + os << "color=red, penwidth=3,"; + + // is the current state a target state? +#if 0 + for (int i = 0; i < _transitions.size(); i++) { + if (_interpreter.isMember(elem, _interpreter.getTargetStates(_transitions[i]))) { + os << "color=red, penwidth=3,"; + break; + } + } +#endif + + os << "];" << std::endl; + + std::string details = getDetailedLabel(elem); +// std::cout << details << std::endl; + + if (details.size() > 0) { + os << getPrefix() << "\"" << elemId << "Exec\"["; + os << "fontsize=8,"; + os << "shape=box,"; + os << "color=grey,"; + os << "label=<" << details << ">"; + os << "]" << std::endl; + os << getPrefix() << "\"" << elemId << "\" -> \"" << elemId << "Exec\" [arrowhead=none, color=grey]" << std::endl; + } + +// NodeList childElems = elem.getChildNodes(); +// for (int i = 0; i < childElems.getLength(); i++) { +// if (Interpreter::isState(childElems.item(i))) { +// writeStateElement(os, (Arabica::DOM::Element)childElems.item(i)); +// } +// } + + for (int i = 0; i < childElems.getLength(); i++) { + if (childElems.item(i).getNodeType() == Node_base::ELEMENT_NODE && boost::iequals(TAGNAME(childElems.item(i)), "transition")) { + writeTransitionElement(os, (Arabica::DOM::Element)childElems.item(i)); + bool active = Interpreter::isMember(childElems.item(i), _transitions); + os << getPrefix() << "\"" << elemId << "\" -> \"" << idForNode(childElems.item(i)) << "\" [arrowhead=none" << std::endl; + if (active) { + os << ", penwidth=3, color=red]" << std::endl; + } else { + os << "]" << std::endl; + } + } + if (Interpreter::isState(childElems.item(i))) { + writeStateElement(os, (Arabica::DOM::Element)childElems.item(i)); + } + if (childElems.item(i).getNodeType() == Node_base::ELEMENT_NODE && boost::iequals(TAGNAME(childElems.item(i)), "initial")) { + NodeList grandChildElems = childElems.item(i).getChildNodes(); + for (int j = 0; j < grandChildElems.getLength(); j++) { + if (grandChildElems.item(j).getNodeType() == Node_base::ELEMENT_NODE && boost::iequals(TAGNAME(grandChildElems.item(j)), "transition")) { + writeTransitionElement(os, (Arabica::DOM::Element)grandChildElems.item(j)); + os << getPrefix() << "\"" << elemId << "\" -> \"" << idForNode(grandChildElems.item(j)) << "\"" << std::endl; + } + } + } + } + + if (subgraph) { + _indentation--; + os << getPrefix() << "} " << std::endl; + } + +} + +void SCXMLDotWriter::writeTransitionElement(std::ostream& os, const Arabica::DOM::Element& elem) { + std::string elemId = idForNode(elem); + + Arabica::XPath::NodeSet targetStates = _interpreter.getTargetStates(elem); + + bool active = Interpreter::isMember(elem, _transitions); + + std::string label; + os << getPrefix() << "\"" << elemId << "\"["; + if (active) { + os << "color=red, penwidth=3, "; + } + os << "fontsize=10,"; + os << "shape=box,"; + os << "label=<Transition
"; + if (HAS_ATTR(elem, "event")) + os << "event: " << ATTR(elem, "event"); + if (HAS_ATTR(elem, "cond")) + os << "cond: " << dotEscape(ATTR(elem, "cond")); + if (!HAS_ATTR(elem, "cond") && !HAS_ATTR(elem, "event")) + os << "unconditional"; + os << ">"; + os << "]" << std::endl; + + for (int i = 0; i < targetStates.size(); i++) { + os << getPrefix() << "\"" << elemId << "\" -> \"" << idForNode(targetStates[i]) << "\""; + if (active) { + os << " [penwidth=3, color=red]" << std::endl; + } else { + os << std::endl; + } + writeStateElement(os, (Arabica::DOM::Element)targetStates[i]); + } + +} + +std::string SCXMLDotWriter::getDetailedLabel(const Arabica::DOM::Element& elem, int indentation) { + + /* + + + + + + + + +
onEntry
Details + Nested Content +
+ */ + + std::list content; + + NodeList childElems = elem.getChildNodes(); + for (int i = 0; i < childElems.getLength(); i++) { + if (childElems.item(i).getNodeType() != Node_base::ELEMENT_NODE) + continue; + + if (Interpreter::isState(childElems.item(i)) || + boost::iequals(TAGNAME(childElems.item(i)), "transition") || + boost::iequals(TAGNAME(childElems.item(i)), "initial") || + false) + continue; + + struct ElemDetails details; + details.name = "" + TAGNAME(childElems.item(i)) + ":"; + + // provide details for special elements here + + // param --------- + if (boost::iequals(TAGNAME(childElems.item(i)), "param")) { + if (HAS_ATTR(childElems.item(i), "name")) + details.name += " " + ATTR(childElems.item(i), "name") + " = "; + if (HAS_ATTR(childElems.item(i), "expr")) + details.name += ATTR(childElems.item(i), "expr"); + if (HAS_ATTR(childElems.item(i), "location")) + details.name += ATTR(childElems.item(i), "location"); + } + + // data --------- + if (boost::iequals(TAGNAME(childElems.item(i)), "data")) { + if (HAS_ATTR(childElems.item(i), "id")) + details.name += " " + ATTR(childElems.item(i), "id"); + if (HAS_ATTR(childElems.item(i), "src")) + details.name += ATTR(childElems.item(i), "src"); + if (HAS_ATTR(childElems.item(i), "expr")) + details.name += " = " + ATTR(childElems.item(i), "expr"); + NodeList grandChildElems = childElems.item(i).getChildNodes(); + for (int j = 0; j < grandChildElems.getLength(); j++) { + if (grandChildElems.item(j).getNodeType() == Node_base::TEXT_NODE) { + details.name += dotEscape(grandChildElems.item(j).getNodeValue()); + } + } + } + + // invoke --------- + if (boost::iequals(TAGNAME(childElems.item(i)), "invoke")) { + if (HAS_ATTR(childElems.item(i), "type")) + details.name += "
type = " + ATTR(childElems.item(i), "type"); + if (HAS_ATTR(childElems.item(i), "typeexpr")) + details.name += "
type = " + ATTR(childElems.item(i), "typeexpr"); + if (HAS_ATTR(childElems.item(i), "src")) + details.name += "
src = " + ATTR(childElems.item(i), "src"); + if (HAS_ATTR(childElems.item(i), "srcexpr")) + details.name += "
src = " + ATTR(childElems.item(i), "srcexpr"); + if (HAS_ATTR(childElems.item(i), "id")) + details.name += "
id = " + ATTR(childElems.item(i), "id"); + if (HAS_ATTR(childElems.item(i), "idlocation")) + details.name += "
id = " + ATTR(childElems.item(i), "idlocation"); + } + + // send --------- + if (boost::iequals(TAGNAME(childElems.item(i)), "send")) { + if (HAS_ATTR(childElems.item(i), "type")) + details.name += "
type = " + ATTR(childElems.item(i), "type"); + if (HAS_ATTR(childElems.item(i), "typeexpr")) + details.name += "
type = " + ATTR(childElems.item(i), "typeexpr"); + if (HAS_ATTR(childElems.item(i), "event")) + details.name += "
event = " + ATTR(childElems.item(i), "event"); + if (HAS_ATTR(childElems.item(i), "eventexpr")) + details.name += "
event = " + ATTR(childElems.item(i), "eventexpr"); + if (HAS_ATTR(childElems.item(i), "target")) + details.name += "
target = " + ATTR(childElems.item(i), "target"); + if (HAS_ATTR(childElems.item(i), "targetexpr")) + details.name += "
target = " + ATTR(childElems.item(i), "targetexpr"); + if (HAS_ATTR(childElems.item(i), "delay")) + details.name += "
delay = " + ATTR(childElems.item(i), "delay"); + if (HAS_ATTR(childElems.item(i), "delayexpr")) + details.name += "
delay = " + ATTR(childElems.item(i), "delayexpr"); + } + + // script --------- + if (boost::iequals(TAGNAME(childElems.item(i)), "script")) { + details.name += " "; + if (HAS_ATTR(childElems.item(i), "src")) + details.name += ATTR(childElems.item(i), "src"); + NodeList grandChildElems = childElems.item(i).getChildNodes(); + for (int j = 0; j < grandChildElems.getLength(); j++) { + if (grandChildElems.item(j).getNodeType() == Node_base::TEXT_NODE) { + details.name += dotEscape(grandChildElems.item(j).getNodeValue()); + } + } + } + + // if --------- + if (boost::iequals(TAGNAME(childElems.item(i)), "if")) { + if (HAS_ATTR(childElems.item(i), "cond")) + details.name += " cond = " + dotEscape(ATTR(childElems.item(i), "cond")); + } + + // elseif --------- + if (boost::iequals(TAGNAME(childElems.item(i)), "elseif")) { + if (HAS_ATTR(childElems.item(i), "cond")) + details.name += " cond = " + dotEscape(ATTR(childElems.item(i), "cond")); + } + + // log --------- + if (boost::iequals(TAGNAME(childElems.item(i)), "log")) { + details.name += " "; + if (HAS_ATTR(childElems.item(i), "label")) + details.name += ATTR(childElems.item(i), "label") + " = "; + if (HAS_ATTR(childElems.item(i), "expr")) + details.name += ATTR(childElems.item(i), "expr"); + } + + // foreach --------- + if (boost::iequals(TAGNAME(childElems.item(i)), "foreach")) { + if (HAS_ATTR(childElems.item(i), "item")) + details.name += "
  item = " + ATTR(childElems.item(i), "item"); + if (HAS_ATTR(childElems.item(i), "array")) + details.name += "
  array = " + ATTR(childElems.item(i), "array"); + if (HAS_ATTR(childElems.item(i), "index")) + details.name += "
  index = " + ATTR(childElems.item(i), "index"); + } + + // recurse + details.content = getDetailedLabel((Arabica::DOM::Element)childElems.item(i), indentation + 1); + content.push_back(details); + } + + std::stringstream ssContent; + + if (content.size() > 0) { + ssContent << ""; + + std::list::iterator contentIter = content.begin(); + while(contentIter != content.end()) { + ssContent << ""; +// ssContent << ""; + ssContent << ""; + ssContent << ""; + + if (contentIter->content.size() > 0) { + ssContent << ""; +// ssContent << ""; + ssContent << ""; + ssContent << ""; + } + contentIter++; + + } + ssContent << "
" << contentIter->name << "" << contentIter->name << "
" << contentIter->details << "" << contentIter->content << "
"; + } + return ssContent.str(); +} + +std::string SCXMLDotWriter::dotEscape(const std::string& text) { + std::string escaped(text); + boost::replace_all(escaped, " ", " "); + boost::replace_all(escaped, "\t", "   "); + boost::replace_all(escaped, "<", "<"); + boost::replace_all(escaped, ">", ">"); + boost::replace_all(escaped, "\"", """); + boost::replace_all(escaped, "\n", "
"); + + return escaped; +} + +std::string SCXMLDotWriter::colorForIndent(int indent) { + int color = 255 - (16 * indent); + std::stringstream ss; + ss << std::hex << color; + ss << std::hex << color; + ss << std::hex << color; + return ss.str(); +} + +std::string SCXMLDotWriter::nameForNode(const Arabica::DOM::Node& node) { + std::string elemName; + if (node.getNodeType() == Node_base::ELEMENT_NODE) { + Arabica::DOM::Element elem = (Arabica::DOM::Element)node; + if (elem.hasAttribute("name")) { + elemName = elem.getAttribute("name"); + } else if (elem.hasAttribute("id")) { + elemName = elem.getAttribute("id"); + } + } + if (elemName.size() == 0) + elemName = boost::lexical_cast(node.getLocalName()); + + return elemName; + +} + +std::string SCXMLDotWriter::idForNode(const Arabica::DOM::Node& node) { + std::string elemId; + + // try to get the id as the name or id attribute + if (node.getNodeType() == Node_base::ELEMENT_NODE) { + Arabica::DOM::Element elem = (Arabica::DOM::Element)node; + if (elem.hasAttribute("name")) { + elemId = elem.getAttribute("name"); + } else if (elem.hasAttribute("id")) { + elemId = elem.getAttribute("id"); + } + } + + // no luck, create id from position in tree + if (elemId.size() == 0) { + Arabica::DOM::Node tmpParent = node; + Arabica::DOM::Node tmpIndex; + do { + if (tmpParent.getNodeType() != Node_base::ELEMENT_NODE) + continue; + + tmpIndex = tmpParent; + int index = 0; + + while((tmpIndex = tmpIndex.getPreviousSibling())) + index++; + + std::stringstream ssElemId; + ssElemId << TAGNAME(tmpParent) << index << "."; + elemId = ssElemId.str() + elemId; + } while ((tmpParent = tmpParent.getParentNode())); +// elemId = ssElemId.str(); + } + + std::replace(elemId.begin(), elemId.end(), '-', '_'); + + return elemId; +} + +} \ No newline at end of file diff --git a/src/uscxml/debug/SCXMLDotWriter.cpp.old b/src/uscxml/debug/SCXMLDotWriter.cpp.old deleted file mode 100644 index 20d82c9..0000000 --- a/src/uscxml/debug/SCXMLDotWriter.cpp.old +++ /dev/null @@ -1,359 +0,0 @@ -#include "uscxml/Common.h" -#include "SCXMLDotWriter.h" -#include "uscxml/Interpreter.h" -#include // replace_all - -namespace uscxml { - -using namespace Arabica::DOM; - -int SCXMLDotWriter::_indentation = 0; - -SCXMLDotWriter::SCXMLDotWriter(Interpreter* interpreter) { - _interpreter = interpreter; -} - -SCXMLDotWriter::~SCXMLDotWriter() { - -} - -std::string SCXMLDotWriter::getPrefix() { - std::string prefix = ""; - for (int i = 0; i < _indentation; i++) - prefix += " "; - return prefix; -} - -void SCXMLDotWriter::toDot(const std::string& filename, Interpreter* interpreter) { - std::ofstream outfile(filename.c_str()); - NodeList scxmlElems = interpreter->getDocument().getElementsByTagName("scxml"); - SCXMLDotWriter writer(interpreter); - if (scxmlElems.getLength() > 0) { - _indentation++; - outfile << "digraph {" << std::endl; - outfile << "rankdir=LR;" << std::endl; - writer.writeSCXMLElement(outfile, (Arabica::DOM::Element)scxmlElems.item(0)); - _indentation--; - outfile << "}" << std::endl; - } - -} - -void SCXMLDotWriter::writeSCXMLElement(std::ostream& os, const Arabica::DOM::Element& elem) { - writeStateElement(os, elem); - -// std::string elemId = idForNode(elem); -// os << getPrefix() << "subgraph \"cluster" << elemId.substr(1, elemId.length() - 1) << " {" << std::endl; -// _indentation++; -// os << getPrefix() << "label=\"" << nameForNode(elem) << "\"" << std::endl; -// writeStateElement(os, (Arabica::DOM::Element)_interpreter->getInitialState()); -// os << getPrefix() << "} " << std::endl; - -} - -void SCXMLDotWriter::writeStateElement(std::ostream& os, const Arabica::DOM::Element& elem) { - - std::string elemId = idForNode(elem); - NodeList childElems = elem.getChildNodes(); - - if (_knownIds.find(elemId) != _knownIds.end()) - return; - _knownIds.insert(elemId); - - bool subgraph = Interpreter::isCompound(elem) || Interpreter::isParallel(elem); - if (subgraph) { - _indentation++; - os << getPrefix() << "subgraph \"cluster_" << elemId << "\" {" << std::endl; - os << getPrefix() << "label=\"" << nameForNode(elem) << "\\l\"" << std::endl; - } - - os << getPrefix() << "\"" << elemId << "\"["; - os << "label=<State
" << nameForNode(elem) << ">,"; - if (_interpreter->isInitial(elem)) - os << "style=filled,"; - if (_interpreter->isFinal(elem)) - os << "shape=doublecircle,"; - os << "];" << std::endl; - - std::string details = getDetailedLabel(elem); -// std::cout << details << std::endl; - - if (details.size() > 0) { - os << getPrefix() << "\"" << elemId << "Exec\"["; -// os << "fontsize=10,"; - os << "shape=box,"; - os << "color=grey,"; - os << "label=<" << details << ">"; - os << "]" << std::endl; - os << getPrefix() << "\"" << elemId << "\" -> \"" << elemId << "Exec\" [arrowhead=none, color=grey]" << std::endl; - } - -// NodeList childElems = elem.getChildNodes(); -// for (int i = 0; i < childElems.getLength(); i++) { -// if (Interpreter::isState(childElems.item(i))) { -// writeStateElement(os, (Arabica::DOM::Element)childElems.item(i)); -// } -// } - - for (int i = 0; i < childElems.getLength(); i++) { - if (childElems.item(i).getNodeType() == Node_base::ELEMENT_NODE && boost::iequals(TAGNAME(childElems.item(i)), "transition")) { - writeTransitionElement(os, (Arabica::DOM::Element)childElems.item(i)); - os << getPrefix() << "\"" << elemId << "\" -> \"" << idForNode(childElems.item(i)) << "\"" << std::endl; - } - if (Interpreter::isState(childElems.item(i))) { - writeStateElement(os, (Arabica::DOM::Element)childElems.item(i)); - } - if (childElems.item(i).getNodeType() == Node_base::ELEMENT_NODE && boost::iequals(TAGNAME(childElems.item(i)), "initial")) { - NodeList grandChildElems = childElems.item(i).getChildNodes(); - for (int j = 0; j < grandChildElems.getLength(); j++) { - if (grandChildElems.item(j).getNodeType() == Node_base::ELEMENT_NODE && boost::iequals(TAGNAME(grandChildElems.item(j)), "transition")) { - writeTransitionElement(os, (Arabica::DOM::Element)grandChildElems.item(j)); - os << getPrefix() << "\"" << elemId << "\" -> \"" << idForNode(grandChildElems.item(j)) << "\"" << std::endl; - } - } - } - } - - if (subgraph) { - _indentation--; - os << getPrefix() << "} " << std::endl; - } - -} - -void SCXMLDotWriter::writeTransitionElement(std::ostream& os, const Arabica::DOM::Element& elem) { - std::string elemId = idForNode(elem); - - Arabica::XPath::NodeSet targetStates = _interpreter->getTargetStates(elem); - - std::string label; - os << getPrefix() << "\"" << elemId << "\"["; -// os << "fontsize=10,"; - os << "shape=box,"; - os << "label=<Transition
"; - if (HAS_ATTR(elem, "event")) - os << "event: " << ATTR(elem, "event"); - if (HAS_ATTR(elem, "cond")) - os << "cond: " << ATTR(elem, "cond"); - if (!HAS_ATTR(elem, "cond") && !HAS_ATTR(elem, "event")) - os << "unconditional"; - os << ">"; - os << "]" << std::endl; - - for (int i = 0; i < targetStates.size(); i++) { - os << getPrefix() << "\"" << elemId << "\" -> \"" << idForNode(targetStates[i]) << "\"" << std::endl; - writeStateElement(os, (Arabica::DOM::Element)targetStates[i]); - } - -} - -std::string SCXMLDotWriter::getDetailedLabel(const Arabica::DOM::Element& elem, int indentation) { - -/* - - - - - - - - -
onEntry
Details - Nested Content -
-*/ - - std::list content; - - NodeList childElems = elem.getChildNodes(); - for (int i = 0; i < childElems.getLength(); i++) { - if (childElems.item(i).getNodeType() != Node_base::ELEMENT_NODE) - continue; - - if (Interpreter::isState(childElems.item(i)) || - boost::iequals(TAGNAME(childElems.item(i)), "transition") || - boost::iequals(TAGNAME(childElems.item(i)), "initial") || - false) - continue; - - struct ElemDetails details; - details.name = "" + TAGNAME(childElems.item(i)) + ""; - - // provide details for special elements here - - // param --------- - if (boost::iequals(TAGNAME(childElems.item(i)), "param")) { - if (HAS_ATTR(childElems.item(i), "name")) - details.name += " " + ATTR(childElems.item(i), "name") + " = "; - if (HAS_ATTR(childElems.item(i), "expr")) - details.name += ATTR(childElems.item(i), "expr"); - if (HAS_ATTR(childElems.item(i), "location")) - details.name += ATTR(childElems.item(i), "location"); - } - - // data --------- - if (boost::iequals(TAGNAME(childElems.item(i)), "data")) { - if (HAS_ATTR(childElems.item(i), "id")) - details.name += " " + ATTR(childElems.item(i), "id") + " = "; - if (HAS_ATTR(childElems.item(i), "src")) - details.name += ATTR(childElems.item(i), "src"); - if (HAS_ATTR(childElems.item(i), "expr")) - details.name += ATTR(childElems.item(i), "expr"); - NodeList grandChildElems = childElems.item(i).getChildNodes(); - for (int j = 0; j < grandChildElems.getLength(); j++) { - if (grandChildElems.item(j).getNodeType() == Node_base::TEXT_NODE) { - details.name += dotEscape(grandChildElems.item(j).getNodeValue()); - } - } - } - - // invoke --------- - if (boost::iequals(TAGNAME(childElems.item(i)), "invoke")) { - if (HAS_ATTR(childElems.item(i), "type")) - details.name += "
type = " + ATTR(childElems.item(i), "type"); - if (HAS_ATTR(childElems.item(i), "typeexpr")) - details.name += "
type = " + ATTR(childElems.item(i), "typeexpr"); - if (HAS_ATTR(childElems.item(i), "src")) - details.name += "
src = " + ATTR(childElems.item(i), "src"); - if (HAS_ATTR(childElems.item(i), "srcexpr")) - details.name += "
src = " + ATTR(childElems.item(i), "srcexpr"); - if (HAS_ATTR(childElems.item(i), "id")) - details.name += "
id = " + ATTR(childElems.item(i), "id"); - if (HAS_ATTR(childElems.item(i), "idlocation")) - details.name += "
id = " + ATTR(childElems.item(i), "idlocation"); - } - - // send --------- - if (boost::iequals(TAGNAME(childElems.item(i)), "send")) { - if (HAS_ATTR(childElems.item(i), "type")) - details.name += "
type = " + ATTR(childElems.item(i), "type"); - if (HAS_ATTR(childElems.item(i), "typeexpr")) - details.name += "
type = " + ATTR(childElems.item(i), "typeexpr"); - if (HAS_ATTR(childElems.item(i), "event")) - details.name += "
event = " + ATTR(childElems.item(i), "event"); - if (HAS_ATTR(childElems.item(i), "eventexpr")) - details.name += "
event = " + ATTR(childElems.item(i), "eventexpr"); - if (HAS_ATTR(childElems.item(i), "target")) - details.name += "
target = " + ATTR(childElems.item(i), "target"); - if (HAS_ATTR(childElems.item(i), "targetexpr")) - details.name += "
target = " + ATTR(childElems.item(i), "targetexpr"); - if (HAS_ATTR(childElems.item(i), "delay")) - details.name += "
delay = " + ATTR(childElems.item(i), "delay"); - if (HAS_ATTR(childElems.item(i), "delayexpr")) - details.name += "
delay = " + ATTR(childElems.item(i), "delayexpr"); - } - - // script --------- - if (boost::iequals(TAGNAME(childElems.item(i)), "script")) { - details.name += " "; - if (HAS_ATTR(childElems.item(i), "src")) - details.name += ATTR(childElems.item(i), "src"); - NodeList grandChildElems = childElems.item(i).getChildNodes(); - for (int j = 0; j < grandChildElems.getLength(); j++) { - if (grandChildElems.item(j).getNodeType() == Node_base::TEXT_NODE) { - details.name += dotEscape(grandChildElems.item(j).getNodeValue()); - } - } - } - - // recurse - details.content = getDetailedLabel((Arabica::DOM::Element)childElems.item(i), indentation + 1); - content.push_back(details); - } - - std::stringstream ssContent; - - if (content.size() > 0) { - ssContent << ""; - - std::list::iterator contentIter = content.begin(); - while(contentIter != content.end()) { - ssContent << ""; -// ssContent << ""; - ssContent << ""; - ssContent << ""; - - if (contentIter->content.size() > 0) { - ssContent << ""; -// ssContent << ""; - ssContent << ""; - ssContent << ""; - } - contentIter++; - - } - ssContent << "
" << contentIter->name << "" << contentIter->name << "
" << contentIter->details << "" << contentIter->content << "
"; - } - return ssContent.str(); -} - -std::string SCXMLDotWriter::dotEscape(const std::string& text) { - std::string escaped(text); - boost::replace_all(escaped, "", ""); - - return escaped; -} - -std::string SCXMLDotWriter::colorForIndent(int indent) { - int color = 255 - (16 * indent); - std::stringstream ss; - ss << std::hex << color; - ss << std::hex << color; - ss << std::hex << color; - return ss.str(); -} - -std::string SCXMLDotWriter::nameForNode(const Arabica::DOM::Node& node) { - std::string elemName; - if (node.getNodeType() == Node_base::ELEMENT_NODE) { - Arabica::DOM::Element elem = (Arabica::DOM::Element)node; - if (elem.hasAttribute("name")) { - elemName = elem.getAttribute("name"); - } else if (elem.hasAttribute("id")) { - elemName = elem.getAttribute("id"); - } - } - if (elemName.size() == 0) - elemName = boost::lexical_cast(node.getLocalName()); - - return elemName; - -} - -std::string SCXMLDotWriter::idForNode(const Arabica::DOM::Node& node) { - std::string elemId; - if (node.getNodeType() == Node_base::ELEMENT_NODE) { - Arabica::DOM::Element elem = (Arabica::DOM::Element)node; - if (elem.hasAttribute("name")) { - elemId = elem.getAttribute("name"); - } else if (elem.hasAttribute("id")) { - elemId = elem.getAttribute("id"); - } - } - if (elemId.size() == 0) { - Arabica::DOM::Node tmpParent = node; - Arabica::DOM::Node tmpIndex; - do { - if (tmpParent.getNodeType() != Node_base::ELEMENT_NODE) - continue; - - tmpIndex = tmpParent; - int index = 0; - - while((tmpIndex = tmpIndex.getPreviousSibling())) - index++; - - std::stringstream ssElemId; - ssElemId << TAGNAME(tmpParent) << index << "."; - elemId = ssElemId.str() + elemId; - } while ((tmpParent = tmpParent.getParentNode())); -// elemId = ssElemId.str(); - } - - std::replace(elemId.begin(), elemId.end(), '-', '_'); -// std::replace(elemId.begin(), elemId.end(), '.', '_'); - - return elemId; -} - -} \ No newline at end of file diff --git a/src/uscxml/debug/SCXMLDotWriter.h b/src/uscxml/debug/SCXMLDotWriter.h index 0666aa5..07b34b1 100644 --- a/src/uscxml/debug/SCXMLDotWriter.h +++ b/src/uscxml/debug/SCXMLDotWriter.h @@ -1,7 +1,9 @@ #ifndef SCXMLDOTWRITER_H_AOP0OHXX #define SCXMLDOTWRITER_H_AOP0OHXX +#include "uscxml/Interpreter.h" #include +#include #include #include @@ -9,7 +11,28 @@ namespace uscxml { class Interpreter; -class SCXMLDotWriter { + + +/** + * This writer, added as a monitor will output .dot files. + * + * # create a set of pdfs form the dot files + * $ dot -Tpdf -O *.dot + * or + * $ find . -name "*.dot" -exec dot -Tpdf -O {} \; + * + * # create a movie from the pdfs + * $ dot -Tgif -O *.dot + * or + * $ find . -name "*.dot" -exec dot -Tgif -O {} \; + * + * $ ffmpeg -r 3 -i .%06d.dot.gif -r 25 movie.mpg + * $ convert -delay 20 *.gif animated.gif + * + * # unflatten can be used to create more compact graphs + * find . -name "*.dot" -exec unflatten -f -l2 -o {}.flat.dot {} \; + */ +class SCXMLDotWriter : public InterpreterMonitor { public: struct ElemDetails { @@ -18,25 +41,43 @@ public: std::string content; }; - SCXMLDotWriter(InterpreterImpl* interpreter); + SCXMLDotWriter(); ~SCXMLDotWriter(); - static void toDot(const std::string& filename, InterpreterImpl* interpreter); - void writeSCXMLElement(std::ostream& os, const Arabica::DOM::Element& elem); - void writeStateElement(std::ostream& os, const Arabica::DOM::Element& elem); - void writeTransitionElement(std::ostream& os, const Arabica::DOM::Element& elem); + virtual void onStableConfiguration(Interpreter interpreter); + virtual void afterCompletion(Interpreter interpreter); + virtual void beforeTakingTransitions(Interpreter interpreter, const Arabica::XPath::NodeSet& transitions); + virtual void beforeMicroStep(Interpreter interpreter); + + static void toDot(const std::string& filename, + Interpreter interpreter, + const Arabica::XPath::NodeSet& transitions = Arabica::XPath::NodeSet()); std::string getDetailedLabel(const Arabica::DOM::Element& elem, int indentation = 0); std::string colorForIndent(int indent); std::string idForNode(const Arabica::DOM::Node& node); std::string nameForNode(const Arabica::DOM::Node& node); + std::string getPrefix(); - static std::string getPrefix(); static std::string dotEscape(const std::string& text); +protected: + + SCXMLDotWriter(Interpreter interpreter, + const Arabica::XPath::NodeSet& transitions); + + void writeSCXMLElement(std::ostream& os, const Arabica::DOM::Element& elem); + void writeStateElement(std::ostream& os, const Arabica::DOM::Element& elem); + void writeTransitionElement(std::ostream& os, const Arabica::DOM::Element& elem); + + int _iteration; std::set _knownIds; - static int _indentation; + int _indentation; + + // these are only set in ephemeral instances per monitor call + Arabica::XPath::NodeSet _transitions; + Interpreter _interpreter; }; } diff --git a/src/uscxml/interpreter/InterpreterDraft6.cpp b/src/uscxml/interpreter/InterpreterDraft6.cpp index aa09b53..881fa8b 100644 --- a/src/uscxml/interpreter/InterpreterDraft6.cpp +++ b/src/uscxml/interpreter/InterpreterDraft6.cpp @@ -121,6 +121,21 @@ void InterpreterDraft6::interpret() { } assert(initialTransitions.size() > 0); + + monIter_t monIter = _monitors.begin(); + while(monIter != _monitors.end()) { + try { + (*monIter)->beforeTakingTransitions(shared_from_this(), initialTransitions); + } catch (Event e) { + LOG(ERROR) << "Syntax error when calling beforeTakingTransitions on monitors: " << std::endl << e << std::endl; + } catch (boost::bad_weak_ptr e) { + LOG(ERROR) << "Unclean shutdown " << std::endl << std::endl; + } catch (...) { + LOG(ERROR) << "An exception occured when calling beforeTakingTransitions on monitors"; + } + monIter++; + } + enterStates(initialTransitions); // _mutex.unlock(); @@ -135,7 +150,7 @@ void InterpreterDraft6::interpret() { void InterpreterDraft6::mainEventLoop() { - std::set::iterator monIter; + monIter_t monIter; while(_running) { NodeSet enabledTransitions; @@ -218,6 +233,14 @@ void InterpreterDraft6::mainEventLoop() { // assume that we have a legal configuration as soon as the internal queue is empty assert(hasLegalConfiguration()); +#if 0 + std::cout << "Configuration: "; + for (int i = 0; i < _configuration.size(); i++) { + std::cout << ATTR(_configuration[i], "id") << ", "; + } + std::cout << std::endl; +#endif + monIter = _monitors.begin(); // if (!_sendQueue || _sendQueue->isEmpty()) { while(monIter != _monitors.end()) { @@ -614,7 +637,7 @@ void InterpreterDraft6::exitInterpreter() { void InterpreterDraft6::exitStates(const Arabica::XPath::NodeSet& enabledTransitions) { NodeSet statesToExit; - std::set::iterator monIter; + monIter_t monIter; #if VERBOSE std::cout << "Enabled exit transitions: " << std::endl; @@ -768,7 +791,7 @@ void InterpreterDraft6::exitStates(const Arabica::XPath::NodeSet& e void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet& enabledTransitions) { NodeSet statesToEnter; NodeSet statesForDefaultEntry; - std::set::iterator monIter; + monIter_t monIter; #if VERBOSE std::cout << "Enabled enter transitions: " << std::endl; diff --git a/src/uscxml/plugins/datamodel/CMakeLists.txt b/src/uscxml/plugins/datamodel/CMakeLists.txt index 731e316..ce13cdb 100644 --- a/src/uscxml/plugins/datamodel/CMakeLists.txt +++ b/src/uscxml/plugins/datamodel/CMakeLists.txt @@ -3,6 +3,8 @@ if (JSC_FOUND AND BUILD_DM_ECMA) file(GLOB JSC_DATAMODEL ecmascript/JavaScriptCore/*.cpp ecmascript/JavaScriptCore/*.h + ecmascript/*.cpp + ecmascript/*.h ) source_group("Datamodel\\jsc" FILES ${JSC_DATAMODEL}) file(GLOB_RECURSE JSC_DOM @@ -32,6 +34,8 @@ else() file(GLOB V8_DATAMODEL ecmascript/v8/*.cpp ecmascript/v8/*.h + ecmascript/*.cpp + ecmascript/*.h ) source_group("Datamodel\\v8" FILES ${V8_DATAMODEL}) file(GLOB_RECURSE V8_DOM diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.cpp new file mode 100644 index 0000000..f2c3a8e --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.cpp @@ -0,0 +1,19 @@ +#include "JSCDOM.h" + +namespace Arabica { +namespace DOM { + +JSCDOM::JSCDOM() { + xpath = NULL; + storage = NULL; +} + +JSCDOM::~JSCDOM() { + if (xpath) + delete(xpath); + if (storage) + delete(storage); +} + +} +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h new file mode 100644 index 0000000..e88851e --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h @@ -0,0 +1,39 @@ +#ifndef JSCDOM_H_1RC5LCG8 +#define JSCDOM_H_1RC5LCG8 + +#include "uscxml/Interpreter.h" +#include +#include +#include "../Storage.h" + +#define JSC_DESTRUCTOR(type) \ +static void jsDestructor(JSObjectRef object) { \ + type* thing = static_cast(JSObjectGetPrivate(object)); \ + if (thing) {\ + delete thing->nativeObj; \ + delete thing; \ + JSObjectSetPrivate(object, NULL);\ + }\ +} + +#define JSC_DESTRUCTOR_KEEP_WRAPPED(type) \ +static void jsDestructor(JSObjectRef object) { \ +type* thing = static_cast(JSObjectGetPrivate(object)); \ +delete thing; \ +} + +namespace Arabica { +namespace DOM { + +class JSCDOM { +public: + JSCDOM(); + virtual ~JSCDOM(); + uscxml::Storage* storage; + Arabica::XPath::XPath* xpath; +}; + +} +} + +#endif /* end of include guard: JSCDOM_H_1RC5LCG8 */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 7f6a9e7..712799c 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -1,6 +1,7 @@ #include "uscxml/Common.h" +#include "uscxml/config.h" #include "JSCDataModel.h" -#include "dom/JSCDOM.h" +#include "JSCDOM.h" #include "dom/JSCDocument.h" #include "dom/JSCSCXMLEvent.h" @@ -77,6 +78,7 @@ boost::shared_ptr JSCDataModel::create(InterpreterImpl* interpret dm->_dom = new JSCDOM(); dm->_dom->xpath = new XPath(); dm->_dom->xpath->setNamespaceContext(interpreter->getNSContext()); + dm->_dom->storage = new Storage(URL::getResourceDir() + PATH_SEPERATOR + interpreter->getName() + ".storage"); // introduce global functions as objects for private data JSClassRef jsInClassRef = JSClassCreate(&jsInClassDef); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index c5e9587..f7360d4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -4,7 +4,7 @@ #include "uscxml/Interpreter.h" #include #include -#include "dom/JSCDOM.h" +#include "JSCDOM.h" #ifdef BUILD_AS_PLUGINS #include "uscxml/plugins/Plugins.h" diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.h index 01628a6..3e98cab 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCNode.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.h index 9fe225b..f0ec864 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCText.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.h index 0bdca74..1155a0a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCNode.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.h index 7c4e96f..63bf840 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCCharacterData.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp deleted file mode 100644 index 1b5aaef..0000000 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "JSCDOM.h" - -namespace Arabica { -namespace DOM { - -JSCDOM::JSCDOM() { - xpath = NULL; -} - -JSCDOM::~JSCDOM() { - if (xpath) - delete(xpath); -} - -} -} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h deleted file mode 100644 index bffeab8..0000000 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef JSCDOM_H_1RC5LCG8 -#define JSCDOM_H_1RC5LCG8 - -#include "uscxml/Interpreter.h" -#include -#include - -#define JSC_DESTRUCTOR(type) \ -static void jsDestructor(JSObjectRef object) { \ - type* thing = static_cast(JSObjectGetPrivate(object)); \ - if (thing) {\ - delete thing->nativeObj; \ - delete thing; \ - JSObjectSetPrivate(object, NULL);\ - }\ -} - -#define JSC_DESTRUCTOR_KEEP_WRAPPED(type) \ -static void jsDestructor(JSObjectRef object) { \ -type* thing = static_cast(JSObjectGetPrivate(object)); \ -delete thing; \ -} - -namespace Arabica { -namespace DOM { - -class JSCDOM { -public: - JSCDOM(); - virtual ~JSCDOM(); - - Arabica::XPath::XPath* xpath; -}; - -} -} - -#endif /* end of include guard: JSCDOM_H_1RC5LCG8 */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.h index 551c2fe..9169604 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp index 4fae6c9..a7f170f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp @@ -21,6 +21,7 @@ JSStaticValue JSCDocument::staticValues[] = { { "doctype", doctypeAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "implementation", implementationAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "documentElement", documentElementAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "localStorage", localStorageCustomAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h index 6657f3b..7663d98 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCNode.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { @@ -58,6 +58,7 @@ public: static JSValueRef doctypeAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef implementationAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef documentElementAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); + static JSValueRef localStorageCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSStaticValue staticValues[]; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp index c6fdce1..52d6a88 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp @@ -1,4 +1,5 @@ #include "JSCDocument.h" +#include "JSCStorage.h" #include "JSCXPathResult.h" #include "JSCNode.h" #include @@ -6,6 +7,23 @@ namespace Arabica { namespace DOM { +JSValueRef JSCDocument::localStorageCustomAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(object); + + if (!privData->dom->storage) { + return JSValueMakeUndefined(ctx); + } + + JSClassRef retClass = JSCStorage::getTmpl(); + struct JSCStorage::JSCStoragePrivate* retPrivData = new JSCStorage::JSCStoragePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retPrivData->dom->storage; + + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, retClass, retPrivData); + return arbaicaRetObj; + +} + JSValueRef JSCDocument::evaluateCustomCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(object); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.h index 3a9d8d6..fbe47e9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCNode.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.h index 3dc46f4..635f78d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCNode.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.h index 9520a8b..43df02d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCNode.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.h index 69f54a3..b952750 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCNode.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.h index 428274f..2dddf57 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCNode.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.h index c82bfdd..251ab72 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp.old b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp.old deleted file mode 100644 index 7d38f9f..0000000 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp.old +++ /dev/null @@ -1,60 +0,0 @@ -#include "JSCNode.h" -#include - -namespace uscxml { - -using namespace Arabica::DOM; - -JSStaticValue JSCNode::staticValues[] = { - { "nodeName", nodeNameAttrGetter, nodeValueAttrSetter, kJSPropertyAttributeDontDelete }, - { "nodeValue", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "nodeType", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "parentNode", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "childNodes", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "firstChild", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "lastChild", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "previousSibling", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "nextSibling", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "attributes", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "ownerDocument", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "namespaceURI", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "prefix", nodeValueAttrGetter, prefixAttrSetter, kJSPropertyAttributeDontDelete }, - { "localName", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "baseURI", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "textContent", nodeValueAttrGetter, textContentAttrSetter, kJSPropertyAttributeDontDelete }, - { "parentElement", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "ELEMENT_NODE", ELEMENT_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "ATTRIBUTE_NODE", ATTRIBUTE_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "TEXT_NODE", TEXT_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "CDATA_SECTION_NODE", CDATA_SECTION_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "ENTITY_REFERENCE_NODE", ENTITY_REFERENCE_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "ENTITY_NODE", ENTITY_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "PROCESSING_INSTRUCTION_NODE", PROCESSING_INSTRUCTION_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "COMMENT_NODE", COMMENT_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "DOCUMENT_NODE", DOCUMENT_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "DOCUMENT_TYPE_NODE", DOCUMENT_TYPE_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "DOCUMENT_FRAGMENT_NODE", DOCUMENT_FRAGMENT_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "NOTATION_NODE", NOTATION_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "MAX_TYPE", MAX_TYPEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { 0, 0, 0, 0 } -}; - -JSStaticFunction JSCNode::staticFunctions[] = { - { "insertBefore", insertBeforeCallback, kJSPropertyAttributeDontDelete }, - { "replaceChild", replaceChildCallback, kJSPropertyAttributeDontDelete }, - { "removeChild", removeChildCallback, kJSPropertyAttributeDontDelete }, - { "appendChild", appendChildCallback, kJSPropertyAttributeDontDelete }, - { "hasChildNodes", hasChildNodesCallback, kJSPropertyAttributeDontDelete }, - { "cloneNode", cloneNodeCallback, kJSPropertyAttributeDontDelete }, - { "normalize", normalizeCallback, kJSPropertyAttributeDontDelete }, - { "isSupported", isSupportedCallback, kJSPropertyAttributeDontDelete }, - { "hasAttributes", hasAttributesCallback, kJSPropertyAttributeDontDelete }, - { "lookupPrefix", lookupPrefixCallback, kJSPropertyAttributeDontDelete }, - { "isDefaultNamespace", isDefaultNamespaceCallback, kJSPropertyAttributeDontDelete }, - { "lookupNamespaceURI", lookupNamespaceURICallback, kJSPropertyAttributeDontDelete }, - { "addEventListener", addEventListenerCallback, kJSPropertyAttributeDontDelete }, - { "removeEventListener", removeEventListenerCallback, kJSPropertyAttributeDontDelete }, - { 0, 0, 0 } -}; - -} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h index d833ecb..9849d72 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h.old b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h.old deleted file mode 100644 index 677a63b..0000000 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h.old +++ /dev/null @@ -1,223 +0,0 @@ -#ifndef JSCNODE_H_6BAK1S3C -#define JSCNODE_H_6BAK1S3C - -#include "JSCDOM.h" - -namespace uscxml { - -class JSCNode { -public: - static JSValueRef nodeNameAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef nodeValueAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef nodeTypeAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef parentNodeAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef childNodesAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef firstChildAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef lastChildAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef previousSiblingAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef nextSiblingAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef attributesAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef ownerDocumentAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef namespaceURIAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef prefixAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef localNameAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef baseURIAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef textContentAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef parentElementAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - - static bool nodeValueAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { - return false; - } - static bool prefixAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { - return false; - } - static bool textContentAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { - return false; - } - - static JSValueRef insertBeforeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef replaceChildCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef removeChildCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef appendChildCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef hasChildNodesCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef cloneNodeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef normalizeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef isSupportedCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef hasAttributesCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef lookupPrefixCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef isDefaultNamespaceCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef lookupNamespaceURICallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef addEventListenerCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - static JSValueRef removeEventListenerCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - assert(false); - return JSValueMakeUndefined(ctx); - } - - static JSValueRef ELEMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::ELEMENT_NODE); - } - static JSValueRef ATTRIBUTE_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::ATTRIBUTE_NODE); - } - static JSValueRef TEXT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::TEXT_NODE); - } - static JSValueRef CDATA_SECTION_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::CDATA_SECTION_NODE); - } - static JSValueRef ENTITY_REFERENCE_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::ENTITY_REFERENCE_NODE); - } - static JSValueRef ENTITY_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::ENTITY_NODE); - } - static JSValueRef PROCESSING_INSTRUCTION_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::PROCESSING_INSTRUCTION_NODE); - } - static JSValueRef COMMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::COMMENT_NODE); - } - static JSValueRef DOCUMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::DOCUMENT_NODE); - } - static JSValueRef DOCUMENT_TYPE_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::DOCUMENT_TYPE_NODE); - } - static JSValueRef DOCUMENT_FRAGMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::DOCUMENT_FRAGMENT_NODE); - } - static JSValueRef NOTATION_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::NOTATION_NODE); - } - static JSValueRef MAX_TYPEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { - assert(false); - return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::MAX_TYPE); - } - - JSC_DESTRUCTOR(Arabica::DOM::Node); - - static JSStaticValue staticValues[]; - static JSStaticFunction staticFunctions[]; - - static JSClassRef Tmpl; - static JSClassRef getTmpl() { - if (Tmpl == NULL) { - JSClassDefinition classDef = kJSClassDefinitionEmpty; - classDef.staticValues = staticValues; - classDef.staticFunctions = staticFunctions; - classDef.finalize = jsDestructor; - - Tmpl = JSClassCreate(&classDef); - JSClassRetain(Tmpl); - } - return Tmpl; - } - -}; - -} - - -#endif /* end of include guard: JSCNODE_H_6BAK1S3C */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeCustom.cpp index 82965ad..159ff56 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeCustom.cpp @@ -5,28 +5,23 @@ namespace Arabica { namespace DOM { JSValueRef JSCNode::attributesCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { -#if 0 - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); if (!privData->nativeObj->hasAttributes()) { - return v8::Undefined(); + return JSValueMakeUndefined(ctx); } - Arabica::DOM::NamedNodeMap* arbaicaRet = new Arabica::DOM::NamedNodeMap(privData->nativeObj->getAttributes()); - - v8::Handle arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + Arabica::DOM::NamedNodeMap* retVal = new Arabica::DOM::NamedNodeMap(privData->nativeObj->getAttributes()); + JSClassRef retClass = JSCNamedNodeMap::getTmpl(); - struct V8NamedNodeMap::V8NamedNodeMapPrivate* retPrivData = new V8NamedNodeMap::V8NamedNodeMapPrivate(); + struct JSCNamedNodeMap::JSCNamedNodeMapPrivate* retPrivData = new JSCNamedNodeMap::JSCNamedNodeMapPrivate(); retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; + retPrivData->nativeObj = retVal; - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8NamedNodeMap::jsDestructor); - return arbaicaRetObj; + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); -#endif + return retObj; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.h index fca81b8..feb9be5 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.h index b38d04e..5db3af8 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.h index bb84c50..b043d14 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCNode.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.h index fc8c44b..4ebdefb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCNode.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.h index 8e00401..d3a25d5 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp new file mode 100644 index 0000000..f3c709b --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp @@ -0,0 +1,155 @@ +#include "JSCStorage.h" + +namespace Arabica { +namespace DOM { + +JSClassRef JSCStorage::Tmpl; + +JSStaticValue JSCStorage::staticValues[] = { + { "length", lengthAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + + { 0, 0, 0, 0 } +}; + +JSStaticFunction JSCStorage::staticFunctions[] = { + { "key", keyCallback, kJSPropertyAttributeDontDelete }, + { "getItem", getItemCallback, kJSPropertyAttributeDontDelete }, + { "setItem", setItemCallback, kJSPropertyAttributeDontDelete }, + { "removeItem", removeItemCallback, kJSPropertyAttributeDontDelete }, + { "clear", clearCallback, kJSPropertyAttributeDontDelete }, + { 0, 0, 0 } +}; + +JSValueRef JSCStorage::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { + struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(object); + + return JSValueMakeNumber(ctx, privData->nativeObj->getLength()); +} + +JSValueRef JSCStorage::keyCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { + if (argumentCount < 1) { + std::string errorMsg = "Wrong number of arguments in key"; + JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); + JSValueRef exceptionString =JSValueMakeString(ctx, string); + JSStringRelease(string); + *exception = JSValueToObject(ctx, exceptionString, NULL); + return NULL; + } + + struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(thisObj); + + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + + std::string retVal = privData->nativeObj->key(localIndex); + + JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); + JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); + return jscRetVal; +} + +JSValueRef JSCStorage::getItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { + if (argumentCount < 1) { + std::string errorMsg = "Wrong number of arguments in getItem"; + JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); + JSValueRef exceptionString =JSValueMakeString(ctx, string); + JSStringRelease(string); + *exception = JSValueToObject(ctx, exceptionString, NULL); + return NULL; + } + + struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(thisObj); + + JSStringRef stringReflocalKey = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localKeyMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalKey); + char* localKeyBuffer = new char[localKeyMaxSize]; + JSStringGetUTF8CString(stringReflocalKey, localKeyBuffer, localKeyMaxSize); + std::string localKey(localKeyBuffer); + JSStringRelease(stringReflocalKey); + free(localKeyBuffer); + + + std::string retVal = privData->nativeObj->getItem(localKey); + + JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); + JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); + return jscRetVal; +} + +JSValueRef JSCStorage::setItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { + if (argumentCount < 2) { + std::string errorMsg = "Wrong number of arguments in setItem"; + JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); + JSValueRef exceptionString =JSValueMakeString(ctx, string); + JSStringRelease(string); + *exception = JSValueToObject(ctx, exceptionString, NULL); + return NULL; + } + + struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(thisObj); + + JSStringRef stringReflocalKey = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localKeyMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalKey); + char* localKeyBuffer = new char[localKeyMaxSize]; + JSStringGetUTF8CString(stringReflocalKey, localKeyBuffer, localKeyMaxSize); + std::string localKey(localKeyBuffer); + JSStringRelease(stringReflocalKey); + free(localKeyBuffer); + + JSStringRef stringReflocalValue = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localValueMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalValue); + char* localValueBuffer = new char[localValueMaxSize]; + JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, localValueMaxSize); + std::string localValue(localValueBuffer); + JSStringRelease(stringReflocalValue); + free(localValueBuffer); + + + privData->nativeObj->setItem(localKey, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; +} + +JSValueRef JSCStorage::removeItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { + if (argumentCount < 1) { + std::string errorMsg = "Wrong number of arguments in removeItem"; + JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); + JSValueRef exceptionString =JSValueMakeString(ctx, string); + JSStringRelease(string); + *exception = JSValueToObject(ctx, exceptionString, NULL); + return NULL; + } + + struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(thisObj); + + JSStringRef stringReflocalKey = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localKeyMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalKey); + char* localKeyBuffer = new char[localKeyMaxSize]; + JSStringGetUTF8CString(stringReflocalKey, localKeyBuffer, localKeyMaxSize); + std::string localKey(localKeyBuffer); + JSStringRelease(stringReflocalKey); + free(localKeyBuffer); + + + privData->nativeObj->removeItem(localKey); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; +} + +JSValueRef JSCStorage::clearCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { + + struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(thisObj); + + + privData->nativeObj->clear(); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; +} + + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.h new file mode 100644 index 0000000..afb9714 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.h @@ -0,0 +1,73 @@ +/* + This file is part of the Wrapper open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef JSCStorage_h +#define JSCStorage_h + +#include +#include "DOM/Node.hpp" +#include +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" + +namespace Arabica { +namespace DOM { + +class JSCStorage { +public: + struct JSCStoragePrivate { + JSCDOM* dom; + uscxml::Storage* nativeObj; + }; + + JSC_DESTRUCTOR_KEEP_WRAPPED(JSCStoragePrivate); + + static JSValueRef keyCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSValueRef getItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSValueRef setItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSValueRef removeItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSValueRef clearCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + + static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); + + + static JSStaticValue staticValues[]; + static JSStaticFunction staticFunctions[]; + + static JSClassRef Tmpl; + static JSClassRef getTmpl() { + if (Tmpl == NULL) { + JSClassDefinition classDef = kJSClassDefinitionEmpty; + classDef.staticValues = staticValues; + classDef.staticFunctions = staticFunctions; + classDef.finalize = jsDestructor; + + Tmpl = JSClassCreate(&classDef); + JSClassRetain(Tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // JSCStorage_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.h index 786df27..663124f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "JSCCharacterData.h" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.h index cd6ead7..9686a2c 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include -#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h" +#include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" namespace Arabica { namespace DOM { diff --git a/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp b/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp new file mode 100644 index 0000000..9131784 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/Storage.cpp @@ -0,0 +1,74 @@ +#include "Storage.h" +#include + +namespace uscxml { + +Storage::Storage(const std::string& filename) { + _filename = filename; + std::cout << _filename << std::endl; + std::fstream file; + file.open(_filename.c_str(), std::ios_base::in); + // read content into data + std::string key; + std::string value; + + while(std::getline(file, key, '\0')) { + if(std::getline(file, value, '\0')) { + _data[key] = value; + } + } + file.close(); +} + +Storage::~Storage() { + std::fstream file; + file.open(_filename.c_str(), std::ios_base::out); +// file.clear(); + + std::map::iterator dataIter = _data.begin(); + while(dataIter != _data.end()) { + // include trailing \0 + file.write(dataIter->first.c_str(), dataIter->first.length() + 1); + file.write(dataIter->second.c_str(), dataIter->second.length() + 1); + dataIter++; + } +// file.flush(); + file.close(); +} + +unsigned long Storage::getLength() { + return _data.size(); +} + +std::string Storage::key(unsigned long index) { + if (index > getLength()) + return ""; + + std::map::iterator dataIter = _data.begin(); + for (int i = 0; i < index; i++) { + dataIter++; + } + return dataIter->first; +} + +std::string Storage::getItem(const std::string& key) { + if (_data.find(key) == _data.end()) + return ""; + return _data[key]; +} + +void Storage::setItem(const std::string& key, const std::string& value) { + _data[key] = value; +} + +void Storage::removeItem(const std::string& key) { + if (_data.find(key) == _data.end()) + return; + _data.erase(key); +} + +void Storage::clear() { + _data.clear(); +} + +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/Storage.h b/src/uscxml/plugins/datamodel/ecmascript/Storage.h new file mode 100644 index 0000000..7caeb76 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/Storage.h @@ -0,0 +1,30 @@ +#ifndef STORAGE_H_L672TNX +#define STORAGE_H_L672TNX + +#include +#include +#include +#include + +namespace uscxml { + +class Storage { +public: + Storage(const std::string& filename); + ~Storage(); + + unsigned long getLength(); + std::string key(unsigned long index); + std::string getItem(const std::string& key); + void setItem(const std::string& key, const std::string& value); + void removeItem(const std::string& key); + void clear(); + +protected: + std::map _data; + std::string _filename; +}; + +} + +#endif /* end of include guard: STORAGE_H_L672TNX */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp new file mode 100644 index 0000000..be20bee --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp @@ -0,0 +1,17 @@ +#include "V8DOM.h" + +namespace Arabica { +namespace DOM { + +V8DOM::V8DOM() { +} + +V8DOM::~V8DOM() { + if (xpath) + delete(xpath); + if (storage) + delete(storage); +} + +} +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h new file mode 100644 index 0000000..43b98ce --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h @@ -0,0 +1,83 @@ +#ifndef V8DOM_H_LKE1HKJK +#define V8DOM_H_LKE1HKJK + +#include "uscxml/Interpreter.h" +#include +#include +#include "../Storage.h" + +#define V8_DESTRUCTOR(type) \ +static void jsDestructor(v8::Persistent object, void* data) { \ + v8::HandleScope handleScope; \ + type* thing = static_cast(v8::Local::Cast(object->ToObject()->GetInternalField(0))->Value()); \ + delete thing->nativeObj; \ + delete thing; \ + object.Dispose(); \ + object.Clear(); \ +} + +#define V8_DESTRUCTOR_KEEP_WRAPPED(type) \ +static void jsDestructor(v8::Persistent object, void* data) { \ +v8::HandleScope handleScope; \ +type* thing = static_cast(v8::Local::Cast(object->ToObject()->GetInternalField(0))->Value()); \ +delete thing; \ +object.Dispose(); \ +object.Clear(); \ +} + +namespace Arabica { +namespace DOM { + +class V8DOM { +public: + V8DOM(); + virtual ~V8DOM(); + + template + static T* toClassPtr(v8::Local data) { + if(data.IsEmpty()) + return NULL; + else if(!data->IsExternal()) + return NULL; + else + return static_cast(v8::External::Unwrap(data)); + return NULL; + } + static v8::Local toExternal(void* pointer) { + v8::HandleScope scope; + return scope.Close(v8::External::New(pointer)); + } + + Arabica::XPath::XPath* xpath; + uscxml::Storage* storage; +}; + +class V8Exception : public std::runtime_error { +public: + + V8Exception(const std::string& reason) : + std::runtime_error("DOMException") { + } // V8Exception + + V8Exception(const V8Exception& rhs) : + std::runtime_error(rhs), + reason_(rhs.reason_) { + } // DOMException + + virtual ~V8Exception() throw() { + } // DOMBadCast + + virtual const char* what() const throw() { + return reason_.c_str(); + } // what + +private: + DOMBadCast& operator=(const DOMBadCast&); + bool operator==(const DOMBadCast&) const; + + std::string reason_; +}; // class DOMException + +} +} +#endif /* end of include guard: V8DOM_H_LKE1HKJK */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index b394171..017b2eb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -1,6 +1,7 @@ #include "uscxml/Common.h" +#include "uscxml/config.h" #include "V8DataModel.h" -#include "dom/V8DOM.h" +#include "V8DOM.h" #include "dom/V8Document.h" #include "dom/V8Node.h" #include "dom/V8SCXMLEvent.h" @@ -29,6 +30,15 @@ V8DataModel::V8DataModel() { // _contexts.push_back(v8::Context::New()); } +V8DataModel::~V8DataModel() { + while(_contexts.size() > 0) { + _contexts.back().Dispose(); + _contexts.pop_back(); + } + if (_dom) + delete _dom; +} + boost::shared_ptr V8DataModel::create(InterpreterImpl* interpreter) { boost::shared_ptr dm = boost::shared_ptr(new V8DataModel()); dm->_interpreter = interpreter; @@ -39,6 +49,7 @@ boost::shared_ptr V8DataModel::create(InterpreterImpl* interprete // dom->interpreter = interpreter; dm->_dom->xpath = new XPath(); dm->_dom->xpath->setNamespaceContext(interpreter->getNSContext()); + dm->_dom->storage = new Storage(URL::getResourceDir() + PATH_SEPERATOR + interpreter->getName() + ".storage"); // see http://stackoverflow.com/questions/3171418/v8-functiontemplate-class-instance @@ -111,13 +122,6 @@ v8::Handle V8DataModel::getIOProcessors(v8::Local propert return dataModel->_ioProcessors; } -V8DataModel::~V8DataModel() { - while(_contexts.size() > 0) { - _contexts.back().Dispose(); - _contexts.pop_back(); - } -} - void V8DataModel::pushContext() { _contexts.push_back(_contexts.back().New(_contexts.back())); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index da69c4f..9d17093 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -4,7 +4,7 @@ #include "uscxml/Interpreter.h" #include #include -#include "dom/V8DOM.h" +#include "V8DOM.h" #ifdef BUILD_AS_PLUGINS #include "uscxml/plugins/Plugins.h" diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h index 9829023..f216215 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h index 3b95b84..5f936d2 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Text.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h index 6c51ca7..d5846e4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h index 074da74..a19462d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8CharacterData.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp deleted file mode 100644 index 4562fe3..0000000 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "V8DOM.h" - -namespace Arabica { -namespace DOM { - -V8DOM::V8DOM() { - -} - -} -} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h deleted file mode 100644 index 10528e8..0000000 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef V8DOM_H_LKE1HKJK -#define V8DOM_H_LKE1HKJK - -#include "uscxml/Interpreter.h" -#include -#include - -#define V8_DESTRUCTOR(type) \ -static void jsDestructor(v8::Persistent object, void* data) { \ - v8::HandleScope handleScope; \ - type* thing = static_cast(v8::Local::Cast(object->ToObject()->GetInternalField(0))->Value()); \ - delete thing->nativeObj; \ - delete thing; \ - object.Dispose(); \ - object.Clear(); \ -} - -#define V8_DESTRUCTOR_KEEP_WRAPPED(type) \ -static void jsDestructor(v8::Persistent object, void* data) { \ -v8::HandleScope handleScope; \ -type* thing = static_cast(v8::Local::Cast(object->ToObject()->GetInternalField(0))->Value()); \ -delete thing; \ -object.Dispose(); \ -object.Clear(); \ -} - -namespace Arabica { -namespace DOM { - -class V8DOM { -public: - V8DOM(); - virtual ~V8DOM() { }; - - template - static T* toClassPtr(v8::Local data) { - if(data.IsEmpty()) - return NULL; - else if(!data->IsExternal()) - return NULL; - else - return static_cast(v8::External::Unwrap(data)); - return NULL; - } - static v8::Local toExternal(void* pointer) { - v8::HandleScope scope; - return scope.Close(v8::External::New(pointer)); - } - - Arabica::XPath::XPath* xpath; -}; - -class V8Exception : public std::runtime_error { -public: - - V8Exception(const std::string& reason) : - std::runtime_error("DOMException") { - } // V8Exception - - V8Exception(const V8Exception& rhs) : - std::runtime_error(rhs), - reason_(rhs.reason_) { - } // DOMException - - virtual ~V8Exception() throw() { - } // DOMBadCast - - virtual const char* what() const throw() { - return reason_.c_str(); - } // what - -private: - DOMBadCast& operator=(const DOMBadCast&); - bool operator==(const DOMBadCast&) const; - - std::string reason_; -}; // class DOMException - -} -} -#endif /* end of include guard: V8DOM_H_LKE1HKJK */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h index 5c58e22..58d6f9a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h index 2db4b54..a023ac9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { @@ -60,6 +60,7 @@ public: static v8::Handle doctypeAttrGetter(v8::Local property, const v8::AccessorInfo& info); static v8::Handle implementationAttrGetter(v8::Local property, const v8::AccessorInfo& info); static v8::Handle documentElementAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle localStorageCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info); static v8::Persistent Tmpl; static v8::Handle getTmpl() { @@ -80,6 +81,8 @@ public: v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); instance->SetAccessor(v8::String::NewSymbol("documentElement"), V8Document::documentElementAttrGetter, 0, v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("localStorage"), V8Document::localStorageCustomAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); prototype->Set(v8::String::NewSymbol("createElement"), v8::FunctionTemplate::New(V8Document::createElementCallback, v8::Undefined()), static_cast(v8::DontDelete)); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp index 1e0b700..cd7f942 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp @@ -1,9 +1,28 @@ #include "V8Document.h" #include "V8XPathResult.h" +#include "V8Storage.h" namespace Arabica { namespace DOM { +v8::Handle V8Document::localStorageCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + v8::Handle retCtor = V8Storage::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + V8Storage::V8StoragePrivate* retPrivData = new V8Storage::V8StoragePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = privData->dom->storage; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8XPathResult::jsDestructor); + return retObj; + +} + v8::Handle V8Document::evaluateCustomCallback(const v8::Arguments& args) { if (args.Length() < 1) diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h index c669b05..641aacd 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h index 59c2607..d1551a3 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h index e5a52bf..7263ab1 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h index 6e85585..88a284b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h index 86dd61b..cc25213 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h index be89037..d918186 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h index 2ea8ddc..b4fbad4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h index c454e65..341c63a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h index 97b5d4f..b95f4c1 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h index 0745728..51f324b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h index 56b61eb..d31d5d9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h index 8b71ed7..3c5e6ee 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp new file mode 100644 index 0000000..d9ab828 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp @@ -0,0 +1,83 @@ +#include "V8Storage.h" + +namespace Arabica { +namespace DOM { + +v8::Persistent V8Storage::Tmpl; + + +v8::Handle V8Storage::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::Integer::New(privData->nativeObj->getLength()); +} +v8::Handle V8Storage::keyCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in key"); + + v8::Local self = args.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + + std::string retVal = privData->nativeObj->key(localIndex); + + return v8::String::New(retVal.c_str()); +} + +v8::Handle V8Storage::getItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getItem"); + + v8::Local self = args.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localKey(args[0]); + + std::string retVal = privData->nativeObj->getItem(*localKey); + + return v8::String::New(retVal.c_str()); +} + +v8::Handle V8Storage::setItemCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in setItem"); + + v8::Local self = args.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localKey(args[0]); + v8::String::AsciiValue localValue(args[1]); + + privData->nativeObj->setItem(*localKey, *localValue); + + return v8::Undefined(); +} + +v8::Handle V8Storage::removeItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeItem"); + + v8::Local self = args.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localKey(args[0]); + + privData->nativeObj->removeItem(*localKey); + + return v8::Undefined(); +} + +v8::Handle V8Storage::clearCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + privData->nativeObj->clear(); + + return v8::Undefined(); +} + +bool V8Storage::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.h new file mode 100644 index 0000000..4d6692d --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.h @@ -0,0 +1,90 @@ +/* + This file is part of the Wrapper open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8Storage_h +#define V8Storage_h + +#include +#include "DOM/Node.hpp" +#include "string" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8Storage { +public: + struct V8StoragePrivate { + V8DOM* dom; + uscxml::Storage* nativeObj; + }; + + V8_DESTRUCTOR_KEEP_WRAPPED(V8StoragePrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle keyCallback(const v8::Arguments&); + static v8::Handle getItemCallback(const v8::Arguments&); + static v8::Handle setItemCallback(const v8::Arguments&); + static v8::Handle removeItemCallback(const v8::Arguments&); + static v8::Handle clearCallback(const v8::Arguments&); + + static v8::Handle lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Storage")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("length"), V8Storage::lengthAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("key"), + v8::FunctionTemplate::New(V8Storage::keyCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getItem"), + v8::FunctionTemplate::New(V8Storage::getItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setItem"), + v8::FunctionTemplate::New(V8Storage::setItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeItem"), + v8::FunctionTemplate::New(V8Storage::removeItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("clear"), + v8::FunctionTemplate::New(V8Storage::clearCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8Storage_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h index 61b92fb..0604984 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8CharacterData.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h index f6a2d10..b613b93 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h @@ -24,7 +24,7 @@ #include #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index 4a1ce05..a72fc6c 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -73,8 +73,6 @@ boost::shared_ptr SWIDataModel::create(InterpreterImpl* interpret LOG(ERROR) << "Error intializing prolog engine"; PL_halt(1); return boost::shared_ptr(); - } else { - LOG(WARNING) << "Instantiating more than one SWI prolog datamodel will lead to weird effects as I cannot seperate the environments"; } PL_set_engine(PL_ENGINE_CURRENT, &engine); @@ -98,6 +96,7 @@ boost::shared_ptr SWIDataModel::create(InterpreterImpl* interpret } } else { + LOG(WARNING) << "Instantiating more than one SWI prolog datamodel will lead to weird effects as I cannot seperate the environments"; engine = PL_create_engine(NULL); } diff --git a/src/uscxml/plugins/invoker/audio/AudioToolbox.mm b/src/uscxml/plugins/invoker/audio/AudioToolbox.mm index 44720b1..58e0224 100644 --- a/src/uscxml/plugins/invoker/audio/AudioToolbox.mm +++ b/src/uscxml/plugins/invoker/audio/AudioToolbox.mm @@ -4,10 +4,20 @@ #import #import +#ifdef __has_feature +# if __has_feature(objc_arc) +# define(HAS_AUTORELEASE_POOL) +# endif +#endif + namespace uscxml { AudioToolbox::AudioToolbox(const std::string filename) { - @autoreleasepool { +#if HAS_AUTORELEASE_POOL + @autoreleasepool { +#else + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif _afId = 0; NSString* filePath = [NSString stringWithCString:filename.c_str() encoding:NSASCIIStringEncoding]; NSURL* afUrl = [NSURL fileURLWithPath:filePath]; @@ -44,7 +54,11 @@ AudioToolbox::AudioToolbox(const std::string filename) { return; } - } +#if HAS_AUTORELEASE_POOL + } +#else + [pool drain]; +#endif } AudioToolbox::~AudioToolbox() { diff --git a/src/uscxml/plugins/invoker/audio/OpenALInvoker.cpp b/src/uscxml/plugins/invoker/audio/OpenALInvoker.cpp index 6b52c8c..6403a80 100644 --- a/src/uscxml/plugins/invoker/audio/OpenALInvoker.cpp +++ b/src/uscxml/plugins/invoker/audio/OpenALInvoker.cpp @@ -29,6 +29,7 @@ OpenALInvoker::OpenALInvoker() { _alContext = NULL; _alDevice = NULL; _thread = NULL; + _listenerPos[0] = _listenerPos[1] = _listenerPos[2] = 0; } OpenALInvoker::~OpenALInvoker() { @@ -131,6 +132,18 @@ void OpenALInvoker::send(const SendRequest& req) { returnErrorExecution(ex.what()); } } + + if (boost::iequals(req.name, "move.listener")) { + getPosFromParams(req.params, _listenerPos); + try { + alcMakeContextCurrent(_alContext); + alListenerfv(AL_POSITION, _listenerPos); + OpenALPlayer::checkOpenALError(__LINE__); + } catch (std::exception ex) { + returnErrorExecution(ex.what()); + } + } + } void OpenALInvoker::start() { diff --git a/src/uscxml/plugins/invoker/audio/OpenALInvoker.h b/src/uscxml/plugins/invoker/audio/OpenALInvoker.h index 086bfe8..2ef567b 100644 --- a/src/uscxml/plugins/invoker/audio/OpenALInvoker.h +++ b/src/uscxml/plugins/invoker/audio/OpenALInvoker.h @@ -66,6 +66,7 @@ protected: bool _isStarted; bool _isRunning; + float _listenerPos[3]; static void fillBuffers(void* userdata); void start(); diff --git a/src/uscxml/plugins/invoker/audio/OpenALPlayer.h b/src/uscxml/plugins/invoker/audio/OpenALPlayer.h index 4d7d189..7ea069d 100644 --- a/src/uscxml/plugins/invoker/audio/OpenALPlayer.h +++ b/src/uscxml/plugins/invoker/audio/OpenALPlayer.h @@ -63,7 +63,6 @@ private: void updateBuffers(); void init(); - void checkOpenALError(int line); // static wrapper as an entry point for pthreads static void updateBuffersWrapper(void *obj); @@ -76,6 +75,7 @@ public: virtual ~OpenALPlayer(); unsigned int isPlaying(); + static void checkOpenALError(int line); ALfloat* getPosition(); void setPosition(ALfloat[3]); diff --git a/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp index f53eb67..059e7f5 100644 --- a/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp @@ -2,6 +2,7 @@ #include "XHTMLInvoker.h" #include #include +#include #ifdef BUILD_AS_PLUGINS #include @@ -101,6 +102,8 @@ bool XHTMLInvoker::httpRecvRequest(const HTTPServer::Request& req) { content = templateURL.getInContent(); } + std::cout << content; + _interpreter->getDataModel().replaceExpressions(content); reply.content = content; diff --git a/test/samples/uscxml/applications/SpatialMapTicker.java b/test/samples/uscxml/applications/SpatialMapTicker.java index d161264..5ccb0a2 100644 --- a/test/samples/uscxml/applications/SpatialMapTicker.java +++ b/test/samples/uscxml/applications/SpatialMapTicker.java @@ -20,14 +20,14 @@ public class SpatialMapTicker { public class SensorMessage { public String message; - public String severity; - public SensorMessage(String message, String severity) { + public int severity; + public SensorMessage(String message, int severity) { this.message = message; this.severity = severity; } public SensorMessage(String message) { this.message = message; - this.severity = "Notice"; + this.severity = 3; } } @@ -108,7 +108,7 @@ public class SpatialMapTicker { } private void run() { - messages.add(new SensorMessage("Oil pressure threshold exceeded", "Error")); + messages.add(new SensorMessage("Oil pressure threshold exceeded")); messages.add(new SensorMessage("Error #245 in diagnostics unit")); messages.add(new SensorMessage("Error #32 in diagnostics unit")); messages.add(new SensorMessage("Error #81 in diagnostics unit")); @@ -144,8 +144,8 @@ public class SpatialMapTicker { msg.putMeta("html", sensor.getHTML()); msg.putMeta("time", nowString); msg.putMeta("timeStamp", Long.toString(now.getTime())); - msg.putMeta("lastMsg", sensor.messages.getFirst().message); - msg.putMeta("severity", sensor.messages.getFirst().severity); + msg.putMeta("message", sensor.messages.getFirst().message); + msg.putMeta("severity", Integer.toString(random.nextInt(10))); pub.send(msg); } } diff --git a/test/samples/uscxml/applications/spoken-map-ticker.scxml b/test/samples/uscxml/applications/spoken-map-ticker.scxml index 682429d..926cd6c 100644 --- a/test/samples/uscxml/applications/spoken-map-ticker.scxml +++ b/test/samples/uscxml/applications/spoken-map-ticker.scxml @@ -22,7 +22,7 @@ - + @@ -43,16 +43,17 @@ ${_event.data} + - + - ${_event.data.lastMsg} + ${_event.data.message} diff --git a/test/samples/uscxml/applications/spoken-map-ticker.xhtml b/test/samples/uscxml/applications/spoken-map-ticker.xhtml index e656be3..98df9ea 100644 --- a/test/samples/uscxml/applications/spoken-map-ticker.xhtml +++ b/test/samples/uscxml/applications/spoken-map-ticker.xhtml @@ -223,7 +223,7 @@ // addMarker(message); }); //]]> - + diff --git a/test/samples/uscxml/test-ecmascript.scxml b/test/samples/uscxml/test-ecmascript.scxml index 7dfd94c..4f0ff04 100644 --- a/test/samples/uscxml/test-ecmascript.scxml +++ b/test/samples/uscxml/test-ecmascript.scxml @@ -1,4 +1,4 @@ - + @@ -33,6 +33,10 @@ + diff --git a/test/samples/uscxml/test-scenegraph.scxml b/test/samples/uscxml/test-scenegraph.scxml index 0efcd6d..f0d1173 100644 --- a/test/samples/uscxml/test-scenegraph.scxml +++ b/test/samples/uscxml/test-scenegraph.scxml @@ -23,17 +23,17 @@ - + - + - + diff --git a/test/src/test-arabica-xpath.cpp b/test/src/test-arabica-xpath.cpp index 2991dc0..ced1de3 100644 --- a/test/src/test-arabica-xpath.cpp +++ b/test/src/test-arabica-xpath.cpp @@ -15,7 +15,7 @@ public: virtual Arabica::XPath::XPathValue resolveVariable(const string_type& /* namepace_uri */, const string_type& name) const { using namespace Arabica::XPath; - typename VarMap::const_iterator n = map_.find(name); + VarMap::const_iterator n = map_.find(name); if(n == map_.end()) throw UnboundVariableException(string_adaptor::asStdString(name)); return XPathValue(new NodeSetValue((*n).second)); -- cgit v0.12