From 794575f01ce5a6bf7e377eb815f3def5aded74f5 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Thu, 20 Jun 2013 21:53:21 +0200 Subject: New version with XHTML invoker --- CMakeLists.txt | 90 +- README.md | 5 +- apps/uscxml-browser.cpp | 2 +- apps/w3c-mmi/MMIEventServlet.cpp | 310 +++--- apps/w3c-mmi/MMIEventServlet.h | 2 +- apps/w3c-mmi/im/MMISessionManager.cpp | 465 ++++---- apps/w3c-mmi/im/MMISessionManager.h | 6 +- apps/w3c-mmi/im/uscxml-interaction-manager.cpp | 2 +- apps/w3c-mmi/mc/uscxml-modality-component.cpp | 2 +- config.h.in | 3 + contrib/cmake/BinaryExists.cmake | 1 + contrib/cmake/CrossCompile-Android.cmake | 1125 ++++++++++++++++++++ contrib/cmake/CrossCompile-iOS-Sim.cmake | 91 ++ contrib/cmake/CrossCompile-iOS.cmake | 93 ++ contrib/cmake/FindArabica.cmake | 1 + contrib/cmake/FindEVENT.cmake | 13 + contrib/local/compress_and_upload_deps.sh | 8 +- src/bindings/swig/php/uscxmlNativePHP.php | 6 +- src/uscxml/Common.h | 2 + src/uscxml/Factory.cpp | 42 +- src/uscxml/Factory.h | 14 +- src/uscxml/Interpreter.cpp | 15 +- src/uscxml/Interpreter.h | 8 +- src/uscxml/Message.cpp | 23 +- src/uscxml/Message.h | 3 +- src/uscxml/NameSpacingParser.cpp | 64 +- src/uscxml/NameSpacingParser.h | 32 +- src/uscxml/interpreter/InterpreterDraft6.cpp | 2 +- .../plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp | 84 +- .../plugins/datamodel/ecmascript/v8/dom/V8Attr.h | 88 +- .../datamodel/ecmascript/v8/dom/V8CDATASection.cpp | 12 +- .../datamodel/ecmascript/v8/dom/V8CDATASection.h | 44 +- .../ecmascript/v8/dom/V8CharacterData.cpp | 144 +-- .../datamodel/ecmascript/v8/dom/V8CharacterData.h | 106 +- .../datamodel/ecmascript/v8/dom/V8Comment.cpp | 12 +- .../datamodel/ecmascript/v8/dom/V8Comment.h | 44 +- .../ecmascript/v8/dom/V8DOMImplementation.cpp | 108 +- .../ecmascript/v8/dom/V8DOMImplementation.h | 60 +- .../datamodel/ecmascript/v8/dom/V8Document.cpp | 558 +++++----- .../datamodel/ecmascript/v8/dom/V8Document.h | 170 +-- .../ecmascript/v8/dom/V8DocumentFragment.cpp | 12 +- .../ecmascript/v8/dom/V8DocumentFragment.h | 44 +- .../datamodel/ecmascript/v8/dom/V8DocumentType.cpp | 112 +- .../datamodel/ecmascript/v8/dom/V8DocumentType.h | 98 +- .../datamodel/ecmascript/v8/dom/V8Element.cpp | 418 ++++---- .../datamodel/ecmascript/v8/dom/V8Element.h | 158 +-- .../datamodel/ecmascript/v8/dom/V8Entity.cpp | 42 +- .../plugins/datamodel/ecmascript/v8/dom/V8Entity.h | 80 +- .../ecmascript/v8/dom/V8EntityReference.cpp | 12 +- .../ecmascript/v8/dom/V8EntityReference.h | 44 +- .../datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp | 258 ++--- .../datamodel/ecmascript/v8/dom/V8NamedNodeMap.h | 108 +- .../plugins/datamodel/ecmascript/v8/dom/V8Node.cpp | 558 +++++----- .../plugins/datamodel/ecmascript/v8/dom/V8Node.h | 250 ++--- .../datamodel/ecmascript/v8/dom/V8NodeList.cpp | 54 +- .../datamodel/ecmascript/v8/dom/V8NodeList.h | 58 +- .../datamodel/ecmascript/v8/dom/V8NodeSet.cpp | 44 +- .../datamodel/ecmascript/v8/dom/V8NodeSet.h | 82 +- .../datamodel/ecmascript/v8/dom/V8Notation.cpp | 32 +- .../datamodel/ecmascript/v8/dom/V8Notation.h | 56 +- .../ecmascript/v8/dom/V8ProcessingInstruction.cpp | 44 +- .../ecmascript/v8/dom/V8ProcessingInstruction.h | 58 +- .../datamodel/ecmascript/v8/dom/V8SCXMLEvent.cpp | 108 +- .../datamodel/ecmascript/v8/dom/V8SCXMLEvent.h | 120 +-- .../plugins/datamodel/ecmascript/v8/dom/V8Text.cpp | 44 +- .../plugins/datamodel/ecmascript/v8/dom/V8Text.h | 50 +- .../datamodel/ecmascript/v8/dom/V8XPathResult.cpp | 104 +- .../datamodel/ecmascript/v8/dom/V8XPathResult.h | 108 +- .../plugins/datamodel/prolog/swi/SWIDataModel.cpp | 76 +- .../plugins/datamodel/prolog/swi/SWIDataModel.h | 2 +- src/uscxml/plugins/element/mmi/MMIEvents.cpp | 74 +- src/uscxml/plugins/element/mmi/MMIEvents.h | 2 +- src/uscxml/plugins/invoker/CMakeLists.txt | 17 + .../plugins/invoker/http/HTTPServletInvoker.cpp | 4 +- .../plugins/invoker/http/HTTPServletInvoker.h | 2 +- .../plugins/invoker/vxml/VoiceXMLInvoker.cpp | 6 +- src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h | 2 +- src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp | 195 ++++ src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.h | 55 + src/uscxml/plugins/ioprocessor/CMakeLists.txt | 31 + .../ioprocessor/basichttp/BasicHTTPIOProcessor.cpp | 5 +- .../ioprocessor/basichttp/BasicHTTPIOProcessor.h | 2 +- .../plugins/ioprocessor/comet/CometIOProcessor.cpp | 94 ++ .../plugins/ioprocessor/comet/CometIOProcessor.h | 53 + .../ioprocessor/modality/MMIHTTPIOProcessor.cpp | 5 +- .../ioprocessor/modality/MMIHTTPIOProcessor.h | 62 +- .../plugins/ioprocessor/modality/MMIMessages.cpp | 123 +-- .../plugins/ioprocessor/modality/MMIMessages.h | 90 +- .../ioprocessor/modality/MMIProtoBridge.cpp | 8 +- .../plugins/ioprocessor/modality/MMIProtoBridge.h | 2 +- .../ioprocessor/sample/SampleIOProcessor.cpp | 41 + .../plugins/ioprocessor/sample/SampleIOProcessor.h | 39 + src/uscxml/server/HTTPServer.cpp | 56 +- src/uscxml/server/HTTPServer.h | 15 +- src/uscxml/server/InterpreterServlet.cpp | 3 +- src/uscxml/server/InterpreterServlet.h | 2 +- test/samples/uscxml/templates/mc-html.html | 455 +++++--- test/samples/uscxml/templates/xhtml-invoker.html | 228 ++++ test/samples/uscxml/test-mmi-im.scxml | 11 +- test/samples/uscxml/test-xhtml-invoker.scxml | 33 + test/src/scxml-test-framework-client.cpp | 6 +- test/src/test-url.cpp | 12 +- 102 files changed, 5656 insertions(+), 3171 deletions(-) create mode 100644 contrib/cmake/BinaryExists.cmake create mode 100644 contrib/cmake/CrossCompile-Android.cmake create mode 100644 contrib/cmake/CrossCompile-iOS-Sim.cmake create mode 100644 contrib/cmake/CrossCompile-iOS.cmake create mode 100644 src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp create mode 100644 src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.h create mode 100644 src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.cpp create mode 100644 src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.h create mode 100644 src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.cpp create mode 100644 src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.h create mode 100644 test/samples/uscxml/templates/xhtml-invoker.html create mode 100644 test/samples/uscxml/test-xhtml-invoker.scxml diff --git a/CMakeLists.txt b/CMakeLists.txt index bc48b2e..a4104fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.4) # specify USCXML version SET(USCXML_VERSION_MAJOR "0") SET(USCXML_VERSION_MINOR "0") -SET(USCXML_VERSION_PATCH "4") +SET(USCXML_VERSION_PATCH "5") SET(USCXML_VERSION ${USCXML_VERSION_MAJOR}.${USCXML_VERSION_MINOR}.${USCXML_VERSION_PATCH}) # build type has to be set before the project definition @@ -15,6 +15,12 @@ ELSE() ENDIF() project(uscxml) + +# CMake 2.8.11 reports AMD64 for Windows 64Bit, where earlier versions reported x86 +if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") + set(CMAKE_SYSTEM_PROCESSOR "x86") +endif() + # use folders in the IDEs for the various targets (e.g. Library, Testing, Tools ..) set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -63,6 +69,7 @@ if(CMAKE_CROSSCOMPILING) if (IOS) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY "ONLY") SET(USCXML_PREBUILT_LIBRARY_PATH "${PROJECT_SOURCE_DIR}/contrib/prebuilt/ios/${CMAKE_SYSTEM_VERSION}") + SET(USCXML_PREBUILT_LIBRARY_PATH "${PROJECT_SOURCE_DIR}/contrib/prebuilt/ios/") elseif (ANDROID) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY "ONLY") # we need both to find jni - we don't? SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM "BOTH") @@ -84,17 +91,26 @@ endif() SET(USCXML_LIBRARY_HOST_URL_PREFIX "http://uscxml.tk.informatik.tu-darmstadt.de/prebuilt" CACHE STRING "The root path of an URL where to look for prebuilt libraries.") -if (WIN32 AND 64BIT_HOST) - SET(USCXML_LIBRARY_ARCHIVE_NAME uscxml-prebuilt-${CMAKE_SYSTEM_NAME_LC}-${CMAKE_SYSTEM_PROCESSOR}_64.tgz) +if (CMAKE_CROSSCOMPILING) + if (IOS) + SET(USCXML_LIBRARY_ARCHIVE_NAME uscxml-prebuilt-ios.tgz) + elseif(ANDROID) + SET(USCXML_LIBRARY_ARCHIVE_NAME uscxml-prebuilt-android.tgz) + else() + endif() else() - SET(USCXML_LIBRARY_ARCHIVE_NAME uscxml-prebuilt-${CMAKE_SYSTEM_NAME_LC}-${CMAKE_SYSTEM_PROCESSOR}.tgz) + if (WIN32 AND 64BIT_HOST) + SET(USCXML_LIBRARY_ARCHIVE_NAME uscxml-prebuilt-${CMAKE_SYSTEM_NAME_LC}-${CMAKE_SYSTEM_PROCESSOR}_64.tgz) + else() + SET(USCXML_LIBRARY_ARCHIVE_NAME uscxml-prebuilt-${CMAKE_SYSTEM_NAME_LC}-${CMAKE_SYSTEM_PROCESSOR}.tgz) + endif() endif() if (NOT EXISTS ${USCXML_PREBUILT_LIBRARY_PATH}) message(STATUS "Downloading prebuilt libraries: ${USCXML_LIBRARY_HOST_URL_PREFIX}/${USCXML_VERSION}/${USCXML_LIBRARY_ARCHIVE_NAME}") file(DOWNLOAD ${USCXML_LIBRARY_HOST_URL_PREFIX}/${USCXML_VERSION}/${USCXML_LIBRARY_ARCHIVE_NAME} ${PROJECT_SOURCE_DIR}/contrib/prebuilt/${USCXML_LIBRARY_ARCHIVE_NAME} - INACTIVITY_TIMEOUT 60 STATUS DOWNLOAD_STATUS SHOW_PROGRESS) + INACTIVITY_TIMEOUT 60 STATUS DOWNLOAD_STATUS SHOW_PROGRESS) list(GET DOWNLOAD_STATUS 0 STATUS_CODE) list(GET DOWNLOAD_STATUS 1 STATUS_STRING) if(STATUS_CODE EQUAL 0) @@ -111,6 +127,12 @@ if (NOT EXISTS ${USCXML_PREBUILT_LIBRARY_PATH}) endif() endif() +if (WIN32 OR CMAKE_CROSSCOMPILING) + OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF) +else() + OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON) +endif() + # # BUILD_PREFER_PREBUILT_LIBS: # Do we want to search system paths or contrib/prebuilt first? @@ -131,8 +153,6 @@ else() endif() include_directories(${USCXML_PREBUILT_LIBRARY_PATH}/include) -#message("CMAKE_FIND_ROOT_PATH: ${CMAKE_FIND_ROOT_PATH}") - if (WIN32) include_directories(${PROJECT_SOURCE_DIR}/contrib/src/getopt) endif() @@ -171,6 +191,7 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/contrib/cmake) include("${CMAKE_MODULE_PATH}/USCXMLMacros.cmake") include("${CMAKE_MODULE_PATH}/FunctionExists.cmake") include("${CMAKE_MODULE_PATH}/HeaderExists.cmake") +include("${CMAKE_MODULE_PATH}/BinaryExists.cmake") # we need USCXML_CORE_LIBS here for -lgcov set(USCXML_CORE_LIBS) @@ -181,7 +202,7 @@ set(USCXML_INCLUDE_DIRS) # some compiler flags #message("CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) # best practices from scott meyers @@ -229,7 +250,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") else() add_definitions(-rdynamic) endif() -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") +elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") add_definitions("-DZMQ_STATIC") add_definitions("-DPCRE_STATIC") add_definitions("-DUMUNDO_STATIC") @@ -239,7 +260,7 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NODEFAULTLIB") # SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:MSVCRTD.lib") -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-parentheses-equality") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-string-plus-int") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-non-literal-null-conversion") @@ -254,6 +275,24 @@ endif() set(CMAKE_COMPILER_STRING "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") +# see http://www.mail-archive.com/cmake@cmake.org/msg23240.html +if (APPLE) +# add_definitions("-D_DARWIN_UNLIMITED_SELECT") + set(CMAKE_OSX_ARCHITECTURES "x86_64;i386") + # support leopard and above + set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6) + foreach(FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS) + set(${FLAGS} "${${FLAGS}} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}") + endforeach() +endif() + +if (IOS) + set(CMAKE_OSX_DEPLOYMENT_TARGET 4.3) + foreach(FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS) + set(${FLAGS} "${${FLAGS}} -miphoneos-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}") + endforeach() +endif() + ############################################################ # postfixes for all built targets depending on build type ############################################################ @@ -280,7 +319,10 @@ else() add_definitions("-DUSCXML_STATIC") endif() -# prefer static libraries for linking +# library suffix order +if (IOS) + LIST(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dylib") +endif() set(CMAKE_FIND_LIBRARY_SUFFIXES_SHARED ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES_STATIC .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) @@ -330,12 +372,36 @@ include_directories(src) if (NOT WIN32) # libxml2 set(CMAKE_FIND_FRAMEWORK "LAST") + + # message("CMAKE_FIND_LIBRARY_SUFFIXES: ${CMAKE_FIND_LIBRARY_SUFFIXES}") + # message("CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}") + # message("CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") + # message("CMAKE_SYSTEM_INCLUDE_PATH: ${CMAKE_SYSTEM_INCLUDE_PATH}") + # message("CMAKE_SYSTEM_LIBRARY_PATH: ${CMAKE_SYSTEM_LIBRARY_PATH}") + # message("CMAKE_SYSTEM_PROGRAM_PATH: ${CMAKE_SYSTEM_PROGRAM_PATH}") + # message("CMAKE_FIND_ROOT_PATH: ${CMAKE_FIND_ROOT_PATH}") + find_package(LibXml2 REQUIRED) include_directories(${LIBXML2_INCLUDE_DIR}) list (APPEND USCXML_CORE_LIBS ${LIBXML2_LIBRARIES}) set(XML_LIBRARIES ${LIBXML2_LIBRARIES}) list (APPEND USCXML_CORE_LIBS "dl") list (APPEND USCXML_CORE_LIBS "pthread") + if (APPLE) + find_library(APP_SERVICES_LIBRARY ApplicationServices) + find_library(COREFOUNDATION_LIBRARY CoreFoundation) + message(FATAL_ERROR "COREFOUNDATION_LIBRARY: ${COREFOUNDATION_LIBRARY}") + list (APPEND USCXML_CORE_LIBS ${APP_SERVICES_LIBRARY}) + list (APPEND USCXML_CORE_LIBS ${COREFOUNDATION_LIBRARY}) + endif() + if (IOS) + find_library(COREFOUNDATION_LIBRARY CoreFoundation) + list (APPEND USCXML_CORE_LIBS ${COREFOUNDATION_LIBRARY}/CoreFoundation) + find_library(SECURITY_LIBRARY Security) + list (APPEND USCXML_CORE_LIBS ${SECURITY_LIBRARY}/Security) + list (APPEND USCXML_CORE_LIBS "z") + + endif() elseif(WIN32) list (APPEND XML_LIBRARIES "Ws2_32") list (APPEND XML_LIBRARIES "Winmm") @@ -619,7 +685,7 @@ message(STATUS " Available language bindings .... : ${AVAILABLE_LANGUAGE_BINDIN if (BUILD_SHARED_LIBS AND BUILD_BINDINGS) message(STATUS "") message(STATUS " Warning: Building language bindings BUILD_SHARED_LIBS=ON") - message(STATUS " introduces runtime dependency to libumundocore") + message(STATUS " introduces runtime dependency to libuscxml") message(STATUS "") endif() diff --git a/README.md b/README.md index 34683f8..bc88d48 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,9 @@ uSCXML is a SCXML interpreter written in C/C++. It is mostly feature-complete an It runs on Linux, Windows and MacOSX, each 32- as well as 64Bits. There are still a few rough edges, especially with the plugins and custom extensions. -There is no technical reason for it not to run on iOS and Android as well, but we did not yet setup -the respective build-process and did not precompile required libraries. +The latest release will also compile for iOS using the toolchain files in contrib/cmake/ but +does not feature the ecmascript nor the prolog datamodel. I will work on the Android version as soon as +I have some time at my hands. * Datamodels * Full [ECMAScript datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/ecmascript) using Google's v8 and JavaScriptCore (JSC is incomplete) diff --git a/apps/uscxml-browser.cpp b/apps/uscxml-browser.cpp index afe4e7f..39f81d7 100644 --- a/apps/uscxml-browser.cpp +++ b/apps/uscxml-browser.cpp @@ -170,7 +170,7 @@ int main(int argc, char** argv) { // intialize http server on given port HTTPServer::getInstance(port); - + LOG(INFO) << "Processing " << argv[optind]; Interpreter interpreter = Interpreter::fromURI(argv[optind]); if (interpreter) { diff --git a/apps/w3c-mmi/MMIEventServlet.cpp b/apps/w3c-mmi/MMIEventServlet.cpp index 5ee1807..cb5136a 100644 --- a/apps/w3c-mmi/MMIEventServlet.cpp +++ b/apps/w3c-mmi/MMIEventServlet.cpp @@ -32,179 +32,179 @@ else if (boost::iequals(mmiEvent.getLocalName(), #type)) { \ } namespace uscxml { - - using namespace Arabica::DOM; - - MMIEventServlet::MMIEventServlet(const std::string& path) : _path(path) { - // register at http server - bool success = HTTPServer::registerServlet(_path, this); - assert(success); - } - - MMIEventServlet::~MMIEventServlet() { - HTTPServer* httpServer = HTTPServer::getInstance(); - httpServer->unregisterServlet(this); - } - - void MMIEventServlet::send(const MMIEvent& mmiEvent) { - URL url(mmiEvent.target); - url.addMonitor(this); - - std::stringstream content; - content << mmiEvent.toXML(); - url.setOutContent(content.str()); - url.download(); - - } - void MMIEventServlet::httpRecvRequest(const HTTPServer::Request& req) { +using namespace Arabica::DOM; - // is this a request from a HTML browser? - - - NameSpacingParser* parser = NameSpacingParser::fromXML(req.data.compound.at("content").atom); - if (!parser) { - evhttp_send_error(req.curlReq, 402, NULL); - return; - } - - Document mmiDoc = parser->getDocument(); - std::cout << mmiDoc.getNamespaceURI() << std::endl; - Node mmiEvent = mmiDoc.getFirstChild(); - // get the first element +MMIEventServlet::MMIEventServlet(const std::string& path) : _path(path) { + // register at http server + bool success = HTTPServer::registerServlet(_path, this); + assert(success); +} + +MMIEventServlet::~MMIEventServlet() { + HTTPServer* httpServer = HTTPServer::getInstance(); + httpServer->unregisterServlet(this); +} + +void MMIEventServlet::send(const MMIEvent& mmiEvent) { + URL url(mmiEvent.target); + url.addMonitor(this); + + std::stringstream content; + content << mmiEvent.toXML(); + url.setOutContent(content.str()); + url.download(); + +} + +bool MMIEventServlet::httpRecvRequest(const HTTPServer::Request& req) { + + // is this a request from a HTML browser? + + + Document mmiDoc = NameSpacingParser::fromXML(req.data.compound.at("content").atom).getDocument(); + if (!mmiDoc) { + evhttp_send_error(req.curlReq, 402, NULL); + return true; + } + + std::cout << mmiDoc.getNamespaceURI() << std::endl; + Node mmiEvent = mmiDoc.getFirstChild(); + // get the first element + while (mmiEvent && mmiEvent.getNodeType() != Node_base::ELEMENT_NODE) { + mmiEvent = mmiEvent.getNextSibling(); + } + // get the contained message + if (boost::iequals(mmiEvent.getLocalName(), "mmi")) { + mmiEvent = mmiEvent.getFirstChild(); while (mmiEvent && mmiEvent.getNodeType() != Node_base::ELEMENT_NODE) { mmiEvent = mmiEvent.getNextSibling(); } - // get the contained message - if (boost::iequals(mmiEvent.getLocalName(), "mmi")) { - mmiEvent = mmiEvent.getFirstChild(); - while (mmiEvent && mmiEvent.getNodeType() != Node_base::ELEMENT_NODE) { - mmiEvent = mmiEvent.getNextSibling(); - } - } - std::cout << mmiEvent << std::endl; - - if (!mmiEvent) { - evhttp_send_error(req.curlReq, 402, NULL); - return; - } + } + std::cout << mmiEvent << std::endl; - std::set::iterator monIter; - if (false) {} - MMI_HTTP_EVENT_CASE(NewContextRequest) - MMI_HTTP_EVENT_CASE(NewContextResponse) - MMI_HTTP_EVENT_CASE(PrepareRequest) - MMI_HTTP_EVENT_CASE(PrepareResponse) - MMI_HTTP_EVENT_CASE(StartRequest) - MMI_HTTP_EVENT_CASE(StartResponse) - MMI_HTTP_EVENT_CASE(DoneNotification) - MMI_HTTP_EVENT_CASE(CancelRequest) - MMI_HTTP_EVENT_CASE(CancelResponse) - MMI_HTTP_EVENT_CASE(PauseRequest) - MMI_HTTP_EVENT_CASE(PauseResponse) - MMI_HTTP_EVENT_CASE(ResumeRequest) - MMI_HTTP_EVENT_CASE(ResumeResponse) - MMI_HTTP_EVENT_CASE(ExtensionNotification) - MMI_HTTP_EVENT_CASE(ClearContextRequest) - MMI_HTTP_EVENT_CASE(ClearContextResponse) - MMI_HTTP_EVENT_CASE(StatusRequest) - MMI_HTTP_EVENT_CASE(StatusResponse) - else { - LOG(ERROR) << "Unknown MMI Event"; - evhttp_send_error(req.curlReq, 402, NULL); - return; - } - - evhttp_send_reply(req.curlReq, 204, NULL, NULL); + if (!mmiEvent) { + evhttp_send_error(req.curlReq, 402, NULL); + return true; + } + + std::set::iterator monIter; + if (false) {} + MMI_HTTP_EVENT_CASE(NewContextRequest) + MMI_HTTP_EVENT_CASE(NewContextResponse) + MMI_HTTP_EVENT_CASE(PrepareRequest) + MMI_HTTP_EVENT_CASE(PrepareResponse) + MMI_HTTP_EVENT_CASE(StartRequest) + MMI_HTTP_EVENT_CASE(StartResponse) + MMI_HTTP_EVENT_CASE(DoneNotification) + MMI_HTTP_EVENT_CASE(CancelRequest) + MMI_HTTP_EVENT_CASE(CancelResponse) + MMI_HTTP_EVENT_CASE(PauseRequest) + MMI_HTTP_EVENT_CASE(PauseResponse) + MMI_HTTP_EVENT_CASE(ResumeRequest) + MMI_HTTP_EVENT_CASE(ResumeResponse) + MMI_HTTP_EVENT_CASE(ExtensionNotification) + MMI_HTTP_EVENT_CASE(ClearContextRequest) + MMI_HTTP_EVENT_CASE(ClearContextResponse) + MMI_HTTP_EVENT_CASE(StatusRequest) + MMI_HTTP_EVENT_CASE(StatusResponse) + else { + LOG(ERROR) << "Unknown MMI Event"; + evhttp_send_error(req.curlReq, 402, NULL); + return true; + } + + evhttp_send_reply(req.curlReq, 204, NULL, NULL); #if 0 - Event reqEvent = req; - reqEvent.type = Event::EXTERNAL; - bool scxmlStructFound = false; - - if (reqEvent.data.compound["header"].compound.find("Content-Type") != reqEvent.data.compound["header"].compound.end() && - boost::iequals(reqEvent.data.compound["header"].compound["Content-Type"].atom, "application/x-www-form-urlencoded")) { - std::stringstream ss(reqEvent.data.compound["content"].atom); - std::string term; - while(std::getline(ss, term, '&')) { - size_t split = term.find_first_of("="); - if (split != std::string::npos) { - std::string key = evhttp_decode_uri(term.substr(0, split).c_str()); - std::string value = evhttp_decode_uri(term.substr(split + 1).c_str()); - if (boost::iequals(key, "_scxmleventname")) { - reqEvent.name = value; - } else if (boost::iequals(key, "content")) { - reqEvent.initContent(value); - } else { - reqEvent.data.compound[key] = value; - reqEvent.params.insert(std::make_pair(key, value)); - } + Event reqEvent = req; + reqEvent.type = Event::EXTERNAL; + bool scxmlStructFound = false; + + if (reqEvent.data.compound["header"].compound.find("Content-Type") != reqEvent.data.compound["header"].compound.end() && + boost::iequals(reqEvent.data.compound["header"].compound["Content-Type"].atom, "application/x-www-form-urlencoded")) { + std::stringstream ss(reqEvent.data.compound["content"].atom); + std::string term; + while(std::getline(ss, term, '&')) { + size_t split = term.find_first_of("="); + if (split != std::string::npos) { + std::string key = evhttp_decode_uri(term.substr(0, split).c_str()); + std::string value = evhttp_decode_uri(term.substr(split + 1).c_str()); + if (boost::iequals(key, "_scxmleventname")) { + reqEvent.name = value; + } else if (boost::iequals(key, "content")) { + reqEvent.initContent(value); } else { - // this is most likely wrong - reqEvent.content = evhttp_decode_uri(term.c_str()); + reqEvent.data.compound[key] = value; + reqEvent.params.insert(std::make_pair(key, value)); } - } - } else { - if (reqEvent.data.compound["header"].compound.find("_scxmleventstruct") != reqEvent.data.compound["header"].compound.end()) { - // TODO: this looses all other information - reqEvent = Event::fromXML(evhttp_decode_uri(reqEvent.data.compound["header"].compound["_scxmleventstruct"].atom.c_str())); - scxmlStructFound = true; - } - if (reqEvent.data.compound["header"].compound.find("_scxmleventname") != reqEvent.data.compound["header"].compound.end()) { - reqEvent.name = evhttp_decode_uri(reqEvent.data.compound["header"].compound["_scxmleventname"].atom.c_str()); + } else { + // this is most likely wrong + reqEvent.content = evhttp_decode_uri(term.c_str()); } } - std::map::iterator headerIter = reqEvent.data.compound["header"].compound.begin(); - while(headerIter != reqEvent.data.compound["header"].compound.end()) { - reqEvent.data.compound[headerIter->first] = Data(evhttp_decode_uri(headerIter->second.atom.c_str()), Data::VERBATIM); - headerIter++; + } else { + if (reqEvent.data.compound["header"].compound.find("_scxmleventstruct") != reqEvent.data.compound["header"].compound.end()) { + // TODO: this looses all other information + reqEvent = Event::fromXML(evhttp_decode_uri(reqEvent.data.compound["header"].compound["_scxmleventstruct"].atom.c_str())); + scxmlStructFound = true; } - - - /// test532 - if (reqEvent.name.length() == 0) - reqEvent.name = "http." + req.data.compound.at("type").atom; - - if (!scxmlStructFound) { - // get content into event - reqEvent.data.compound["content"] = Data(req.content, Data::VERBATIM); + if (reqEvent.data.compound["header"].compound.find("_scxmleventname") != reqEvent.data.compound["header"].compound.end()) { + reqEvent.name = evhttp_decode_uri(reqEvent.data.compound["header"].compound["_scxmleventname"].atom.c_str()); } - - evhttp_send_reply(req.curlReq, 200, "OK", NULL); -#endif } - - void MMIEventServlet::downloadStarted(const URL& url) {} - - void MMIEventServlet::downloadCompleted(const URL& url) { - std::map >::iterator reqIter = _sendRequests.begin(); - while(reqIter != _sendRequests.end()) { - if (reqIter->second.first == url) { - _sendRequests.erase(reqIter); - return; - } - reqIter++; + std::map::iterator headerIter = reqEvent.data.compound["header"].compound.begin(); + while(headerIter != reqEvent.data.compound["header"].compound.end()) { + reqEvent.data.compound[headerIter->first] = Data(evhttp_decode_uri(headerIter->second.atom.c_str()), Data::VERBATIM); + headerIter++; + } + + + /// test532 + if (reqEvent.name.length() == 0) + reqEvent.name = "http." + req.data.compound.at("type").atom; + + if (!scxmlStructFound) { + // get content into event + reqEvent.data.compound["content"] = Data(req.content, Data::VERBATIM); + } + + evhttp_send_reply(req.curlReq, 200, "OK", NULL); +#endif + return true; +} + +void MMIEventServlet::downloadStarted(const URL& url) {} + +void MMIEventServlet::downloadCompleted(const URL& url) { + std::map >::iterator reqIter = _sendRequests.begin(); + while(reqIter != _sendRequests.end()) { + if (reqIter->second.first == url) { + _sendRequests.erase(reqIter); + return; } - assert(false); + reqIter++; } - - void MMIEventServlet::downloadFailed(const URL& url, int errorCode) { - - std::map >::iterator reqIter = _sendRequests.begin(); - while(reqIter != _sendRequests.end()) { - if (reqIter->second.first == url) { - Event failEvent; - failEvent.name = "error.communication"; + assert(false); +} + +void MMIEventServlet::downloadFailed(const URL& url, int errorCode) { + + std::map >::iterator reqIter = _sendRequests.begin(); + while(reqIter != _sendRequests.end()) { + if (reqIter->second.first == url) { + Event failEvent; + failEvent.name = "error.communication"; // returnEvent(failEvent); - - _sendRequests.erase(reqIter); - return; - } - reqIter++; + + _sendRequests.erase(reqIter); + return; } - assert(false); - + reqIter++; } - - + assert(false); + +} + + } \ No newline at end of file diff --git a/apps/w3c-mmi/MMIEventServlet.h b/apps/w3c-mmi/MMIEventServlet.h index 10adbc3..d760149 100644 --- a/apps/w3c-mmi/MMIEventServlet.h +++ b/apps/w3c-mmi/MMIEventServlet.h @@ -30,7 +30,7 @@ namespace uscxml { } /// HTTPServlet - void httpRecvRequest(const HTTPServer::Request& req); + bool httpRecvRequest(const HTTPServer::Request& req); void setURL(const std::string& url) { _url = url; } diff --git a/apps/w3c-mmi/im/MMISessionManager.cpp b/apps/w3c-mmi/im/MMISessionManager.cpp index 768a8a1..83d4dea 100644 --- a/apps/w3c-mmi/im/MMISessionManager.cpp +++ b/apps/w3c-mmi/im/MMISessionManager.cpp @@ -7,251 +7,290 @@ namespace uscxml { - using namespace Arabica::DOM; +using namespace Arabica::DOM; - MMISessionManager::MMISessionManager(Interpreter interpreter) : _protoInterpreter(interpreter) { - bool success = HTTPServer::registerServlet(interpreter.getName(), this); - assert(success); - _factory = new Factory(Factory::getInstance()); - _factory->registerIOProcessor(new MMIIOProcessor(this)); - } +MMISessionManager::MMISessionManager(Interpreter interpreter) : _protoInterpreter(interpreter) { + bool success = HTTPServer::registerServlet(interpreter.getName(), this); + assert(success); + _factory = new Factory(Factory::getInstance()); + _factory->registerIOProcessor(new MMIIOProcessor(this)); +} - MMISessionManager::~MMISessionManager() { - HTTPServer* httpServer = HTTPServer::getInstance(); - httpServer->unregisterServlet(this); - } - - void MMISessionManager::setupHTMLClient(const HTTPServer::Request& req) { - // open template file - HTTPServer::Reply reply(req); - URL templateURL(_protoInterpreter.getBaseURI().asString() + "/templates/mc-html.html"); - templateURL.download(true); - std::string templateContent = templateURL.getInContent(); - boost::replace_all(templateContent, "${im.url}", _url); - reply.content = templateContent; - HTTPServer::reply(reply); +MMISessionManager::~MMISessionManager() { + HTTPServer* httpServer = HTTPServer::getInstance(); + httpServer->unregisterServlet(this); +} + +void MMISessionManager::setupHTMLClient(const HTTPServer::Request& req) { + // open template file + HTTPServer::Reply reply(req); + URL templateURL(_protoInterpreter.getBaseURI().asString() + "/templates/mc-html.html"); + templateURL.download(true); + std::string templateContent = templateURL.getInContent(); + boost::replace_all(templateContent, "${im.url}", _url); + reply.content = templateContent; + HTTPServer::reply(reply); +} + +bool MMISessionManager::httpRecvRequest(const HTTPServer::Request& req) { + // is this an initial request from an HTML MC? + if (!req.data["query"]["token"] && // no token in query + !req.data["query"]["context"] && // no context in query + boost::iequals(req.data["type"].atom, "get") && // request type is GET + boost::icontains(req.data["header"]["Accept"].atom, "text/html") && // accepts html + req.content.length() == 0) { // no content + setupHTMLClient(req); + return true; } - void MMISessionManager::httpRecvRequest(const HTTPServer::Request& req) { - // is this an initial request from an HTML MC? - if (!req.data["query"]["token"] && // no token in query - boost::iequals(req.data["type"].atom, "get") && // request type is GET - boost::icontains(req.data["header"]["Accept"].atom, "text/html") && // accepts html - req.content.length() == 0) { // no content - setupHTMLClient(req); - return; - } - - // is this a comet longpolling request? - if (req.data["query"]["token"] && - boost::iequals(req.data["type"].atom, "get")) { + // is this a comet longpolling request? + if (boost::iequals(req.data["type"].atom, "get") && + (req.data["query"]["token"] || req.data["query"]["context"])) { + std::string token = req.data["query"]["token"].atom; + if (req.data["query"]["token"]) { std::string token = req.data["query"]["token"].atom; if (_tokens.find(token) != _tokens.end()) { MMISessionManager::CometMMISession* comet = static_cast(_tokens[token]); comet->longPoll(req); - return; + return true; + } else { + LOG(ERROR) << "No session for given token"; + } + } else if (req.data["query"]["context"]) { + std::string context = req.data["query"]["context"].atom; + if (_sessions.find(context) != _sessions.end()) { + MMISessionManager::CometMMISession* comet = static_cast(_sessions[context]); + comet->longPoll(req); + return true; + } else { + LOG(ERROR) << "No session for given context"; } } + } - // assume that there is an mmi event inside - NameSpacingParser* parser = NameSpacingParser::fromXML(req.data.compound.at("content").atom); - if (!parser) { - evhttp_send_error(req.curlReq, 204, NULL); - return; - } + // assume that there is an mmi event inside + Document mmiDoc = NameSpacingParser::fromXML(req.data.compound.at("content").atom).getDocument(); - Node mmiEvent = MMIEvent::getEventNode(parser->getDocument()); - if (!mmiEvent) { - evhttp_send_error(req.curlReq, 204, NULL); - return; - } + if (!mmiDoc) { + evhttp_send_error(req.curlReq, 204, NULL); + return true; + } - switch(MMIEvent::getType(mmiEvent)) { - case MMIEvent::NEWCONTEXTREQUEST: { - received(NewContextRequest::fromXML(mmiEvent), req.data["query"]["token"].atom); - evhttp_send_error(req.curlReq, 204, NULL); - break; - } - case MMIEvent::EXTENSIONNOTIFICATION: { - received(ExtensionNotification::fromXML(mmiEvent)); - evhttp_send_error(req.curlReq, 204, NULL); - break; - } - default: { - LOG(ERROR) << "Unknown MMI Event"; - evhttp_send_error(req.curlReq, 204, NULL); - break; - } - } + Node mmiEvent = MMIEvent::getEventNode(mmiDoc); + if (!mmiEvent) { + evhttp_send_error(req.curlReq, 204, NULL); + return true; } - - void MMISessionManager::received(const ExtensionNotification& mmiEvent) { - assert(_sessions.find(mmiEvent.context) != _sessions.end()); + + switch(MMIEvent::getType(mmiEvent)) { + case MMIEvent::NEWCONTEXTREQUEST: { + received(NewContextRequest::fromXML(mmiEvent), req.data["query"]["token"].atom); + evhttp_send_error(req.curlReq, 204, NULL); + break; + } + case MMIEvent::EXTENSIONNOTIFICATION: { + received(ExtensionNotification::fromXML(mmiEvent)); + evhttp_send_error(req.curlReq, 204, NULL); + break; + } + case MMIEvent::DONENOTIFICATION: { + received(DoneNotification::fromXML(mmiEvent)); + evhttp_send_error(req.curlReq, 204, NULL); + break; + } + case MMIEvent::STARTRESPONSE: { + evhttp_send_error(req.curlReq, 204, NULL); + break; + } + default: { + LOG(ERROR) << "Unknown MMI Event: " << ATTR(mmiEvent, "localName"); + evhttp_send_error(req.curlReq, 204, NULL); + break; + } + } + return true; +} + +void MMISessionManager::received(const ExtensionNotification& mmiEvent) { + if(_sessions.find(mmiEvent.context) != _sessions.end()) { _sessions[mmiEvent.context]->_interpreter.receive(mmiEvent); + } else { + LOG(ERROR) << "No session for given context"; } - - void MMISessionManager::received(const NewContextRequest& mmiEvent, const std::string& token) { - - // copy DOM from prototype instance - Arabica::DOM::DOMImplementation domFactory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); - Arabica::DOM::Document newDOM = domFactory.createDocument("", "", 0); - newDOM.appendChild(newDOM.importNode(_protoInterpreter.getDocument().getDocumentElement(), true)); - - // instantiate new interpreter and name it after the context - std::string contextId = Interpreter::getUUID(); - Interpreter interpreter = Interpreter::fromDOM(newDOM); - interpreter.setFactory(_factory); - interpreter.setName(contextId); - interpreter.setNameSpaceInfo(_protoInterpreter.getNameSpaceInfo()); - interpreter.setBaseURI(_protoInterpreter.getBaseURI().asString()); - - MMISession* session; - - if (token.length() > 0) { - session = new MMISessionManager::CometMMISession(); - static_cast(session)->_token = token; - _tokens[token] = session; - } else { - // todo handle other cases - session = new MMISessionManager::CometMMISession(); - } - session->_interpreter = interpreter; - - // save interpreter - _sessions[contextId] = session; - - interpreter.start(); - interpreter.receive(mmiEvent); +} +void MMISessionManager::received(const DoneNotification& mmiEvent) { + if(_sessions.find(mmiEvent.context) != _sessions.end()) { + _sessions[mmiEvent.context]->_interpreter.receive(mmiEvent); + } else { + LOG(ERROR) << "No session for given context"; } +} + +void MMISessionManager::received(const NewContextRequest& mmiEvent, const std::string& token) { + + // copy DOM from prototype instance + Arabica::DOM::DOMImplementation domFactory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); + Arabica::DOM::Document newDOM = domFactory.createDocument("", "", 0); + newDOM.appendChild(newDOM.importNode(_protoInterpreter.getDocument().getDocumentElement(), true)); + + // instantiate new interpreter and name it after the context + std::string contextId = Interpreter::getUUID(); + Interpreter interpreter = Interpreter::fromDOM(newDOM); + interpreter.setFactory(_factory); + interpreter.setName(contextId); + interpreter.setNameSpaceInfo(_protoInterpreter.getNameSpaceInfo()); + interpreter.setBaseURI(_protoInterpreter.getBaseURI().asString()); - void MMISessionManager::received(const NewContextResponse& mmiEvent) { + MMISession* session; + + if (token.length() > 0) { + session = new MMISessionManager::CometMMISession(); + static_cast(session)->_token = token; + _tokens[token] = session; + } else { + // todo handle other cases + session = new MMISessionManager::CometMMISession(); } + session->_interpreter = interpreter; + + // save interpreter + _sessions[contextId] = session; + + interpreter.start(); + interpreter.receive(mmiEvent); + +} - void MMISessionManager::send(const std::string& name, const SendRequest& req) { - assert(_sessions.find(name) != _sessions.end()); - _sessions[name]->send(req); +void MMISessionManager::received(const NewContextResponse& mmiEvent, const std::string& token) { + if (_tokens.find(token) != _tokens.end()) { + _tokens.erase(token); } - - void MMISessionManager::CometMMISession::send(const SendRequest& req) { - tthread::lock_guard lock(_mutex); - if (!_longPollingReq) { - _outQueue.push_back(req); - return; +} + +void MMISessionManager::send(const std::string& name, const SendRequest& req) { + assert(_sessions.find(name) != _sessions.end()); + _sessions[name]->send(req); +} + +void MMISessionManager::CometMMISession::send(const SendRequest& req) { + tthread::lock_guard lock(_mutex); + if (!_longPollingReq) { + _outQueue.push_back(req); + return; + } + + if (req.dom) { + std::stringstream ss; + Node mmiEvent = MMIEvent::getEventNode(req.dom); + HTTPServer::Reply reply(_longPollingReq); + + switch (MMIEvent::getType(mmiEvent)) { + case MMIEvent::NEWCONTEXTRESPONSE: { + NewContextResponse response = NewContextResponse::fromXML(mmiEvent); + ss << response.toXML(); + reply.content = ss.str(); + break; } - - if (req.dom) { - std::stringstream ss; - Node mmiEvent = MMIEvent::getEventNode(req.dom); - HTTPServer::Reply reply(_longPollingReq); - - switch (MMIEvent::getType(mmiEvent)) { - case MMIEvent::NEWCONTEXTRESPONSE: { - NewContextResponse response = NewContextResponse::fromXML(mmiEvent); - ss << response.toXML(); - reply.content = ss.str(); - break; - } - case MMIEvent::STARTREQUEST: { - StartRequest request = StartRequest::fromXML(mmiEvent); - std::cout << mmiEvent << std::endl; - ss << request.toXML(); - reply.content = ss.str(); - break; - } - default: - break; - } - reply.headers["Content-Type"] = "application/xml"; - HTTPServer::reply(reply); - _longPollingReq = HTTPServer::Request(); + case MMIEvent::STARTREQUEST: { + StartRequest request = StartRequest::fromXML(mmiEvent); + ss << request.toXML(); + reply.content = ss.str(); + break; } - } - - void MMISessionManager::CometMMISession::receive(const Arabica::DOM::Node& msg) { - - } - - void MMISessionManager::CometMMISession::longPoll(const HTTPServer::Request& req) { - tthread::lock_guard lock(_mutex); - if (_longPollingReq) - evhttp_send_error(_longPollingReq.curlReq, 204, NULL); - _longPollingReq = req; - if (!_outQueue.empty()) { - send(_outQueue.front()); - _outQueue.pop_front(); + default: + break; } + reply.headers["Content-Type"] = "application/xml"; + HTTPServer::reply(reply); + _longPollingReq = HTTPServer::Request(); } +} - boost::shared_ptr MMISessionManager::MMIIOProcessor::create(InterpreterImpl* interpreter) { - boost::shared_ptr ioProc = boost::shared_ptr(new MMISessionManager::MMIIOProcessor(_sessionManager)); - return ioProc; - } - - Data MMISessionManager::MMIIOProcessor::getDataModelVariables() { - Data data; - return data; +void MMISessionManager::CometMMISession::receive(const Arabica::DOM::Node& msg) { + +} + +void MMISessionManager::CometMMISession::longPoll(const HTTPServer::Request& req) { + tthread::lock_guard lock(_mutex); + if (_longPollingReq) + evhttp_send_error(_longPollingReq.curlReq, 204, NULL); + _longPollingReq = req; + if (!_outQueue.empty()) { + send(_outQueue.front()); + _outQueue.pop_front(); } - - void MMISessionManager::MMIIOProcessor::send(const SendRequest& req) { - SendRequest reqCopy(req); - - if (req.dom) { - Arabica::DOM::Node mmiEvent = MMIEvent::getEventNode(req.dom); - if (!mmiEvent || !mmiEvent.getNodeType() == Node_base::ELEMENT_NODE) - return; - - Arabica::DOM::Element mmiElem = Arabica::DOM::Element(mmiEvent); - switch (MMIEvent::getType(mmiEvent)) { - case MMIEvent::STARTRESPONSE: - case MMIEvent::PREPARERESPONSE: - case MMIEvent::PAUSERESPONSE: - case MMIEvent::RESUMERESPONSE: - case MMIEvent::CANCELRESPONSE: - case MMIEvent::DONENOTIFICATION: - case MMIEvent::NEWCONTEXTRESPONSE: - case MMIEvent::CLEARCONTEXTRESPONSE: - case MMIEvent::STATUSRESPONSE: { - // all of the above have a status - if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Status")) { - mmiElem.setAttributeNS(MMIEvent::nameSpace, "Status", "Success"); - } - } - case MMIEvent::PAUSEREQUEST: - case MMIEvent::RESUMEREQUEST: - case MMIEvent::CANCELREQUEST: - case MMIEvent::CLEARCONTEXTREQUEST: - case MMIEvent::STATUSREQUEST: { - // all of the above have a context - if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Context")) { - mmiElem.setAttributeNS(MMIEvent::nameSpace, "Context", _interpreter->getName()); - } - } - default: { - if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Source")) { - mmiElem.setAttributeNS(MMIEvent::nameSpace, "Source", _sessionManager->getURL()); - } - if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Target")) { - if (boost::starts_with(_interpreter->getCurrentEvent().name, "mmi.")) { - mmiElem.setAttributeNS(MMIEvent::nameSpace, "Target", _interpreter->getCurrentEvent().origin); - } - } - if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "RequestID")) { - if (boost::starts_with(_interpreter->getCurrentEvent().name, "mmi.")) { - mmiElem.setAttributeNS(MMIEvent::nameSpace, "RequestID", _interpreter->getCurrentEvent().sendid); - } - } +} + +boost::shared_ptr MMISessionManager::MMIIOProcessor::create(InterpreterImpl* interpreter) { + boost::shared_ptr ioProc = boost::shared_ptr(new MMISessionManager::MMIIOProcessor(_sessionManager)); + return ioProc; +} + +Data MMISessionManager::MMIIOProcessor::getDataModelVariables() { + Data data; + return data; +} + +void MMISessionManager::MMIIOProcessor::send(const SendRequest& req) { + SendRequest reqCopy(req); + + if (req.dom) { + Arabica::DOM::Node mmiEvent = MMIEvent::getEventNode(req.dom); + if (!mmiEvent || !mmiEvent.getNodeType() == Node_base::ELEMENT_NODE) + return; + + Arabica::DOM::Element mmiElem = Arabica::DOM::Element(mmiEvent); + switch (MMIEvent::getType(mmiEvent)) { + case MMIEvent::STARTRESPONSE: + case MMIEvent::PREPARERESPONSE: + case MMIEvent::PAUSERESPONSE: + case MMIEvent::RESUMERESPONSE: + case MMIEvent::CANCELRESPONSE: + case MMIEvent::DONENOTIFICATION: + case MMIEvent::NEWCONTEXTRESPONSE: + case MMIEvent::CLEARCONTEXTRESPONSE: + case MMIEvent::STATUSRESPONSE: { + // all of the above have a status + if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Status")) { + mmiElem.setAttributeNS(MMIEvent::nameSpace, "Status", "Success"); + } + } + case MMIEvent::PAUSEREQUEST: + case MMIEvent::RESUMEREQUEST: + case MMIEvent::CANCELREQUEST: + case MMIEvent::CLEARCONTEXTREQUEST: + case MMIEvent::STATUSREQUEST: { + // all of the above have a context + if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Context")) { + mmiElem.setAttributeNS(MMIEvent::nameSpace, "Context", _interpreter->getName()); + } + } + default: { + if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Source")) { + mmiElem.setAttributeNS(MMIEvent::nameSpace, "Source", _sessionManager->getURL()); + } + if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "Target")) { + if (boost::starts_with(_interpreter->getCurrentEvent().name, "mmi.")) { + mmiElem.setAttributeNS(MMIEvent::nameSpace, "Target", _interpreter->getCurrentEvent().origin); } } - - if (MMIEvent::getType(mmiEvent) == MMIEvent::EXTENSIONNOTIFICATION && !mmiElem.hasAttribute("Name") && req.name.length() > 0) { - mmiElem.setAttribute("Name", req.name); + if (!mmiElem.hasAttributeNS(MMIEvent::nameSpace, "RequestID")) { + if (boost::starts_with(_interpreter->getCurrentEvent().name, "mmi.")) { + mmiElem.setAttributeNS(MMIEvent::nameSpace, "RequestID", _interpreter->getCurrentEvent().sendid); + } } - // use session mgr to dispatch to session - - _sessionManager->send(_interpreter->getName(), reqCopy); } - + } + + if (MMIEvent::getType(mmiEvent) == MMIEvent::EXTENSIONNOTIFICATION && !mmiElem.hasAttribute("Name") && req.name.length() > 0) { + mmiElem.setAttribute("Name", req.name); + } + // use session mgr to dispatch to session + + _sessionManager->send(_interpreter->getName(), reqCopy); } +} + } \ No newline at end of file diff --git a/apps/w3c-mmi/im/MMISessionManager.h b/apps/w3c-mmi/im/MMISessionManager.h index 2ca3d0c..d3b0c48 100644 --- a/apps/w3c-mmi/im/MMISessionManager.h +++ b/apps/w3c-mmi/im/MMISessionManager.h @@ -21,7 +21,6 @@ namespace uscxml { class CometMMISession : public MMISession { public: - HTTPServer::Request _request; std::deque _outQueue; HTTPServer::Request _longPollingReq; std::string _token; @@ -51,7 +50,7 @@ namespace uscxml { void send(const std::string& name, const SendRequest& req); /// HTTPServlet - void httpRecvRequest(const HTTPServer::Request& req); + bool httpRecvRequest(const HTTPServer::Request& req); void setURL(const std::string& url) { _url = url; } @@ -63,8 +62,9 @@ namespace uscxml { protected: void received(const NewContextRequest& mmiEvent, const std::string& token = ""); - void received(const NewContextResponse& mmiEvent); + void received(const NewContextResponse& mmiEvent, const std::string& token = ""); void received(const ExtensionNotification& mmiEvent); + void received(const DoneNotification& mmiEvent); void setupHTMLClient(const HTTPServer::Request& req); diff --git a/apps/w3c-mmi/im/uscxml-interaction-manager.cpp b/apps/w3c-mmi/im/uscxml-interaction-manager.cpp index a7162cc..13189fc 100644 --- a/apps/w3c-mmi/im/uscxml-interaction-manager.cpp +++ b/apps/w3c-mmi/im/uscxml-interaction-manager.cpp @@ -169,7 +169,7 @@ int main(int argc, char** argv) { // intialize http server on given port HTTPServer::getInstance(port); - + LOG(INFO) << "Processing " << argv[optind]; Interpreter protoInterpreter = Interpreter::fromURI(argv[optind]); if (protoInterpreter) { diff --git a/apps/w3c-mmi/mc/uscxml-modality-component.cpp b/apps/w3c-mmi/mc/uscxml-modality-component.cpp index afe4e7f..39f81d7 100644 --- a/apps/w3c-mmi/mc/uscxml-modality-component.cpp +++ b/apps/w3c-mmi/mc/uscxml-modality-component.cpp @@ -170,7 +170,7 @@ int main(int argc, char** argv) { // intialize http server on given port HTTPServer::getInstance(port); - + LOG(INFO) << "Processing " << argv[optind]; Interpreter interpreter = Interpreter::fromURI(argv[optind]); if (interpreter) { diff --git a/config.h.in b/config.h.in index a66a825..250bb1f 100644 --- a/config.h.in +++ b/config.h.in @@ -72,4 +72,7 @@ #cmakedefine HAS_EXECINFO_H #cmakedefine HAS_DLFCN_H +/** Binaries we found */ +#cmakedefine HAS_XDG_OPEN + #endif \ No newline at end of file diff --git a/contrib/cmake/BinaryExists.cmake b/contrib/cmake/BinaryExists.cmake new file mode 100644 index 0000000..0300f98 --- /dev/null +++ b/contrib/cmake/BinaryExists.cmake @@ -0,0 +1 @@ +find_program(HAS_XDG_OPEN "xdg-open") \ No newline at end of file diff --git a/contrib/cmake/CrossCompile-Android.cmake b/contrib/cmake/CrossCompile-Android.cmake new file mode 100644 index 0000000..37c9ad1 --- /dev/null +++ b/contrib/cmake/CrossCompile-Android.cmake @@ -0,0 +1,1125 @@ +# ------------------------------------------------------------------------------ +# Android CMake toolchain file, for use with the Android NDK r5-r8 +# Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended). +# See home page: http://code.google.com/p/android-cmake/ +# +# The file is mantained by the OpenCV project. And also can be found at +# http://code.opencv.org/projects/opencv/repository/revisions/master/changes/android/android.toolchain.cmake +# +# Usage Linux: +# $ export ANDROID_NDK=/absolute/path/to/the/android-ndk +# $ mkdir build && cd build +# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. +# $ make -j8 +# +# Usage Linux (using standalone toolchain): +# $ export ANDROID_STANDALONE_TOOLCHAIN=/absolute/path/to/android-toolchain +# $ mkdir build && cd build +# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. +# $ make -j8 +# +# Usage Windows: +# You need native port of make to build your project. +# Android NDK r7 (or newer) already has make.exe on board. +# For older NDK you have to install it separately. +# For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm +# +# $ SET ANDROID_NDK=C:\absolute\path\to\the\android-ndk +# $ mkdir build && cd build +# $ cmake.exe -G"MinGW Makefiles" +# -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake +# -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" .. +# $ "%ANDROID_NDK%\prebuilt\windows\bin\make.exe" +# +# +# Options (can be set as cmake parameters: -D=): +# ANDROID_NDK=/opt/android-ndk - path to the NDK root. +# Can be set as environment variable. Can be set only at first cmake run. +# +# ANDROID_STANDALONE_TOOLCHAIN=/opt/android-toolchain - path to the +# standalone toolchain. This option is not used if full NDK is found +# (ignored if ANDROID_NDK is set). +# Can be set as environment variable. Can be set only at first cmake run. +# +# ANDROID_ABI=armeabi-v7a - specifies the target Application Binary +# Interface (ABI). This option nearly matches to the APP_ABI variable +# used by ndk-build tool from Android NDK. +# +# Possible targets are: +# "armeabi" - matches to the NDK ABI with the same name. +# See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation. +# "armeabi-v7a" - matches to the NDK ABI with the same name. +# See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation. +# "armeabi-v7a with NEON" - same as armeabi-v7a, but +# sets NEON as floating-point unit +# "armeabi-v7a with VFPV3" - same as armeabi-v7a, but +# sets VFPV3 as floating-point unit (has 32 registers instead of 16). +# "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP. +# "x86" - matches to the NDK ABI with the same name. +# See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation. +# "mips" - matches to the NDK ABI with the same name +# (not testes on real devices) +# +# ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for. +# Option is read-only when standalone toolchain used. +# +# ANDROID_FORCE_ARM_BUILD=OFF - set true to generate 32-bit ARM instructions +# instead of Thumb-1. Is not available for "x86" (inapplicable) and +# "armeabi-v6 with VFP" (forced) ABIs. +# +# ANDROID_NO_UNDEFINED=ON - set true to show all undefined symbols as linker +# errors even if they are not used. +# +# ANDROID_SO_UNDEFINED=OFF - set true to allow undefined symbols in shared +# libraries. Automatically turned on for NDK r5x and r6x due to GLESv2 +# problems. +# +# LIBRARY_OUTPUT_PATH_ROOT=${CMAKE_SOURCE_DIR} - where to output binary +# files. See additional details below. +# +# ANDROID_SET_OBSOLETE_VARIABLES=ON - it set, then toolchain defines some +# obsolete variables which were set by previous versions of this file for +# backward compatibility. +# +# +# What?: +# android-cmake toolchain searches for NDK/toolchain in the following order: +# ANDROID_NDK - cmake parameter +# ANDROID_NDK - environment variable +# ANDROID_STANDALONE_TOOLCHAIN - cmake parameter +# ANDROID_STANDALONE_TOOLCHAIN - environment variable +# ANDROID_NDK - default locations +# ANDROID_STANDALONE_TOOLCHAIN - default locations +# +# Make sure to do the following in your scripts: +# SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" ) +# SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" ) +# The flags will be prepopulated with critical flags, so don't loose them. +# Also be aware that toolchain also sets configuration-specific compiler +# flags and linker flags. +# +# ANDROID and BUILD_ANDROID will be set to true, you may test any of these +# variables to make necessary Android-specific configuration changes. +# +# Also ARMEABI or ARMEABI_V7A or X86 will be set true, mutually exclusive. +# NEON option will be set true if VFP is set to NEON. +# +# LIBRARY_OUTPUT_PATH_ROOT should be set in cache to determine where Android +# libraries will be installed. +# Default is ${CMAKE_SOURCE_DIR}, and the android libs will always be +# under the ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME} +# (depending on the target ABI). This is convenient for Android packaging. +# +# Authors: +# Ethan Rublee ethan.ruble@gmail.com +# Andrey Kamaev andrey.kamaev@itseez.com +# +# Change Log: +# - initial version December 2010 +# - modified April 2011 +# [+] added possibility to build with NDK (without standalone toolchain) +# [+] support cross-compilation on Windows (native, no cygwin support) +# [+] added compiler option to force "char" type to be signed +# [+] added toolchain option to compile to 32-bit ARM instructions +# [+] added toolchain option to disable SWIG search +# [+] added platform "armeabi-v7a with VFPV3" +# [~] ARM_TARGETS renamed to ARM_TARGET +# [+] EXECUTABLE_OUTPUT_PATH is set by toolchain (required on Windows) +# [~] Fixed bug with ANDROID_API_LEVEL variable +# [~] turn off SWIG search if it is not found first time +# - modified May 2011 +# [~] ANDROID_LEVEL is renamed to ANDROID_API_LEVEL +# [+] ANDROID_API_LEVEL is detected by toolchain if not specified +# [~] added guard to prevent changing of output directories on the first +# cmake pass +# [~] toolchain exits with error if ARM_TARGET is not recognized +# - modified June 2011 +# [~] default NDK path is updated for version r5c +# [+] variable CMAKE_SYSTEM_PROCESSOR is set based on ARM_TARGET +# [~] toolchain install directory is added to linker paths +# [-] removed SWIG-related stuff from toolchain +# [+] added macro find_host_package, find_host_program to search +# packages/programs on the host system +# [~] fixed path to STL library +# - modified July 2011 +# [~] fixed options caching +# [~] search for all supported NDK versions +# [~] allowed spaces in NDK path +# - modified September 2011 +# [~] updated for NDK r6b +# - modified November 2011 +# [*] rewritten for NDK r7 +# [+] x86 toolchain support (experimental) +# [+] added "armeabi-v6 with VFP" ABI for ARMv6 processors. +# [~] improved compiler and linker flags management +# [+] support different build flags for Release and Debug configurations +# [~] by default compiler flags the same as used by ndk-build (but only +# where reasonable) +# [~] ANDROID_NDK_TOOLCHAIN_ROOT is splitted to ANDROID_STANDALONE_TOOLCHAIN +# and ANDROID_TOOLCHAIN_ROOT +# [~] ARM_TARGET is renamed to ANDROID_ABI +# [~] ARMEABI_NDK_NAME is renamed to ANDROID_NDK_ABI_NAME +# [~] ANDROID_API_LEVEL is renamed to ANDROID_NATIVE_API_LEVEL +# - modified January 2012 +# [+] added stlport_static support (experimental) +# [+] added special check for cygwin +# [+] filtered out hidden files (starting with .) while globbing inside NDK +# [+] automatically applied GLESv2 linkage fix for NDK revisions 5-6 +# [+] added ANDROID_GET_ABI_RAWNAME to get NDK ABI names by CMake flags +# - modified February 2012 +# [+] updated for NDK r7b +# [~] fixed cmake try_compile() command +# [~] Fix for missing install_name_tool on OS X +# - modified March 2012 +# [~] fixed incorrect C compiler flags +# [~] fixed CMAKE_SYSTEM_PROCESSOR change on ANDROID_ABI change +# [+] improved toolchain loading speed +# [+] added assembler language support (.S) +# [+] allowed preset search paths and extra search suffixes +# - modified April 2012 +# [+] updated for NDK r7c +# [~] fixed most of problems with compiler/linker flags and caching +# [+] added option ANDROID_FUNCTION_LEVEL_LINKING +# - modified May 2012 +# [+] updated for NDK r8 +# [+] added mips architecture support +# - modified August 2012 +# [+] updated for NDK r8b +# [~] all intermediate files generated by toolchain are moved into CMakeFiles +# [~] libstdc++ and libsupc are removed from explicit link libraries +# ------------------------------------------------------------------------------ + +cmake_minimum_required( VERSION 2.6.3 ) + +if( DEFINED CMAKE_CROSSCOMPILING ) + # subsequent toolchain loading is not really needed + return() +endif() + +get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) +if( _CMAKE_IN_TRY_COMPILE ) + include( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL ) +endif() + +# this one is important +set( CMAKE_SYSTEM_NAME Linux ) +# this one not so much +set( CMAKE_SYSTEM_VERSION 1 ) + +set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) +if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS) + if( CMAKE_HOST_WIN32 ) + file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) + set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}/android-ndk" "$ENV{SystemDrive}/NVPACK/android-ndk" ) + else() + file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS ) + set( ANDROID_NDK_SEARCH_PATHS /opt/android-ndk "${ANDROID_NDK_SEARCH_PATHS}/NVPACK/android-ndk" ) + endif() +endif() +if(NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH) + set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain ) +endif() + +set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" ) +set( ANDROID_SUPPORTED_ABIS_x86 "x86" ) +set( ANDROID_SUPPORTED_ABIS_mipsel "mips" ) + +set( ANDROID_DEFAULT_NDK_API_LEVEL 8 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 ) + + +macro( __LIST_FILTER listvar regex ) + if( ${listvar} ) + foreach( __val ${${listvar}} ) + if( __val MATCHES "${regex}" ) + list( REMOVE_ITEM ${listvar} "${__val}" ) + endif() + endforeach() + endif() +endmacro() + +macro( __INIT_VARIABLE var_name ) + set( __test_path 0 ) + foreach( __var ${ARGN} ) + if( __var STREQUAL "PATH" ) + set( __test_path 1 ) + break() + endif() + endforeach() + if( __test_path AND NOT EXISTS "${${var_name}}" ) + unset( ${var_name} CACHE ) + endif() + if( "${${var_name}}" STREQUAL "" ) + set( __values 0 ) + foreach( __var ${ARGN} ) + if( __var STREQUAL "VALUES" ) + set( __values 1 ) + elseif( NOT __var STREQUAL "PATH" ) + set( __obsolete 0 ) + if( __var MATCHES "^OBSOLETE_.*$" ) + string( REPLACE "OBSOLETE_" "" __var "${__var}" ) + set( __obsolete 1 ) + endif() + if( __var MATCHES "^ENV_.*$" ) + string( REPLACE "ENV_" "" __var "${__var}" ) + set( __value "$ENV{${__var}}" ) + elseif( DEFINED ${__var} ) + set( __value "${${__var}}" ) + else() + if( __values ) + set( __value "${__var}" ) + else() + set( __value "" ) + endif() + endif() + if( NOT "${__value}" STREQUAL "" ) + if( __test_path ) + if( EXISTS "${__value}" ) + set( ${var_name} "${__value}" ) + if( __obsolete ) + message( WARNING "Using value of obsolete variable ${__var} as initial value for ${var_name}. Please note, that ${__var} can be completely removed in future versions of the toolchain." ) + endif() + break() + endif() + else() + set( ${var_name} "${__value}" ) + if( __obsolete ) + message( WARNING "Using value of obsolete variable ${__var} as initial value for ${var_name}. Please note, that ${__var} can be completely removed in future versions of the toolchain." ) + endif() + break() + endif() + endif() + endif() + endforeach() + unset( __value ) + unset( __values ) + unset( __obsolete ) + endif() + unset( __test_path ) +endmacro() + +macro( __DETECT_NATIVE_API_LEVEL _var _path ) + SET( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*$" ) + FILE( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) + if( NOT __apiFileContent ) + message( SEND_ERROR "Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) + endif() + string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" ) + unset( __apiFileContent ) + unset( __ndkApiLevelRegex ) +endmacro() + +macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) + file( GLOB __gccExePath "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) + __LIST_FILTER( __gccExePath "bin/[.].*-gcc${TOOL_OS_SUFFIX}$" ) + list( LENGTH __gccExePath __gccExePathsCount ) + if( NOT __gccExePathsCount EQUAL 1 ) + message( WARNING "Could not uniquely determine machine name for compiler from ${_root}." ) + set( ${_var} "" ) + else() + get_filename_component( __gccExeName "${__gccExePath}" NAME_WE ) + string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" ) + endif() + unset( __gccExePath ) + unset( __gccExePathsCount ) + unset( __gccExeName ) +endmacro() + +macro( __COPY_IF_DIFFERENT _source _destination ) + execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${_source}" "${_destination}" RESULT_VARIABLE __fileCopyProcess ) + if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${_destination}") + message( SEND_ERROR "Failed copying of ${_source} to the ${_destination}" ) + endif() + unset( __fileCopyProcess ) +endmacro() + + +# stl version: by default gnustl_static will be used +set( ANDROID_USE_STLPORT FALSE CACHE BOOL "Experimental: use stlport_static instead of gnustl_static") +mark_as_advanced( ANDROID_USE_STLPORT ) + +# fight against cygwin +set( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools") +mark_as_advanced( ANDROID_FORBID_SYGWIN ) +if( ANDROID_FORBID_SYGWIN ) + if( CYGWIN ) + message( FATAL_ERROR "Android NDK and android-cmake toolchain are not welcome Cygwin. It is unlikely that this cmake toolchain will work under cygwin. But if you want to try then you can set cmake variable ANDROID_FORBID_SYGWIN to FALSE and rerun cmake." ) + endif() + + if( CMAKE_HOST_WIN32 ) + # remove cygwin from PATH + set( __new_path "$ENV{PATH}") + __LIST_FILTER( __new_path "cygwin" ) + set(ENV{PATH} "${__new_path}") + unset(__new_path) + endif() +endif() + +# detect current host platform +set( TOOL_OS_SUFFIX "" ) +if( CMAKE_HOST_APPLE ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86" ) +elseif( CMAKE_HOST_WIN32 ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "windows" ) + set( TOOL_OS_SUFFIX ".exe" ) +elseif( CMAKE_HOST_UNIX ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86" ) +else() + message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) +endif() + +# see if we have path to Android NDK +__INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK ) +if( NOT ANDROID_NDK ) + # see if we have path to Android standalone toolchain + __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN OBSOLETE_ANDROID_NDK_TOOLCHAIN_ROOT OBSOLETE_ENV_ANDROID_NDK_TOOLCHAIN_ROOT ) + + if( NOT ANDROID_STANDALONE_TOOLCHAIN ) + #try to find Android NDK in one of the the default locations + set( __ndkSearchPaths ) + foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} ) + foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} ) + list( APPEND __ndkSearchPaths "${__ndkSearchPath}${suffix}" ) + endforeach() + endforeach() + __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} ) + unset( __ndkSearchPaths ) + + if( ANDROID_NDK ) + message( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" ) + message( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" ) + else() + #try to find Android standalone toolchain in one of the the default locations + __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH ) + + if( ANDROID_STANDALONE_TOOLCHAIN ) + message( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" ) + message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" ) + endif( ANDROID_STANDALONE_TOOLCHAIN ) + endif( ANDROID_NDK ) + endif( NOT ANDROID_STANDALONE_TOOLCHAIN ) +endif( NOT ANDROID_NDK ) + +# remember found paths +if( ANDROID_NDK ) + get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE ) + # try to detect change + if( CMAKE_AR ) + string( LENGTH "${ANDROID_NDK}" __length ) + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath ) + if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK ) + message( FATAL_ERROR "It is not possible to change path to the NDK on subsequent run." ) + endif() + unset( __androidNdkPreviousPath ) + unset( __length ) + endif() + set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" ) + set( BUILD_WITH_ANDROID_NDK True ) +elseif( ANDROID_STANDALONE_TOOLCHAIN ) + get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE ) + # try to detect change + if( CMAKE_AR ) + string( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length ) + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidStandaloneToolchainPreviousPath ) + if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN ) + message( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." ) + endif() + unset( __androidStandaloneToolchainPreviousPath ) + unset( __length ) + endif() + set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" ) + set( BUILD_WITH_STANDALONE_TOOLCHAIN True ) +else() + list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH) + message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolcahin. + You should either set an environment variable: + export ANDROID_NDK=~/my-android-ndk + or + export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain + or put the toolchain or NDK in the default path: + sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH} + sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" ) +endif() + +# get all the details about standalone toolchain +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" ) + set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) + set( __availableToolchains "standalone" ) + __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" ) + if( NOT __availableToolchainMachines ) + message( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." ) + endif() + if( __availableToolchainMachines MATCHES i686 ) + set( __availableToolchainArchs "x86" ) + elseif( __availableToolchainMachines MATCHES arm ) + set( __availableToolchainArchs "arm" ) + elseif( __availableToolchainMachines MATCHES mipsel ) + set( __availableToolchainArchs "mipsel" ) + endif() + if( ANDROID_COMPILER_VERSION ) + # do not run gcc every time because it is relatevely expencive + set( __availableToolchainCompilerVersions "${ANDROID_COMPILER_VERSION}" ) + else() + execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" --version + OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) + endif() +endif() + +# get all the details about NDK +if( BUILD_WITH_ANDROID_NDK ) + file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" ) + string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) + file( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" ) + __LIST_FILTER( __availableToolchains "^[.]" ) + set( __availableToolchainMachines "" ) + set( __availableToolchainArchs "" ) + set( __availableToolchainCompilerVersions "" ) + foreach( __toolchain ${__availableToolchains} ) + __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK}/toolchains/${__toolchain}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + if( __machine ) + string( REGEX MATCH "[0-9]+[.][0-9]+[.]*[0-9]*$" __version "${__toolchain}" ) + string( REGEX MATCH "^[^-]+" __arch "${__toolchain}" ) + list( APPEND __availableToolchainMachines "${__machine}" ) + list( APPEND __availableToolchainArchs "${__arch}" ) + list( APPEND __availableToolchainCompilerVersions "${__version}" ) + else() + list( REMOVE_ITEM __availableToolchains "${__toolchain}" ) + endif() + endforeach() + if( NOT __availableToolchains ) + message( FATAL_ERROR "Could not any working toolchain in the NDK. Probably your Android NDK is broken." ) + endif() +endif() + +# build list of available ABIs +if( NOT ANDROID_SUPPORTED_ABIS ) + set( ANDROID_SUPPORTED_ABIS "" ) + set( __uniqToolchainArchNames ${__availableToolchainArchs} ) + list( REMOVE_DUPLICATES __uniqToolchainArchNames ) + list( SORT __uniqToolchainArchNames ) + foreach( __arch ${__uniqToolchainArchNames} ) + list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) + endforeach() + unset( __uniqToolchainArchNames ) + if( NOT ANDROID_SUPPORTED_ABIS ) + message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) + endif() +endif() + +# choose target ABI +__INIT_VARIABLE( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${ANDROID_SUPPORTED_ABIS} ) +# verify that target ABI is supported +list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx ) +if( __androidAbiIdx EQUAL -1 ) + string( REPLACE ";" "\", \"", PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" ) + message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain. + Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\" + " ) +endif() +unset( __androidAbiIdx ) + +# remember target ABI +set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) + +# set target ABI options +if( ANDROID_ABI STREQUAL "x86" ) + set( X86 true ) + set( ANDROID_NDK_ABI_NAME "x86" ) + set( ANDROID_ARCH_NAME "x86" ) + set( ANDROID_ARCH_FULLNAME "x86" ) + set( CMAKE_SYSTEM_PROCESSOR "i686" ) +elseif( ANDROID_ABI STREQUAL "mips" ) + set( MIPS true ) + set( ANDROID_NDK_ABI_NAME "mips" ) + set( ANDROID_ARCH_NAME "mips" ) + set( ANDROID_ARCH_FULLNAME "mipsel" ) + set( CMAKE_SYSTEM_PROCESSOR "mips" ) +elseif( ANDROID_ABI STREQUAL "armeabi" ) + set( ARMEABI true ) + set( ANDROID_NDK_ABI_NAME "armeabi" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_ARCH_FULLNAME "arm" ) + set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) +elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" ) + set( ARMEABI_V6 true ) + set( ANDROID_NDK_ABI_NAME "armeabi" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_ARCH_FULLNAME "arm" ) + set( CMAKE_SYSTEM_PROCESSOR "armv6" ) + # need always fallback to older platform + set( ARMEABI true ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a") + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_ARCH_FULLNAME "arm" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" ) + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_ARCH_FULLNAME "arm" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) + set( VFPV3 true ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_ARCH_FULLNAME "arm" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) + set( VFPV3 true ) + set( NEON true ) +else() + message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." ) +endif() + +if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" ) + # really dirty hack + # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run... + file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" ) +endif() + +set( ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} CACHE INTERNAL "ANDROID_ABI can be changed only to one of these ABIs. Changing to any other ABI requires to reset cmake cache." ) +if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME} ) + set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} ) +endif() + +if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) + __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF ) + set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE ) + mark_as_advanced( ANDROID_FORCE_ARM_BUILD ) +else() + unset( ANDROID_FORCE_ARM_BUILD CACHE ) +endif() + +# choose toolchain +if( ANDROID_TOOLCHAIN_NAME ) + list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx ) + if( __toolchainIdx EQUAL -1 ) + message( FATAL_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing. You need to remove CMakeCache.txt and rerun cmake manually to change the toolchain" ) + endif() + list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch ) + if( NOT __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME ) + message( SEND_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) + endif() +else() + set( __toolchainIdx -1 ) + set( __applicableToolchains "" ) + set( __toolchainMaxVersion "0.0.0" ) + list( LENGTH __availableToolchains __availableToolchainsCount ) + math( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" ) + foreach( __idx RANGE ${__availableToolchainsCount} ) + list( GET __availableToolchainArchs ${__idx} __toolchainArch ) + if( __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME ) + list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion ) + if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion ) + set( __toolchainMaxVersion "${__toolchainVersion}" ) + set( __toolchainIdx ${__idx} ) + endif() + endif() + endforeach() + unset( __availableToolchainsCount ) + unset( __toolchainMaxVersion ) + unset( __toolchainVersion ) +endif() +unset( __toolchainArch ) +if( __toolchainIdx EQUAL -1 ) + message( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." ) +endif() +list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME ) +list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME ) +list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION ) +set( ANDROID_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" CACHE INTERNAL "Name of toolchain used" ) +set( ANDROID_COMPILER_VERSION "${ANDROID_COMPILER_VERSION}" CACHE INTERNAL "compiler version from selected toolchain" ) +unset( __toolchainIdx ) +unset( __availableToolchains ) +unset( __availableToolchainMachines ) +unset( __availableToolchainArchs ) +unset( __availableToolchainCompilerVersions ) + +# choose native API level +__INIT_VARIABLE( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL ) +string( REGEX MATCH "[0-9]+" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" ) +# validate +list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) +if( __levelIdx EQUAL -1 ) + message( SEND_ERROR "Specified Android native API level (${ANDROID_NATIVE_API_LEVEL}) is not supported by your NDK/toolchain." ) +endif() +unset( __levelIdx ) +if( BUILD_WITH_ANDROID_NDK ) + __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) + if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL ) + message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) + endif() + unset( __realApiLevel ) +endif() +set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) +if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) + set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) +endif() + +# setup paths +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) + set( __stlLibPath "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) +endif() +if( BUILD_WITH_ANDROID_NDK ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) + if( ANDROID_USE_STLPORT ) + set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" ) + set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}" ) + else() + if( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) + set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/include" ) + set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}" ) + else() + set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include" ) + set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}" ) + endif() + endif() +endif() + +# specify the cross compiler +set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" ) +set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" ) +set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "Assembler" ) +if( CMAKE_VERSION VERSION_LESS 2.8.5 ) + set( CMAKE_ASM_COMPILER_ARG1 "-c" ) +endif() +# there may be a way to make cmake deduce these TODO deduce the rest of the tools +set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) +set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) +set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" ) +set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" ) +set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" ) +set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" ) +set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" ) +set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" ) +if( APPLE ) + find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool ) + if( NOT CMAKE_INSTALL_NAME_TOOL ) + message( FATAL_ERROR "Could not find install_name_tool, please check your installation." ) + endif() + mark_as_advanced( CMAKE_INSTALL_NAME_TOOL ) +endif() + +# export directories +set( ANDROID_SYSTEM_INCLUDE_DIRS "" ) +set( ANDROID_SYSTEM_LIB_DIRS "" ) + +# setup output directories +set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" ) +set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) + +if(NOT _CMAKE_IN_TRY_COMPILE) + if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) + else() + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) + endif() + set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) +endif() + +# includes +list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_SYSROOT}/usr/include" ) +if( __stlIncludePath AND EXISTS "${__stlIncludePath}" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${__stlIncludePath}" ) +endif() + +# c++ bits includes +if( __stlLibPath AND EXISTS "${__stlLibPath}/include" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${__stlLibPath}/include" ) +endif() +if( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/thumb/bits" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) +elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) +elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) +elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/bits" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) +endif() + +# flags and definitions +if(ANDROID_SYSROOT MATCHES "[ ;\"]") + set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" ) + # quotes will break try_compile and compiler identification + message(WARNING "Your Android system root has non-alphanumeric symbols. It can break compiler features detection and the whole build.") +else() + set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) +endif() + +remove_definitions( -DANDROID ) +add_definitions( -DANDROID ) + +# Force set compilers because standard identification works badly for us +include( CMakeForceCompiler ) +CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU ) +set( CMAKE_C_PLATFORM_ID Linux ) +set( CMAKE_C_SIZEOF_DATA_PTR 4 ) +set( CMAKE_C_HAS_ISYSROOT 1 ) +set( CMAKE_C_COMPILER_ABI ELF ) +CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU ) +set( CMAKE_CXX_PLATFORM_ID Linux ) +set( CMAKE_CXX_SIZEOF_DATA_PTR 4 ) +set( CMAKE_CXX_HAS_ISYSROOT 1 ) +set( CMAKE_CXX_COMPILER_ABI ELF ) +# force ASM compiler (required for CMake < 2.8.5) +set( CMAKE_ASM_COMPILER_ID_RUN TRUE ) +set( CMAKE_ASM_COMPILER_ID GNU ) +set( CMAKE_ASM_COMPILER_WORKS TRUE ) +set( CMAKE_ASM_COMPILER_FORCED TRUE ) +set( CMAKE_COMPILER_IS_GNUASM 1) + +# NDK flags +if( ARMEABI OR ARMEABI_V7A ) + # NDK also defines -ffunction-sections -funwind-tables but they result in worse OpenCV performance + set( _CMAKE_CXX_FLAGS "-fPIC -Wno-psabi" ) + set( _CMAKE_C_FLAGS "-fPIC -Wno-psabi" ) + remove_definitions( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ) + add_definitions( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ) + # extra arm-specific flags + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) +elseif( X86 ) + set( _CMAKE_CXX_FLAGS "-funwind-tables" ) + set( _CMAKE_C_FLAGS "-funwind-tables" ) +elseif( MIPS ) + set( _CMAKE_CXX_FLAGS "-fpic -Wno-psabi -fno-strict-aliasing -finline-functions -ffunction-sections -funwind-tables -fmessage-length=0 -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" ) + set( _CMAKE_CXX_FLAGS "-fpic -Wno-psabi -fno-strict-aliasing -finline-functions -ffunction-sections -funwind-tables -fmessage-length=0 -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) +else() + set( _CMAKE_CXX_FLAGS "" ) + set( _CMAKE_C_FLAGS "" ) +endif() + +if( ANDROID_USE_STLPORT ) + set( _CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions" ) + set( _CMAKE_C_FLAGS "${_CMAKE_C_FLAGS} -fno-exceptions" ) +else() + set( _CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS} -frtti -fexceptions" ) + set( _CMAKE_C_FLAGS "${_CMAKE_C_FLAGS} -fexceptions" ) +endif() + +# release and debug flags +if( ARMEABI OR ARMEABI_V7A ) + if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 ) + # It is recommended to use the -mthumb compiler flag to force the generation + # of 16-bit Thumb-1 instructions (the default being 32-bit ARM ones). + # O3 instead of O2/Os in release mode - like cmake sets for desktop gcc + set( _CMAKE_CXX_FLAGS_RELEASE "-mthumb -O3" ) + set( _CMAKE_C_FLAGS_RELEASE "-mthumb -O3" ) + set( _CMAKE_CXX_FLAGS_DEBUG "-marm -Os -finline-limit=64" ) + set( _CMAKE_C_FLAGS_DEBUG "-marm -Os -finline-limit=64" ) + else() + # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI + # O3 instead of O2/Os in release mode - like cmake sets for desktop gcc + set( _CMAKE_CXX_FLAGS_RELEASE "-marm -O3 -fstrict-aliasing" ) + set( _CMAKE_C_FLAGS_RELEASE "-marm -O3 -fstrict-aliasing" ) + set( _CMAKE_CXX_FLAGS_DEBUG "-marm -O0 -finline-limit=300" ) + set( _CMAKE_C_FLAGS_DEBUG "-marm -O0 -finline-limit=300" ) + endif() +elseif( X86 ) + set( _CMAKE_CXX_FLAGS_RELEASE "-O3 -fstrict-aliasing" ) + set( _CMAKE_C_FLAGS_RELEASE "-O3 -fstrict-aliasing" ) + set( _CMAKE_CXX_FLAGS_DEBUG "-O0 -finline-limit=300" ) + set( _CMAKE_C_FLAGS_DEBUG "-O0 -finline-limit=300" ) +elseif( MIPS ) + set( _CMAKE_CXX_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" ) + set( _CMAKE_C_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" ) + set( _CMAKE_CXX_FLAGS_DEBUG "-O0 -g" ) + set( _CMAKE_C_FLAGS_DEBUG "-O0 -g" ) +endif() +set( _CMAKE_CXX_FLAGS_RELEASE "${_CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" ) +set( _CMAKE_C_FLAGS_RELEASE "${_CMAKE_C_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" ) +set( _CMAKE_CXX_FLAGS_DEBUG "${_CMAKE_CXX_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG" ) +set( _CMAKE_C_FLAGS_DEBUG "${_CMAKE_C_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG" ) + +# ABI-specific flags +if( ARMEABI_V7A ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) + if( NEON ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" ) + elseif( VFPV3 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" ) + else() + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfp" ) + endif() +elseif( ARMEABI_V6 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) +elseif( ARMEABI ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) +elseif( X86 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" )#sse? +endif() + +# linker flags +if( NOT DEFINED __ndklibspath ) + set( __ndklibspath "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ndklibs/${ANDROID_NDK_ABI_NAME}" ) +endif() +list( APPEND ANDROID_SYSTEM_LIB_DIRS "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ) +set( ANDROID_LINKER_FLAGS "" ) + +# STL +if( ANDROID_USE_STLPORT ) + if( EXISTS "${__stlLibPath}/libstlport_static.a" ) + set( CMAKE_CXX_CREATE_SHARED_LIBRARY " -o \"${__stlLibPath}/libstlport_static.a\"") + set( CMAKE_CXX_CREATE_SHARED_MODULE " -o \"${__stlLibPath}/libstlport_static.a\"") + endif() +else( ANDROID_USE_STLPORT ) + if( EXISTS "${__stlLibPath}/libgnustl_static.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/libgnustl_static.a" "${__ndklibspath}/libstdc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/thumb/libstdc++.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/thumb/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) + elseif( EXISTS "${__stlLibPath}/libstdc++.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) + endif() + if( EXISTS "${__stlLibPath}/libsupc++.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" ) + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" ) + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" ) + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) + elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" ) + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) + endif() + list( APPEND ANDROID_SYSTEM_LIB_DIRS "${__ndklibspath}" ) +endif( ANDROID_USE_STLPORT ) + +# cleanup for STL search +unset( __stlIncludePath ) +unset( __stlLibPath ) + +# other linker flags +__INIT_VARIABLE( ANDROID_NO_UNDEFINED OBSOLETE_NO_UNDEFINED VALUES ON ) +set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" FORCE ) +mark_as_advanced( ANDROID_NO_UNDEFINED ) +if( ANDROID_NO_UNDEFINED ) + set( ANDROID_LINKER_FLAGS "-Wl,--no-undefined ${ANDROID_LINKER_FLAGS}" ) +endif() + +if (ANDROID_NDK MATCHES "-r[56].?$") + # libGLESv2.so in NDK's prior to r7 refers to exteranal symbols. So this flag option is required for all projects using OpenGL from native. + __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES ON ) +else() + __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF ) +endif() + +set( ANDROID_SO_UNDEFINED ${ANDROID_SO_UNDEFINED} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" FORCE ) +mark_as_advanced( ANDROID_SO_UNDEFINED ) +if( ANDROID_SO_UNDEFINED ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" ) +endif() + +__INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON ) +set( ANDROID_FUNCTION_LEVEL_LINKING ON CACHE BOOL "Allows or disallows undefined symbols in shared libraries" FORCE ) +mark_as_advanced( ANDROID_FUNCTION_LEVEL_LINKING ) +if( ANDROID_FUNCTION_LEVEL_LINKING ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" ) + set( ANDROID_LINKER_FLAGS "-Wl,--gc-sections ${ANDROID_LINKER_FLAGS}" ) +endif() + +if( ARMEABI_V7A ) + # this is *required* to use the following linker flags that routes around + # a CPU bug in some Cortex-A8 implementations: + set( ANDROID_LINKER_FLAGS "-Wl,--fix-cortex-a8 ${ANDROID_LINKER_FLAGS}" ) +endif() + +# cache flags +set( CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags" ) +set( CMAKE_C_FLAGS "${_CMAKE_C_FLAGS}" CACHE STRING "c flags" ) +set( CMAKE_CXX_FLAGS_RELEASE "${_CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "c++ Release flags" ) +set( CMAKE_C_FLAGS_RELEASE "${_CMAKE_C_FLAGS_RELEASE}" CACHE STRING "c Release flags" ) +set( CMAKE_CXX_FLAGS_DEBUG "${_CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "c++ Debug flags" ) +set( CMAKE_C_FLAGS_DEBUG "${_CMAKE_C_FLAGS_DEBUG}" CACHE STRING "c Debug flags" ) +set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "linker flags" ) +set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "linker flags" ) +set( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "linker flags" ) + +include_directories( SYSTEM ${ANDROID_SYSTEM_INCLUDE_DIRS} ) +link_directories( ${ANDROID_SYSTEM_LIB_DIRS} ) + +# finish flags +set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Extra Android compiler flags") +set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Extra Android linker flags") +set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" ) +set( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" ) +if( MIPS AND BUILD_WITH_ANDROID_NDK ) + set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" ) + set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" ) + set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.x ${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) +else() + set( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" ) + set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" ) + set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) +endif() + +# set these global flags for cmake client scripts to change behavior +set( ANDROID True ) +set( BUILD_ANDROID True ) + +# where is the target environment +set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) + +# only search for libraries and includes in the ndk toolchain +set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + + +# macro to find packages on the host OS +macro( find_host_package ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_package( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endmacro() + + +# macro to find programs on the host OS +macro( find_host_program ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_program( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endmacro() + + +macro( ANDROID_GET_ABI_RAWNAME TOOLCHAIN_FLAG VAR ) + if( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI" ) + set( ${VAR} "armeabi" ) + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI_V7A" ) + set( ${VAR} "armeabi-v7a" ) + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "X86" ) + set( ${VAR} "x86" ) + else() + set( ${VAR} "unknown" ) + endif() +endmacro() + + +# export toolchain settings for the try_compile() command +if( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" ) + set( __toolchain_config "") + foreach( __var ANDROID_ABI ANDROID_FORCE_ARM_BUILD ANDROID_NATIVE_API_LEVEL ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_SET_OBSOLETE_VARIABLES LIBRARY_OUTPUT_PATH_ROOT ANDROID_USE_STLPORT ANDROID_FORBID_SYGWIN ANDROID_NDK ANDROID_STANDALONE_TOOLCHAIN ANDROID_FUNCTION_LEVEL_LINKING __ndklibspath ) + if( DEFINED ${__var} ) + if( "${__var}" MATCHES " ") + set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" ) + else() + set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" ) + endif() + endif() + endforeach() + file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" ) + unset( __toolchain_config ) + unset( __ndklibspath ) +endif() + + +# set some obsolete variables for backward compatibility +set( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" ) +mark_as_advanced( ANDROID_SET_OBSOLETE_VARIABLES ) +if( ANDROID_SET_OBSOLETE_VARIABLES ) + set( ANDROID_API_LEVEL ${ANDROID_NATIVE_API_LEVEL} ) + set( ARM_TARGET "${ANDROID_ABI}" ) + set( ARMEABI_NDK_NAME "${ANDROID_NDK_ABI_NAME}" ) +endif() + + +# Variables controlling behavior or set by cmake toolchain: +# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips" +# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14 (depends on NDK version) +# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF +# ANDROID_USE_STLPORT : OFF/ON - EXPERIMENTAL!!! +# ANDROID_FORBID_SYGWIN : ON/OFF +# ANDROID_NO_UNDEFINED : ON/OFF +# ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version) +# ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF +# Variables that takes effect only at first run: +# ANDROID_FORCE_ARM_BUILD : ON/OFF +# LIBRARY_OUTPUT_PATH_ROOT : +# Can be set only at the first run: +# ANDROID_NDK +# ANDROID_STANDALONE_TOOLCHAIN +# ANDROID_TOOLCHAIN_NAME : "arm-linux-androideabi-4.4.3" or "arm-linux-androideabi-4.6" or "mipsel-linux-android-4.4.3" or "mipsel-linux-android-4.6" or "x86-4.4.3" or "x86-4.6" +# Obsolete: +# ANDROID_API_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL +# ARM_TARGET : superseded by ANDROID_ABI +# ARM_TARGETS : superseded by ANDROID_ABI (can be set only) +# ANDROID_NDK_TOOLCHAIN_ROOT : superseded by ANDROID_STANDALONE_TOOLCHAIN (can be set only) +# ANDROID_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL (completely removed) +# +# Primary read-only variables: +# ANDROID : always TRUE +# ARMEABI : TRUE for arm v6 and older devices +# ARMEABI_V6 : TRUE for arm v6 +# ARMEABI_V7A : TRUE for arm v7a +# NEON : TRUE if NEON unit is enabled +# VFPV3 : TRUE if VFP version 3 is enabled +# X86 : TRUE if configured for x86 +# BUILD_ANDROID : always TRUE +# BUILD_WITH_ANDROID_NDK : TRUE if NDK is used +# BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used +# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform +# ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a" or "x86" depending on ANDROID_ABI +# ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI +# TOOL_OS_SUFFIX : "" or ".exe" depending on host platform +# ANDROID_SYSROOT : path to the compiler sysroot +# ANDROID_SYSTEM_INCLUDE_DIRS +# ANDROID_SYSTEM_LIB_DIRS +# Obsolete: +# ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME +# +# Secondary (less stable) read-only variables: +# ANDROID_COMPILER_VERSION : GCC version used +# ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform +# ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI +# ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux" +# ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK) +# ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK +# +# Defaults: +# ANDROID_DEFAULT_NDK_API_LEVEL +# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH} +# ANDROID_NDK_SEARCH_PATHS +# ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH +# ANDROID_SUPPORTED_ABIS_${ARCH} +# ANDROID_SUPPORTED_NDK_VERSIONS diff --git a/contrib/cmake/CrossCompile-iOS-Sim.cmake b/contrib/cmake/CrossCompile-iOS-Sim.cmake new file mode 100644 index 0000000..5a11761 --- /dev/null +++ b/contrib/cmake/CrossCompile-iOS-Sim.cmake @@ -0,0 +1,91 @@ +# To cross compile for iOS simulator: +# build$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../contrib/cmake/CrossCompile-iOS-Sim.cmake + +SET(CMAKE_SYSTEM_NAME Generic) +if ("$ENV{IOS_SDK_VERSION}" STREQUAL "") + SET(CMAKE_SYSTEM_VERSION 6.1) +else() + SET(CMAKE_SYSTEM_VERSION $ENV{IOS_SDK_VERSION}) +endif() +SET(CMAKE_SYSTEM_PROCESSOR i386) + +SET(ARCHS "-arch i386") +SET(CMAKE_CROSSCOMPILING_TARGET IOS) +SET(CMAKE_OSX_ARCHITECTURES "i386") +SET(IOS ON) +SET(IOSSIM ON) +SET(UNIX ON) +SET(APPLE ON) + +execute_process(COMMAND xcode-select -print-path + OUTPUT_VARIABLE XCODE_SELECT OUTPUT_STRIP_TRAILING_WHITESPACE) + +if(EXISTS ${XCODE_SELECT}) + SET(DEVROOT "${XCODE_SELECT}/Platforms/iPhoneSimulator.platform/Developer") + if (NOT EXISTS "${DEVROOT}/SDKs/iPhoneSimulator${CMAKE_SYSTEM_VERSION}.sdk") + # specified SDK version does not exist, use last one + file(GLOB INSTALLED_SDKS ${DEVROOT}/SDKs/*) + list(SORT INSTALLED_SDKS) + list(REVERSE INSTALLED_SDKS) + list(GET INSTALLED_SDKS 0 LATEST_SDK) + string(REGEX MATCH "[0-9]\\.[0-9]" CMAKE_SYSTEM_VERSION ${LATEST_SDK}) + endif() +else() + SET(DEVROOT "/Developer/Platforms/iPhoneSimulator.platform/Developer") +endif() + +if (${CMAKE_SYSTEM_VERSION} VERSION_EQUAL "6.0" OR ${CMAKE_SYSTEM_VERSION} VERSION_GREATER "6.0") + set(IOS6_OR_LATER ON) +else() + set(IOS6_OR_LATER OFF) +endif() + +if (IOS6_OR_LATER) + # we have to use clang - llvm will choke on those __has_feature macros? + SET (CMAKE_C_COMPILER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang") + SET (CMAKE_CXX_COMPILER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++") + + if ($ENV{MACOSX_DEPLOYMENT_TARGET}) + message(FATAL_ERROR "llvm will croak with MACOSX_DEPLOYMENT_TARGET environment variable set when building for ios - unset MACOSX_DEPLOYMENT_TARGET") + endif() + +else() + SET (CMAKE_C_COMPILER "${DEVROOT}/usr/bin/gcc") + SET (CMAKE_CXX_COMPILER "${DEVROOT}/usr/bin/g++") +endif() + +SET(SDKROOT "${DEVROOT}/SDKs/iPhoneSimulator${CMAKE_SYSTEM_VERSION}.sdk") +SET(CMAKE_OSX_SYSROOT "${SDKROOT}") +SET(CMAKE_SYSTEM_PREFIX_PATH "/;/usr;/usr/local;/opt/local") + +# This gets overridden somewhere! +SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so;.dylib") + +set(CMAKE_SYSTEM_FRAMEWORK_PATH + ~/Library/Frameworks + /Library/Frameworks + /Network/Library/Frameworks + /System/Library/Frameworks) + +# force compiler and linker flags +SET(CMAKE_C_LINK_FLAGS ${ARCHS}) +SET(CMAKE_CXX_LINK_FLAGS ${ARCHS}) +SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${SDKROOT}") +SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${SDKROOT}") + +# SET(CMAKE_C_FLAGS ${ARCHS}) # C_FLAGS wont stick, use ADD_DEFINITIONS instead +# SET(CMAKE_CXX_FLAGS ${ARCHS}) +ADD_DEFINITIONS(${ARCHS}) +ADD_DEFINITIONS("--sysroot=${SDKROOT}") + +# ios headers +INCLUDE_DIRECTORIES(SYSTEM "${SDKROOT}/usr/include") + +# ios libraries +LINK_DIRECTORIES("${SDKROOT}/usr/lib/system") +LINK_DIRECTORIES("${SDKROOT}/usr/lib") + +SET (CMAKE_FIND_ROOT_PATH "${SDKROOT}") +SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) +SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) +SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) diff --git a/contrib/cmake/CrossCompile-iOS.cmake b/contrib/cmake/CrossCompile-iOS.cmake new file mode 100644 index 0000000..6d8bf7d --- /dev/null +++ b/contrib/cmake/CrossCompile-iOS.cmake @@ -0,0 +1,93 @@ +# To cross compile for iPhone: +# build$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../contrib/cmake/CrossCompile-iOS.cmake + +SET(CMAKE_SYSTEM_NAME Generic) +if ("$ENV{IOS_SDK_VERSION}" STREQUAL "") + SET(CMAKE_SYSTEM_VERSION 6.1) +else() + SET(CMAKE_SYSTEM_VERSION $ENV{IOS_SDK_VERSION}) +endif() +SET(CMAKE_SYSTEM_PROCESSOR arm) + +SET(CMAKE_CROSSCOMPILING_TARGET IOS) +SET(IOS ON) +SET(UNIX ON) +SET(APPLE ON) + +execute_process(COMMAND xcode-select -print-path + OUTPUT_VARIABLE XCODE_SELECT OUTPUT_STRIP_TRAILING_WHITESPACE) + +if(EXISTS ${XCODE_SELECT}) + SET(DEVROOT "${XCODE_SELECT}/Platforms/iPhoneOS.platform/Developer") + if (NOT EXISTS "${DEVROOT}/SDKs/iPhoneOS${CMAKE_SYSTEM_VERSION}.sdk") + # specified SDK version does not exist, use last one + file(GLOB INSTALLED_SDKS ${DEVROOT}/SDKs/*) + list(SORT INSTALLED_SDKS) + list(REVERSE INSTALLED_SDKS) + list(GET INSTALLED_SDKS 0 LATEST_SDK) + string(REGEX MATCH "[0-9]\\.[0-9]" CMAKE_SYSTEM_VERSION ${LATEST_SDK}) + endif() +else() + SET(DEVROOT "/Developer/Platforms/iPhoneOS.platform/Developer") +endif() + +if (${CMAKE_SYSTEM_VERSION} VERSION_EQUAL "6.0" OR ${CMAKE_SYSTEM_VERSION} VERSION_GREATER "6.0") + set(IOS6_OR_LATER ON) +else() + set(IOS6_OR_LATER OFF) +endif() + +if (IOS6_OR_LATER) + # no armv6 support in ios6 - armv7s was added, but we did no compile our dependencies for it + SET(CMAKE_OSX_ARCHITECTURES armv7 armv7s) + SET(ARCHS "-arch armv7 -arch armv7s") + + # we have to use clang - llvm will choke on those __has_feature macros? + SET (CMAKE_C_COMPILER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang") + SET (CMAKE_CXX_COMPILER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++") + + if ($ENV{MACOSX_DEPLOYMENT_TARGET}) + message(FATAL_ERROR "llvm will croak with MACOSX_DEPLOYMENT_TARGET environment variable set when building for ios - unset MACOSX_DEPLOYMENT_TARGET") + endif() + +else() + SET(CMAKE_OSX_ARCHITECTURES armv6 armv7) + SET(ARCHS "-arch armv6 -arch armv7") + + SET (CMAKE_C_COMPILER "${DEVROOT}/usr/bin/gcc") + SET (CMAKE_CXX_COMPILER "${DEVROOT}/usr/bin/g++") + +endif() + +SET(SDKROOT "${DEVROOT}/SDKs/iPhoneOS${CMAKE_SYSTEM_VERSION}.sdk") +SET(CMAKE_OSX_SYSROOT "${SDKROOT}") +SET(CMAKE_SYSTEM_PREFIX_PATH "/;/usr;/usr/local;/opt/local") + +# This gets overridden somewhere! +SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so;.dylib") + +set(CMAKE_SYSTEM_FRAMEWORK_PATH + ~/Library/Frameworks + /Library/Frameworks + /Network/Library/Frameworks + /System/Library/Frameworks) + +# force compiler and linker flags +SET(CMAKE_C_LINK_FLAGS ${ARCHS}) +SET(CMAKE_CXX_LINK_FLAGS ${ARCHS}) +# SET(CMAKE_C_FLAGS ${ARCHS}) # C_FLAGS wont stick, use ADD_DEFINITIONS instead +# SET(CMAKE_CXX_FLAGS ${ARCHS}) +ADD_DEFINITIONS(${ARCHS}) +ADD_DEFINITIONS("--sysroot=${SDKROOT}") + +# ios headers +INCLUDE_DIRECTORIES(SYSTEM "${SDKROOT}/usr/include") + +# ios libraries +LINK_DIRECTORIES("${SDKROOT}/usr/lib/system") +LINK_DIRECTORIES("${SDKROOT}/usr/lib") + +SET (CMAKE_FIND_ROOT_PATH "${SDKROOT}") +SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) +SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) +SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) diff --git a/contrib/cmake/FindArabica.cmake b/contrib/cmake/FindArabica.cmake index 8e60d56..018ff89 100644 --- a/contrib/cmake/FindArabica.cmake +++ b/contrib/cmake/FindArabica.cmake @@ -9,6 +9,7 @@ FIND_PATH(ARABICA_INCLUDE_DIR Arabica/getparam.hpp /opt HINTS $ENV{ARABICA_SRC} ) + set(ARABICA_LIBRARY) FIND_LIBRARY(ARABICA_LIBRARY_RELEASE NAMES arabica diff --git a/contrib/cmake/FindEVENT.cmake b/contrib/cmake/FindEVENT.cmake index ef6089b..7904b6a 100644 --- a/contrib/cmake/FindEVENT.cmake +++ b/contrib/cmake/FindEVENT.cmake @@ -36,6 +36,19 @@ if (NOT WIN32) HINTS $ENV{EVENT_SRC}/.libs/ ) list (APPEND EVENT_LIBRARY ${EVENT_LIBRARY_THREADS}) + + FIND_LIBRARY(EVENT_LIBRARY_EXTRA + NAMES event_extra + HINTS $ENV{EVENT_SRC}/.libs/ + ) + list (APPEND EVENT_LIBRARY ${EVENT_LIBRARY_EXTRA}) + + FIND_LIBRARY(EVENT_LIBRARY_CORE + NAMES event_core + HINTS $ENV{EVENT_SRC}/.libs/ + ) + list (APPEND EVENT_LIBRARY ${EVENT_LIBRARY_CORE}) + endif() INCLUDE(FindPackageHandleStandardArgs) diff --git a/contrib/local/compress_and_upload_deps.sh b/contrib/local/compress_and_upload_deps.sh index ae53c7f..3cc9684 100755 --- a/contrib/local/compress_and_upload_deps.sh +++ b/contrib/local/compress_and_upload_deps.sh @@ -9,9 +9,11 @@ CWD=`pwd` cd $DIR if [ "$USCXML_PREBUILT_HOST" == "" ]; then - USCXML_PREBUILT_HOST="admin@uscxml.tk.informatik.tu-darmstadt.de:/var/www/html/uscxml/prebuilt" + USCXML_PREBUILT_HOST="admin@uscxml.tk.informatik.tu-darmstadt.de" fi +USCXML_PREBUILT_PATH="/var/www/html/uscxml/prebuilt" + if [ "$1" == "" ] || [ "$2" == "" ]; then echo "$ME " exit @@ -26,13 +28,15 @@ VERSION=$2 cd ../prebuilt +ssh ${USCXML_PREBUILT_HOST} mkdir -p ${USCXML_PREBUILT_PATH}/${VERSION} + PLATFORMS=`find . -maxdepth 1 -type d -regex ./[^\.].*` for FILE in ${PLATFORMS}; do PLATFORM=`basename $FILE` if [ "$PLATFORM" != "include" ]; then echo $FILE tar cvzf uscxml-prebuilt-${PLATFORM}.tgz ${FILE} - scp uscxml-prebuilt-${PLATFORM}.tgz ${USCXML_PREBUILT_HOST}/${VERSION} + scp uscxml-prebuilt-${PLATFORM}.tgz ${USCXML_PREBUILT_HOST}:${USCXML_PREBUILT_PATH}/${VERSION} rm uscxml-prebuilt-${PLATFORM}.tgz fi done \ No newline at end of file diff --git a/src/bindings/swig/php/uscxmlNativePHP.php b/src/bindings/swig/php/uscxmlNativePHP.php index 7d8b0aa..b16f074 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 @@ -284,6 +284,10 @@ class Data { return $r; } + static function toJSON($data) { + return Data_toJSON($data); + } + static function fromXML($xmlString) { $r=Data_fromXML($xmlString); if (is_resource($r)) { diff --git a/src/uscxml/Common.h b/src/uscxml/Common.h index 5840d97..279306a 100644 --- a/src/uscxml/Common.h +++ b/src/uscxml/Common.h @@ -3,6 +3,8 @@ #ifdef _WIN32 #include +// see http://stackoverflow.com/questions/1372480/c-redefinition-header-files +#define _WINSOCKAPI_ // stops windows.h including winsock.h #include #else #include diff --git a/src/uscxml/Factory.cpp b/src/uscxml/Factory.cpp index cc7eeb3..a13a887 100644 --- a/src/uscxml/Factory.cpp +++ b/src/uscxml/Factory.cpp @@ -6,17 +6,21 @@ #include "uscxml/Interpreter.h" #include +// see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system + #ifdef BUILD_AS_PLUGINS # include "uscxml/plugins/Plugins.h" #else # include "uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h" +# include "uscxml/plugins/ioprocessor/comet/CometIOProcessor.h" # include "uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h" # include "uscxml/plugins/invoker/scxml/USCXMLInvoker.h" # include "uscxml/plugins/invoker/http/HTTPServletInvoker.h" # include "uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.h" # include "uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h" # include "uscxml/plugins/invoker/system/SystemInvoker.h" +# include "uscxml/plugins/invoker/xhtml/XHTMLInvoker.h" #ifdef PROTOBUF_FOUND # include "uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h" @@ -148,21 +152,21 @@ Factory::Factory() { } #endif -#if defined V8_FOUND and defined BUILD_DM_ECMA +#if (defined V8_FOUND && defined BUILD_DM_ECMA) { V8DataModel* dataModel = new V8DataModel(); registerDataModel(dataModel); } #endif -#if defined JSC_FOUND and defined BUILD_DM_ECMA +#if (defined JSC_FOUND && defined BUILD_DM_ECMA) { JSCDataModel* dataModel = new JSCDataModel(); registerDataModel(dataModel); } #endif -#if defined SWI_FOUND and defined BUILD_DM_PROLOG +#if (defined SWI_FOUND && defined BUILD_DM_PROLOG) { SWIDataModel* dataModel = new SWIDataModel(); registerDataModel(dataModel); @@ -177,10 +181,10 @@ Factory::Factory() { #endif #ifdef PROTOBUF_FOUND - { - MMIHTTPIOProcessor* ioProcessor = new MMIHTTPIOProcessor(); - registerIOProcessor(ioProcessor); - } + { + MMIHTTPIOProcessor* ioProcessor = new MMIHTTPIOProcessor(); + registerIOProcessor(ioProcessor); + } #endif // these are always available @@ -189,6 +193,10 @@ Factory::Factory() { registerDataModel(dataModel); } { + XHTMLInvoker* invoker = new XHTMLInvoker(); + registerInvoker(invoker); + } + { USCXMLInvoker* invoker = new USCXMLInvoker(); registerInvoker(invoker); } @@ -232,7 +240,7 @@ Factory::Factory() { PostponeElement* element = new PostponeElement(); registerExecutableContent(element); } - + #endif } @@ -292,18 +300,18 @@ std::map Factory::getIOProcessors() { if (_parentFactory) { ioProcs = _parentFactory->getIOProcessors(); } - + std::map::iterator ioProcIter = _ioProcessors.begin(); while(ioProcIter != _ioProcessors.end()) { ioProcs.insert(std::make_pair(ioProcIter->first, ioProcIter->second)); ioProcIter++; } - + return ioProcs; } boost::shared_ptr Factory::createInvoker(const std::string& type, InterpreterImpl* interpreter) { - + // do we have this type ourself? if (_invokerAliases.find(type) != _invokerAliases.end()) { std::string canonicalName = _invokerAliases[type]; @@ -318,12 +326,12 @@ boost::shared_ptr Factory::createInvoker(const std::string& type, I } else { LOG(ERROR) << "No " << type << " Invoker known"; } - + return boost::shared_ptr(); } boost::shared_ptr Factory::createDataModel(const std::string& type, InterpreterImpl* interpreter) { - + // do we have this type ourself? if (_dataModelAliases.find(type) != _dataModelAliases.end()) { std::string canonicalName = _dataModelAliases[type]; @@ -331,14 +339,14 @@ boost::shared_ptr Factory::createDataModel(const std::string& typ return _dataModels[canonicalName]->create(interpreter); } } - + // lookup in parent factory if (_parentFactory) { return _parentFactory->createDataModel(type, interpreter); } else { LOG(ERROR) << "No " << type << " Datamodel known"; } - + return boost::shared_ptr(); } @@ -350,14 +358,14 @@ boost::shared_ptr Factory::createIOProcessor(const std::string& return _ioProcessors[canonicalName]->create(interpreter); } } - + // lookup in parent factory if (_parentFactory) { return _parentFactory->createIOProcessor(type, interpreter); } else { LOG(ERROR) << "No " << type << " Datamodel known"; } - + return boost::shared_ptr(); } diff --git a/src/uscxml/Factory.h b/src/uscxml/Factory.h index d92d105..b3bfded 100644 --- a/src/uscxml/Factory.h +++ b/src/uscxml/Factory.h @@ -116,13 +116,13 @@ public: void setType(const std::string& type) { _type = type; } - + virtual Data getDataModelVariables() = 0; virtual void send(const SendRequest& req) = 0; - + virtual void runOnMainThread() {}; void returnEvent(Event& event); - + protected: InterpreterImpl* _interpreter; std::string _invokeId; @@ -136,11 +136,11 @@ public: EventHandler(boost::shared_ptr const impl) : _impl(impl) { } EventHandler(const EventHandler& other) : _impl(other._impl) { } virtual ~EventHandler() {}; - + virtual std::set getNames() { return _impl->getNames(); } - + virtual Data getDataModelVariables() const { return _impl->getDataModelVariables(); }; @@ -150,7 +150,7 @@ public: virtual void runOnMainThread() { return _impl->runOnMainThread(); } - + void setInterpreter(InterpreterImpl* interpreter) { _impl->setInterpreter(interpreter); } @@ -382,7 +382,7 @@ public: boost::shared_ptr createExecutableContent(const std::string& localName, const std::string& nameSpace, InterpreterImpl* interpreter); std::map getIOProcessors(); - + static Factory* getInstance(); std::map _dataModels; diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 8bb6499..bdda8c8 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -133,16 +133,19 @@ Interpreter Interpreter::fromInputSource(Arabica::SAX::InputSource& tthread::lock_guard lock(_instanceMutex); boost::shared_ptr interpreterImpl = boost::shared_ptr(new InterpreterDraft6); Interpreter interpreter; - NameSpacingParser* parser = new NameSpacingParser(); - if (parser->parse(source) && parser->getDocument() && parser->getDocument().hasChildNodes()) { - interpreterImpl->setNameSpaceInfo(parser->nameSpace); - interpreterImpl->_document = parser->getDocument(); + NameSpacingParser parser; + if (parser.parse(source) && parser.getDocument() && parser.getDocument().hasChildNodes()) { + interpreterImpl->setNameSpaceInfo(parser.nameSpace); + interpreterImpl->_document = parser.getDocument(); interpreterImpl->init(); interpreter = Interpreter(interpreterImpl); _instances[interpreterImpl->getSessionId()] = interpreterImpl; + } else { + if (parser.errorsReported()) { + LOG(ERROR) << parser.errors(); + } } // interpreter->init(); - delete parser; return interpreter; } @@ -260,7 +263,7 @@ void InterpreterImpl::init() { if (_factory == NULL) _factory = Factory::getInstance(); - + } else { LOG(ERROR) << "Cannot find SCXML element" << std::endl; _done = true; diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index 7c95426..7de6c63 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -135,8 +135,10 @@ public: return ""; } void setNameSpaceInfo(const std::map nameSpaceInfo); - std::map getNameSpaceInfo() { return _nameSpaceInfo; } - + std::map getNameSpaceInfo() { + return _nameSpaceInfo; + } + void receiveInternal(const Event& event); void receive(const Event& event, bool toFront = false); @@ -391,7 +393,7 @@ public: std::map getNameSpaceInfo() { return _impl->getNameSpaceInfo(); } - + void setCmdLineOptions(int argc, char** argv) { return _impl->setCmdLineOptions(argc, argv); } diff --git a/src/uscxml/Message.cpp b/src/uscxml/Message.cpp index 2425c76..2e82b69 100644 --- a/src/uscxml/Message.cpp +++ b/src/uscxml/Message.cpp @@ -276,6 +276,8 @@ Data Data::fromJSON(const std::string& jsonString) { size_t currTok = 0; do { + jsmntok_t t2 = t[currTok]; + std::string value = trimmed.substr(t[currTok].start, t[currTok].end - t[currTok].start); switch (t[currTok].type) { case JSMN_STRING: dataStack.back()->type = Data::VERBATIM; @@ -291,13 +293,18 @@ Data Data::fromJSON(const std::string& jsonString) { break; } + t2 = t[currTok]; + value = trimmed.substr(t[currTok].start, t[currTok].end - t[currTok].start); + // there are no more tokens if (t[currTok].end == 0 || tokenStack.empty()) break; // next token starts after current one => pop - if (t[currTok].end > tokenStack.back().end) + if (t[currTok].end > tokenStack.back().end) { tokenStack.pop_back(); + dataStack.pop_back(); + } if (tokenStack.back().type == JSMN_OBJECT && (t[currTok].type == JSMN_PRIMITIVE || t[currTok].type == JSMN_STRING)) { // grab key and push new data @@ -328,7 +335,7 @@ void Event::initContent(const std::string& content) { Arabica::SAX2DOM::Parser parser; Arabica::SAX::CatchErrorHandler errorHandler; parser.setErrorHandler(errorHandler); - + std::istringstream is(content); Arabica::SAX::InputSource inputSource; inputSource.setByteStream(is); @@ -336,7 +343,7 @@ void Event::initContent(const std::string& content) { dom = parser.getDocument(); return; } - + this->content = content; } @@ -513,6 +520,13 @@ std::ostream& operator<< (std::ostream& os, const Event& event) { #ifndef SWIGJAVA std::ostream& operator<< (std::ostream& os, const Data& data) { + os << Data::toJSON(data); + return os; +} +#endif + +std::string Data::toJSON(const Data& data) { + std::stringstream os; std::string indent; for (int i = 0; i < _dataIndentation; i++) { indent += " "; @@ -564,8 +578,7 @@ std::ostream& operator<< (std::ostream& os, const Data& data) { } else { os << "undefined"; } - return os; + return os.str(); } -#endif } \ No newline at end of file diff --git a/src/uscxml/Message.h b/src/uscxml/Message.h index 0f82947..dd62702 100644 --- a/src/uscxml/Message.h +++ b/src/uscxml/Message.h @@ -42,7 +42,7 @@ public: const Data operator[](const std::string& key) const { return operator[](key.c_str()); } - + const Data operator[](const char* key) const { if (hasKey(key)) return compound.at(key); @@ -63,6 +63,7 @@ public: } static Data fromJSON(const std::string& jsonString); + static std::string toJSON(const Data& data); static Data fromXML(const std::string& xmlString); Arabica::DOM::Document toDocument(); std::string toXMLString() { diff --git a/src/uscxml/NameSpacingParser.cpp b/src/uscxml/NameSpacingParser.cpp index 21d9704..619d62c 100644 --- a/src/uscxml/NameSpacingParser.cpp +++ b/src/uscxml/NameSpacingParser.cpp @@ -1,44 +1,42 @@ +#include #include "NameSpacingParser.h" #include +#include namespace uscxml { - - NameSpacingParser* NameSpacingParser::fromXML(const std::string& xml) { - if (xml.length() == 0) - return NULL; - std::stringstream* ss = new std::stringstream(); - (*ss) << xml; - // we need an auto_ptr for arabica to assume ownership - std::auto_ptr ssPtr(ss); - Arabica::SAX::InputSource inputSource; - inputSource.setByteStream(ssPtr); - return fromInputSource(inputSource); - } - NameSpacingParser* NameSpacingParser::fromInputSource(Arabica::SAX::InputSource& source) { - NameSpacingParser* parser = new NameSpacingParser(); - if(!parser->parse(source) || !parser->getDocument().hasChildNodes()) { - if(parser->_errorHandler.errorsReported()) { - LOG(ERROR) << "could not parse input:"; - LOG(ERROR) << parser->_errorHandler.errors() << std::endl; - } else { - Arabica::SAX::InputSourceResolver resolver(source, Arabica::default_string_adaptor()); - if (!resolver.resolve()) { - LOG(ERROR) << source.getSystemId() << ": no such file"; - } +NameSpacingParser NameSpacingParser::fromXML(const std::string& xml) { + std::stringstream* ss = new std::stringstream(); + (*ss) << xml; + // we need an auto_ptr for arabica to assume ownership + std::auto_ptr ssPtr(ss); + Arabica::SAX::InputSource inputSource; + inputSource.setByteStream(ssPtr); + return fromInputSource(inputSource); +} + +NameSpacingParser NameSpacingParser::fromInputSource(Arabica::SAX::InputSource& source) { + NameSpacingParser parser; + if(!parser.parse(source) || !parser.getDocument().hasChildNodes()) { + if(parser._errorHandler.errorsReported()) { + LOG(ERROR) << "could not parse input:"; + LOG(ERROR) << parser._errorHandler.errors() << std::endl; + } else { + Arabica::SAX::InputSourceResolver resolver(source, Arabica::default_string_adaptor()); + if (!resolver.resolve()) { + LOG(ERROR) << source.getSystemId() << ": no such file"; } - delete parser; } - return parser; } + return parser; +} - NameSpacingParser::NameSpacingParser() { - Arabica::SAX::CatchErrorHandler errorHandler; - setErrorHandler(errorHandler); - } - - void NameSpacingParser::startPrefixMapping(const std::string& prefix, const std::string& uri) { - nameSpace.insert(std::make_pair(uri, prefix)); - } +NameSpacingParser::NameSpacingParser() { + setErrorHandler(_errorHandler); +} + +void NameSpacingParser::startPrefixMapping(const std::string& prefix, const std::string& uri) { + nameSpace.insert(std::make_pair(uri, prefix)); +} } \ No newline at end of file diff --git a/src/uscxml/NameSpacingParser.h b/src/uscxml/NameSpacingParser.h index 7dcefcf..fddf306 100644 --- a/src/uscxml/NameSpacingParser.h +++ b/src/uscxml/NameSpacingParser.h @@ -5,21 +5,29 @@ #include namespace uscxml { - - class NameSpacingParser : public Arabica::SAX2DOM::Parser { - public: - NameSpacingParser(); - static NameSpacingParser* fromXML(const std::string& xml); - static NameSpacingParser* fromInputSource(Arabica::SAX::InputSource& source); - void startPrefixMapping(const std::string& prefix, const std::string& uri); +class NameSpacingParser : public Arabica::SAX2DOM::Parser { +public: + NameSpacingParser(); + static NameSpacingParser fromXML(const std::string& xml); + static NameSpacingParser fromInputSource(Arabica::SAX::InputSource& source); - Arabica::SAX::CatchErrorHandler _errorHandler; - std::map nameSpace; + void startPrefixMapping(const std::string& prefix, const std::string& uri); - private: - NameSpacingParser(const NameSpacingParser& other) {} - }; + std::map nameSpace; + + virtual bool errorsReported() { + return _errorHandler.errorsReported(); + } + + virtual const std::string& errors() { + return _errorHandler.errors(); + } + +private: + Arabica::SAX::CatchErrorHandler _errorHandler; + NameSpacingParser(const NameSpacingParser& other) {} +}; } diff --git a/src/uscxml/interpreter/InterpreterDraft6.cpp b/src/uscxml/interpreter/InterpreterDraft6.cpp index fb6a637..915eba5 100644 --- a/src/uscxml/interpreter/InterpreterDraft6.cpp +++ b/src/uscxml/interpreter/InterpreterDraft6.cpp @@ -15,7 +15,7 @@ void InterpreterDraft6::interpret() { init(); // std::cout << _scxml << std::endl; - + if (!_scxml) { // _mutex.unlock(); return; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp index d16f81b..bee6042 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp @@ -5,59 +5,59 @@ namespace Arabica { namespace DOM { - v8::Persistent V8Attr::Tmpl; +v8::Persistent V8Attr::Tmpl; - v8::Handle V8Attr::nameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Attr::nameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getName().c_str()); - } + return v8::String::New(privData->nativeObj->getName().c_str()); +} - v8::Handle V8Attr::specifiedAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Attr::specifiedAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::Boolean::New(privData->nativeObj->getSpecified()); - } + return v8::Boolean::New(privData->nativeObj->getSpecified()); +} - v8::Handle V8Attr::valueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Attr::valueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getValue().c_str()); - } + return v8::String::New(privData->nativeObj->getValue().c_str()); +} - void V8Attr::valueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localValue(value); - privData->nativeObj->setValue(*localValue); - } +void V8Attr::valueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localValue(value); + privData->nativeObj->setValue(*localValue); +} - v8::Handle V8Attr::ownerElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Attr::ownerElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - if (!privData->nativeObj->getOwnerElement()) return v8::Undefined(); - Arabica::DOM::Element* arbaicaRet = new Arabica::DOM::Element(privData->nativeObj->getOwnerElement()); + if (!privData->nativeObj->getOwnerElement()) return v8::Undefined(); + Arabica::DOM::Element* arbaicaRet = new Arabica::DOM::Element(privData->nativeObj->getOwnerElement()); - v8::Handle arbaicaRetCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + v8::Handle arbaicaRetCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8Element::jsDestructor); - return arbaicaRetObj; + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - } - bool V8Attr::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Element::jsDestructor); + return arbaicaRetObj; -} -} +} +bool V8Attr::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h index e317698..9829023 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h @@ -33,50 +33,50 @@ namespace DOM { class V8Attr { public: - struct V8AttrPrivate { - V8DOM* dom; - Arabica::DOM::Attr* nativeObj; - }; - - V8_DESTRUCTOR(V8AttrPrivate); - static bool hasInstance(v8::Handle); - - - static v8::Handle nameAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle specifiedAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle valueAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static void valueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); - static v8::Handle ownerElementAttrGetter(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("Attr")); - 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("name"), V8Attr::nameAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("specified"), V8Attr::specifiedAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("value"), V8Attr::valueAttrGetter, V8Attr::valueAttrSetter, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("ownerElement"), V8Attr::ownerElementAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8AttrPrivate { + V8DOM* dom; + Arabica::DOM::Attr* nativeObj; + }; + + V8_DESTRUCTOR(V8AttrPrivate); + static bool hasInstance(v8::Handle); + + + static v8::Handle nameAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle specifiedAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle valueAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static void valueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); + static v8::Handle ownerElementAttrGetter(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("Attr")); + 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("name"), V8Attr::nameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("specified"), V8Attr::specifiedAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("value"), V8Attr::valueAttrGetter, V8Attr::valueAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("ownerElement"), V8Attr::ownerElementAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp index 90495f4..a9e5ac9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp @@ -4,11 +4,11 @@ namespace Arabica { namespace DOM { - v8::Persistent V8CDATASection::Tmpl; +v8::Persistent V8CDATASection::Tmpl; - bool V8CDATASection::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8CDATASection::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h index f9767a0..3b95b84 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h @@ -33,37 +33,37 @@ namespace DOM { class V8CDATASection { public: - struct V8CDATASectionPrivate { - V8DOM* dom; - Arabica::DOM::CDATASection* nativeObj; - }; + struct V8CDATASectionPrivate { + V8DOM* dom; + Arabica::DOM::CDATASection* nativeObj; + }; - V8_DESTRUCTOR(V8CDATASectionPrivate); - static bool hasInstance(v8::Handle); + V8_DESTRUCTOR(V8CDATASectionPrivate); + static bool hasInstance(v8::Handle); - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("CDATASection")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("CDATASection")); + tmpl->ReadOnlyPrototype(); - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + instance->SetInternalFieldCount(1); - tmpl->Inherit(V8Text::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8Text::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp index 74c80ea..459cf96 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp @@ -4,102 +4,102 @@ namespace Arabica { namespace DOM { - v8::Persistent V8CharacterData::Tmpl; +v8::Persistent V8CharacterData::Tmpl; - v8::Handle V8CharacterData::dataAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8CharacterData::dataAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getData().c_str()); - } + return v8::String::New(privData->nativeObj->getData().c_str()); +} - void V8CharacterData::dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localData(value); - privData->nativeObj->setData(*localData); - } +void V8CharacterData::dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localData(value); + privData->nativeObj->setData(*localData); +} - v8::Handle V8CharacterData::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8CharacterData::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::Integer::New(privData->nativeObj->getLength()); - } - v8::Handle V8CharacterData::substringDataCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in substringData"); + return v8::Integer::New(privData->nativeObj->getLength()); +} +v8::Handle V8CharacterData::substringDataCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in substringData"); - v8::Local self = args.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + v8::Local self = args.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localCount = args[1]->ToNumber()->Uint32Value(); - std::string retVal = privData->nativeObj->substringData(localOffset, localCount); + std::string retVal = privData->nativeObj->substringData(localOffset, localCount); - return v8::String::New(retVal.c_str()); - } + return v8::String::New(retVal.c_str()); +} - v8::Handle V8CharacterData::appendDataCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in appendData"); +v8::Handle V8CharacterData::appendDataCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in appendData"); - v8::Local self = args.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localArg(args[0]); + v8::Local self = args.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localArg(args[0]); - privData->nativeObj->appendData(*localArg); + privData->nativeObj->appendData(*localArg); - return v8::Undefined(); - } + return v8::Undefined(); +} - v8::Handle V8CharacterData::insertDataCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in insertData"); +v8::Handle V8CharacterData::insertDataCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in insertData"); - v8::Local self = args.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - v8::String::AsciiValue localArg(args[1]); + v8::Local self = args.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + v8::String::AsciiValue localArg(args[1]); - privData->nativeObj->insertData(localOffset, *localArg); + privData->nativeObj->insertData(localOffset, *localArg); - return v8::Undefined(); - } + return v8::Undefined(); +} - v8::Handle V8CharacterData::deleteDataCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in deleteData"); +v8::Handle V8CharacterData::deleteDataCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in deleteData"); - v8::Local self = args.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + v8::Local self = args.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localCount = args[1]->ToNumber()->Uint32Value(); - privData->nativeObj->deleteData(localOffset, localCount); + privData->nativeObj->deleteData(localOffset, localCount); - return v8::Undefined(); - } + return v8::Undefined(); +} - v8::Handle V8CharacterData::replaceDataCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in replaceData"); +v8::Handle V8CharacterData::replaceDataCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in replaceData"); - v8::Local self = args.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - unsigned long localCount = args[1]->ToNumber()->Uint32Value(); - v8::String::AsciiValue localArg(args[2]); + v8::Local self = args.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + v8::String::AsciiValue localArg(args[2]); - privData->nativeObj->replaceData(localOffset, localCount, *localArg); + privData->nativeObj->replaceData(localOffset, localCount, *localArg); - return v8::Undefined(); - } + return v8::Undefined(); +} - bool V8CharacterData::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8CharacterData::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h index fe93896..6c51ca7 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h @@ -33,59 +33,59 @@ namespace DOM { class V8CharacterData { public: - struct V8CharacterDataPrivate { - V8DOM* dom; - Arabica::DOM::CharacterData* nativeObj; - }; - - V8_DESTRUCTOR(V8CharacterDataPrivate); - static bool hasInstance(v8::Handle); - - static v8::Handle substringDataCallback(const v8::Arguments&); - static v8::Handle appendDataCallback(const v8::Arguments&); - static v8::Handle insertDataCallback(const v8::Arguments&); - static v8::Handle deleteDataCallback(const v8::Arguments&); - static v8::Handle replaceDataCallback(const v8::Arguments&); - - static v8::Handle dataAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static void dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); - 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("CharacterData")); - 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("data"), V8CharacterData::dataAttrGetter, V8CharacterData::dataAttrSetter, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("length"), V8CharacterData::lengthAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - prototype->Set(v8::String::NewSymbol("substringData"), - v8::FunctionTemplate::New(V8CharacterData::substringDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("appendData"), - v8::FunctionTemplate::New(V8CharacterData::appendDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("insertData"), - v8::FunctionTemplate::New(V8CharacterData::insertDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("deleteData"), - v8::FunctionTemplate::New(V8CharacterData::deleteDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("replaceData"), - v8::FunctionTemplate::New(V8CharacterData::replaceDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8CharacterDataPrivate { + V8DOM* dom; + Arabica::DOM::CharacterData* nativeObj; + }; + + V8_DESTRUCTOR(V8CharacterDataPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle substringDataCallback(const v8::Arguments&); + static v8::Handle appendDataCallback(const v8::Arguments&); + static v8::Handle insertDataCallback(const v8::Arguments&); + static v8::Handle deleteDataCallback(const v8::Arguments&); + static v8::Handle replaceDataCallback(const v8::Arguments&); + + static v8::Handle dataAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static void dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); + 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("CharacterData")); + 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("data"), V8CharacterData::dataAttrGetter, V8CharacterData::dataAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("length"), V8CharacterData::lengthAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("substringData"), + v8::FunctionTemplate::New(V8CharacterData::substringDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("appendData"), + v8::FunctionTemplate::New(V8CharacterData::appendDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("insertData"), + v8::FunctionTemplate::New(V8CharacterData::insertDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("deleteData"), + v8::FunctionTemplate::New(V8CharacterData::deleteDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("replaceData"), + v8::FunctionTemplate::New(V8CharacterData::replaceDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp index e470a70..f754ea7 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp @@ -4,11 +4,11 @@ namespace Arabica { namespace DOM { - v8::Persistent V8Comment::Tmpl; +v8::Persistent V8Comment::Tmpl; - bool V8Comment::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8Comment::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h index c659150..074da74 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h @@ -33,37 +33,37 @@ namespace DOM { class V8Comment { public: - struct V8CommentPrivate { - V8DOM* dom; - Arabica::DOM::Comment* nativeObj; - }; + struct V8CommentPrivate { + V8DOM* dom; + Arabica::DOM::Comment* nativeObj; + }; - V8_DESTRUCTOR(V8CommentPrivate); - static bool hasInstance(v8::Handle); + V8_DESTRUCTOR(V8CommentPrivate); + static bool hasInstance(v8::Handle); - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Comment")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Comment")); + tmpl->ReadOnlyPrototype(); - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + instance->SetInternalFieldCount(1); - tmpl->Inherit(V8CharacterData::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8CharacterData::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp index 0f81958..f7a7575 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp @@ -5,77 +5,77 @@ namespace Arabica { namespace DOM { - v8::Persistent V8DOMImplementation::Tmpl; +v8::Persistent V8DOMImplementation::Tmpl; - v8::Handle V8DOMImplementation::hasFeatureCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in hasFeature"); +v8::Handle V8DOMImplementation::hasFeatureCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in hasFeature"); - v8::Local self = args.Holder(); - struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localFeature(args[0]); - v8::String::AsciiValue localVersion(args[1]); + v8::Local self = args.Holder(); + struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localFeature(args[0]); + v8::String::AsciiValue localVersion(args[1]); - bool retVal = privData->nativeObj->hasFeature(*localFeature, *localVersion); + bool retVal = privData->nativeObj->hasFeature(*localFeature, *localVersion); - return v8::Boolean::New(retVal); - } + return v8::Boolean::New(retVal); +} - v8::Handle V8DOMImplementation::createDocumentTypeCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in createDocumentType"); +v8::Handle V8DOMImplementation::createDocumentTypeCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in createDocumentType"); - v8::Local self = args.Holder(); - struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localQualifiedName(args[0]); - v8::String::AsciiValue localPublicId(args[1]); - v8::String::AsciiValue localSystemId(args[2]); + v8::Local self = args.Holder(); + struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localQualifiedName(args[0]); + v8::String::AsciiValue localPublicId(args[1]); + v8::String::AsciiValue localSystemId(args[2]); - Arabica::DOM::DocumentType* retVal = new Arabica::DOM::DocumentType(privData->nativeObj->createDocumentType(*localQualifiedName, *localPublicId, *localSystemId)); - v8::Handle retCtor = V8DocumentType::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::DocumentType* retVal = new Arabica::DOM::DocumentType(privData->nativeObj->createDocumentType(*localQualifiedName, *localPublicId, *localSystemId)); + v8::Handle retCtor = V8DocumentType::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8DocumentType::V8DocumentTypePrivate* retPrivData = new V8DocumentType::V8DocumentTypePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8DocumentType::V8DocumentTypePrivate* retPrivData = new V8DocumentType::V8DocumentTypePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8DocumentType::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8DocumentType::jsDestructor); + return retObj; - } +} - v8::Handle V8DOMImplementation::createDocumentCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in createDocument"); - if (!(V8DocumentType::hasInstance(args[2]))) - throw V8Exception("Parameter mismatch while calling createDocument"); +v8::Handle V8DOMImplementation::createDocumentCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in createDocument"); + if (!(V8DocumentType::hasInstance(args[2]))) + throw V8Exception("Parameter mismatch while calling createDocument"); - v8::Local self = args.Holder(); - struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); - Arabica::DOM::DocumentType* localDoctype = V8DOM::toClassPtr(args[2]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local self = args.Holder(); + struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + Arabica::DOM::DocumentType* localDoctype = V8DOM::toClassPtr(args[2]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Document* retVal = new Arabica::DOM::Document(privData->nativeObj->createDocument(*localNamespaceURI, *localQualifiedName, *localDoctype)); - v8::Handle retCtor = V8Document::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Document* retVal = new Arabica::DOM::Document(privData->nativeObj->createDocument(*localNamespaceURI, *localQualifiedName, *localDoctype)); + v8::Handle retCtor = V8Document::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Document::V8DocumentPrivate* retPrivData = new V8Document::V8DocumentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Document::V8DocumentPrivate* retPrivData = new V8Document::V8DocumentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Document::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Document::jsDestructor); + return retObj; - } +} - bool V8DOMImplementation::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8DOMImplementation::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h index 6fb8c7e..5c58e22 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h @@ -32,45 +32,45 @@ namespace DOM { class V8DOMImplementation { public: - struct V8DOMImplementationPrivate { - V8DOM* dom; - Arabica::DOM::DOMImplementation* nativeObj; - }; + struct V8DOMImplementationPrivate { + V8DOM* dom; + Arabica::DOM::DOMImplementation* nativeObj; + }; - V8_DESTRUCTOR(V8DOMImplementationPrivate); - static bool hasInstance(v8::Handle); + V8_DESTRUCTOR(V8DOMImplementationPrivate); + static bool hasInstance(v8::Handle); - static v8::Handle hasFeatureCallback(const v8::Arguments&); - static v8::Handle createDocumentTypeCallback(const v8::Arguments&); - static v8::Handle createDocumentCallback(const v8::Arguments&); + static v8::Handle hasFeatureCallback(const v8::Arguments&); + static v8::Handle createDocumentTypeCallback(const v8::Arguments&); + static v8::Handle createDocumentCallback(const v8::Arguments&); - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("DOMImplementation")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("DOMImplementation")); + tmpl->ReadOnlyPrototype(); - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + instance->SetInternalFieldCount(1); - prototype->Set(v8::String::NewSymbol("hasFeature"), - v8::FunctionTemplate::New(V8DOMImplementation::hasFeatureCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createDocumentType"), - v8::FunctionTemplate::New(V8DOMImplementation::createDocumentTypeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createDocument"), - v8::FunctionTemplate::New(V8DOMImplementation::createDocumentCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasFeature"), + v8::FunctionTemplate::New(V8DOMImplementation::hasFeatureCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createDocumentType"), + v8::FunctionTemplate::New(V8DOMImplementation::createDocumentTypeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createDocument"), + v8::FunctionTemplate::New(V8DOMImplementation::createDocumentCallback, v8::Undefined()), static_cast(v8::DontDelete)); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp index d9d123a..06191ea 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp @@ -15,397 +15,397 @@ namespace Arabica { namespace DOM { - v8::Persistent V8Document::Tmpl; +v8::Persistent V8Document::Tmpl; - v8::Handle V8Document::doctypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Document::doctypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - if (!privData->nativeObj->getDoctype()) return v8::Undefined(); - Arabica::DOM::DocumentType* arbaicaRet = new Arabica::DOM::DocumentType(privData->nativeObj->getDoctype()); + if (!privData->nativeObj->getDoctype()) return v8::Undefined(); + Arabica::DOM::DocumentType* arbaicaRet = new Arabica::DOM::DocumentType(privData->nativeObj->getDoctype()); - v8::Handle arbaicaRetCtor = V8DocumentType::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + v8::Handle arbaicaRetCtor = V8DocumentType::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - struct V8DocumentType::V8DocumentTypePrivate* retPrivData = new V8DocumentType::V8DocumentTypePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8DocumentType::jsDestructor); - return arbaicaRetObj; + struct V8DocumentType::V8DocumentTypePrivate* retPrivData = new V8DocumentType::V8DocumentTypePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - } + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8DocumentType::jsDestructor); + return arbaicaRetObj; - v8::Handle V8Document::implementationAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +} - if (!privData->nativeObj->getImplementation()) return v8::Undefined(); - Arabica::DOM::DOMImplementation* arbaicaRet = new Arabica::DOM::DOMImplementation(privData->nativeObj->getImplementation()); +v8::Handle V8Document::implementationAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::Handle arbaicaRetCtor = V8DOMImplementation::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + if (!privData->nativeObj->getImplementation()) return v8::Undefined(); + Arabica::DOM::DOMImplementation* arbaicaRet = new Arabica::DOM::DOMImplementation(privData->nativeObj->getImplementation()); - struct V8DOMImplementation::V8DOMImplementationPrivate* retPrivData = new V8DOMImplementation::V8DOMImplementationPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8DOMImplementation::jsDestructor); - return arbaicaRetObj; + v8::Handle arbaicaRetCtor = V8DOMImplementation::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - } + struct V8DOMImplementation::V8DOMImplementationPrivate* retPrivData = new V8DOMImplementation::V8DOMImplementationPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - v8::Handle V8Document::documentElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8DOMImplementation::jsDestructor); + return arbaicaRetObj; - if (!privData->nativeObj->getDocumentElement()) return v8::Undefined(); - Arabica::DOM::Element* arbaicaRet = new Arabica::DOM::Element(privData->nativeObj->getDocumentElement()); +} - v8::Handle arbaicaRetCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); +v8::Handle V8Document::documentElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8Element::jsDestructor); - return arbaicaRetObj; + if (!privData->nativeObj->getDocumentElement()) return v8::Undefined(); + Arabica::DOM::Element* arbaicaRet = new Arabica::DOM::Element(privData->nativeObj->getDocumentElement()); - } - v8::Handle V8Document::createElementCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createElement"); + v8::Handle arbaicaRetCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localTagName(args[0]); + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - Arabica::DOM::Element* retVal = new Arabica::DOM::Element(privData->nativeObj->createElement(*localTagName)); - v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Element::jsDestructor); + return arbaicaRetObj; - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +} +v8::Handle V8Document::createElementCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createElement"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localTagName(args[0]); - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; + Arabica::DOM::Element* retVal = new Arabica::DOM::Element(privData->nativeObj->createElement(*localTagName)); + v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::createDocumentFragmentCallback(const v8::Arguments& args) { + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; - Arabica::DOM::DocumentFragment* retVal = new Arabica::DOM::DocumentFragment(privData->nativeObj->createDocumentFragment()); - v8::Handle retCtor = V8DocumentFragment::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8DocumentFragment::V8DocumentFragmentPrivate* retPrivData = new V8DocumentFragment::V8DocumentFragmentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::createDocumentFragmentCallback(const v8::Arguments& args) { - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - retObj.MakeWeak(0, V8DocumentFragment::jsDestructor); - return retObj; + Arabica::DOM::DocumentFragment* retVal = new Arabica::DOM::DocumentFragment(privData->nativeObj->createDocumentFragment()); + v8::Handle retCtor = V8DocumentFragment::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8DocumentFragment::V8DocumentFragmentPrivate* retPrivData = new V8DocumentFragment::V8DocumentFragmentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::createTextNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createTextNode"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localData(args[0]); + retObj.MakeWeak(0, V8DocumentFragment::jsDestructor); + return retObj; - Arabica::DOM::Text* retVal = new Arabica::DOM::Text(privData->nativeObj->createTextNode(*localData)); - v8::Handle retCtor = V8Text::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::createTextNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createTextNode"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localData(args[0]); - retObj.MakeWeak(0, V8Text::jsDestructor); - return retObj; + Arabica::DOM::Text* retVal = new Arabica::DOM::Text(privData->nativeObj->createTextNode(*localData)); + v8::Handle retCtor = V8Text::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::createCommentCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createComment"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localData(args[0]); + retObj.MakeWeak(0, V8Text::jsDestructor); + return retObj; - Arabica::DOM::Comment* retVal = new Arabica::DOM::Comment(privData->nativeObj->createComment(*localData)); - v8::Handle retCtor = V8Comment::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8Comment::V8CommentPrivate* retPrivData = new V8Comment::V8CommentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::createCommentCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createComment"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localData(args[0]); - retObj.MakeWeak(0, V8Comment::jsDestructor); - return retObj; + Arabica::DOM::Comment* retVal = new Arabica::DOM::Comment(privData->nativeObj->createComment(*localData)); + v8::Handle retCtor = V8Comment::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8Comment::V8CommentPrivate* retPrivData = new V8Comment::V8CommentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::createCDATASectionCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createCDATASection"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localData(args[0]); + retObj.MakeWeak(0, V8Comment::jsDestructor); + return retObj; - Arabica::DOM::CDATASection* retVal = new Arabica::DOM::CDATASection(privData->nativeObj->createCDATASection(*localData)); - v8::Handle retCtor = V8CDATASection::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8CDATASection::V8CDATASectionPrivate* retPrivData = new V8CDATASection::V8CDATASectionPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::createCDATASectionCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createCDATASection"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localData(args[0]); - retObj.MakeWeak(0, V8CDATASection::jsDestructor); - return retObj; + Arabica::DOM::CDATASection* retVal = new Arabica::DOM::CDATASection(privData->nativeObj->createCDATASection(*localData)); + v8::Handle retCtor = V8CDATASection::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8CDATASection::V8CDATASectionPrivate* retPrivData = new V8CDATASection::V8CDATASectionPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::createProcessingInstructionCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in createProcessingInstruction"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localTarget(args[0]); - v8::String::AsciiValue localData(args[1]); + retObj.MakeWeak(0, V8CDATASection::jsDestructor); + return retObj; - Arabica::DOM::ProcessingInstruction* retVal = new Arabica::DOM::ProcessingInstruction(privData->nativeObj->createProcessingInstruction(*localTarget, *localData)); - v8::Handle retCtor = V8ProcessingInstruction::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8ProcessingInstruction::V8ProcessingInstructionPrivate* retPrivData = new V8ProcessingInstruction::V8ProcessingInstructionPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::createProcessingInstructionCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in createProcessingInstruction"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localTarget(args[0]); + v8::String::AsciiValue localData(args[1]); - retObj.MakeWeak(0, V8ProcessingInstruction::jsDestructor); - return retObj; + Arabica::DOM::ProcessingInstruction* retVal = new Arabica::DOM::ProcessingInstruction(privData->nativeObj->createProcessingInstruction(*localTarget, *localData)); + v8::Handle retCtor = V8ProcessingInstruction::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8ProcessingInstruction::V8ProcessingInstructionPrivate* retPrivData = new V8ProcessingInstruction::V8ProcessingInstructionPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::createAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createAttribute"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + retObj.MakeWeak(0, V8ProcessingInstruction::jsDestructor); + return retObj; - Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->createAttribute(*localName)); - v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::createAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createAttribute"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->createAttribute(*localName)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::createEntityReferenceCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createEntityReference"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; - Arabica::DOM::EntityReference* retVal = new Arabica::DOM::EntityReference(privData->nativeObj->createEntityReference(*localName)); - v8::Handle retCtor = V8EntityReference::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8EntityReference::V8EntityReferencePrivate* retPrivData = new V8EntityReference::V8EntityReferencePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::createEntityReferenceCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createEntityReference"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - retObj.MakeWeak(0, V8EntityReference::jsDestructor); - return retObj; + Arabica::DOM::EntityReference* retVal = new Arabica::DOM::EntityReference(privData->nativeObj->createEntityReference(*localName)); + v8::Handle retCtor = V8EntityReference::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8EntityReference::V8EntityReferencePrivate* retPrivData = new V8EntityReference::V8EntityReferencePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::getElementsByTagNameCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getElementsByTagName"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localTagname(args[0]); + retObj.MakeWeak(0, V8EntityReference::jsDestructor); + return retObj; - Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->nativeObj->getElementsByTagName(*localTagname)); - v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::getElementsByTagNameCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getElementsByTagName"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localTagname(args[0]); - retObj.MakeWeak(0, V8NodeList::jsDestructor); - return retObj; + Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->nativeObj->getElementsByTagName(*localTagname)); + v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::importNodeCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in importNode"); - if (!(V8Node::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling importNode"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Node* localImportedNode = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; - bool localDeep = args[1]->ToBoolean()->BooleanValue(); + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->importNode(*localImportedNode, localDeep)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::importNodeCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in importNode"); + if (!(V8Node::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling importNode"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localImportedNode = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; + bool localDeep = args[1]->ToBoolean()->BooleanValue(); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->importNode(*localImportedNode, localDeep)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::createElementNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in createElementNS"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - Arabica::DOM::Element* retVal = new Arabica::DOM::Element(privData->nativeObj->createElementNS(*localNamespaceURI, *localQualifiedName)); - v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::createElementNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in createElementNS"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; + Arabica::DOM::Element* retVal = new Arabica::DOM::Element(privData->nativeObj->createElementNS(*localNamespaceURI, *localQualifiedName)); + v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::createAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in createAttributeNS"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; - Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->createAttributeNS(*localNamespaceURI, *localQualifiedName)); - v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::createAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in createAttributeNS"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->createAttributeNS(*localNamespaceURI, *localQualifiedName)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::getElementsByTagNameNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getElementsByTagNameNS"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; - Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); - v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::getElementsByTagNameNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getElementsByTagNameNS"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - retObj.MakeWeak(0, V8NodeList::jsDestructor); - return retObj; + Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); + v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle V8Document::getElementByIdCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getElementById"); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localElementId(args[0]); + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; - Arabica::DOM::Element* retVal = new Arabica::DOM::Element(privData->nativeObj->getElementById(*localElementId)); - v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Document::getElementByIdCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getElementById"); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localElementId(args[0]); - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; + Arabica::DOM::Element* retVal = new Arabica::DOM::Element(privData->nativeObj->getElementById(*localElementId)); + v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - } + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - bool V8Document::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); -} -} + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; + +} + +bool V8Document::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h index c12e0dc..2db4b54 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h @@ -33,91 +33,91 @@ namespace DOM { class V8Document { public: - struct V8DocumentPrivate { - V8DOM* dom; - Arabica::DOM::Document* nativeObj; - }; - - V8_DESTRUCTOR(V8DocumentPrivate); - static bool hasInstance(v8::Handle); - - static v8::Handle createElementCallback(const v8::Arguments&); - static v8::Handle createDocumentFragmentCallback(const v8::Arguments&); - static v8::Handle createTextNodeCallback(const v8::Arguments&); - static v8::Handle createCommentCallback(const v8::Arguments&); - static v8::Handle createCDATASectionCallback(const v8::Arguments&); - static v8::Handle createProcessingInstructionCallback(const v8::Arguments&); - static v8::Handle createAttributeCallback(const v8::Arguments&); - static v8::Handle createEntityReferenceCallback(const v8::Arguments&); - static v8::Handle getElementsByTagNameCallback(const v8::Arguments&); - static v8::Handle importNodeCallback(const v8::Arguments&); - static v8::Handle createElementNSCallback(const v8::Arguments&); - static v8::Handle createAttributeNSCallback(const v8::Arguments&); - static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments&); - static v8::Handle getElementByIdCallback(const v8::Arguments&); - static v8::Handle evaluateCustomCallback(const v8::Arguments&); - - 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::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Document")); - 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("doctype"), V8Document::doctypeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("implementation"), V8Document::implementationAttrGetter, 0, - 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)); - - prototype->Set(v8::String::NewSymbol("createElement"), - v8::FunctionTemplate::New(V8Document::createElementCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createDocumentFragment"), - v8::FunctionTemplate::New(V8Document::createDocumentFragmentCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createTextNode"), - v8::FunctionTemplate::New(V8Document::createTextNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createComment"), - v8::FunctionTemplate::New(V8Document::createCommentCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createCDATASection"), - v8::FunctionTemplate::New(V8Document::createCDATASectionCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createProcessingInstruction"), - v8::FunctionTemplate::New(V8Document::createProcessingInstructionCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createAttribute"), - v8::FunctionTemplate::New(V8Document::createAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createEntityReference"), - v8::FunctionTemplate::New(V8Document::createEntityReferenceCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagName"), - v8::FunctionTemplate::New(V8Document::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("importNode"), - v8::FunctionTemplate::New(V8Document::importNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createElementNS"), - v8::FunctionTemplate::New(V8Document::createElementNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createAttributeNS"), - v8::FunctionTemplate::New(V8Document::createAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), - v8::FunctionTemplate::New(V8Document::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementById"), - v8::FunctionTemplate::New(V8Document::getElementByIdCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("evaluate"), - v8::FunctionTemplate::New(V8Document::evaluateCustomCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8DocumentPrivate { + V8DOM* dom; + Arabica::DOM::Document* nativeObj; + }; + + V8_DESTRUCTOR(V8DocumentPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle createElementCallback(const v8::Arguments&); + static v8::Handle createDocumentFragmentCallback(const v8::Arguments&); + static v8::Handle createTextNodeCallback(const v8::Arguments&); + static v8::Handle createCommentCallback(const v8::Arguments&); + static v8::Handle createCDATASectionCallback(const v8::Arguments&); + static v8::Handle createProcessingInstructionCallback(const v8::Arguments&); + static v8::Handle createAttributeCallback(const v8::Arguments&); + static v8::Handle createEntityReferenceCallback(const v8::Arguments&); + static v8::Handle getElementsByTagNameCallback(const v8::Arguments&); + static v8::Handle importNodeCallback(const v8::Arguments&); + static v8::Handle createElementNSCallback(const v8::Arguments&); + static v8::Handle createAttributeNSCallback(const v8::Arguments&); + static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments&); + static v8::Handle getElementByIdCallback(const v8::Arguments&); + static v8::Handle evaluateCustomCallback(const v8::Arguments&); + + 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::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Document")); + 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("doctype"), V8Document::doctypeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("implementation"), V8Document::implementationAttrGetter, 0, + 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)); + + prototype->Set(v8::String::NewSymbol("createElement"), + v8::FunctionTemplate::New(V8Document::createElementCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createDocumentFragment"), + v8::FunctionTemplate::New(V8Document::createDocumentFragmentCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createTextNode"), + v8::FunctionTemplate::New(V8Document::createTextNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createComment"), + v8::FunctionTemplate::New(V8Document::createCommentCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createCDATASection"), + v8::FunctionTemplate::New(V8Document::createCDATASectionCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createProcessingInstruction"), + v8::FunctionTemplate::New(V8Document::createProcessingInstructionCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createAttribute"), + v8::FunctionTemplate::New(V8Document::createAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createEntityReference"), + v8::FunctionTemplate::New(V8Document::createEntityReferenceCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagName"), + v8::FunctionTemplate::New(V8Document::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("importNode"), + v8::FunctionTemplate::New(V8Document::importNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createElementNS"), + v8::FunctionTemplate::New(V8Document::createElementNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createAttributeNS"), + v8::FunctionTemplate::New(V8Document::createAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), + v8::FunctionTemplate::New(V8Document::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementById"), + v8::FunctionTemplate::New(V8Document::getElementByIdCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("evaluate"), + v8::FunctionTemplate::New(V8Document::evaluateCustomCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp index e6bec84..1403574 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp @@ -4,11 +4,11 @@ namespace Arabica { namespace DOM { - v8::Persistent V8DocumentFragment::Tmpl; +v8::Persistent V8DocumentFragment::Tmpl; - bool V8DocumentFragment::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8DocumentFragment::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h index cf7f6ba..c669b05 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h @@ -33,37 +33,37 @@ namespace DOM { class V8DocumentFragment { public: - struct V8DocumentFragmentPrivate { - V8DOM* dom; - Arabica::DOM::DocumentFragment* nativeObj; - }; + struct V8DocumentFragmentPrivate { + V8DOM* dom; + Arabica::DOM::DocumentFragment* nativeObj; + }; - V8_DESTRUCTOR(V8DocumentFragmentPrivate); - static bool hasInstance(v8::Handle); + V8_DESTRUCTOR(V8DocumentFragmentPrivate); + static bool hasInstance(v8::Handle); - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("DocumentFragment")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("DocumentFragment")); + tmpl->ReadOnlyPrototype(); - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + instance->SetInternalFieldCount(1); - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp index a2098f2..6b9a7b0 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp @@ -5,79 +5,79 @@ namespace Arabica { namespace DOM { - v8::Persistent V8DocumentType::Tmpl; +v8::Persistent V8DocumentType::Tmpl; - v8::Handle V8DocumentType::nameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8DocumentType::nameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getName().c_str()); - } + return v8::String::New(privData->nativeObj->getName().c_str()); +} - v8::Handle V8DocumentType::entitiesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8DocumentType::entitiesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - - Arabica::DOM::NamedNodeMap* arbaicaRet = new Arabica::DOM::NamedNodeMap(privData->nativeObj->getEntities()); - v8::Handle arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + Arabica::DOM::NamedNodeMap* arbaicaRet = new Arabica::DOM::NamedNodeMap(privData->nativeObj->getEntities()); - struct V8NamedNodeMap::V8NamedNodeMapPrivate* retPrivData = new V8NamedNodeMap::V8NamedNodeMapPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8NamedNodeMap::jsDestructor); - return arbaicaRetObj; + v8::Handle arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - } + struct V8NamedNodeMap::V8NamedNodeMapPrivate* retPrivData = new V8NamedNodeMap::V8NamedNodeMapPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - v8::Handle V8DocumentType::notationsAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8NamedNodeMap::jsDestructor); + return arbaicaRetObj; - - Arabica::DOM::NamedNodeMap* arbaicaRet = new Arabica::DOM::NamedNodeMap(privData->nativeObj->getNotations()); +} - v8::Handle arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); +v8::Handle V8DocumentType::notationsAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - struct V8NamedNodeMap::V8NamedNodeMapPrivate* retPrivData = new V8NamedNodeMap::V8NamedNodeMapPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8NamedNodeMap::jsDestructor); - return arbaicaRetObj; - } + Arabica::DOM::NamedNodeMap* arbaicaRet = new Arabica::DOM::NamedNodeMap(privData->nativeObj->getNotations()); - v8::Handle V8DocumentType::publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::Handle arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - return v8::String::New(privData->nativeObj->getPublicId().c_str()); - } + struct V8NamedNodeMap::V8NamedNodeMapPrivate* retPrivData = new V8NamedNodeMap::V8NamedNodeMapPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - v8::Handle V8DocumentType::systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8NamedNodeMap::jsDestructor); + return arbaicaRetObj; - return v8::String::New(privData->nativeObj->getSystemId().c_str()); - } +} - v8::Handle V8DocumentType::internalSubsetAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8DocumentType::publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getInternalSubset().c_str()); - } - bool V8DocumentType::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } + return v8::String::New(privData->nativeObj->getPublicId().c_str()); +} -} -} +v8::Handle V8DocumentType::systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->nativeObj->getSystemId().c_str()); +} + +v8::Handle V8DocumentType::internalSubsetAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->nativeObj->getInternalSubset().c_str()); +} +bool V8DocumentType::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h index 65ce30c..59c2607 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h @@ -33,55 +33,55 @@ namespace DOM { class V8DocumentType { public: - struct V8DocumentTypePrivate { - V8DOM* dom; - Arabica::DOM::DocumentType* nativeObj; - }; - - V8_DESTRUCTOR(V8DocumentTypePrivate); - static bool hasInstance(v8::Handle); - - - static v8::Handle nameAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle entitiesAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle notationsAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle internalSubsetAttrGetter(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("DocumentType")); - 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("name"), V8DocumentType::nameAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("entities"), V8DocumentType::entitiesAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("notations"), V8DocumentType::notationsAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("publicId"), V8DocumentType::publicIdAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("systemId"), V8DocumentType::systemIdAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("internalSubset"), V8DocumentType::internalSubsetAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8DocumentTypePrivate { + V8DOM* dom; + Arabica::DOM::DocumentType* nativeObj; + }; + + V8_DESTRUCTOR(V8DocumentTypePrivate); + static bool hasInstance(v8::Handle); + + + static v8::Handle nameAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle entitiesAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle notationsAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle internalSubsetAttrGetter(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("DocumentType")); + 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("name"), V8DocumentType::nameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("entities"), V8DocumentType::entitiesAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("notations"), V8DocumentType::notationsAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("publicId"), V8DocumentType::publicIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("systemId"), V8DocumentType::systemIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("internalSubset"), V8DocumentType::internalSubsetAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp index d476daa..680dd5e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp @@ -6,297 +6,297 @@ namespace Arabica { namespace DOM { - v8::Persistent V8Element::Tmpl; +v8::Persistent V8Element::Tmpl; - v8::Handle V8Element::tagNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Element::tagNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getTagName().c_str()); - } - v8::Handle V8Element::getAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getAttribute"); + return v8::String::New(privData->nativeObj->getTagName().c_str()); +} +v8::Handle V8Element::getAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getAttribute"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - std::string retVal = privData->nativeObj->getAttribute(*localName); + std::string retVal = privData->nativeObj->getAttribute(*localName); - return v8::String::New(retVal.c_str()); - } + return v8::String::New(retVal.c_str()); +} - v8::Handle V8Element::setAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in setAttribute"); +v8::Handle V8Element::setAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in setAttribute"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); - v8::String::AsciiValue localValue(args[1]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); + v8::String::AsciiValue localValue(args[1]); - privData->nativeObj->setAttribute(*localName, *localValue); + privData->nativeObj->setAttribute(*localName, *localValue); - return v8::Undefined(); - } + return v8::Undefined(); +} - v8::Handle V8Element::removeAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeAttribute"); +v8::Handle V8Element::removeAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeAttribute"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - privData->nativeObj->removeAttribute(*localName); + privData->nativeObj->removeAttribute(*localName); - return v8::Undefined(); - } + return v8::Undefined(); +} - v8::Handle V8Element::getAttributeNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getAttributeNode"); +v8::Handle V8Element::getAttributeNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getAttributeNode"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->getAttributeNode(*localName)); - v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->getAttributeNode(*localName)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; - } +} - v8::Handle V8Element::setAttributeNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in setAttributeNode"); - if (!(V8Attr::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling setAttributeNode"); +v8::Handle V8Element::setAttributeNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in setAttributeNode"); + if (!(V8Attr::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling setAttributeNode"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Attr* localNewAttr = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Attr* localNewAttr = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->setAttributeNode(*localNewAttr)); - v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->setAttributeNode(*localNewAttr)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; - } +} - v8::Handle V8Element::removeAttributeNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeAttributeNode"); - if (!(V8Attr::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling removeAttributeNode"); +v8::Handle V8Element::removeAttributeNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeAttributeNode"); + if (!(V8Attr::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling removeAttributeNode"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Attr* localOldAttr = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Attr* localOldAttr = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->removeAttributeNode(*localOldAttr)); - v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->removeAttributeNode(*localOldAttr)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; - } +} - v8::Handle V8Element::getElementsByTagNameCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getElementsByTagName"); +v8::Handle V8Element::getElementsByTagNameCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getElementsByTagName"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->nativeObj->getElementsByTagName(*localName)); - v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->nativeObj->getElementsByTagName(*localName)); + v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8NodeList::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; - } +} - v8::Handle V8Element::getAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getAttributeNS"); +v8::Handle V8Element::getAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getAttributeNS"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - std::string retVal = privData->nativeObj->getAttributeNS(*localNamespaceURI, *localLocalName); + std::string retVal = privData->nativeObj->getAttributeNS(*localNamespaceURI, *localLocalName); - return v8::String::New(retVal.c_str()); - } + return v8::String::New(retVal.c_str()); +} - v8::Handle V8Element::setAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in setAttributeNS"); +v8::Handle V8Element::setAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in setAttributeNS"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); - v8::String::AsciiValue localValue(args[2]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + v8::String::AsciiValue localValue(args[2]); - privData->nativeObj->setAttributeNS(*localNamespaceURI, *localQualifiedName, *localValue); + privData->nativeObj->setAttributeNS(*localNamespaceURI, *localQualifiedName, *localValue); - return v8::Undefined(); - } + return v8::Undefined(); +} - v8::Handle V8Element::removeAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in removeAttributeNS"); +v8::Handle V8Element::removeAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in removeAttributeNS"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - privData->nativeObj->removeAttributeNS(*localNamespaceURI, *localLocalName); + privData->nativeObj->removeAttributeNS(*localNamespaceURI, *localLocalName); - return v8::Undefined(); - } + return v8::Undefined(); +} - v8::Handle V8Element::getAttributeNodeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getAttributeNodeNS"); +v8::Handle V8Element::getAttributeNodeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getAttributeNodeNS"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->getAttributeNodeNS(*localNamespaceURI, *localLocalName)); - v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->getAttributeNodeNS(*localNamespaceURI, *localLocalName)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; - } +} - v8::Handle V8Element::setAttributeNodeNSCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in setAttributeNodeNS"); - if (!(V8Attr::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling setAttributeNodeNS"); +v8::Handle V8Element::setAttributeNodeNSCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in setAttributeNodeNS"); + if (!(V8Attr::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling setAttributeNodeNS"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Attr* localNewAttr = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Attr* localNewAttr = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->setAttributeNodeNS(*localNewAttr)); - v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->nativeObj->setAttributeNodeNS(*localNewAttr)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; - } +} - v8::Handle V8Element::getElementsByTagNameNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getElementsByTagNameNS"); +v8::Handle V8Element::getElementsByTagNameNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getElementsByTagNameNS"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); - v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); + v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8NodeList::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; - } +} - v8::Handle V8Element::hasAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in hasAttribute"); +v8::Handle V8Element::hasAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in hasAttribute"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - bool retVal = privData->nativeObj->hasAttribute(*localName); + bool retVal = privData->nativeObj->hasAttribute(*localName); - return v8::Boolean::New(retVal); - } + return v8::Boolean::New(retVal); +} - v8::Handle V8Element::hasAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in hasAttributeNS"); +v8::Handle V8Element::hasAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in hasAttributeNS"); - v8::Local self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - bool retVal = privData->nativeObj->hasAttributeNS(*localNamespaceURI, *localLocalName); + bool retVal = privData->nativeObj->hasAttributeNS(*localNamespaceURI, *localLocalName); - return v8::Boolean::New(retVal); - } + return v8::Boolean::New(retVal); +} - bool V8Element::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8Element::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h index 499ae0e..e5a52bf 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h @@ -33,85 +33,85 @@ namespace DOM { class V8Element { public: - struct V8ElementPrivate { - V8DOM* dom; - Arabica::DOM::Element* nativeObj; - }; - - V8_DESTRUCTOR(V8ElementPrivate); - static bool hasInstance(v8::Handle); - - static v8::Handle getAttributeCallback(const v8::Arguments&); - static v8::Handle setAttributeCallback(const v8::Arguments&); - static v8::Handle removeAttributeCallback(const v8::Arguments&); - static v8::Handle getAttributeNodeCallback(const v8::Arguments&); - static v8::Handle setAttributeNodeCallback(const v8::Arguments&); - static v8::Handle removeAttributeNodeCallback(const v8::Arguments&); - static v8::Handle getElementsByTagNameCallback(const v8::Arguments&); - static v8::Handle getAttributeNSCallback(const v8::Arguments&); - static v8::Handle setAttributeNSCallback(const v8::Arguments&); - static v8::Handle removeAttributeNSCallback(const v8::Arguments&); - static v8::Handle getAttributeNodeNSCallback(const v8::Arguments&); - static v8::Handle setAttributeNodeNSCallback(const v8::Arguments&); - static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments&); - static v8::Handle hasAttributeCallback(const v8::Arguments&); - static v8::Handle hasAttributeNSCallback(const v8::Arguments&); - - static v8::Handle tagNameAttrGetter(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("Element")); - 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("tagName"), V8Element::tagNameAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - prototype->Set(v8::String::NewSymbol("getAttribute"), - v8::FunctionTemplate::New(V8Element::getAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttribute"), - v8::FunctionTemplate::New(V8Element::setAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeAttribute"), - v8::FunctionTemplate::New(V8Element::removeAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getAttributeNode"), - v8::FunctionTemplate::New(V8Element::getAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttributeNode"), - v8::FunctionTemplate::New(V8Element::setAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeAttributeNode"), - v8::FunctionTemplate::New(V8Element::removeAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagName"), - v8::FunctionTemplate::New(V8Element::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getAttributeNS"), - v8::FunctionTemplate::New(V8Element::getAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttributeNS"), - v8::FunctionTemplate::New(V8Element::setAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeAttributeNS"), - v8::FunctionTemplate::New(V8Element::removeAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getAttributeNodeNS"), - v8::FunctionTemplate::New(V8Element::getAttributeNodeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttributeNodeNS"), - v8::FunctionTemplate::New(V8Element::setAttributeNodeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), - v8::FunctionTemplate::New(V8Element::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasAttribute"), - v8::FunctionTemplate::New(V8Element::hasAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasAttributeNS"), - v8::FunctionTemplate::New(V8Element::hasAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8ElementPrivate { + V8DOM* dom; + Arabica::DOM::Element* nativeObj; + }; + + V8_DESTRUCTOR(V8ElementPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle getAttributeCallback(const v8::Arguments&); + static v8::Handle setAttributeCallback(const v8::Arguments&); + static v8::Handle removeAttributeCallback(const v8::Arguments&); + static v8::Handle getAttributeNodeCallback(const v8::Arguments&); + static v8::Handle setAttributeNodeCallback(const v8::Arguments&); + static v8::Handle removeAttributeNodeCallback(const v8::Arguments&); + static v8::Handle getElementsByTagNameCallback(const v8::Arguments&); + static v8::Handle getAttributeNSCallback(const v8::Arguments&); + static v8::Handle setAttributeNSCallback(const v8::Arguments&); + static v8::Handle removeAttributeNSCallback(const v8::Arguments&); + static v8::Handle getAttributeNodeNSCallback(const v8::Arguments&); + static v8::Handle setAttributeNodeNSCallback(const v8::Arguments&); + static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments&); + static v8::Handle hasAttributeCallback(const v8::Arguments&); + static v8::Handle hasAttributeNSCallback(const v8::Arguments&); + + static v8::Handle tagNameAttrGetter(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("Element")); + 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("tagName"), V8Element::tagNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("getAttribute"), + v8::FunctionTemplate::New(V8Element::getAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttribute"), + v8::FunctionTemplate::New(V8Element::setAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttribute"), + v8::FunctionTemplate::New(V8Element::removeAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNode"), + v8::FunctionTemplate::New(V8Element::getAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNode"), + v8::FunctionTemplate::New(V8Element::setAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttributeNode"), + v8::FunctionTemplate::New(V8Element::removeAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagName"), + v8::FunctionTemplate::New(V8Element::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNS"), + v8::FunctionTemplate::New(V8Element::getAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNS"), + v8::FunctionTemplate::New(V8Element::setAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttributeNS"), + v8::FunctionTemplate::New(V8Element::removeAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNodeNS"), + v8::FunctionTemplate::New(V8Element::getAttributeNodeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNodeNS"), + v8::FunctionTemplate::New(V8Element::setAttributeNodeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), + v8::FunctionTemplate::New(V8Element::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttribute"), + v8::FunctionTemplate::New(V8Element::hasAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttributeNS"), + v8::FunctionTemplate::New(V8Element::hasAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp index 6db7b15..f3ce21d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp @@ -4,32 +4,32 @@ namespace Arabica { namespace DOM { - v8::Persistent V8Entity::Tmpl; +v8::Persistent V8Entity::Tmpl; - v8::Handle V8Entity::publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8EntityPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Entity::publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8EntityPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getPublicId().c_str()); - } + return v8::String::New(privData->nativeObj->getPublicId().c_str()); +} - v8::Handle V8Entity::systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8EntityPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Entity::systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8EntityPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getSystemId().c_str()); - } + return v8::String::New(privData->nativeObj->getSystemId().c_str()); +} - v8::Handle V8Entity::notationNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8EntityPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Entity::notationNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8EntityPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getNotationName().c_str()); - } - bool V8Entity::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } + return v8::String::New(privData->nativeObj->getNotationName().c_str()); +} +bool V8Entity::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h index acea6ea..6e85585 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h @@ -33,46 +33,46 @@ namespace DOM { class V8Entity { public: - struct V8EntityPrivate { - V8DOM* dom; - Arabica::DOM::Entity* nativeObj; - }; - - V8_DESTRUCTOR(V8EntityPrivate); - static bool hasInstance(v8::Handle); - - - static v8::Handle publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle notationNameAttrGetter(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("Entity")); - 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("publicId"), V8Entity::publicIdAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("systemId"), V8Entity::systemIdAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("notationName"), V8Entity::notationNameAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8EntityPrivate { + V8DOM* dom; + Arabica::DOM::Entity* nativeObj; + }; + + V8_DESTRUCTOR(V8EntityPrivate); + static bool hasInstance(v8::Handle); + + + static v8::Handle publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle notationNameAttrGetter(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("Entity")); + 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("publicId"), V8Entity::publicIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("systemId"), V8Entity::systemIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("notationName"), V8Entity::notationNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp index 95ceee8..197fadd 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp @@ -4,11 +4,11 @@ namespace Arabica { namespace DOM { - v8::Persistent V8EntityReference::Tmpl; +v8::Persistent V8EntityReference::Tmpl; - bool V8EntityReference::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8EntityReference::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h index 9bfb86d..86dd61b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h @@ -33,37 +33,37 @@ namespace DOM { class V8EntityReference { public: - struct V8EntityReferencePrivate { - V8DOM* dom; - Arabica::DOM::EntityReference* nativeObj; - }; + struct V8EntityReferencePrivate { + V8DOM* dom; + Arabica::DOM::EntityReference* nativeObj; + }; - V8_DESTRUCTOR(V8EntityReferencePrivate); - static bool hasInstance(v8::Handle); + V8_DESTRUCTOR(V8EntityReferencePrivate); + static bool hasInstance(v8::Handle); - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("EntityReference")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("EntityReference")); + tmpl->ReadOnlyPrototype(); - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + instance->SetInternalFieldCount(1); - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp index e09bbb8..037d651 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp @@ -4,185 +4,185 @@ namespace Arabica { namespace DOM { - v8::Persistent V8NamedNodeMap::Tmpl; +v8::Persistent V8NamedNodeMap::Tmpl; - v8::Handle V8NamedNodeMap::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8NamedNodeMap::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::Integer::New(privData->nativeObj->getLength()); - } - v8::Handle V8NamedNodeMap::getNamedItemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getNamedItem"); + return v8::Integer::New(privData->nativeObj->getLength()); +} +v8::Handle V8NamedNodeMap::getNamedItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getNamedItem"); - v8::Local self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->getNamedItem(*localName)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->getNamedItem(*localName)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - } +} - v8::Handle V8NamedNodeMap::setNamedItemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in setNamedItem"); - if (!(V8Node::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling setNamedItem"); +v8::Handle V8NamedNodeMap::setNamedItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in setNamedItem"); + if (!(V8Node::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling setNamedItem"); - v8::Local self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Node* localArg = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localArg = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->setNamedItem(*localArg)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->setNamedItem(*localArg)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - } +} - v8::Handle V8NamedNodeMap::removeNamedItemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeNamedItem"); +v8::Handle V8NamedNodeMap::removeNamedItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeNamedItem"); - v8::Local self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->removeNamedItem(*localName)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->removeNamedItem(*localName)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - } +} - v8::Handle V8NamedNodeMap::itemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in item"); +v8::Handle V8NamedNodeMap::itemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in item"); - v8::Local self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + v8::Local self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->item(localIndex)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->item(localIndex)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - } +} - v8::Handle V8NamedNodeMap::getNamedItemNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getNamedItemNS"); +v8::Handle V8NamedNodeMap::getNamedItemNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getNamedItemNS"); - v8::Local self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->getNamedItemNS(*localNamespaceURI, *localLocalName)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->getNamedItemNS(*localNamespaceURI, *localLocalName)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - } +} - v8::Handle V8NamedNodeMap::setNamedItemNSCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in setNamedItemNS"); - if (!(V8Node::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling setNamedItemNS"); +v8::Handle V8NamedNodeMap::setNamedItemNSCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in setNamedItemNS"); + if (!(V8Node::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling setNamedItemNS"); - v8::Local self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Node* localArg = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localArg = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->setNamedItemNS(*localArg)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->setNamedItemNS(*localArg)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - } +} - v8::Handle V8NamedNodeMap::removeNamedItemNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in removeNamedItemNS"); +v8::Handle V8NamedNodeMap::removeNamedItemNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in removeNamedItemNS"); - v8::Local self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->removeNamedItemNS(*localNamespaceURI, *localLocalName)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->removeNamedItemNS(*localNamespaceURI, *localLocalName)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - } +} - bool V8NamedNodeMap::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8NamedNodeMap::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h index a98c5ee..be89037 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h @@ -32,60 +32,60 @@ namespace DOM { class V8NamedNodeMap { public: - struct V8NamedNodeMapPrivate { - V8DOM* dom; - Arabica::DOM::NamedNodeMap* nativeObj; - }; - - V8_DESTRUCTOR(V8NamedNodeMapPrivate); - static bool hasInstance(v8::Handle); - - static v8::Handle getNamedItemCallback(const v8::Arguments&); - static v8::Handle setNamedItemCallback(const v8::Arguments&); - static v8::Handle removeNamedItemCallback(const v8::Arguments&); - static v8::Handle itemCallback(const v8::Arguments&); - static v8::Handle getNamedItemNSCallback(const v8::Arguments&); - static v8::Handle setNamedItemNSCallback(const v8::Arguments&); - static v8::Handle removeNamedItemNSCallback(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("NamedNodeMap")); - 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"), V8NamedNodeMap::lengthAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - prototype->Set(v8::String::NewSymbol("getNamedItem"), - v8::FunctionTemplate::New(V8NamedNodeMap::getNamedItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setNamedItem"), - v8::FunctionTemplate::New(V8NamedNodeMap::setNamedItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeNamedItem"), - v8::FunctionTemplate::New(V8NamedNodeMap::removeNamedItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("item"), - v8::FunctionTemplate::New(V8NamedNodeMap::itemCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getNamedItemNS"), - v8::FunctionTemplate::New(V8NamedNodeMap::getNamedItemNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setNamedItemNS"), - v8::FunctionTemplate::New(V8NamedNodeMap::setNamedItemNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeNamedItemNS"), - v8::FunctionTemplate::New(V8NamedNodeMap::removeNamedItemNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8NamedNodeMapPrivate { + V8DOM* dom; + Arabica::DOM::NamedNodeMap* nativeObj; + }; + + V8_DESTRUCTOR(V8NamedNodeMapPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle getNamedItemCallback(const v8::Arguments&); + static v8::Handle setNamedItemCallback(const v8::Arguments&); + static v8::Handle removeNamedItemCallback(const v8::Arguments&); + static v8::Handle itemCallback(const v8::Arguments&); + static v8::Handle getNamedItemNSCallback(const v8::Arguments&); + static v8::Handle setNamedItemNSCallback(const v8::Arguments&); + static v8::Handle removeNamedItemNSCallback(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("NamedNodeMap")); + 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"), V8NamedNodeMap::lengthAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("getNamedItem"), + v8::FunctionTemplate::New(V8NamedNodeMap::getNamedItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setNamedItem"), + v8::FunctionTemplate::New(V8NamedNodeMap::setNamedItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeNamedItem"), + v8::FunctionTemplate::New(V8NamedNodeMap::removeNamedItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("item"), + v8::FunctionTemplate::New(V8NamedNodeMap::itemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getNamedItemNS"), + v8::FunctionTemplate::New(V8NamedNodeMap::getNamedItemNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setNamedItemNS"), + v8::FunctionTemplate::New(V8NamedNodeMap::setNamedItemNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeNamedItemNS"), + v8::FunctionTemplate::New(V8NamedNodeMap::removeNamedItemNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp index 31f6457..c5b1b83 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp @@ -5,376 +5,376 @@ namespace Arabica { namespace DOM { - v8::Persistent V8Node::Tmpl; +v8::Persistent V8Node::Tmpl; - v8::Handle V8Node::nodeNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Node::nodeNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getNodeName().c_str()); - } + return v8::String::New(privData->nativeObj->getNodeName().c_str()); +} - v8::Handle V8Node::nodeValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Node::nodeValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getNodeValue().c_str()); - } + return v8::String::New(privData->nativeObj->getNodeValue().c_str()); +} - void V8Node::nodeValueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localNodeValue(value); - privData->nativeObj->setNodeValue(*localNodeValue); - } +void V8Node::nodeValueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNodeValue(value); + privData->nativeObj->setNodeValue(*localNodeValue); +} - v8::Handle V8Node::nodeTypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Node::nodeTypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::Integer::New(privData->nativeObj->getNodeType()); - } + return v8::Integer::New(privData->nativeObj->getNodeType()); +} - v8::Handle V8Node::parentNodeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Node::parentNodeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - if (!privData->nativeObj->getParentNode()) return v8::Undefined(); - Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->getParentNode()); + if (!privData->nativeObj->getParentNode()) return v8::Undefined(); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->getParentNode()); - v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); - return arbaicaRetObj; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - } + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; - v8::Handle V8Node::childNodesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +} - - Arabica::DOM::NodeList* arbaicaRet = new Arabica::DOM::NodeList(privData->nativeObj->getChildNodes()); +v8::Handle V8Node::childNodesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::Handle arbaicaRetCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8NodeList::jsDestructor); - return arbaicaRetObj; + Arabica::DOM::NodeList* arbaicaRet = new Arabica::DOM::NodeList(privData->nativeObj->getChildNodes()); - } + v8::Handle arbaicaRetCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - v8::Handle V8Node::firstChildAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - if (!privData->nativeObj->getFirstChild()) return v8::Undefined(); - Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->getFirstChild()); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8NodeList::jsDestructor); + return arbaicaRetObj; - v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); +} - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); - return arbaicaRetObj; +v8::Handle V8Node::firstChildAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - } + if (!privData->nativeObj->getFirstChild()) return v8::Undefined(); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->getFirstChild()); - v8::Handle V8Node::lastChildAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - if (!privData->nativeObj->getLastChild()) return v8::Undefined(); - Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->getLastChild()); + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); - return arbaicaRetObj; - - } - - v8::Handle V8Node::previousSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - - if (!privData->nativeObj->getPreviousSibling()) return v8::Undefined(); - Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->getPreviousSibling()); - - v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); - return arbaicaRetObj; - - } +} - v8::Handle V8Node::nextSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Node::lastChildAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - if (!privData->nativeObj->getNextSibling()) return v8::Undefined(); - Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->getNextSibling()); - - v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); - return arbaicaRetObj; + if (!privData->nativeObj->getLastChild()) return v8::Undefined(); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->getLastChild()); - } + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - v8::Handle V8Node::ownerDocumentAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - if (!privData->nativeObj->getOwnerDocument()) return v8::Undefined(); - Arabica::DOM::Document* arbaicaRet = new Arabica::DOM::Document(privData->nativeObj->getOwnerDocument()); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; - v8::Handle arbaicaRetCtor = V8Document::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); +} - struct V8Document::V8DocumentPrivate* retPrivData = new V8Document::V8DocumentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8Document::jsDestructor); - return arbaicaRetObj; +v8::Handle V8Node::previousSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - } + if (!privData->nativeObj->getPreviousSibling()) return v8::Undefined(); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->getPreviousSibling()); - v8::Handle V8Node::namespaceURIAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - return v8::String::New(privData->nativeObj->getNamespaceURI().c_str()); - } + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - v8::Handle V8Node::prefixAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; - return v8::String::New(privData->nativeObj->getPrefix().c_str()); - } +} - void V8Node::prefixAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localPrefix(value); - privData->nativeObj->setPrefix(*localPrefix); - } +v8::Handle V8Node::nextSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::Handle V8Node::localNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + if (!privData->nativeObj->getNextSibling()) return v8::Undefined(); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->getNextSibling()); - return v8::String::New(privData->nativeObj->getLocalName().c_str()); - } - v8::Handle V8Node::insertBeforeCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in insertBefore"); - if (!((V8Node::hasInstance(args[0])) && (V8Node::hasInstance(args[1])))) - throw V8Exception("Parameter mismatch while calling insertBefore"); + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - v8::Local self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Node* localNewChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node* localRefChild = V8DOM::toClassPtr(args[1]->ToObject()->GetInternalField(0))->nativeObj; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->insertBefore(*localNewChild, *localRefChild)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +} - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); +v8::Handle V8Node::ownerDocumentAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + if (!privData->nativeObj->getOwnerDocument()) return v8::Undefined(); + Arabica::DOM::Document* arbaicaRet = new Arabica::DOM::Document(privData->nativeObj->getOwnerDocument()); - } + v8::Handle arbaicaRetCtor = V8Document::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - v8::Handle V8Node::replaceChildCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in replaceChild"); - if (!((V8Node::hasInstance(args[0])) && (V8Node::hasInstance(args[1])))) - throw V8Exception("Parameter mismatch while calling replaceChild"); + struct V8Document::V8DocumentPrivate* retPrivData = new V8Document::V8DocumentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - v8::Local self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Node* localNewChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node* localOldChild = V8DOM::toClassPtr(args[1]->ToObject()->GetInternalField(0))->nativeObj; + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Document::jsDestructor); + return arbaicaRetObj; - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->replaceChild(*localNewChild, *localOldChild)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +} - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle V8Node::namespaceURIAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + return v8::String::New(privData->nativeObj->getNamespaceURI().c_str()); +} - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; +v8::Handle V8Node::prefixAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - } + return v8::String::New(privData->nativeObj->getPrefix().c_str()); +} - v8::Handle V8Node::removeChildCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeChild"); - if (!(V8Node::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling removeChild"); +void V8Node::prefixAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localPrefix(value); + privData->nativeObj->setPrefix(*localPrefix); +} - v8::Local self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Node* localOldChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; +v8::Handle V8Node::localNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->removeChild(*localOldChild)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + return v8::String::New(privData->nativeObj->getLocalName().c_str()); +} +v8::Handle V8Node::insertBeforeCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in insertBefore"); + if (!((V8Node::hasInstance(args[0])) && (V8Node::hasInstance(args[1])))) + throw V8Exception("Parameter mismatch while calling insertBefore"); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + v8::Local self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localNewChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; + Arabica::DOM::Node* localRefChild = V8DOM::toClassPtr(args[1]->ToObject()->GetInternalField(0))->nativeObj; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->insertBefore(*localNewChild, *localRefChild)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - } + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Handle V8Node::appendChildCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in appendChild"); - if (!(V8Node::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling appendChild"); + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - v8::Local self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::DOM::Node* localNewChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; +} - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->appendChild(*localNewChild)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); +v8::Handle V8Node::replaceChildCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in replaceChild"); + if (!((V8Node::hasInstance(args[0])) && (V8Node::hasInstance(args[1])))) + throw V8Exception("Parameter mismatch while calling replaceChild"); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + v8::Local self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localNewChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; + Arabica::DOM::Node* localOldChild = V8DOM::toClassPtr(args[1]->ToObject()->GetInternalField(0))->nativeObj; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->replaceChild(*localNewChild, *localOldChild)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - } + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Handle V8Node::hasChildNodesCallback(const v8::Arguments& args) { + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - v8::Local self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +} - bool retVal = privData->nativeObj->hasChildNodes(); +v8::Handle V8Node::removeChildCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeChild"); + if (!(V8Node::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling removeChild"); - return v8::Boolean::New(retVal); - } + v8::Local self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localOldChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; - v8::Handle V8Node::cloneNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in cloneNode"); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->removeChild(*localOldChild)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - v8::Local self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - bool localDeep = args[0]->ToBoolean()->BooleanValue(); + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->cloneNode(localDeep)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); +} - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; +v8::Handle V8Node::appendChildCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in appendChild"); + if (!(V8Node::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling appendChild"); - } + v8::Local self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localNewChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->nativeObj; - v8::Handle V8Node::normalizeCallback(const v8::Arguments& args) { + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->appendChild(*localNewChild)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - v8::Local self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - privData->nativeObj->normalize(); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - return v8::Undefined(); - } + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - v8::Handle V8Node::isSupportedCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in isSupported"); +} - v8::Local self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localFeature(args[0]); - v8::String::AsciiValue localVersion(args[1]); +v8::Handle V8Node::hasChildNodesCallback(const v8::Arguments& args) { - bool retVal = privData->nativeObj->isSupported(*localFeature, *localVersion); + v8::Local self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::Boolean::New(retVal); - } + bool retVal = privData->nativeObj->hasChildNodes(); - v8::Handle V8Node::hasAttributesCallback(const v8::Arguments& args) { + return v8::Boolean::New(retVal); +} - v8::Local self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Node::cloneNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in cloneNode"); - bool retVal = privData->nativeObj->hasAttributes(); + v8::Local self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + bool localDeep = args[0]->ToBoolean()->BooleanValue(); - return v8::Boolean::New(retVal); - } + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->cloneNode(localDeep)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - bool V8Node::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; -} -} + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + +} + +v8::Handle V8Node::normalizeCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + privData->nativeObj->normalize(); + + return v8::Undefined(); +} + +v8::Handle V8Node::isSupportedCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in isSupported"); + + v8::Local self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localFeature(args[0]); + v8::String::AsciiValue localVersion(args[1]); + + bool retVal = privData->nativeObj->isSupported(*localFeature, *localVersion); + + return v8::Boolean::New(retVal); +} + +v8::Handle V8Node::hasAttributesCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + bool retVal = privData->nativeObj->hasAttributes(); + + return v8::Boolean::New(retVal); +} + +bool V8Node::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h index 6bb90f9..2ea8ddc 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h @@ -32,131 +32,131 @@ namespace DOM { class V8Node { public: - struct V8NodePrivate { - V8DOM* dom; - Arabica::DOM::Node* nativeObj; - }; - - V8_DESTRUCTOR(V8NodePrivate); - static bool hasInstance(v8::Handle); - - static v8::Handle insertBeforeCallback(const v8::Arguments&); - static v8::Handle replaceChildCallback(const v8::Arguments&); - static v8::Handle removeChildCallback(const v8::Arguments&); - static v8::Handle appendChildCallback(const v8::Arguments&); - static v8::Handle hasChildNodesCallback(const v8::Arguments&); - static v8::Handle cloneNodeCallback(const v8::Arguments&); - static v8::Handle normalizeCallback(const v8::Arguments&); - static v8::Handle isSupportedCallback(const v8::Arguments&); - static v8::Handle hasAttributesCallback(const v8::Arguments&); - - static v8::Handle nodeNameAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle nodeValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static void nodeValueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); - static v8::Handle nodeTypeAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle parentNodeAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle childNodesAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle firstChildAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle lastChildAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle previousSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle nextSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle attributesCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle ownerDocumentAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle namespaceURIAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle prefixAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static void prefixAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); - static v8::Handle localNameAttrGetter(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("Node")); - 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("nodeName"), V8Node::nodeNameAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("nodeValue"), V8Node::nodeValueAttrGetter, V8Node::nodeValueAttrSetter, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("nodeType"), V8Node::nodeTypeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("parentNode"), V8Node::parentNodeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("childNodes"), V8Node::childNodesAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("firstChild"), V8Node::firstChildAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("lastChild"), V8Node::lastChildAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("previousSibling"), V8Node::previousSiblingAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("nextSibling"), V8Node::nextSiblingAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("attributes"), V8Node::attributesCustomAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("ownerDocument"), V8Node::ownerDocumentAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("namespaceURI"), V8Node::namespaceURIAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("prefix"), V8Node::prefixAttrGetter, V8Node::prefixAttrSetter, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("localName"), V8Node::localNameAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - prototype->Set(v8::String::NewSymbol("insertBefore"), - v8::FunctionTemplate::New(V8Node::insertBeforeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("replaceChild"), - v8::FunctionTemplate::New(V8Node::replaceChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeChild"), - v8::FunctionTemplate::New(V8Node::removeChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("appendChild"), - v8::FunctionTemplate::New(V8Node::appendChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasChildNodes"), - v8::FunctionTemplate::New(V8Node::hasChildNodesCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("cloneNode"), - v8::FunctionTemplate::New(V8Node::cloneNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("normalize"), - v8::FunctionTemplate::New(V8Node::normalizeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("isSupported"), - v8::FunctionTemplate::New(V8Node::isSupportedCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasAttributes"), - v8::FunctionTemplate::New(V8Node::hasAttributesCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - tmpl->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(1), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(1), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(2), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(2), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(3), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(3), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(4), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(4), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(5), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(5), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(6), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(6), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(7), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(7), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(8), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(8), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(9), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(9), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(10), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(10), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(11), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(11), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(12), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(12), static_cast(v8::ReadOnly | v8::DontEnum)); - - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8NodePrivate { + V8DOM* dom; + Arabica::DOM::Node* nativeObj; + }; + + V8_DESTRUCTOR(V8NodePrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle insertBeforeCallback(const v8::Arguments&); + static v8::Handle replaceChildCallback(const v8::Arguments&); + static v8::Handle removeChildCallback(const v8::Arguments&); + static v8::Handle appendChildCallback(const v8::Arguments&); + static v8::Handle hasChildNodesCallback(const v8::Arguments&); + static v8::Handle cloneNodeCallback(const v8::Arguments&); + static v8::Handle normalizeCallback(const v8::Arguments&); + static v8::Handle isSupportedCallback(const v8::Arguments&); + static v8::Handle hasAttributesCallback(const v8::Arguments&); + + static v8::Handle nodeNameAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle nodeValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static void nodeValueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); + static v8::Handle nodeTypeAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle parentNodeAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle childNodesAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle firstChildAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle lastChildAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle previousSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle nextSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle attributesCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle ownerDocumentAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle namespaceURIAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle prefixAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static void prefixAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); + static v8::Handle localNameAttrGetter(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("Node")); + 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("nodeName"), V8Node::nodeNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nodeValue"), V8Node::nodeValueAttrGetter, V8Node::nodeValueAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nodeType"), V8Node::nodeTypeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("parentNode"), V8Node::parentNodeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("childNodes"), V8Node::childNodesAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("firstChild"), V8Node::firstChildAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("lastChild"), V8Node::lastChildAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("previousSibling"), V8Node::previousSiblingAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nextSibling"), V8Node::nextSiblingAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("attributes"), V8Node::attributesCustomAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("ownerDocument"), V8Node::ownerDocumentAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("namespaceURI"), V8Node::namespaceURIAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("prefix"), V8Node::prefixAttrGetter, V8Node::prefixAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("localName"), V8Node::localNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("insertBefore"), + v8::FunctionTemplate::New(V8Node::insertBeforeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("replaceChild"), + v8::FunctionTemplate::New(V8Node::replaceChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeChild"), + v8::FunctionTemplate::New(V8Node::removeChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("appendChild"), + v8::FunctionTemplate::New(V8Node::appendChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasChildNodes"), + v8::FunctionTemplate::New(V8Node::hasChildNodesCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("cloneNode"), + v8::FunctionTemplate::New(V8Node::cloneNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("normalize"), + v8::FunctionTemplate::New(V8Node::normalizeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("isSupported"), + v8::FunctionTemplate::New(V8Node::isSupportedCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttributes"), + v8::FunctionTemplate::New(V8Node::hasAttributesCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + tmpl->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(1), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(1), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(2), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(2), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(3), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(3), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(4), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(4), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(5), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(5), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(6), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(6), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(7), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(7), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(8), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(8), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(9), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(9), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(10), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(10), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(11), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(11), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(12), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(12), static_cast(v8::ReadOnly | v8::DontEnum)); + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp index bc2afb5..bee706e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp @@ -4,41 +4,41 @@ namespace Arabica { namespace DOM { - v8::Persistent V8NodeList::Tmpl; +v8::Persistent V8NodeList::Tmpl; - v8::Handle V8NodeList::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodeListPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8NodeList::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodeListPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::Integer::New(privData->nativeObj->getLength()); - } - v8::Handle V8NodeList::itemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in item"); + return v8::Integer::New(privData->nativeObj->getLength()); +} +v8::Handle V8NodeList::itemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in item"); - v8::Local self = args.Holder(); - struct V8NodeListPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + v8::Local self = args.Holder(); + struct V8NodeListPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->item(localIndex)); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->item(localIndex)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - } +} - bool V8NodeList::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8NodeList::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h index 8a07998..c454e65 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h @@ -32,44 +32,44 @@ namespace DOM { class V8NodeList { public: - struct V8NodeListPrivate { - V8DOM* dom; - Arabica::DOM::NodeList* nativeObj; - }; + struct V8NodeListPrivate { + V8DOM* dom; + Arabica::DOM::NodeList* nativeObj; + }; - V8_DESTRUCTOR(V8NodeListPrivate); - static bool hasInstance(v8::Handle); + V8_DESTRUCTOR(V8NodeListPrivate); + static bool hasInstance(v8::Handle); - static v8::Handle itemCallback(const v8::Arguments&); + static v8::Handle itemCallback(const v8::Arguments&); - static v8::Handle lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("NodeList")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("NodeList")); + tmpl->ReadOnlyPrototype(); - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings - instance->SetAccessor(v8::String::NewSymbol("length"), V8NodeList::lengthAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetInternalFieldCount(1); - instance->SetIndexedPropertyHandler(V8NodeList::indexedPropertyCustomGetter, 0); - prototype->Set(v8::String::NewSymbol("item"), - v8::FunctionTemplate::New(V8NodeList::itemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + instance->SetAccessor(v8::String::NewSymbol("length"), V8NodeList::lengthAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetIndexedPropertyHandler(V8NodeList::indexedPropertyCustomGetter, 0); + prototype->Set(v8::String::NewSymbol("item"), + v8::FunctionTemplate::New(V8NodeList::itemCallback, v8::Undefined()), static_cast(v8::DontDelete)); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp index 6f59a90..fade729 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp @@ -3,35 +3,35 @@ namespace Arabica { namespace DOM { - v8::Persistent V8NodeSet::Tmpl; +v8::Persistent V8NodeSet::Tmpl; - v8::Handle V8NodeSet::sizeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8NodeSet::sizeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::Integer::New(privData->nativeObj->size()); - } + return v8::Integer::New(privData->nativeObj->size()); +} - v8::Handle V8NodeSet::emptyAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8NodeSet::emptyAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::Boolean::New(privData->nativeObj->empty()); - } - v8::Handle V8NodeSet::toDocumentOrderCallback(const v8::Arguments& args) { + return v8::Boolean::New(privData->nativeObj->empty()); +} +v8::Handle V8NodeSet::toDocumentOrderCallback(const v8::Arguments& args) { - v8::Local self = args.Holder(); - struct V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::Local self = args.Holder(); + struct V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - privData->nativeObj->to_document_order(); + privData->nativeObj->to_document_order(); - return v8::Undefined(); - } + return v8::Undefined(); +} - bool V8NodeSet::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8NodeSet::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h index 78e4410..97b5d4f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h @@ -32,47 +32,47 @@ namespace DOM { class V8NodeSet { public: - struct V8NodeSetPrivate { - V8DOM* dom; - Arabica::XPath::NodeSet* nativeObj; - }; - - V8_DESTRUCTOR(V8NodeSetPrivate); - static bool hasInstance(v8::Handle); - - static v8::Handle toDocumentOrderCallback(const v8::Arguments&); - - static v8::Handle sizeAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle emptyAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); - - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("NodeSet")); - 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("size"), V8NodeSet::sizeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("empty"), V8NodeSet::emptyAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - instance->SetIndexedPropertyHandler(V8NodeSet::indexedPropertyCustomGetter, 0); - prototype->Set(v8::String::NewSymbol("toDocumentOrder"), - v8::FunctionTemplate::New(V8NodeSet::toDocumentOrderCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8NodeSetPrivate { + V8DOM* dom; + Arabica::XPath::NodeSet* nativeObj; + }; + + V8_DESTRUCTOR(V8NodeSetPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle toDocumentOrderCallback(const v8::Arguments&); + + static v8::Handle sizeAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle emptyAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("NodeSet")); + 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("size"), V8NodeSet::sizeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("empty"), V8NodeSet::emptyAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + instance->SetIndexedPropertyHandler(V8NodeSet::indexedPropertyCustomGetter, 0); + prototype->Set(v8::String::NewSymbol("toDocumentOrder"), + v8::FunctionTemplate::New(V8NodeSet::toDocumentOrderCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp index 5ecdd10..129563d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp @@ -4,25 +4,25 @@ namespace Arabica { namespace DOM { - v8::Persistent V8Notation::Tmpl; +v8::Persistent V8Notation::Tmpl; - v8::Handle V8Notation::publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NotationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Notation::publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NotationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getPublicId().c_str()); - } + return v8::String::New(privData->nativeObj->getPublicId().c_str()); +} - v8::Handle V8Notation::systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8NotationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8Notation::systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8NotationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getSystemId().c_str()); - } - bool V8Notation::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } + return v8::String::New(privData->nativeObj->getSystemId().c_str()); +} +bool V8Notation::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h index 2102a24..0745728 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h @@ -33,43 +33,43 @@ namespace DOM { class V8Notation { public: - struct V8NotationPrivate { - V8DOM* dom; - Arabica::DOM::Notation* nativeObj; - }; + struct V8NotationPrivate { + V8DOM* dom; + Arabica::DOM::Notation* nativeObj; + }; - V8_DESTRUCTOR(V8NotationPrivate); - static bool hasInstance(v8::Handle); + V8_DESTRUCTOR(V8NotationPrivate); + static bool hasInstance(v8::Handle); - static v8::Handle publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle systemIdAttrGetter(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("Notation")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Notation")); + tmpl->ReadOnlyPrototype(); - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings - instance->SetAccessor(v8::String::NewSymbol("publicId"), V8Notation::publicIdAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("systemId"), V8Notation::systemIdAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetInternalFieldCount(1); + instance->SetAccessor(v8::String::NewSymbol("publicId"), V8Notation::publicIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("systemId"), V8Notation::systemIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp index f28a56d..c6d2b28 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp @@ -4,32 +4,32 @@ namespace Arabica { namespace DOM { - v8::Persistent V8ProcessingInstruction::Tmpl; +v8::Persistent V8ProcessingInstruction::Tmpl; - v8::Handle V8ProcessingInstruction::targetAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8ProcessingInstruction::targetAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getTarget().c_str()); - } + return v8::String::New(privData->nativeObj->getTarget().c_str()); +} - v8::Handle V8ProcessingInstruction::dataAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8ProcessingInstruction::dataAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getData().c_str()); - } + return v8::String::New(privData->nativeObj->getData().c_str()); +} - void V8ProcessingInstruction::dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::String::AsciiValue localData(value); - privData->nativeObj->setData(*localData); - } - bool V8ProcessingInstruction::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +void V8ProcessingInstruction::dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localData(value); + privData->nativeObj->setData(*localData); +} +bool V8ProcessingInstruction::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h index a588b1f..56b61eb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h @@ -33,44 +33,44 @@ namespace DOM { class V8ProcessingInstruction { public: - struct V8ProcessingInstructionPrivate { - V8DOM* dom; - Arabica::DOM::ProcessingInstruction* nativeObj; - }; + struct V8ProcessingInstructionPrivate { + V8DOM* dom; + Arabica::DOM::ProcessingInstruction* nativeObj; + }; - V8_DESTRUCTOR(V8ProcessingInstructionPrivate); - static bool hasInstance(v8::Handle); + V8_DESTRUCTOR(V8ProcessingInstructionPrivate); + static bool hasInstance(v8::Handle); - static v8::Handle targetAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle dataAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static void dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); + static v8::Handle targetAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle dataAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static void dataAttrSetter(v8::Local property, v8::Local value, 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("ProcessingInstruction")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("ProcessingInstruction")); + tmpl->ReadOnlyPrototype(); - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings - instance->SetAccessor(v8::String::NewSymbol("target"), V8ProcessingInstruction::targetAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("data"), V8ProcessingInstruction::dataAttrGetter, V8ProcessingInstruction::dataAttrSetter, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetInternalFieldCount(1); + instance->SetAccessor(v8::String::NewSymbol("target"), V8ProcessingInstruction::targetAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("data"), V8ProcessingInstruction::dataAttrGetter, V8ProcessingInstruction::dataAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.cpp index 54006d5..9679d74 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.cpp @@ -4,74 +4,74 @@ namespace Arabica { namespace DOM { - v8::Persistent V8SCXMLEvent::Tmpl; +v8::Persistent V8SCXMLEvent::Tmpl; - v8::Handle V8SCXMLEvent::nameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8SCXMLEvent::nameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->name.c_str()); - } + return v8::String::New(privData->nativeObj->name.c_str()); +} - v8::Handle V8SCXMLEvent::originAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8SCXMLEvent::originAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - if (privData->nativeObj->origin.length() == 0) - return v8::Undefined(); - return v8::String::New(privData->nativeObj->origin.c_str()); - } + if (privData->nativeObj->origin.length() == 0) + return v8::Undefined(); + return v8::String::New(privData->nativeObj->origin.c_str()); +} - v8::Handle V8SCXMLEvent::origintypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8SCXMLEvent::origintypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - if (privData->nativeObj->origintype.length() == 0) - return v8::Undefined(); - return v8::String::New(privData->nativeObj->origintype.c_str()); - } + if (privData->nativeObj->origintype.length() == 0) + return v8::Undefined(); + return v8::String::New(privData->nativeObj->origintype.c_str()); +} - v8::Handle V8SCXMLEvent::rawAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8SCXMLEvent::rawAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - if (privData->nativeObj->raw.length() == 0) - return v8::Undefined(); - return v8::String::New(privData->nativeObj->raw.c_str()); - } + if (privData->nativeObj->raw.length() == 0) + return v8::Undefined(); + return v8::String::New(privData->nativeObj->raw.c_str()); +} - v8::Handle V8SCXMLEvent::domAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8SCXMLEvent::domAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - if (!privData->nativeObj->dom) return v8::Undefined(); - Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->dom); + if (!privData->nativeObj->dom) return v8::Undefined(); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->nativeObj->dom); - v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = arbaicaRet; - - arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); - return arbaicaRetObj; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - } + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; - v8::Handle V8SCXMLEvent::invokeidAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +} - if (privData->nativeObj->invokeid.length() == 0) - return v8::Undefined(); - return v8::String::New(privData->nativeObj->invokeid.c_str()); - } - bool V8SCXMLEvent::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +v8::Handle V8SCXMLEvent::invokeidAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); -} -} + if (privData->nativeObj->invokeid.length() == 0) + return v8::Undefined(); + return v8::String::New(privData->nativeObj->invokeid.c_str()); +} +bool V8SCXMLEvent::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h index 992b83e..670d818 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h @@ -32,66 +32,66 @@ namespace DOM { class V8SCXMLEvent { public: - struct V8SCXMLEventPrivate { - V8DOM* dom; - uscxml::Event* nativeObj; - }; - - V8_DESTRUCTOR(V8SCXMLEventPrivate); - static bool hasInstance(v8::Handle); - - - static v8::Handle typeCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle nameAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle originAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle origintypeAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle rawAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle domAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle sendidCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle invokeidAttrGetter(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("SCXMLEvent")); - 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("type"), V8SCXMLEvent::typeCustomAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("name"), V8SCXMLEvent::nameAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("origin"), V8SCXMLEvent::originAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("origintype"), V8SCXMLEvent::origintypeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("raw"), V8SCXMLEvent::rawAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("dom"), V8SCXMLEvent::domAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("sendid"), V8SCXMLEvent::sendidCustomAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("invokeid"), V8SCXMLEvent::invokeidAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - - tmpl->Set(v8::String::NewSymbol("INTERNAL"), v8::Integer::New(1), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("INTERNAL"), v8::Integer::New(1), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("EXTERNAL"), v8::Integer::New(2), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("EXTERNAL"), v8::Integer::New(2), static_cast(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("PLATFORM"), v8::Integer::New(3), static_cast(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("PLATFORM"), v8::Integer::New(3), static_cast(v8::ReadOnly | v8::DontEnum)); - - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8SCXMLEventPrivate { + V8DOM* dom; + uscxml::Event* nativeObj; + }; + + V8_DESTRUCTOR(V8SCXMLEventPrivate); + static bool hasInstance(v8::Handle); + + + static v8::Handle typeCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle nameAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle originAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle origintypeAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle rawAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle domAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle sendidCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle invokeidAttrGetter(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("SCXMLEvent")); + 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("type"), V8SCXMLEvent::typeCustomAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("name"), V8SCXMLEvent::nameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("origin"), V8SCXMLEvent::originAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("origintype"), V8SCXMLEvent::origintypeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("raw"), V8SCXMLEvent::rawAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("dom"), V8SCXMLEvent::domAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("sendid"), V8SCXMLEvent::sendidCustomAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("invokeid"), V8SCXMLEvent::invokeidAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + + tmpl->Set(v8::String::NewSymbol("INTERNAL"), v8::Integer::New(1), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("INTERNAL"), v8::Integer::New(1), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("EXTERNAL"), v8::Integer::New(2), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("EXTERNAL"), v8::Integer::New(2), static_cast(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("PLATFORM"), v8::Integer::New(3), static_cast(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("PLATFORM"), v8::Integer::New(3), static_cast(v8::ReadOnly | v8::DontEnum)); + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp index fb027d5..42b298a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp @@ -4,34 +4,34 @@ namespace Arabica { namespace DOM { - v8::Persistent V8Text::Tmpl; +v8::Persistent V8Text::Tmpl; - v8::Handle V8Text::splitTextCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in splitText"); +v8::Handle V8Text::splitTextCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in splitText"); - v8::Local self = args.Holder(); - struct V8TextPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + v8::Local self = args.Holder(); + struct V8TextPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - Arabica::DOM::Text* retVal = new Arabica::DOM::Text(privData->nativeObj->splitText(localOffset)); - v8::Handle retCtor = V8Text::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Text* retVal = new Arabica::DOM::Text(privData->nativeObj->splitText(localOffset)); + v8::Handle retCtor = V8Text::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Text::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Text::jsDestructor); + return retObj; - } +} - bool V8Text::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8Text::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h index bbf2577..61b92fb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h @@ -33,40 +33,40 @@ namespace DOM { class V8Text { public: - struct V8TextPrivate { - V8DOM* dom; - Arabica::DOM::Text* nativeObj; - }; + struct V8TextPrivate { + V8DOM* dom; + Arabica::DOM::Text* nativeObj; + }; - V8_DESTRUCTOR(V8TextPrivate); - static bool hasInstance(v8::Handle); + V8_DESTRUCTOR(V8TextPrivate); + static bool hasInstance(v8::Handle); - static v8::Handle splitTextCallback(const v8::Arguments&); + static v8::Handle splitTextCallback(const v8::Arguments&); - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Text")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Text")); + tmpl->ReadOnlyPrototype(); - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + instance->SetInternalFieldCount(1); - prototype->Set(v8::String::NewSymbol("splitText"), - v8::FunctionTemplate::New(V8Text::splitTextCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("splitText"), + v8::FunctionTemplate::New(V8Text::splitTextCallback, v8::Undefined()), static_cast(v8::DontDelete)); - tmpl->Inherit(V8CharacterData::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8CharacterData::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp index 38f69ae..968e53d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp @@ -4,82 +4,82 @@ namespace Arabica { namespace DOM { - v8::Persistent V8XPathResult::Tmpl; +v8::Persistent V8XPathResult::Tmpl; - v8::Handle V8XPathResult::numberValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8XPathResult::numberValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::Number::New(privData->nativeObj->asNumber()); - } + return v8::Number::New(privData->nativeObj->asNumber()); +} - v8::Handle V8XPathResult::stringValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8XPathResult::stringValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->asString().c_str()); - } + return v8::String::New(privData->nativeObj->asString().c_str()); +} - v8::Handle V8XPathResult::booleanValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +v8::Handle V8XPathResult::booleanValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - return v8::Boolean::New(privData->nativeObj->asBool()); - } - v8::Handle V8XPathResult::asNodeSetCallback(const v8::Arguments& args) { + return v8::Boolean::New(privData->nativeObj->asBool()); +} +v8::Handle V8XPathResult::asNodeSetCallback(const v8::Arguments& args) { - v8::Local self = args.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::Local self = args.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - Arabica::XPath::NodeSet* retVal = new Arabica::XPath::NodeSet(privData->nativeObj->asNodeSet()); - v8::Handle retCtor = V8NodeSet::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::XPath::NodeSet* retVal = new Arabica::XPath::NodeSet(privData->nativeObj->asNodeSet()); + v8::Handle retCtor = V8NodeSet::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); - struct V8NodeSet::V8NodeSetPrivate* retPrivData = new V8NodeSet::V8NodeSetPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8NodeSet::V8NodeSetPrivate* retPrivData = new V8NodeSet::V8NodeSetPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8NodeSet::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8NodeSet::jsDestructor); + return retObj; - } +} - v8::Handle V8XPathResult::asBoolCallback(const v8::Arguments& args) { +v8::Handle V8XPathResult::asBoolCallback(const v8::Arguments& args) { - v8::Local self = args.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::Local self = args.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - bool retVal = privData->nativeObj->asBool(); + bool retVal = privData->nativeObj->asBool(); - return v8::Boolean::New(retVal); - } + return v8::Boolean::New(retVal); +} - v8::Handle V8XPathResult::asStringCallback(const v8::Arguments& args) { +v8::Handle V8XPathResult::asStringCallback(const v8::Arguments& args) { - v8::Local self = args.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::Local self = args.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - std::string retVal = privData->nativeObj->asString(); + std::string retVal = privData->nativeObj->asString(); - return v8::String::New(retVal.c_str()); - } + return v8::String::New(retVal.c_str()); +} - v8::Handle V8XPathResult::asNumberCallback(const v8::Arguments& args) { +v8::Handle V8XPathResult::asNumberCallback(const v8::Arguments& args) { - v8::Local self = args.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::Local self = args.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - double retVal = privData->nativeObj->asNumber(); + double retVal = privData->nativeObj->asNumber(); - return v8::Number::New(retVal); - } + return v8::Number::New(retVal); +} - bool V8XPathResult::hasInstance(v8::Handle value) { - return getTmpl()->HasInstance(value); - } +bool V8XPathResult::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); +} -} -} +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h index 1fae618..f6a2d10 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h @@ -32,60 +32,60 @@ namespace DOM { class V8XPathResult { public: - struct V8XPathResultPrivate { - V8DOM* dom; - Arabica::XPath::XPathValue* nativeObj; - }; - - V8_DESTRUCTOR(V8XPathResultPrivate); - static bool hasInstance(v8::Handle); - - static v8::Handle asNodeSetCallback(const v8::Arguments&); - static v8::Handle asBoolCallback(const v8::Arguments&); - static v8::Handle asStringCallback(const v8::Arguments&); - static v8::Handle asNumberCallback(const v8::Arguments&); - - static v8::Handle numberValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle stringValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle booleanValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); - static v8::Handle singleNodeValueCustomAttrGetter(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("XPathResult")); - 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("numberValue"), V8XPathResult::numberValueAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("stringValue"), V8XPathResult::stringValueAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("booleanValue"), V8XPathResult::booleanValueAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("singleNodeValue"), V8XPathResult::singleNodeValueCustomAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - prototype->Set(v8::String::NewSymbol("asNodeSet"), - v8::FunctionTemplate::New(V8XPathResult::asNodeSetCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("asBool"), - v8::FunctionTemplate::New(V8XPathResult::asBoolCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("asString"), - v8::FunctionTemplate::New(V8XPathResult::asStringCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("asNumber"), - v8::FunctionTemplate::New(V8XPathResult::asNumberCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + struct V8XPathResultPrivate { + V8DOM* dom; + Arabica::XPath::XPathValue* nativeObj; + }; + + V8_DESTRUCTOR(V8XPathResultPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle asNodeSetCallback(const v8::Arguments&); + static v8::Handle asBoolCallback(const v8::Arguments&); + static v8::Handle asStringCallback(const v8::Arguments&); + static v8::Handle asNumberCallback(const v8::Arguments&); + + static v8::Handle numberValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle stringValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle booleanValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle singleNodeValueCustomAttrGetter(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("XPathResult")); + 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("numberValue"), V8XPathResult::numberValueAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("stringValue"), V8XPathResult::stringValueAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("booleanValue"), V8XPathResult::booleanValueAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("singleNodeValue"), V8XPathResult::singleNodeValueCustomAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("asNodeSet"), + v8::FunctionTemplate::New(V8XPathResult::asNodeSetCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asBool"), + v8::FunctionTemplate::New(V8XPathResult::asBoolCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asString"), + v8::FunctionTemplate::New(V8XPathResult::asStringCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asNumber"), + v8::FunctionTemplate::New(V8XPathResult::asNumberCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } }; diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index b031c00..c92274c 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -23,7 +23,7 @@ SWIDataModel::SWIDataModel() { // SWI prolog does not support passing user data static InterpreterImpl* _swiInterpreterPtr; - + boost::shared_ptr SWIDataModel::create(InterpreterImpl* interpreter) { boost::shared_ptr dm = boost::shared_ptr(new SWIDataModel()); dm->_interpreter = interpreter; @@ -50,7 +50,7 @@ boost::shared_ptr SWIDataModel::create(InterpreterImpl* interpret // load SWI XML parser PlCall("use_module", PlCompound("library", PlTerm("sgml"))); - + // load json parser PlCall("use_module", PlCompound("library", PlTerm("http/json"))); PlCall("use_module", PlCompound("library", PlTerm("http/json_convert"))); @@ -95,7 +95,7 @@ foreign_t SWIDataModel::inPredicate(term_t a0, int arity, void* context) { } return FALSE; } - + void SWIDataModel::registerIOProcessor(const std::string& name, const IOProcessor& ioprocessor) { // std::cout << "SWIDataModel::registerIOProcessor" << std::endl; } @@ -129,7 +129,7 @@ void SWIDataModel::setEvent(const Event& event) { // remove old event try { PlCall("retractall(event(_))"); - + // simple values PlCall("assert", PlCompound("event", PlCompound("name", PlTerm(event.name.c_str())))); PlCall("assert", PlCompound("event", PlCompound("origin", PlString(event.origin.c_str())))); @@ -140,22 +140,22 @@ void SWIDataModel::setEvent(const Event& event) { // event.type std::string type; switch (event.type) { - case Event::PLATFORM: - type = "platform"; - break; - case Event::INTERNAL: - type = "internal"; - break; - case Event::EXTERNAL: - type = "external"; - break; + case Event::PLATFORM: + type = "platform"; + break; + case Event::INTERNAL: + type = "internal"; + break; + case Event::EXTERNAL: + type = "external"; + break; } PlCall("assert", PlCompound("event", PlCompound("type", PlTerm(type.c_str())))); - + // event.sendid if (!event.hideSendId) PlCall("assert", PlCompound("event", PlCompound("sendid", PlTerm(event.sendid.c_str())))); - + // event.data URL domUrl; if (event.dom) { @@ -167,8 +167,8 @@ void SWIDataModel::setEvent(const Event& event) { PlCall(dataInitStr.str().c_str()); } else if (event.content.size() > 0) { PlCall("assert", PlCompound("event", PlCompound("data", PlString(Interpreter::spaceNormalize(event.content).c_str())))); - } - + } + // event.params size_t uniqueKeys = 0; Event::params_t::const_iterator paramIter = event.params.begin(); @@ -195,7 +195,7 @@ void SWIDataModel::setEvent(const Event& event) { paramExpr << "assert(event(param(" << paramArray.str() << ")))"; //std::cout << paramExpr.str() << std::endl; PlCall(paramExpr.str().c_str()); - + paramIter = lastValueIter; } } @@ -249,7 +249,7 @@ void SWIDataModel::setForeach(const std::string& item, PlCall("retractall", PlCompound(index.c_str(), 1)); PlCall("retractall", PlCompound(item.c_str(), 1)); PlCall("assert", PlCompound(index.c_str(), PlTerm((long)iteration))); - + std::map vars = resolveAtoms(compound, orig); std::map::iterator varIter = vars.begin(); while(varIter != vars.end()) { @@ -307,28 +307,28 @@ std::string SWIDataModel::evalAsString(const std::string& expr) { std::map SWIDataModel::resolveAtoms(PlTerm& term, PlTerm& orig) { std::map atoms; switch (orig.type()) { - case PL_VARIABLE: { - atoms[(char *)orig] = term; - break; + case PL_VARIABLE: { + atoms[(char *)orig] = term; + break; + } + case PL_ATOM: + break; + case PL_STRING: + break; + case PL_INTEGER: + break; + case PL_TERM: + for (int i = 1; i <= orig.arity(); i++) { + PlTerm newTerm = term[i]; + PlTerm newOrig = orig[i]; + std::map result = resolveAtoms(newTerm, newOrig); + atoms.insert(result.begin(), result.end()); } - case PL_ATOM: - break; - case PL_STRING: - break; - case PL_INTEGER: - break; - case PL_TERM: - for (int i = 1; i <= orig.arity(); i++) { - PlTerm newTerm = term[i]; - PlTerm newOrig = orig[i]; - std::map result = resolveAtoms(newTerm, newOrig); - atoms.insert(result.begin(), result.end()); - } - break; + break; } return atoms; } - + void SWIDataModel::assign(const Arabica::DOM::Element& assignElem, const Arabica::DOM::Document& doc, const std::string& content) { @@ -353,7 +353,7 @@ void SWIDataModel::assign(const Arabica::DOM::Element& assignElem, callAssert = "asserta"; } } - + URL domUrl; Data json; if (!doc) diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h index e33724f..504dd3a 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h @@ -62,7 +62,7 @@ public: static foreign_t inPredicate(term_t a0, int arity, void* context); protected: std::map resolveAtoms(PlTerm& term, PlTerm& orig); - + Event _event; PlEngine* _plEngine; diff --git a/src/uscxml/plugins/element/mmi/MMIEvents.cpp b/src/uscxml/plugins/element/mmi/MMIEvents.cpp index 5d688ff..f1110b7 100644 --- a/src/uscxml/plugins/element/mmi/MMIEvents.cpp +++ b/src/uscxml/plugins/element/mmi/MMIEvents.cpp @@ -1,42 +1,42 @@ #include "MMIEvents.h" namespace uscxml { - - void PrepareRequestElement::enterElement(const Arabica::DOM::Node& node) { - } - void StartRequestElement::enterElement(const Arabica::DOM::Node& node) { - } - void PauseRequestElement::enterElement(const Arabica::DOM::Node& node) { - } - void ResumeRequestElement::enterElement(const Arabica::DOM::Node& node) { - } - void CancelRequestElement::enterElement(const Arabica::DOM::Node& node) { - } - void ClearContextRequestElement::enterElement(const Arabica::DOM::Node& node) { - } - void StatusRequestElement::enterElement(const Arabica::DOM::Node& node) { - } - void NewContextResponseElement::enterElement(const Arabica::DOM::Node& node) { - } - void PrepareResponseElement::enterElement(const Arabica::DOM::Node& node) { - } - void StartResponseElement::enterElement(const Arabica::DOM::Node& node) { - } - void PauseResponseElement::enterElement(const Arabica::DOM::Node& node) { - } - void ResumeResponseElement::enterElement(const Arabica::DOM::Node& node) { - } - void CancelResponseElement::enterElement(const Arabica::DOM::Node& node) { - } - void ClearContextResponseElement::enterElement(const Arabica::DOM::Node& node) { - } - void StatusResponseElement::enterElement(const Arabica::DOM::Node& node) { - } - void DoneNotificationElement::enterElement(const Arabica::DOM::Node& node) { - } - void NewContextRequestElement::enterElement(const Arabica::DOM::Node& node) { - } - void ExtensionNotificationElement::enterElement(const Arabica::DOM::Node& node) { - } + +void PrepareRequestElement::enterElement(const Arabica::DOM::Node& node) { +} +void StartRequestElement::enterElement(const Arabica::DOM::Node& node) { +} +void PauseRequestElement::enterElement(const Arabica::DOM::Node& node) { +} +void ResumeRequestElement::enterElement(const Arabica::DOM::Node& node) { +} +void CancelRequestElement::enterElement(const Arabica::DOM::Node& node) { +} +void ClearContextRequestElement::enterElement(const Arabica::DOM::Node& node) { +} +void StatusRequestElement::enterElement(const Arabica::DOM::Node& node) { +} +void NewContextResponseElement::enterElement(const Arabica::DOM::Node& node) { +} +void PrepareResponseElement::enterElement(const Arabica::DOM::Node& node) { +} +void StartResponseElement::enterElement(const Arabica::DOM::Node& node) { +} +void PauseResponseElement::enterElement(const Arabica::DOM::Node& node) { +} +void ResumeResponseElement::enterElement(const Arabica::DOM::Node& node) { +} +void CancelResponseElement::enterElement(const Arabica::DOM::Node& node) { +} +void ClearContextResponseElement::enterElement(const Arabica::DOM::Node& node) { +} +void StatusResponseElement::enterElement(const Arabica::DOM::Node& node) { +} +void DoneNotificationElement::enterElement(const Arabica::DOM::Node& node) { +} +void NewContextRequestElement::enterElement(const Arabica::DOM::Node& node) { +} +void ExtensionNotificationElement::enterElement(const Arabica::DOM::Node& node) { +} } \ No newline at end of file diff --git a/src/uscxml/plugins/element/mmi/MMIEvents.h b/src/uscxml/plugins/element/mmi/MMIEvents.h index 3a31f2a..5df48ec 100644 --- a/src/uscxml/plugins/element/mmi/MMIEvents.h +++ b/src/uscxml/plugins/element/mmi/MMIEvents.h @@ -47,7 +47,7 @@ ELEMENT_MMI_CLASS(StatusResponse); ELEMENT_MMI_CLASS(DoneNotification); ELEMENT_MMI_CLASS(NewContextRequest); ELEMENT_MMI_CLASS(ExtensionNotification); - + #ifdef BUILD_AS_PLUGINS PLUMA_INHERIT_PROVIDER(FetchElement, ExecutableContentImpl); #endif diff --git a/src/uscxml/plugins/invoker/CMakeLists.txt b/src/uscxml/plugins/invoker/CMakeLists.txt index 3f43acb..4e74a8c 100644 --- a/src/uscxml/plugins/invoker/CMakeLists.txt +++ b/src/uscxml/plugins/invoker/CMakeLists.txt @@ -32,6 +32,23 @@ else() list (APPEND USCXML_FILES ${DIRMON_INVOKER}) endif() +# System invoker to open a native command + +file(GLOB_RECURSE XHTML_INVOKER + xhtml/*.cpp + xhtml/*.h +) +source_group("Invoker\\xhtml" FILES ${XHTML_INVOKER}) +if (BUILD_AS_PLUGINS) + add_library( + invoker_xhtml SHARED + ${XHTML_INVOKER}) + target_link_libraries(invoker_xhtml uscxml) + set_target_properties(invoker_xhtml PROPERTIES FOLDER "Plugin Invoker") +else() + list (APPEND USCXML_FILES ${XHTML_INVOKER}) +endif() + # System invoker to open a native command diff --git a/src/uscxml/plugins/invoker/http/HTTPServletInvoker.cpp b/src/uscxml/plugins/invoker/http/HTTPServletInvoker.cpp index 771b159..2c395a8 100644 --- a/src/uscxml/plugins/invoker/http/HTTPServletInvoker.cpp +++ b/src/uscxml/plugins/invoker/http/HTTPServletInvoker.cpp @@ -95,7 +95,7 @@ void HTTPServletInvoker::invoke(const InvokeRequest& req) { /** * Receive a request and deliver it to the interpreter */ -void HTTPServletInvoker::httpRecvRequest(const HTTPServer::Request& req) { +bool HTTPServletInvoker::httpRecvRequest(const HTTPServer::Request& req) { tthread::lock_guard lock(_mutex); // evhttp_request_own(req.curlReq); @@ -108,7 +108,7 @@ void HTTPServletInvoker::httpRecvRequest(const HTTPServer::Request& req) { event.data.compound["reqId"] = Data(toStr((uintptr_t)req.curlReq), Data::VERBATIM); returnEvent(event); - + return true; } std::string HTTPServletInvoker::getPath() { diff --git a/src/uscxml/plugins/invoker/http/HTTPServletInvoker.h b/src/uscxml/plugins/invoker/http/HTTPServletInvoker.h index de9c300..e2d3b2b 100644 --- a/src/uscxml/plugins/invoker/http/HTTPServletInvoker.h +++ b/src/uscxml/plugins/invoker/http/HTTPServletInvoker.h @@ -29,7 +29,7 @@ public: virtual void invoke(const InvokeRequest& req); // HTTPServlet - virtual void httpRecvRequest(const HTTPServer::Request& req); + virtual bool httpRecvRequest(const HTTPServer::Request& req); virtual std::string getPath(); virtual void setURL(const std::string& url) { _url = url; diff --git a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp index 6e0b2af..a71d21a 100644 --- a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp @@ -29,7 +29,7 @@ boost::shared_ptr VoiceXMLInvoker::create(InterpreterImpl* interpre invoker->_pub.registerType("LifeCycleEvent", new ::LifeCycleEvent()); - + invoker->_node.addPublisher(invoker->_pub); invoker->_node.addSubscriber(invoker->_sub); @@ -50,7 +50,7 @@ void VoiceXMLInvoker::send(const SendRequest& req) { std::stringstream domSS; domSS << req.getFirstDOMElement(); start.content = domSS.str(); - + start.contentURL.href = "http://localhost/~sradomski/hello.vxml"; start.requestId = "asdf"; start.source = "asdf"; @@ -61,7 +61,7 @@ void VoiceXMLInvoker::send(const SendRequest& req) { void VoiceXMLInvoker::invoke(const InvokeRequest& req) { _pub.waitForSubscribers(1); - + } } \ No newline at end of file diff --git a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h index ca5f557..d89382e 100644 --- a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h +++ b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h @@ -34,7 +34,7 @@ public: virtual void send(const SendRequest& req); virtual void invoke(const InvokeRequest& req); - + protected: umundo::Node _node; umundo::TypedPublisher _pub; diff --git a/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp new file mode 100644 index 0000000..0c7ef08 --- /dev/null +++ b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp @@ -0,0 +1,195 @@ +#include +#include "XHTMLInvoker.h" +#include +#include + +#ifdef BUILD_AS_PLUGINS +#include +#endif + +#if defined(__APPLE__) and defined(TARGET_OS_MAC) +#include +#include +#endif + +namespace uscxml { + +#ifdef BUILD_AS_PLUGINS +PLUMA_CONNECTOR +bool connect(pluma::Host& host) { + host.add( new XHTMLInvokerProvider() ); + return true; +} +#endif + +XHTMLInvoker::XHTMLInvoker() { +} + +XHTMLInvoker::~XHTMLInvoker() { +}; + +boost::shared_ptr XHTMLInvoker::create(InterpreterImpl* interpreter) { + boost::shared_ptr invoker = boost::shared_ptr(new XHTMLInvoker()); + invoker->_interpreter = interpreter; +// _ioProc = interpreter->getFactory()->createIOProcessor("comet", interpreter); + return invoker; +} + +bool XHTMLInvoker::httpRecvRequest(const HTTPServer::Request& req) { + tthread::lock_guard lock(_mutex); + + // these are the XHR requests + if (boost::iequals(req.data["header"]["X-Requested-With"].atom, "XMLHttpRequest")) { + if (boost::iequals(req.data["type"].atom, "get")) { + if (_longPoll) { + evhttp_send_error(_longPoll.curlReq, 204, NULL); + _longPoll.curlReq = NULL; + } + _longPoll = req; + if (!_outQueue.empty()) { + send(_outQueue.front()); + _outQueue.pop_front(); + } + return true; + } else { + Event ev(req); + if (ev.data["header"]["X-SCXML-Name"]) { + ev.name = ev.data["header"]["X-SCXML-Name"].atom; + } + ev.origin = _invokeId; + ev.initContent(req.data["content"].atom); + ev.data.compound["Connection"] = req.data; + // content is already on ev.raw + ev.data.compound["Connection"].compound.erase("content"); + + returnEvent(ev); + return true; + } + } + + // initial request for a document + if (!req.data["query"] && // no query parameters + boost::iequals(req.data["type"].atom, "get") && // request type is GET + (boost::icontains(req.data["header"]["Accept"].atom, "text/html") || // accepts html or + boost::contains(req.data["header"]["User-Agent"].atom, "MSIE")) && // is the internet explorer + req.content.length() == 0) { // no content + + HTTPServer::Reply reply(req); + URL templateURL("templates/xhtml-invoker.html"); + templateURL.toAbsolute(_interpreter->getBaseURI()); + templateURL.download(true); + std::string templateContent = templateURL.getInContent(); + boost::replace_all(templateContent, "${scxml.server}", _url); + boost::replace_all(templateContent, "${scxml.invokeId}", _invokeId); + + std::string content; + std::stringstream ss; + if (_invokeReq.dom) { + ss << _invokeReq.getFirstDOMElement(); + content = ss.str(); + } else if(_invokeReq.data) { + ss << _invokeReq.data; + content = ss.str(); + } else { + content = _invokeReq.content; + } + boost::replace_all(templateContent, "${scxml.content}", content); + reply.content = templateContent; + reply.headers["Content-Type"] = "text/html"; + + // aggressive caching in IE will return all XHR get requests instantenously with the template otherwise + reply.headers["Cache-Control"] = "no-cache"; + + HTTPServer::reply(reply); + + // queue invoke request for initial html + _longPoll.curlReq = NULL; + _outQueue = std::deque(); + SendRequest sendReq(_invokeReq); + send(sendReq); + + return true; + } + + // don't know what to do with other requests + return false; +} + +Data XHTMLInvoker::getDataModelVariables() { + Data data; + return data; +} + +void XHTMLInvoker::send(const SendRequest& req) { + tthread::lock_guard lock(_mutex); + if (!_longPoll) { + _outQueue.push_back(req); + return; + } + reply(req, _longPoll); + _longPoll.curlReq = NULL; +} + +void XHTMLInvoker::reply(const SendRequest& req, const HTTPServer::Request& longPoll) { + HTTPServer::Reply reply(longPoll); + + if (req.dom) { + std::stringstream ss; + Arabica::DOM::Node content = req.dom.getDocumentElement(); + if (content && boost::iequals(content.getLocalName(), "content")) { + reply.headers["X-SCXML-Type"] = (HAS_ATTR(content, "type") ? ATTR(content, "type") : "replacechildren"); + reply.headers["X-SCXML-XPath"] = (HAS_ATTR(content, "xpath") ? ATTR(content, "xpath") : "/html/body"); + if (HAS_ATTR(content, "attr")) + reply.headers["X-SCXML-Attr"] = ATTR(content, "attr"); + } + ss << req.getFirstDOMElement(); + reply.content = ss.str(); + reply.headers["Content-Type"] = "application/xml"; + } else if (req.data) { + reply.content = Data::toJSON(req.data); + reply.headers["Content-Type"] = "application/json"; + } else if (req.content.length() > 0) { + reply.content = req.content; + reply.headers["Content-Type"] = "application/text"; + } + + if (req.params.find("Content-Type") != req.params.end()) + reply.headers["Content-Type"] = req.params.find("Content-Type")->first; + + HTTPServer::reply(reply); +} + +void XHTMLInvoker::cancel(const std::string sendId) { +} + +void XHTMLInvoker::invoke(const InvokeRequest& req) { + _invokeReq = req; + HTTPServer::registerServlet(_interpreter->getName() + "/xhtml/" + req.invokeid, this); +#if defined(__APPLE__) and defined(TARGET_OS_MAC) + // see http://stackoverflow.com/questions/4177744/c-osx-open-default-browser + CFURLRef url = CFURLCreateWithBytes ( + NULL, // allocator + (UInt8*)_url.c_str(), // URLBytes + _url.length(), // length + kCFStringEncodingASCII, // encoding + NULL // baseURL + ); + LSOpenCFURLRef(url,0); + CFRelease(url); + return; +#endif +#ifdef _WIN32 +// see http://support.microsoft.com/kb/224816 + ShellExecute(NULL, "open", _url.c_str(), NULL, NULL, SW_SHOWNORMAL); + return; +#endif +#ifdef HAS_XDG_OPEN + std::string systemCmd; + systemCmd = "xdg-open "; + systemCmd += _url; + system(systemCmd.c_str()); + return; +#endif +} + +} \ No newline at end of file diff --git a/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.h b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.h new file mode 100644 index 0000000..e94c4fd --- /dev/null +++ b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.h @@ -0,0 +1,55 @@ +#ifndef XHTMLINVOKER_H_W09J90F0 +#define XHTMLINVOKER_H_W09J90F0 + +#include + +#ifdef BUILD_AS_PLUGINS +#include "uscxml/plugins/Plugins.h" +#endif + +namespace uscxml { + +class XHTMLInvoker : public InvokerImpl, public HTTPServlet { +public: + XHTMLInvoker(); + virtual ~XHTMLInvoker(); + virtual boost::shared_ptr create(InterpreterImpl* interpreter); + + virtual std::set getNames() { + std::set names; + names.insert("xhtml"); + names.insert("http://www.w3.org/1999/xhtml"); + return names; + } + + virtual Data getDataModelVariables(); + virtual void send(const SendRequest& req); + virtual void cancel(const std::string sendId); + virtual void invoke(const InvokeRequest& req); + + // HTTPServlet + virtual bool httpRecvRequest(const HTTPServer::Request& request); + virtual void setURL(const std::string& url) { + _url = url; + } + + void reply(const SendRequest& req, const HTTPServer::Request& longPoll); + +protected: + HTTPServer::Request _longPoll; + std::deque _outQueue; + + tthread::recursive_mutex _mutex; + InvokeRequest _invokeReq; + IOProcessor _ioProc; + std::string _url; +}; + +#ifdef BUILD_AS_PLUGINS +PLUMA_INHERIT_PROVIDER(XHTMLInvoker, InvokerImpl); +#endif + +} + + +#endif /* end of include guard: XHTMLINVOKER_H_W09J90F0 */ diff --git a/src/uscxml/plugins/ioprocessor/CMakeLists.txt b/src/uscxml/plugins/ioprocessor/CMakeLists.txt index 0fab6a4..9fda5f8 100644 --- a/src/uscxml/plugins/ioprocessor/CMakeLists.txt +++ b/src/uscxml/plugins/ioprocessor/CMakeLists.txt @@ -1,3 +1,34 @@ +file(GLOB_RECURSE SAMPLE_IOPROCESSOR + sample/*.cpp + sample/*.h +) +source_group("IOProcessor\\sample" FILES ${SAMPLE_IOPROCESSOR}) +if (BUILD_AS_PLUGINS) + add_library( + ioprocessor_sample SHARED + ${SAMPLE_IOPROCESSOR}) + target_link_libraries(ioprocessor_sample uscxml) + set_target_properties(ioprocessor_sample PROPERTIES FOLDER "Plugin IOProcessor") +else() + list (APPEND USCXML_FILES ${SAMPLE_IOPROCESSOR}) +endif() + +file(GLOB_RECURSE COMET_IOPROCESSOR + comet/*.cpp + comet/*.h +) +source_group("IOProcessor\\comet" FILES ${COMET_IOPROCESSOR}) +if (BUILD_AS_PLUGINS) + add_library( + ioprocessor_comet SHARED + ${COMET_IOPROCESSOR}) + target_link_libraries(ioprocessor_comet uscxml) + set_target_properties(ioprocessor_comet PROPERTIES FOLDER "Plugin IOProcessor") +else() + list (APPEND USCXML_FILES ${COMET_IOPROCESSOR}) +endif() + + # LIBEVENT basichttp ioprocessor - this one is already required above file(GLOB_RECURSE BASICHTTP_IOPROCESSOR diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp index 6ddb83c..b2a6824 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp @@ -68,7 +68,7 @@ Data BasicHTTPIOProcessor::getDataModelVariables() { return data; } -void BasicHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) { +bool BasicHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) { Event reqEvent = req; reqEvent.type = Event::EXTERNAL; bool scxmlStructFound = false; @@ -138,6 +138,7 @@ void BasicHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) { returnEvent(reqEvent); evhttp_send_reply(req.curlReq, 200, "OK", NULL); + return true; } void BasicHTTPIOProcessor::send(const SendRequest& req) { @@ -189,7 +190,7 @@ void BasicHTTPIOProcessor::send(const SendRequest& req) { } // content - + if (req.content.size() > 0) { kvps << kvpSeperator << evhttp_encode_uri("content") << "=" << evhttp_encode_uri(req.content.c_str()); kvpSeperator = "&"; diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h index 1848e5e..c0fddc1 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h +++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h @@ -36,7 +36,7 @@ public: Data getDataModelVariables(); /// HTTPServlet - void httpRecvRequest(const HTTPServer::Request& req); + bool httpRecvRequest(const HTTPServer::Request& req); void setURL(const std::string& url) { _url = url; } diff --git a/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.cpp new file mode 100644 index 0000000..8fd1172 --- /dev/null +++ b/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.cpp @@ -0,0 +1,94 @@ +#include +#include "uscxml/plugins/ioprocessor/comet/CometIOProcessor.h" +#include "uscxml/Message.h" +#include + +#include + +#ifdef BUILD_AS_PLUGINS +#include +#endif + +namespace uscxml { + +#ifdef BUILD_AS_PLUGINS +PLUMA_CONNECTOR +bool connect(pluma::Host& host) { + host.add( new CometIOProcessorProvider() ); + return true; +} +#endif + +CometIOProcessor::CometIOProcessor() { +} + +CometIOProcessor::~CometIOProcessor() { +} + +boost::shared_ptr CometIOProcessor::create(InterpreterImpl* interpreter) { + boost::shared_ptr io = boost::shared_ptr(new CometIOProcessor()); + io->_interpreter = interpreter; + + // register at http server + std::string path = interpreter->getName(); + int i = 2; + while (!HTTPServer::registerServlet(path + "/comet", io.get())) { + std::stringstream ss; + ss << interpreter->getName() << i++; + path = ss.str(); + } + + return io; +} + +Data CometIOProcessor::getDataModelVariables() { + Data data; + return data; +} + +void CometIOProcessor::send(const SendRequest& req) { + tthread::lock_guard lock(_mutex); + if (!_longPollingReq) { + _outQueue.push_back(req); + return; + } + reply(req, _longPollingReq); +} + +void CometIOProcessor::reply(const SendRequest& req, const HTTPServer::Request& longPoll) { + HTTPServer::Reply reply(longPoll); + + if (req.dom) { + std::stringstream ss; + ss << req.dom; + reply.content = ss.str(); + reply.headers["Content-Type"] = "application/xml"; + } else if (req.data) { + reply.content = Data::toJSON(req.data); + reply.headers["Content-Type"] = "application/json"; + } else if (req.content.length() > 0) { + reply.content = req.content; + reply.headers["Content-Type"] = "text/plain"; + } + + if (req.params.find("Content-Type") != req.params.end()) + reply.headers["Content-Type"] = req.params.find("Content-Type")->first; + + HTTPServer::reply(reply); +} + +bool CometIOProcessor::httpRecvRequest(const HTTPServer::Request& request) { + tthread::lock_guard lock(_mutex); + + if (_longPollingReq) + // send 204 to last request and remember new one + evhttp_send_error(_longPollingReq.curlReq, 204, NULL); + _longPollingReq = request; + if (!_outQueue.empty()) { + send(_outQueue.front()); + _outQueue.pop_front(); + } + return true; +} + +} \ No newline at end of file diff --git a/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.h b/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.h new file mode 100644 index 0000000..05a3798 --- /dev/null +++ b/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.h @@ -0,0 +1,53 @@ +#ifndef COMETIOPROCESSOR_H_2CUY93KU +#define COMETIOPROCESSOR_H_2CUY93KU + +#include "uscxml/concurrency/eventqueue/DelayedEventQueue.h" +#include "uscxml/server/HTTPServer.h" +#include "uscxml/Interpreter.h" +#include "uscxml/Factory.h" + +#ifdef BUILD_AS_PLUGINS +#include "uscxml/plugins/Plugins.h" +#endif + +namespace uscxml { + +class CometIOProcessor : public IOProcessorImpl, public HTTPServlet { +public: + CometIOProcessor(); + virtual ~CometIOProcessor(); + virtual boost::shared_ptr create(uscxml::InterpreterImpl* interpreter); + + virtual std::set getNames() { + std::set names; + names.insert("comet"); + names.insert("http://www.w3.org/TR/scxml/#CometEventProcessor"); + return names; + } + + /// This method can be overridden for specific replies + virtual void reply(const SendRequest& req, const HTTPServer::Request& longPoll); + + virtual void send(const SendRequest& req); + Data getDataModelVariables(); + + virtual bool httpRecvRequest(const HTTPServer::Request& request); + virtual void setURL(const std::string& url) { + _url = url; + } + +protected: + tthread::recursive_mutex _mutex; + std::string _url; + std::deque _outQueue; + HTTPServer::Request _longPollingReq; + +}; + +#ifdef BUILD_AS_PLUGINS +PLUMA_INHERIT_PROVIDER(CometIOProcessor, IOProcessorImpl); +#endif + +} + +#endif /* end of include guard: COMETIOPROCESSOR_H_2CUY93KU */ \ No newline at end of file diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp index 4734ff5..25e0f8c 100644 --- a/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp @@ -37,7 +37,7 @@ boost::shared_ptr MMIHTTPIOProcessor::create(InterpreterImpl* i return io; } -void MMIHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) { +bool MMIHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) { Event reqEvent = req; reqEvent.type = Event::EXTERNAL; bool scxmlStructFound = false; @@ -107,6 +107,7 @@ void MMIHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) { returnEvent(reqEvent); evhttp_send_reply(req.curlReq, 200, "OK", NULL); + return true; } void MMIHTTPIOProcessor::send(const SendRequest& req) { @@ -158,7 +159,7 @@ void MMIHTTPIOProcessor::send(const SendRequest& req) { } // content - + if (req.content.size() > 0) { kvps << kvpSeperator << evhttp_encode_uri("content") << "=" << evhttp_encode_uri(req.content.c_str()); kvpSeperator = "&"; diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h b/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h index 2dbd595..3c0a9a9 100644 --- a/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h +++ b/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h @@ -16,37 +16,37 @@ #endif namespace uscxml { - - class MMIHTTPIOProcessor : public BasicHTTPIOProcessor { - public: - MMIHTTPIOProcessor(); - virtual ~MMIHTTPIOProcessor(); - virtual boost::shared_ptr create(uscxml::InterpreterImpl* interpreter); - - virtual std::set getNames() { - std::set names; - names.insert("mmihttp"); - names.insert("http://www.w3.org/TR/mmi-arch/#HTTPTransport"); - return names; - } - - virtual void send(const SendRequest& req); - - /// HTTPServlet - void httpRecvRequest(const HTTPServer::Request& req); - - bool canAdaptPath() { - return false; - } - - protected: - std::string _url; - std::map > _sendRequests; - }; - - #ifdef BUILD_AS_PLUGINS - PLUMA_INHERIT_PROVIDER(MMIHTTPIOProcessor, IOProcessorImpl); - #endif + +class MMIHTTPIOProcessor : public BasicHTTPIOProcessor { +public: + MMIHTTPIOProcessor(); + virtual ~MMIHTTPIOProcessor(); + virtual boost::shared_ptr create(uscxml::InterpreterImpl* interpreter); + + virtual std::set getNames() { + std::set names; + names.insert("mmihttp"); + names.insert("http://www.w3.org/TR/mmi-arch/#HTTPTransport"); + return names; + } + + virtual void send(const SendRequest& req); + + /// HTTPServlet + bool httpRecvRequest(const HTTPServer::Request& req); + + bool canAdaptPath() { + return false; + } + +protected: + std::string _url; + std::map > _sendRequests; +}; + +#ifdef BUILD_AS_PLUGINS +PLUMA_INHERIT_PROVIDER(MMIHTTPIOProcessor, IOProcessorImpl); +#endif } diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp b/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp index bf32b9d..006b9e0 100644 --- a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp +++ b/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp @@ -22,68 +22,71 @@ using namespace Arabica::DOM; std::string MMIEvent::nameSpace = "http://www.w3.org/2008/04/mmi-arch"; - MMIEvent::Type MMIEvent::getType(Arabica::DOM::Node node) { - if (!node) - return INVALID; - - if (boost::iequals(node.getLocalName(), "NEWCONTEXTREQUEST")) - return NEWCONTEXTREQUEST; - if (boost::iequals(node.getLocalName(), "NEWCONTEXTRESPONSE")) - return NEWCONTEXTRESPONSE; - if (boost::iequals(node.getLocalName(), "PREPAREREQUEST")) - return PREPAREREQUEST; - if (boost::iequals(node.getLocalName(), "PREPARERESPONSE")) - return PREPARERESPONSE; - if (boost::iequals(node.getLocalName(), "STARTREQUEST")) - return STARTREQUEST; - if (boost::iequals(node.getLocalName(), "STARTRESPONSE")) - return STARTRESPONSE; - if (boost::iequals(node.getLocalName(), "DONENOTIFICATION")) - return DONENOTIFICATION; - if (boost::iequals(node.getLocalName(), "CANCELREQUEST")) - return CANCELREQUEST; - if (boost::iequals(node.getLocalName(), "CANCELRESPONSE")) - return CANCELRESPONSE; - if (boost::iequals(node.getLocalName(), "PAUSEREQUEST")) - return PAUSEREQUEST; - if (boost::iequals(node.getLocalName(), "PAUSERESPONSE")) - return PAUSERESPONSE; - if (boost::iequals(node.getLocalName(), "RESUMEREQUEST")) - return RESUMEREQUEST; - if (boost::iequals(node.getLocalName(), "RESUMERESPONSE")) - return RESUMERESPONSE; - if (boost::iequals(node.getLocalName(), "EXTENSIONNOTIFICATION")) - return EXTENSIONNOTIFICATION; - if (boost::iequals(node.getLocalName(), "CLEARCONTEXTREQUEST")) - return CLEARCONTEXTREQUEST; - if (boost::iequals(node.getLocalName(), "CLEARCONTEXTRESPONSE")) - return CLEARCONTEXTRESPONSE; - if (boost::iequals(node.getLocalName(), "STATUSREQUEST")) - return STATUSREQUEST; - if (boost::iequals(node.getLocalName(), "STATUSRESPONSE")) - return STATUSRESPONSE; +MMIEvent::Type MMIEvent::getType(Arabica::DOM::Node node) { + if (!node) return INVALID; + + if (boost::iequals(node.getLocalName(), "NEWCONTEXTREQUEST")) + return NEWCONTEXTREQUEST; + if (boost::iequals(node.getLocalName(), "NEWCONTEXTRESPONSE")) + return NEWCONTEXTRESPONSE; + if (boost::iequals(node.getLocalName(), "PREPAREREQUEST")) + return PREPAREREQUEST; + if (boost::iequals(node.getLocalName(), "PREPARERESPONSE")) + return PREPARERESPONSE; + if (boost::iequals(node.getLocalName(), "STARTREQUEST")) + return STARTREQUEST; + if (boost::iequals(node.getLocalName(), "STARTRESPONSE")) + return STARTRESPONSE; + if (boost::iequals(node.getLocalName(), "DONENOTIFICATION")) + return DONENOTIFICATION; + if (boost::iequals(node.getLocalName(), "CANCELREQUEST")) + return CANCELREQUEST; + if (boost::iequals(node.getLocalName(), "CANCELRESPONSE")) + return CANCELRESPONSE; + if (boost::iequals(node.getLocalName(), "PAUSEREQUEST")) + return PAUSEREQUEST; + if (boost::iequals(node.getLocalName(), "PAUSERESPONSE")) + return PAUSERESPONSE; + if (boost::iequals(node.getLocalName(), "RESUMEREQUEST")) + return RESUMEREQUEST; + if (boost::iequals(node.getLocalName(), "RESUMERESPONSE")) + return RESUMERESPONSE; + if (boost::iequals(node.getLocalName(), "EXTENSIONNOTIFICATION")) + return EXTENSIONNOTIFICATION; + if (boost::iequals(node.getLocalName(), "CLEARCONTEXTREQUEST")) + return CLEARCONTEXTREQUEST; + if (boost::iequals(node.getLocalName(), "CLEARCONTEXTRESPONSE")) + return CLEARCONTEXTRESPONSE; + if (boost::iequals(node.getLocalName(), "STATUSREQUEST")) + return STATUSREQUEST; + if (boost::iequals(node.getLocalName(), "STATUSRESPONSE")) + return STATUSRESPONSE; + return INVALID; +} + +Arabica::DOM::Node MMIEvent::getEventNode(Arabica::DOM::Node node) { + if (!node) + return node; + + if (node.getNodeType() == Node_base::DOCUMENT_NODE) + node = Arabica::DOM::Document(node).getDocumentElement(); + + // get the first element + while (node && node.getNodeType() != Node_base::ELEMENT_NODE) { + node = node.getNextSibling(); } - - Arabica::DOM::Node MMIEvent::getEventNode(Arabica::DOM::Node node) { - if (node.getNodeType() == Node_base::DOCUMENT_NODE) - node = Arabica::DOM::Document(node).getDocumentElement(); - - // get the first element - while (node && node.getNodeType() != Node_base::ELEMENT_NODE) { + // get the contained message + if (node && getType(node) == INVALID) { + node = node.getFirstChild(); + while (node && node.getNodeType() != Node_base::ELEMENT_NODE && getType(node) == INVALID) { node = node.getNextSibling(); } - // get the contained message - if (node && getType(node) == INVALID) { - node = node.getFirstChild(); - while (node && node.getNodeType() != Node_base::ELEMENT_NODE && getType(node) == INVALID) { - node = node.getNextSibling(); - } - } - return node; } + return node; +} + - Arabica::DOM::Document MMIEvent::toXML() const { Arabica::DOM::DOMImplementation domFactory = Arabica::SimpleDOM::DOMImplementation::getDOMImplementation(); Document doc = domFactory.createDocument(nameSpace, "", 0); @@ -255,7 +258,7 @@ MMIEvent::operator Event() const { } return ev; } - + ContextualizedRequest ContextualizedRequest::fromXML(Arabica::DOM::Node node, InterpreterImpl* interpreter) { ContextualizedRequest msg(MMIEvent::fromXML(node, interpreter)); while (node) { @@ -273,8 +276,8 @@ ContextualizedRequest::operator Event() const { // do we want to represent the context? It's the interpreters name already return ev; } - - + + ContentRequest ContentRequest::fromXML(Arabica::DOM::Node node, InterpreterImpl* interpreter) { ContentRequest msg(ContextualizedRequest::fromXML(node, interpreter)); while (node) { @@ -424,5 +427,5 @@ StatusRequest StatusRequest::fromXML(Arabica::DOM::Node node, Inter return msg; } - + } \ No newline at end of file diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.h b/src/uscxml/plugins/ioprocessor/modality/MMIMessages.h index b7d017f..aedd88c 100644 --- a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.h +++ b/src/uscxml/plugins/ioprocessor/modality/MMIMessages.h @@ -10,44 +10,44 @@ namespace uscxml { class MMIEvent { public: enum Type { - NEWCONTEXTREQUEST, - NEWCONTEXTRESPONSE, - PREPAREREQUEST, - PREPARERESPONSE, - STARTREQUEST, - STARTRESPONSE, - DONENOTIFICATION, - CANCELREQUEST, - CANCELRESPONSE, - PAUSEREQUEST, - PAUSERESPONSE, - RESUMEREQUEST, - RESUMERESPONSE, - EXTENSIONNOTIFICATION, - CLEARCONTEXTREQUEST, - CLEARCONTEXTRESPONSE, - STATUSREQUEST, - STATUSRESPONSE, - INVALID + NEWCONTEXTREQUEST, + NEWCONTEXTRESPONSE, + PREPAREREQUEST, + PREPARERESPONSE, + STARTREQUEST, + STARTRESPONSE, + DONENOTIFICATION, + CANCELREQUEST, + CANCELRESPONSE, + PAUSEREQUEST, + PAUSERESPONSE, + RESUMEREQUEST, + RESUMERESPONSE, + EXTENSIONNOTIFICATION, + CLEARCONTEXTREQUEST, + CLEARCONTEXTRESPONSE, + STATUSREQUEST, + STATUSRESPONSE, + INVALID }; - + static Type getType(Arabica::DOM::Node node); static Arabica::DOM::Node getEventNode(Arabica::DOM::Node node); - + virtual Arabica::DOM::Document toXML() const; static MMIEvent fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL); + InterpreterImpl* interpreter = NULL); // conversion operator operator Event() const; - + std::string source; std::string target; std::string data; std::string requestId; std::string tagName; Type type; - + static std::string nameSpace; protected: @@ -72,7 +72,7 @@ public: } NewContextRequest(const MMIEvent& father) : MMIEvent(father) {} static NewContextRequest fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { MMIEvent event = MMIEvent::fromXML(node, interpreter); event.type = NEWCONTEXTREQUEST; return event; @@ -90,7 +90,7 @@ class ContextualizedRequest : public MMIEvent { public: virtual Arabica::DOM::Document toXML() const; static ContextualizedRequest fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL); + InterpreterImpl* interpreter = NULL); operator Event() const; std::string context; protected: @@ -106,7 +106,7 @@ public: } PauseRequest(const ContextualizedRequest& father) : ContextualizedRequest(father) {} static PauseRequest fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { PauseRequest event = ContextualizedRequest::fromXML(node, interpreter); event.type = PAUSEREQUEST; return event; @@ -127,7 +127,7 @@ public: } ResumeRequest(const ContextualizedRequest& father) : ContextualizedRequest(father) {} static ResumeRequest fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { ResumeRequest event = ContextualizedRequest::fromXML(node, interpreter); event.type = RESUMEREQUEST; return event; @@ -148,7 +148,7 @@ public: } CancelRequest(const ContextualizedRequest& father) : ContextualizedRequest(father) {} static CancelRequest fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { CancelRequest event = ContextualizedRequest::fromXML(node, interpreter); event.type = CANCELREQUEST; return event; @@ -169,7 +169,7 @@ public: } ClearContextRequest(const ContextualizedRequest& father) : ContextualizedRequest(father) {} static ClearContextRequest fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { ClearContextRequest event = ContextualizedRequest::fromXML(node, interpreter); event.type = CLEARCONTEXTREQUEST; return event; @@ -190,7 +190,7 @@ public: } virtual Arabica::DOM::Document toXML() const; static StatusRequest fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL); + InterpreterImpl* interpreter = NULL); operator Event() const; bool automaticUpdate; protected: @@ -207,7 +207,7 @@ public: virtual Arabica::DOM::Document toXML() const; static ContentRequest fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL); + InterpreterImpl* interpreter = NULL); operator Event() const; std::string content; ContentURL contentURL; @@ -224,7 +224,7 @@ public: } PrepareRequest(const ContentRequest& father) : ContentRequest(father) {} static PrepareRequest fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { PrepareRequest event = ContentRequest::fromXML(node, interpreter); event.type = PREPAREREQUEST; return event; @@ -245,7 +245,7 @@ public: } StartRequest(const ContentRequest& father) : ContentRequest(father) {} static StartRequest fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { StartRequest event = ContentRequest::fromXML(node, interpreter); event.type = STARTREQUEST; return event; @@ -267,7 +267,7 @@ public: } virtual Arabica::DOM::Document toXML() const; static ExtensionNotification fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL); + InterpreterImpl* interpreter = NULL); operator Event() const; std::string name; protected: @@ -290,7 +290,7 @@ public: } virtual Arabica::DOM::Document toXML() const; static StatusResponse fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL); + InterpreterImpl* interpreter = NULL); Status status; protected: StatusResponse(const ContextualizedRequest& father) : ContextualizedRequest(father) {} @@ -301,7 +301,7 @@ public: virtual Arabica::DOM::Document toXML() const; StatusInfoResponse(const StatusResponse& father) : StatusResponse(father) {} static StatusInfoResponse fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL); + InterpreterImpl* interpreter = NULL); std::string statusInfo; protected: StatusInfoResponse() {} @@ -315,7 +315,7 @@ public: } PrepareResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} static PrepareResponse fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { PrepareResponse event = StatusInfoResponse::fromXML(node, interpreter); event.type = PREPARERESPONSE; return event; @@ -336,7 +336,7 @@ public: } StartResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} static StartResponse fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { StartResponse event = StatusInfoResponse::fromXML(node, interpreter); event.type = STARTRESPONSE; return event; @@ -357,7 +357,7 @@ public: } CancelResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} static CancelResponse fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { CancelResponse event = StatusInfoResponse::fromXML(node, interpreter); event.type = CANCELRESPONSE; return event; @@ -378,7 +378,7 @@ public: } PauseResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} static PauseResponse fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { PauseResponse event = StatusInfoResponse::fromXML(node, interpreter); event.type = PAUSERESPONSE; return event; @@ -399,7 +399,7 @@ public: } ResumeResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} static ResumeResponse fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { ResumeResponse event = StatusInfoResponse::fromXML(node, interpreter); event.type = RESUMERESPONSE; return event; @@ -420,7 +420,7 @@ public: } ClearContextResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} static ClearContextResponse fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { ClearContextResponse event = StatusInfoResponse::fromXML(node, interpreter); event.type = CLEARCONTEXTRESPONSE; return event; @@ -441,7 +441,7 @@ public: } NewContextResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} static NewContextResponse fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { NewContextResponse event = StatusInfoResponse::fromXML(node, interpreter); event.type = NEWCONTEXTRESPONSE; return event; @@ -463,7 +463,7 @@ public: } DoneNotification(const StatusInfoResponse& father) : StatusInfoResponse(father) {} static DoneNotification fromXML(Arabica::DOM::Node node, - InterpreterImpl* interpreter = NULL) { + InterpreterImpl* interpreter = NULL) { DoneNotification event = StatusInfoResponse::fromXML(node, interpreter); event.type = DONENOTIFICATION; return event; diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.cpp b/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.cpp index 55ee9fe..9e8b5c2 100644 --- a/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.cpp +++ b/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.cpp @@ -11,7 +11,7 @@ namespace uscxml { ::LifeCycleEvent MMIProtoBridge::toProto(const NewContextRequest& mmiEvent) { INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_NEW_CONTEXT_REQUEST); - return lifeCycleEvent; + return lifeCycleEvent; } ::LifeCycleEvent MMIProtoBridge::toProto(const NewContextResponse& mmiEvent) { @@ -32,13 +32,13 @@ namespace uscxml { ::LifeCycleEvent MMIProtoBridge::toProto(const StartRequest& mmiEvent) { INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_START_REQUEST); - ::LifeCycleRequest* lifeCycleRequest = lifeCycleEvent.MutableExtension(::LifeCycleRequest::Request); + ::LifeCycleRequest* lifeCycleRequest = lifeCycleEvent.MutableExtension(::LifeCycleRequest::Request); lifeCycleRequest->set_context(mmiEvent.context); - + ::StartRequest* startRequest = lifeCycleRequest->MutableExtension(::StartRequest::Request); startRequest->set_content(mmiEvent.content); startRequest->set_contenturl(mmiEvent.contentURL.href); - + ::StartRequestData* startRequestData = startRequest->MutableExtension(::StartRequestData::Request); startRequestData->set_data(mmiEvent.data); diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.h b/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.h index 32a69f6..af6c720 100644 --- a/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.h +++ b/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.h @@ -6,7 +6,7 @@ #include "MMIMessages.h" namespace uscxml { - + class MMIProtoBridge { public: static ::LifeCycleEvent toProto(const NewContextRequest&); diff --git a/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.cpp new file mode 100644 index 0000000..da36a17 --- /dev/null +++ b/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.cpp @@ -0,0 +1,41 @@ +#include +#include "uscxml/plugins/ioprocessor/sample/SampleIOProcessor.h" +#include "uscxml/Message.h" +#include + +#include + +#ifdef BUILD_AS_PLUGINS +#include +#endif + +namespace uscxml { + +#ifdef BUILD_AS_PLUGINS +PLUMA_CONNECTOR +bool connect(pluma::Host& host) { + host.add( new SampleIOProcessorProvider() ); + return true; +} +#endif + +SampleIOProcessor::SampleIOProcessor() { +} + +SampleIOProcessor::~SampleIOProcessor() { +} + +boost::shared_ptr SampleIOProcessor::create(InterpreterImpl* interpreter) { + boost::shared_ptr io = boost::shared_ptr(new SampleIOProcessor()); + return io; +} + +Data SampleIOProcessor::getDataModelVariables() { + Data data; + return data; +} + +void SampleIOProcessor::send(const SendRequest& req) { +} + +} \ No newline at end of file diff --git a/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.h b/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.h new file mode 100644 index 0000000..3a58c13 --- /dev/null +++ b/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.h @@ -0,0 +1,39 @@ +#ifndef SAMPLEIOPROCESSOR_H_2CUY93KU +#define SAMPLEIOPROCESSOR_H_2CUY93KU + +#include "uscxml/concurrency/eventqueue/DelayedEventQueue.h" +#include "uscxml/Interpreter.h" +#include "uscxml/Factory.h" + +#ifdef BUILD_AS_PLUGINS +#include "uscxml/plugins/Plugins.h" +#endif + +namespace uscxml { + +class SampleIOProcessor : public IOProcessorImpl { +public: + SampleIOProcessor(); + virtual ~SampleIOProcessor(); + virtual boost::shared_ptr create(uscxml::InterpreterImpl* interpreter); + + virtual std::set getNames() { + std::set names; + names.insert("sample"); + names.insert("http://www.w3.org/TR/scxml/#SampleEventProcessor"); + return names; + } + + virtual void send(const SendRequest& req); + Data getDataModelVariables(); + +protected: +}; + +#ifdef BUILD_AS_PLUGINS +PLUMA_INHERIT_PROVIDER(SampleIOProcessor, IOProcessorImpl); +#endif + +} + +#endif /* end of include guard: SAMPLEIOPROCESSOR_H_2CUY93KU */ \ No newline at end of file diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp index bd24326..f4b1a57 100644 --- a/src/uscxml/server/HTTPServer.cpp +++ b/src/uscxml/server/HTTPServer.cpp @@ -72,7 +72,10 @@ std::map HTTPServer::mimeTypes; HTTPServer* HTTPServer::getInstance(int port) { // tthread::lock_guard lock(_instanceMutex); if (_instance == NULL) { - +#ifdef _WIN32 + WSADATA wsaData; + WSAStartup(MAKEWORD(2, 2), &wsaData); +#endif // this is but a tiny list, supply a content-type
yourself mimeTypes["txt"] = "text/plain"; mimeTypes["c"] = "text/plain"; @@ -109,19 +112,16 @@ std::string HTTPServer::mimeTypeForExtension(const std::string& ext) { return ""; } +/** + * This callback is registered for all HTTP requests + */ void HTTPServer::httpRecvReqCallback(struct evhttp_request *req, void *callbackData) { -// std::cout << (uintptr_t)req << ": Replying" << std::endl; -// evhttp_send_error(req, 404, NULL); -// return; - std::stringstream raw; evhttp_request_own(req); Request request; request.curlReq = req; - - switch (evhttp_request_get_command(req)) { case EVHTTP_REQ_GET: request.data.compound["type"] = Data("get", Data::VERBATIM); @@ -167,7 +167,7 @@ void HTTPServer::httpRecvReqCallback(struct evhttp_request *req, void *callbackD const char* query = evhttp_uri_get_query(evhttp_request_get_evhttp_uri(req)); if (query) raw << "?" << std::string(query); - + raw << " HTTP/" << request.data.compound["httpMajor"].atom << "." << request.data.compound["httpMinor"].atom; raw << std::endl; @@ -237,40 +237,45 @@ void HTTPServer::httpRecvReqCallback(struct evhttp_request *req, void *callbackD request.raw = raw.str(); - if (callbackData == NULL) { + // try with the handler registered for path first + bool answered = false; + if (callbackData != NULL) + answered = ((HTTPServlet*)callbackData)->httpRecvRequest(request); + + if (!answered) HTTPServer::getInstance()->processByMatchingServlet(request); - } else { - ((HTTPServlet*)callbackData)->httpRecvRequest(request); - } } + void HTTPServer::processByMatchingServlet(const Request& request) { + tthread::lock_guard lock(_mutex); + servlet_iter_t servletIter = _servlets.begin(); std::string actualPath = request.data.compound.at("path").atom; - HTTPServlet* bestMatch = NULL; - std::string bestPath; + std::map matches; while(servletIter != _servlets.end()) { // is the servlet path a prefix of the actual path? std::string servletPath = "/" + servletIter->first; if (boost::iequals(actualPath.substr(0, servletPath.length()), servletPath) && // actual path is a prefix - boost::iequals(actualPath.substr(servletPath.length(), 1), "/")) { // and next character is a '/' - if (bestPath.length() < servletPath.length()) { - // this servlet is a better match - bestPath = servletPath; - bestMatch = servletIter->second; - } + boost::iequals(actualPath.substr(servletPath.length(), 1), "/")) { // and next character is a '/' + matches.insert(std::make_pair(servletPath, servletIter->second)); } servletIter++; } - if (bestMatch != NULL) { - bestMatch->httpRecvRequest(request); - } else { - LOG(INFO) << "Got an HTTP request at " << actualPath << " but no servlet is registered there or at a prefix"; - evhttp_send_error(request.curlReq, 404, NULL); + // process by best matching servlet until someone feels responsible + std::map::iterator matchesIter = matches.begin(); + while(matchesIter != matches.end()) { + if (matchesIter->second->httpRecvRequest(request)) { + return; + } + matchesIter++; } + + LOG(INFO) << "Got an HTTP request at " << actualPath << " but no servlet is registered there or at a prefix"; + evhttp_send_error(request.curlReq, 404, NULL); } void HTTPServer::reply(const Reply& reply) { @@ -281,7 +286,6 @@ void HTTPServer::reply(const Reply& reply) { } void HTTPServer::replyCallback(evutil_socket_t fd, short what, void *arg) { - Reply* reply = (Reply*)arg; if (reply->content.size() > 0 && reply->headers.find("Content-Type") == reply->headers.end()) { diff --git a/src/uscxml/server/HTTPServer.h b/src/uscxml/server/HTTPServer.h index bd54166..d216d5e 100644 --- a/src/uscxml/server/HTTPServer.h +++ b/src/uscxml/server/HTTPServer.h @@ -20,7 +20,7 @@ public: Request() : curlReq(NULL) {} std::string content; struct evhttp_request* curlReq; - + operator bool() { return curlReq != NULL; } @@ -50,6 +50,15 @@ public: static void unregisterServlet(HTTPServlet* servlet); private: + struct comp_strsize_less { + bool operator()(std::string const& l, std::string const& r) const { + if (l.size() < r.size()) + return false; + + return l < r; + }; + }; + HTTPServer(unsigned short port); ~HTTPServer(); @@ -86,11 +95,11 @@ private: class HTTPServlet { public: - virtual void httpRecvRequest(const HTTPServer::Request& request) = 0; + virtual bool httpRecvRequest(const HTTPServer::Request& request) = 0; + virtual void setURL(const std::string& url) = 0; /// Called by the server with the actual URL virtual bool canAdaptPath() { return true; } - virtual void setURL(const std::string& url) = 0; /// Called by the server with the actual URL }; } diff --git a/src/uscxml/server/InterpreterServlet.cpp b/src/uscxml/server/InterpreterServlet.cpp index 28b7c1b..b59cc05 100644 --- a/src/uscxml/server/InterpreterServlet.cpp +++ b/src/uscxml/server/InterpreterServlet.cpp @@ -24,7 +24,7 @@ boost::shared_ptr InterpreterServlet::create(InterpreterImpl* i return io; } -void InterpreterServlet::httpRecvRequest(const HTTPServer::Request& req) { +bool InterpreterServlet::httpRecvRequest(const HTTPServer::Request& req) { tthread::lock_guard lock(_mutex); // evhttp_request_own(req.curlReq); @@ -37,6 +37,7 @@ void InterpreterServlet::httpRecvRequest(const HTTPServer::Request& req) { event.origin = toStr((uintptr_t)req.curlReq); event.initContent(event.data.compound["content"].atom); _interpreter->receive(event); + return true; } Data InterpreterServlet::getDataModelVariables() { diff --git a/src/uscxml/server/InterpreterServlet.h b/src/uscxml/server/InterpreterServlet.h index 6c61e47..c00bd11 100644 --- a/src/uscxml/server/InterpreterServlet.h +++ b/src/uscxml/server/InterpreterServlet.h @@ -26,7 +26,7 @@ public: Data getDataModelVariables(); virtual void send(const SendRequest& req); - virtual void httpRecvRequest(const HTTPServer::Request& req); + virtual bool httpRecvRequest(const HTTPServer::Request& req); std::string getPath() { return _path; diff --git a/test/samples/uscxml/templates/mc-html.html b/test/samples/uscxml/templates/mc-html.html index 78bb34e..33eac77 100644 --- a/test/samples/uscxml/templates/mc-html.html +++ b/test/samples/uscxml/templates/mc-html.html @@ -1,159 +1,346 @@ - - + + + + +
diff --git a/test/samples/uscxml/templates/xhtml-invoker.html b/test/samples/uscxml/templates/xhtml-invoker.html new file mode 100644 index 0000000..7773231 --- /dev/null +++ b/test/samples/uscxml/templates/xhtml-invoker.html @@ -0,0 +1,228 @@ + + + + + + + + + + + diff --git a/test/samples/uscxml/test-mmi-im.scxml b/test/samples/uscxml/test-mmi-im.scxml index 4b130bd..70cb3b8 100644 --- a/test/samples/uscxml/test-mmi-im.scxml +++ b/test/samples/uscxml/test-mmi-im.scxml @@ -35,6 +35,7 @@ + @@ -52,7 +53,13 @@ - Click Me + + First name: + Last name: + + @@ -60,7 +67,7 @@ - + diff --git a/test/samples/uscxml/test-xhtml-invoker.scxml b/test/samples/uscxml/test-xhtml-invoker.scxml new file mode 100644 index 0000000..aec4db3 --- /dev/null +++ b/test/samples/uscxml/test-xhtml-invoker.scxml @@ -0,0 +1,33 @@ + + +