diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-06-20 19:53:21 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-06-20 19:53:21 (GMT) |
commit | 794575f01ce5a6bf7e377eb815f3def5aded74f5 (patch) | |
tree | 9c59df64ee290f68b7b6c8698bfac4169684485e | |
parent | d304f85417e3175c5f2ca159dd303309c24e7b81 (diff) | |
download | uscxml-794575f01ce5a6bf7e377eb815f3def5aded74f5.zip uscxml-794575f01ce5a6bf7e377eb815f3def5aded74f5.tar.gz uscxml-794575f01ce5a6bf7e377eb815f3def5aded74f5.tar.bz2 |
New version with XHTML invoker
102 files changed, 5656 insertions, 3171 deletions
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() @@ -5,8 +5,9 @@ uSCXML is a SCXML interpreter written in C/C++. It is mostly feature-complete an It runs on <b>Linux</b>, <b>Windows</b> and <b>MacOSX</b>, 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 <b>iOS</b> using the toolchain files in <tt>contrib/cmake/</tt> 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. * <b>Datamodels</b> * 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<std::string> mmiDoc = parser->getDocument(); - std::cout << mmiDoc.getNamespaceURI() << std::endl; - Node<std::string> 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<std::string> 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<std::string> 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<MMIEventReceiver*>::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<MMIEventReceiver*>::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<std::string, Data>::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<std::string, std::pair<URL, SendRequest> >::iterator reqIter = _sendRequests.begin(); - while(reqIter != _sendRequests.end()) { - if (reqIter->second.first == url) { - _sendRequests.erase(reqIter); - return; - } - reqIter++; + std::map<std::string, Data>::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<std::string, std::pair<URL, SendRequest> >::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<std::string, std::pair<URL, SendRequest> >::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<std::string, std::pair<URL, SendRequest> >::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<MMISessionManager::CometMMISession*>(_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<MMISessionManager::CometMMISession*>(_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<std::string> mmiDoc = NameSpacingParser::fromXML(req.data.compound.at("content").atom).getDocument(); - Node<std::string> 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<std::string> 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<std::string> domFactory = Arabica::SimpleDOM::DOMImplementation<std::string>::getDOMImplementation(); - Arabica::DOM::Document<std::string> 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<MMISessionManager::CometMMISession*>(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<std::string> domFactory = Arabica::SimpleDOM::DOMImplementation<std::string>::getDOMImplementation(); + Arabica::DOM::Document<std::string> 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<MMISessionManager::CometMMISession*>(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<tthread::recursive_mutex> 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<tthread::recursive_mutex> lock(_mutex); + if (!_longPollingReq) { + _outQueue.push_back(req); + return; + } + + if (req.dom) { + std::stringstream ss; + Node<std::string> 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<std::string> 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<std::string>& msg) { - - } - - void MMISessionManager::CometMMISession::longPoll(const HTTPServer::Request& req) { - tthread::lock_guard<tthread::recursive_mutex> 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<IOProcessorImpl> MMISessionManager::MMIIOProcessor::create(InterpreterImpl* interpreter) { - boost::shared_ptr<IOProcessorImpl> ioProc = boost::shared_ptr<IOProcessorImpl>(new MMISessionManager::MMIIOProcessor(_sessionManager)); - return ioProc; - } - - Data MMISessionManager::MMIIOProcessor::getDataModelVariables() { - Data data; - return data; +void MMISessionManager::CometMMISession::receive(const Arabica::DOM::Node<std::string>& msg) { + +} + +void MMISessionManager::CometMMISession::longPoll(const HTTPServer::Request& req) { + tthread::lock_guard<tthread::recursive_mutex> 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<std::string> mmiEvent = MMIEvent::getEventNode(req.dom); - if (!mmiEvent || !mmiEvent.getNodeType() == Node_base::ELEMENT_NODE) - return; - - Arabica::DOM::Element<std::string> mmiElem = Arabica::DOM::Element<std::string>(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<IOProcessorImpl> MMISessionManager::MMIIOProcessor::create(InterpreterImpl* interpreter) { + boost::shared_ptr<IOProcessorImpl> ioProc = boost::shared_ptr<IOProcessorImpl>(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<std::string> mmiEvent = MMIEvent::getEventNode(req.dom); + if (!mmiEvent || !mmiEvent.getNodeType() == Node_base::ELEMENT_NODE) + return; + + Arabica::DOM::Element<std::string> mmiElem = Arabica::DOM::Element<std::string>(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<SendRequest> _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<option_name>=<value>): +# 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 "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES> \"${__stlLibPath}/libstlport_static.a\"") + set( CMAKE_CXX_CREATE_SHARED_MODULE "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES> \"${__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 : <any valid path> +# 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 <prebuilt dir> <version>" 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 <winsock2.h> +// see http://stackoverflow.com/questions/1372480/c-redefinition-header-files +#define _WINSOCKAPI_ // stops windows.h including winsock.h #include <windows.h> #else #include <sys/socket.h> 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 <glog/logging.h> +// 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<std::string, IOProcessorImpl*> Factory::getIOProcessors() { if (_parentFactory) { ioProcs = _parentFactory->getIOProcessors(); } - + std::map<std::string, IOProcessorImpl*>::iterator ioProcIter = _ioProcessors.begin(); while(ioProcIter != _ioProcessors.end()) { ioProcs.insert(std::make_pair(ioProcIter->first, ioProcIter->second)); ioProcIter++; } - + return ioProcs; } boost::shared_ptr<InvokerImpl> 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<InvokerImpl> Factory::createInvoker(const std::string& type, I } else { LOG(ERROR) << "No " << type << " Invoker known"; } - + return boost::shared_ptr<InvokerImpl>(); } boost::shared_ptr<DataModelImpl> 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<DataModelImpl> 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<DataModelImpl>(); } @@ -350,14 +358,14 @@ boost::shared_ptr<IOProcessorImpl> 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<IOProcessorImpl>(); } 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<EventHandlerImpl> const impl) : _impl(impl) { } EventHandler(const EventHandler& other) : _impl(other._impl) { } virtual ~EventHandler() {}; - + virtual std::set<std::string> 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<ExecutableContentImpl> createExecutableContent(const std::string& localName, const std::string& nameSpace, InterpreterImpl* interpreter); std::map<std::string, IOProcessorImpl*> getIOProcessors(); - + static Factory* getInstance(); std::map<std::string, DataModelImpl*> _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<std::string>& tthread::lock_guard<tthread::recursive_mutex> lock(_instanceMutex); boost::shared_ptr<InterpreterDraft6> interpreterImpl = boost::shared_ptr<InterpreterDraft6>(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<std::string, std::string> nameSpaceInfo); - std::map<std::string, std::string> getNameSpaceInfo() { return _nameSpaceInfo; } - + std::map<std::string, std::string> getNameSpaceInfo() { + return _nameSpaceInfo; + } + void receiveInternal(const Event& event); void receive(const Event& event, bool toFront = false); @@ -391,7 +393,7 @@ public: std::map<std::string, std::string> 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<std::string> parser; Arabica::SAX::CatchErrorHandler<std::string> errorHandler; parser.setErrorHandler(errorHandler); - + std::istringstream is(content); Arabica::SAX::InputSource<std::string> 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<std::string> 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 <uscxml/Common.h> #include "NameSpacingParser.h" #include <glog/logging.h> +#include <SAX/helpers/InputSourceResolver.hpp> 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<std::istream> ssPtr(ss); - Arabica::SAX::InputSource<std::string> inputSource; - inputSource.setByteStream(ssPtr); - return fromInputSource(inputSource); - } - NameSpacingParser* NameSpacingParser::fromInputSource(Arabica::SAX::InputSource<std::string>& 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<std::string>()); - 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<std::istream> ssPtr(ss); + Arabica::SAX::InputSource<std::string> inputSource; + inputSource.setByteStream(ssPtr); + return fromInputSource(inputSource); +} + +NameSpacingParser NameSpacingParser::fromInputSource(Arabica::SAX::InputSource<std::string>& 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<std::string>()); + if (!resolver.resolve()) { + LOG(ERROR) << source.getSystemId() << ": no such file"; } - delete parser; } - return parser; } + return parser; +} - NameSpacingParser::NameSpacingParser() { - Arabica::SAX::CatchErrorHandler<std::string> 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 <SAX/helpers/CatchErrorHandler.hpp> namespace uscxml { - - class NameSpacingParser : public Arabica::SAX2DOM::Parser<std::string> { - public: - NameSpacingParser(); - static NameSpacingParser* fromXML(const std::string& xml); - static NameSpacingParser* fromInputSource(Arabica::SAX::InputSource<std::string>& source); - void startPrefixMapping(const std::string& prefix, const std::string& uri); +class NameSpacingParser : public Arabica::SAX2DOM::Parser<std::string> { +public: + NameSpacingParser(); + static NameSpacingParser fromXML(const std::string& xml); + static NameSpacingParser fromInputSource(Arabica::SAX::InputSource<std::string>& source); - Arabica::SAX::CatchErrorHandler<std::string> _errorHandler; - std::map<std::string, std::string> nameSpace; + void startPrefixMapping(const std::string& prefix, const std::string& uri); - private: - NameSpacingParser(const NameSpacingParser& other) {} - }; + std::map<std::string, std::string> nameSpace; + + virtual bool errorsReported() { + return _errorHandler.errorsReported(); + } + + virtual const std::string& errors() { + return _errorHandler.errors(); + } + +private: + Arabica::SAX::CatchErrorHandler<std::string> _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<v8::FunctionTemplate> V8Attr::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Attr::Tmpl; - v8::Handle<v8::Value> V8Attr::nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Attr::nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getName().c_str()); - } + return v8::String::New(privData->nativeObj->getName().c_str()); +} - v8::Handle<v8::Value> V8Attr::specifiedAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Attr::specifiedAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(self->GetInternalField(0)); - return v8::Boolean::New(privData->nativeObj->getSpecified()); - } + return v8::Boolean::New(privData->nativeObj->getSpecified()); +} - v8::Handle<v8::Value> V8Attr::valueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Attr::valueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(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<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localValue(value); - privData->nativeObj->setValue(*localValue); - } +void V8Attr::valueAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localValue(value); + privData->nativeObj->setValue(*localValue); +} - v8::Handle<v8::Value> V8Attr::ownerElementAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Attr::ownerElementAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(self->GetInternalField(0)); - if (!privData->nativeObj->getOwnerElement()) return v8::Undefined(); - Arabica::DOM::Element<std::string>* arbaicaRet = new Arabica::DOM::Element<std::string>(privData->nativeObj->getOwnerElement()); + if (!privData->nativeObj->getOwnerElement()) return v8::Undefined(); + Arabica::DOM::Element<std::string>* arbaicaRet = new Arabica::DOM::Element<std::string>(privData->nativeObj->getOwnerElement()); - v8::Handle<v8::Function> arbaicaRetCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); + v8::Handle<v8::Function> arbaicaRetCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<v8::Value> value) { - return getTmpl()->HasInstance(value); - } + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Element::jsDestructor); + return arbaicaRetObj; -} -} +} +bool V8Attr::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; - - V8_DESTRUCTOR(V8AttrPrivate); - static bool hasInstance(v8::Handle<v8::Value>); - - - static v8::Handle<v8::Value> nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> specifiedAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> valueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static void valueAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> ownerElementAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Attr")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("specified"), V8Attr::specifiedAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("value"), V8Attr::valueAttrGetter, V8Attr::valueAttrSetter, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("ownerElement"), V8Attr::ownerElementAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8AttrPrivate { + V8DOM* dom; + Arabica::DOM::Attr<std::string>* nativeObj; + }; + + V8_DESTRUCTOR(V8AttrPrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + + static v8::Handle<v8::Value> nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> specifiedAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> valueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static void valueAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> ownerElementAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Attr")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("specified"), V8Attr::specifiedAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("value"), V8Attr::valueAttrGetter, V8Attr::valueAttrSetter, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("ownerElement"), V8Attr::ownerElementAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8CDATASection::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8CDATASection::Tmpl; - bool V8CDATASection::hasInstance(v8::Handle<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8CDATASection::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; + struct V8CDATASectionPrivate { + V8DOM* dom; + Arabica::DOM::CDATASection<std::string>* nativeObj; + }; - V8_DESTRUCTOR(V8CDATASectionPrivate); - static bool hasInstance(v8::Handle<v8::Value>); + V8_DESTRUCTOR(V8CDATASectionPrivate); + static bool hasInstance(v8::Handle<v8::Value>); - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("CDATASection")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("CDATASection")); + tmpl->ReadOnlyPrototype(); - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + instance->SetInternalFieldCount(1); - tmpl->Inherit(V8Text::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8Text::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8CharacterData::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8CharacterData::Tmpl; - v8::Handle<v8::Value> V8CharacterData::dataAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8CharacterData::dataAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(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<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localData(value); - privData->nativeObj->setData(*localData); - } +void V8CharacterData::dataAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localData(value); + privData->nativeObj->setData(*localData); +} - v8::Handle<v8::Value> V8CharacterData::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8CharacterData::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - return v8::Integer::New(privData->nativeObj->getLength()); - } - v8::Handle<v8::Value> 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<v8::Value> V8CharacterData::substringDataCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in substringData"); - v8::Local<v8::Object> self = args.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + v8::Local<v8::Object> self = args.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(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<v8::Value> V8CharacterData::appendDataCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in appendData"); +v8::Handle<v8::Value> V8CharacterData::appendDataCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in appendData"); - v8::Local<v8::Object> self = args.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localArg(args[0]); + v8::Local<v8::Object> self = args.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(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<v8::Value> V8CharacterData::insertDataCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in insertData"); +v8::Handle<v8::Value> V8CharacterData::insertDataCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in insertData"); - v8::Local<v8::Object> self = args.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - v8::String::AsciiValue localArg(args[1]); + v8::Local<v8::Object> self = args.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(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<v8::Value> V8CharacterData::deleteDataCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in deleteData"); +v8::Handle<v8::Value> V8CharacterData::deleteDataCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in deleteData"); - v8::Local<v8::Object> self = args.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + v8::Local<v8::Object> self = args.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(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<v8::Value> V8CharacterData::replaceDataCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in replaceData"); +v8::Handle<v8::Value> V8CharacterData::replaceDataCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in replaceData"); - v8::Local<v8::Object> self = args.Holder(); - struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(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<v8::Object> self = args.Holder(); + struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(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<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8CharacterData::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; - - V8_DESTRUCTOR(V8CharacterDataPrivate); - static bool hasInstance(v8::Handle<v8::Value>); - - static v8::Handle<v8::Value> substringDataCallback(const v8::Arguments&); - static v8::Handle<v8::Value> appendDataCallback(const v8::Arguments&); - static v8::Handle<v8::Value> insertDataCallback(const v8::Arguments&); - static v8::Handle<v8::Value> deleteDataCallback(const v8::Arguments&); - static v8::Handle<v8::Value> replaceDataCallback(const v8::Arguments&); - - static v8::Handle<v8::Value> dataAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static void dataAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("CharacterData")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("length"), V8CharacterData::lengthAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - prototype->Set(v8::String::NewSymbol("substringData"), - v8::FunctionTemplate::New(V8CharacterData::substringDataCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("appendData"), - v8::FunctionTemplate::New(V8CharacterData::appendDataCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("insertData"), - v8::FunctionTemplate::New(V8CharacterData::insertDataCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("deleteData"), - v8::FunctionTemplate::New(V8CharacterData::deleteDataCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("replaceData"), - v8::FunctionTemplate::New(V8CharacterData::replaceDataCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8CharacterDataPrivate { + V8DOM* dom; + Arabica::DOM::CharacterData<std::string>* nativeObj; + }; + + V8_DESTRUCTOR(V8CharacterDataPrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + static v8::Handle<v8::Value> substringDataCallback(const v8::Arguments&); + static v8::Handle<v8::Value> appendDataCallback(const v8::Arguments&); + static v8::Handle<v8::Value> insertDataCallback(const v8::Arguments&); + static v8::Handle<v8::Value> deleteDataCallback(const v8::Arguments&); + static v8::Handle<v8::Value> replaceDataCallback(const v8::Arguments&); + + static v8::Handle<v8::Value> dataAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static void dataAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("CharacterData")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("length"), V8CharacterData::lengthAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + prototype->Set(v8::String::NewSymbol("substringData"), + v8::FunctionTemplate::New(V8CharacterData::substringDataCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("appendData"), + v8::FunctionTemplate::New(V8CharacterData::appendDataCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("insertData"), + v8::FunctionTemplate::New(V8CharacterData::insertDataCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("deleteData"), + v8::FunctionTemplate::New(V8CharacterData::deleteDataCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("replaceData"), + v8::FunctionTemplate::New(V8CharacterData::replaceDataCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8Comment::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Comment::Tmpl; - bool V8Comment::hasInstance(v8::Handle<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8Comment::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; + struct V8CommentPrivate { + V8DOM* dom; + Arabica::DOM::Comment<std::string>* nativeObj; + }; - V8_DESTRUCTOR(V8CommentPrivate); - static bool hasInstance(v8::Handle<v8::Value>); + V8_DESTRUCTOR(V8CommentPrivate); + static bool hasInstance(v8::Handle<v8::Value>); - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Comment")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Comment")); + tmpl->ReadOnlyPrototype(); - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + instance->SetInternalFieldCount(1); - tmpl->Inherit(V8CharacterData::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8CharacterData::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8DOMImplementation::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8DOMImplementation::Tmpl; - v8::Handle<v8::Value> V8DOMImplementation::hasFeatureCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in hasFeature"); +v8::Handle<v8::Value> V8DOMImplementation::hasFeatureCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in hasFeature"); - v8::Local<v8::Object> self = args.Holder(); - struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr<V8DOMImplementationPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localFeature(args[0]); - v8::String::AsciiValue localVersion(args[1]); + v8::Local<v8::Object> self = args.Holder(); + struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr<V8DOMImplementationPrivate >(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<v8::Value> V8DOMImplementation::createDocumentTypeCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in createDocumentType"); +v8::Handle<v8::Value> V8DOMImplementation::createDocumentTypeCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in createDocumentType"); - v8::Local<v8::Object> self = args.Holder(); - struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr<V8DOMImplementationPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localQualifiedName(args[0]); - v8::String::AsciiValue localPublicId(args[1]); - v8::String::AsciiValue localSystemId(args[2]); + v8::Local<v8::Object> self = args.Holder(); + struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr<V8DOMImplementationPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localQualifiedName(args[0]); + v8::String::AsciiValue localPublicId(args[1]); + v8::String::AsciiValue localSystemId(args[2]); - Arabica::DOM::DocumentType<std::string>* retVal = new Arabica::DOM::DocumentType<std::string>(privData->nativeObj->createDocumentType(*localQualifiedName, *localPublicId, *localSystemId)); - v8::Handle<v8::Function> retCtor = V8DocumentType::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::DocumentType<std::string>* retVal = new Arabica::DOM::DocumentType<std::string>(privData->nativeObj->createDocumentType(*localQualifiedName, *localPublicId, *localSystemId)); + v8::Handle<v8::Function> retCtor = V8DocumentType::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> 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<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr<V8DOMImplementationPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); - Arabica::DOM::DocumentType<std::string>* localDoctype = V8DOM::toClassPtr<V8DocumentType::V8DocumentTypePrivate >(args[2]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local<v8::Object> self = args.Holder(); + struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr<V8DOMImplementationPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + Arabica::DOM::DocumentType<std::string>* localDoctype = V8DOM::toClassPtr<V8DocumentType::V8DocumentTypePrivate >(args[2]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Document<std::string>* retVal = new Arabica::DOM::Document<std::string>(privData->nativeObj->createDocument(*localNamespaceURI, *localQualifiedName, *localDoctype)); - v8::Handle<v8::Function> retCtor = V8Document::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Document<std::string>* retVal = new Arabica::DOM::Document<std::string>(privData->nativeObj->createDocument(*localNamespaceURI, *localQualifiedName, *localDoctype)); + v8::Handle<v8::Function> retCtor = V8Document::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8DOMImplementation::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; + struct V8DOMImplementationPrivate { + V8DOM* dom; + Arabica::DOM::DOMImplementation<std::string>* nativeObj; + }; - V8_DESTRUCTOR(V8DOMImplementationPrivate); - static bool hasInstance(v8::Handle<v8::Value>); + V8_DESTRUCTOR(V8DOMImplementationPrivate); + static bool hasInstance(v8::Handle<v8::Value>); - static v8::Handle<v8::Value> hasFeatureCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createDocumentTypeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createDocumentCallback(const v8::Arguments&); + static v8::Handle<v8::Value> hasFeatureCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createDocumentTypeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createDocumentCallback(const v8::Arguments&); - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("DOMImplementation")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("DOMImplementation")); + tmpl->ReadOnlyPrototype(); - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createDocumentType"), - v8::FunctionTemplate::New(V8DOMImplementation::createDocumentTypeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createDocument"), - v8::FunctionTemplate::New(V8DOMImplementation::createDocumentCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasFeature"), + v8::FunctionTemplate::New(V8DOMImplementation::hasFeatureCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createDocumentType"), + v8::FunctionTemplate::New(V8DOMImplementation::createDocumentTypeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createDocument"), + v8::FunctionTemplate::New(V8DOMImplementation::createDocumentCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8Document::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Document::Tmpl; - v8::Handle<v8::Value> V8Document::doctypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Document::doctypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - if (!privData->nativeObj->getDoctype()) return v8::Undefined(); - Arabica::DOM::DocumentType<std::string>* arbaicaRet = new Arabica::DOM::DocumentType<std::string>(privData->nativeObj->getDoctype()); + if (!privData->nativeObj->getDoctype()) return v8::Undefined(); + Arabica::DOM::DocumentType<std::string>* arbaicaRet = new Arabica::DOM::DocumentType<std::string>(privData->nativeObj->getDoctype()); - v8::Handle<v8::Function> arbaicaRetCtor = V8DocumentType::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); + v8::Handle<v8::Function> arbaicaRetCtor = V8DocumentType::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<v8::Value> V8Document::implementationAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); +} - if (!privData->nativeObj->getImplementation()) return v8::Undefined(); - Arabica::DOM::DOMImplementation<std::string>* arbaicaRet = new Arabica::DOM::DOMImplementation<std::string>(privData->nativeObj->getImplementation()); +v8::Handle<v8::Value> V8Document::implementationAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::Handle<v8::Function> arbaicaRetCtor = V8DOMImplementation::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); + if (!privData->nativeObj->getImplementation()) return v8::Undefined(); + Arabica::DOM::DOMImplementation<std::string>* arbaicaRet = new Arabica::DOM::DOMImplementation<std::string>(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<v8::Function> arbaicaRetCtor = V8DOMImplementation::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); - } + struct V8DOMImplementation::V8DOMImplementationPrivate* retPrivData = new V8DOMImplementation::V8DOMImplementationPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - v8::Handle<v8::Value> V8Document::documentElementAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* arbaicaRet = new Arabica::DOM::Element<std::string>(privData->nativeObj->getDocumentElement()); +} - v8::Handle<v8::Function> arbaicaRetCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); +v8::Handle<v8::Value> V8Document::documentElementAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* arbaicaRet = new Arabica::DOM::Element<std::string>(privData->nativeObj->getDocumentElement()); - } - v8::Handle<v8::Value> V8Document::createElementCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createElement"); + v8::Handle<v8::Function> arbaicaRetCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); - v8::Local<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElement(*localTagName)); - v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localTagName(args[0]); - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElement(*localTagName)); + v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> V8Document::createDocumentFragmentCallback(const v8::Arguments& args) { + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - v8::Local<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; - Arabica::DOM::DocumentFragment<std::string>* retVal = new Arabica::DOM::DocumentFragment<std::string>(privData->nativeObj->createDocumentFragment()); - v8::Handle<v8::Function> retCtor = V8DocumentFragment::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8DocumentFragment::V8DocumentFragmentPrivate* retPrivData = new V8DocumentFragment::V8DocumentFragmentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> V8Document::createDocumentFragmentCallback(const v8::Arguments& args) { - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + v8::Local<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - retObj.MakeWeak(0, V8DocumentFragment::jsDestructor); - return retObj; + Arabica::DOM::DocumentFragment<std::string>* retVal = new Arabica::DOM::DocumentFragment<std::string>(privData->nativeObj->createDocumentFragment()); + v8::Handle<v8::Function> retCtor = V8DocumentFragment::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8DocumentFragment::V8DocumentFragmentPrivate* retPrivData = new V8DocumentFragment::V8DocumentFragmentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localData(args[0]); + retObj.MakeWeak(0, V8DocumentFragment::jsDestructor); + return retObj; - Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->createTextNode(*localData)); - v8::Handle<v8::Function> retCtor = V8Text::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localData(args[0]); - retObj.MakeWeak(0, V8Text::jsDestructor); - return retObj; + Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->createTextNode(*localData)); + v8::Handle<v8::Function> retCtor = V8Text::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localData(args[0]); + retObj.MakeWeak(0, V8Text::jsDestructor); + return retObj; - Arabica::DOM::Comment<std::string>* retVal = new Arabica::DOM::Comment<std::string>(privData->nativeObj->createComment(*localData)); - v8::Handle<v8::Function> retCtor = V8Comment::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8Comment::V8CommentPrivate* retPrivData = new V8Comment::V8CommentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localData(args[0]); - retObj.MakeWeak(0, V8Comment::jsDestructor); - return retObj; + Arabica::DOM::Comment<std::string>* retVal = new Arabica::DOM::Comment<std::string>(privData->nativeObj->createComment(*localData)); + v8::Handle<v8::Function> retCtor = V8Comment::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8Comment::V8CommentPrivate* retPrivData = new V8Comment::V8CommentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localData(args[0]); + retObj.MakeWeak(0, V8Comment::jsDestructor); + return retObj; - Arabica::DOM::CDATASection<std::string>* retVal = new Arabica::DOM::CDATASection<std::string>(privData->nativeObj->createCDATASection(*localData)); - v8::Handle<v8::Function> retCtor = V8CDATASection::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8CDATASection::V8CDATASectionPrivate* retPrivData = new V8CDATASection::V8CDATASectionPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localData(args[0]); - retObj.MakeWeak(0, V8CDATASection::jsDestructor); - return retObj; + Arabica::DOM::CDATASection<std::string>* retVal = new Arabica::DOM::CDATASection<std::string>(privData->nativeObj->createCDATASection(*localData)); + v8::Handle<v8::Function> retCtor = V8CDATASection::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8CDATASection::V8CDATASectionPrivate* retPrivData = new V8CDATASection::V8CDATASectionPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* retVal = new Arabica::DOM::ProcessingInstruction<std::string>(privData->nativeObj->createProcessingInstruction(*localTarget, *localData)); - v8::Handle<v8::Function> retCtor = V8ProcessingInstruction::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8ProcessingInstruction::V8ProcessingInstructionPrivate* retPrivData = new V8ProcessingInstruction::V8ProcessingInstructionPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* retVal = new Arabica::DOM::ProcessingInstruction<std::string>(privData->nativeObj->createProcessingInstruction(*localTarget, *localData)); + v8::Handle<v8::Function> retCtor = V8ProcessingInstruction::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8ProcessingInstruction::V8ProcessingInstructionPrivate* retPrivData = new V8ProcessingInstruction::V8ProcessingInstructionPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + retObj.MakeWeak(0, V8ProcessingInstruction::jsDestructor); + return retObj; - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttribute(*localName)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttribute(*localName)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; - Arabica::DOM::EntityReference<std::string>* retVal = new Arabica::DOM::EntityReference<std::string>(privData->nativeObj->createEntityReference(*localName)); - v8::Handle<v8::Function> retCtor = V8EntityReference::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8EntityReference::V8EntityReferencePrivate* retPrivData = new V8EntityReference::V8EntityReferencePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - retObj.MakeWeak(0, V8EntityReference::jsDestructor); - return retObj; + Arabica::DOM::EntityReference<std::string>* retVal = new Arabica::DOM::EntityReference<std::string>(privData->nativeObj->createEntityReference(*localName)); + v8::Handle<v8::Function> retCtor = V8EntityReference::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8EntityReference::V8EntityReferencePrivate* retPrivData = new V8EntityReference::V8EntityReferencePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localTagname(args[0]); + retObj.MakeWeak(0, V8EntityReference::jsDestructor); + return retObj; - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(*localTagname)); - v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localTagname(args[0]); - retObj.MakeWeak(0, V8NodeList::jsDestructor); - return retObj; + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(*localTagname)); + v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localImportedNode = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - bool localDeep = args[1]->ToBoolean()->BooleanValue(); + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->importNode(*localImportedNode, localDeep)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + Arabica::DOM::Node<std::string>* localImportedNode = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + bool localDeep = args[1]->ToBoolean()->BooleanValue(); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->importNode(*localImportedNode, localDeep)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElementNS(*localNamespaceURI, *localQualifiedName)); - v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElementNS(*localNamespaceURI, *localQualifiedName)); + v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttributeNS(*localNamespaceURI, *localQualifiedName)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttributeNS(*localNamespaceURI, *localQualifiedName)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); - v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(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<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); + v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localElementId(args[0]); + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; - Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->getElementById(*localElementId)); - v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localElementId(args[0]); - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->getElementById(*localElementId)); + v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - } + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - bool V8Document::hasInstance(v8::Handle<v8::Value> value) { - return getTmpl()->HasInstance(value); - } + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); -} -} + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; + +} + +bool V8Document::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; - - V8_DESTRUCTOR(V8DocumentPrivate); - static bool hasInstance(v8::Handle<v8::Value>); - - static v8::Handle<v8::Value> createElementCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createDocumentFragmentCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createTextNodeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createCommentCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createCDATASectionCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createProcessingInstructionCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createAttributeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createEntityReferenceCallback(const v8::Arguments&); - static v8::Handle<v8::Value> getElementsByTagNameCallback(const v8::Arguments&); - static v8::Handle<v8::Value> importNodeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createElementNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createAttributeNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> getElementsByTagNameNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> getElementByIdCallback(const v8::Arguments&); - static v8::Handle<v8::Value> evaluateCustomCallback(const v8::Arguments&); - - static v8::Handle<v8::Value> doctypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> implementationAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> documentElementAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Document")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("implementation"), V8Document::implementationAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("documentElement"), V8Document::documentElementAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - prototype->Set(v8::String::NewSymbol("createElement"), - v8::FunctionTemplate::New(V8Document::createElementCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createDocumentFragment"), - v8::FunctionTemplate::New(V8Document::createDocumentFragmentCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createTextNode"), - v8::FunctionTemplate::New(V8Document::createTextNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createComment"), - v8::FunctionTemplate::New(V8Document::createCommentCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createCDATASection"), - v8::FunctionTemplate::New(V8Document::createCDATASectionCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createProcessingInstruction"), - v8::FunctionTemplate::New(V8Document::createProcessingInstructionCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createAttribute"), - v8::FunctionTemplate::New(V8Document::createAttributeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createEntityReference"), - v8::FunctionTemplate::New(V8Document::createEntityReferenceCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagName"), - v8::FunctionTemplate::New(V8Document::getElementsByTagNameCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("importNode"), - v8::FunctionTemplate::New(V8Document::importNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createElementNS"), - v8::FunctionTemplate::New(V8Document::createElementNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createAttributeNS"), - v8::FunctionTemplate::New(V8Document::createAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), - v8::FunctionTemplate::New(V8Document::getElementsByTagNameNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementById"), - v8::FunctionTemplate::New(V8Document::getElementByIdCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("evaluate"), - v8::FunctionTemplate::New(V8Document::evaluateCustomCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8DocumentPrivate { + V8DOM* dom; + Arabica::DOM::Document<std::string>* nativeObj; + }; + + V8_DESTRUCTOR(V8DocumentPrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + static v8::Handle<v8::Value> createElementCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createDocumentFragmentCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createTextNodeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createCommentCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createCDATASectionCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createProcessingInstructionCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createAttributeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createEntityReferenceCallback(const v8::Arguments&); + static v8::Handle<v8::Value> getElementsByTagNameCallback(const v8::Arguments&); + static v8::Handle<v8::Value> importNodeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createElementNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createAttributeNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> getElementsByTagNameNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> getElementByIdCallback(const v8::Arguments&); + static v8::Handle<v8::Value> evaluateCustomCallback(const v8::Arguments&); + + static v8::Handle<v8::Value> doctypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> implementationAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> documentElementAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Document")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("implementation"), V8Document::implementationAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("documentElement"), V8Document::documentElementAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + prototype->Set(v8::String::NewSymbol("createElement"), + v8::FunctionTemplate::New(V8Document::createElementCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createDocumentFragment"), + v8::FunctionTemplate::New(V8Document::createDocumentFragmentCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createTextNode"), + v8::FunctionTemplate::New(V8Document::createTextNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createComment"), + v8::FunctionTemplate::New(V8Document::createCommentCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createCDATASection"), + v8::FunctionTemplate::New(V8Document::createCDATASectionCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createProcessingInstruction"), + v8::FunctionTemplate::New(V8Document::createProcessingInstructionCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createAttribute"), + v8::FunctionTemplate::New(V8Document::createAttributeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createEntityReference"), + v8::FunctionTemplate::New(V8Document::createEntityReferenceCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagName"), + v8::FunctionTemplate::New(V8Document::getElementsByTagNameCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("importNode"), + v8::FunctionTemplate::New(V8Document::importNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createElementNS"), + v8::FunctionTemplate::New(V8Document::createElementNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createAttributeNS"), + v8::FunctionTemplate::New(V8Document::createAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), + v8::FunctionTemplate::New(V8Document::getElementsByTagNameNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementById"), + v8::FunctionTemplate::New(V8Document::getElementByIdCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("evaluate"), + v8::FunctionTemplate::New(V8Document::evaluateCustomCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8DocumentFragment::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8DocumentFragment::Tmpl; - bool V8DocumentFragment::hasInstance(v8::Handle<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8DocumentFragment::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; + struct V8DocumentFragmentPrivate { + V8DOM* dom; + Arabica::DOM::DocumentFragment<std::string>* nativeObj; + }; - V8_DESTRUCTOR(V8DocumentFragmentPrivate); - static bool hasInstance(v8::Handle<v8::Value>); + V8_DESTRUCTOR(V8DocumentFragmentPrivate); + static bool hasInstance(v8::Handle<v8::Value>); - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("DocumentFragment")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("DocumentFragment")); + tmpl->ReadOnlyPrototype(); - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + instance->SetInternalFieldCount(1); - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8DocumentType::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8DocumentType::Tmpl; - v8::Handle<v8::Value> V8DocumentType::nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8DocumentType::nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getName().c_str()); - } + return v8::String::New(privData->nativeObj->getName().c_str()); +} - v8::Handle<v8::Value> V8DocumentType::entitiesAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8DocumentType::entitiesAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); - - Arabica::DOM::NamedNodeMap<std::string>* arbaicaRet = new Arabica::DOM::NamedNodeMap<std::string>(privData->nativeObj->getEntities()); - v8::Handle<v8::Function> arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); + Arabica::DOM::NamedNodeMap<std::string>* arbaicaRet = new Arabica::DOM::NamedNodeMap<std::string>(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<v8::Function> arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); - } + struct V8NamedNodeMap::V8NamedNodeMapPrivate* retPrivData = new V8NamedNodeMap::V8NamedNodeMapPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - v8::Handle<v8::Value> V8DocumentType::notationsAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8NamedNodeMap::jsDestructor); + return arbaicaRetObj; - - Arabica::DOM::NamedNodeMap<std::string>* arbaicaRet = new Arabica::DOM::NamedNodeMap<std::string>(privData->nativeObj->getNotations()); +} - v8::Handle<v8::Function> arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); +v8::Handle<v8::Value> V8DocumentType::notationsAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(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<std::string>* arbaicaRet = new Arabica::DOM::NamedNodeMap<std::string>(privData->nativeObj->getNotations()); - v8::Handle<v8::Value> V8DocumentType::publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); + v8::Handle<v8::Function> arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<v8::Value> V8DocumentType::systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(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<v8::Value> V8DocumentType::internalSubsetAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8DocumentType::publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getInternalSubset().c_str()); - } - bool V8DocumentType::hasInstance(v8::Handle<v8::Value> value) { - return getTmpl()->HasInstance(value); - } + return v8::String::New(privData->nativeObj->getPublicId().c_str()); +} -} -} +v8::Handle<v8::Value> V8DocumentType::systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); + + return v8::String::New(privData->nativeObj->getSystemId().c_str()); +} + +v8::Handle<v8::Value> V8DocumentType::internalSubsetAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); + + return v8::String::New(privData->nativeObj->getInternalSubset().c_str()); +} +bool V8DocumentType::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; - - V8_DESTRUCTOR(V8DocumentTypePrivate); - static bool hasInstance(v8::Handle<v8::Value>); - - - static v8::Handle<v8::Value> nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> entitiesAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> notationsAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> internalSubsetAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("DocumentType")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("entities"), V8DocumentType::entitiesAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("notations"), V8DocumentType::notationsAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("publicId"), V8DocumentType::publicIdAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("systemId"), V8DocumentType::systemIdAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("internalSubset"), V8DocumentType::internalSubsetAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8DocumentTypePrivate { + V8DOM* dom; + Arabica::DOM::DocumentType<std::string>* nativeObj; + }; + + V8_DESTRUCTOR(V8DocumentTypePrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + + static v8::Handle<v8::Value> nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> entitiesAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> notationsAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> internalSubsetAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("DocumentType")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("entities"), V8DocumentType::entitiesAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("notations"), V8DocumentType::notationsAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("publicId"), V8DocumentType::publicIdAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("systemId"), V8DocumentType::systemIdAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("internalSubset"), V8DocumentType::internalSubsetAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8Element::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Element::Tmpl; - v8::Handle<v8::Value> V8Element::tagNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Element::tagNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getTagName().c_str()); - } - v8::Handle<v8::Value> 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<v8::Value> V8Element::getAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getAttribute"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(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<v8::Value> V8Element::setAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in setAttribute"); +v8::Handle<v8::Value> V8Element::setAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in setAttribute"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); - v8::String::AsciiValue localValue(args[1]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(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<v8::Value> V8Element::removeAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeAttribute"); +v8::Handle<v8::Value> V8Element::removeAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeAttribute"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(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<v8::Value> V8Element::getAttributeNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getAttributeNode"); +v8::Handle<v8::Value> V8Element::getAttributeNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getAttributeNode"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNode(*localName)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNode(*localName)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> 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<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - Arabica::DOM::Attr<std::string>* localNewAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); + Arabica::DOM::Attr<std::string>* localNewAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNode(*localNewAttr)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNode(*localNewAttr)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> 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<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - Arabica::DOM::Attr<std::string>* localOldAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); + Arabica::DOM::Attr<std::string>* localOldAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->removeAttributeNode(*localOldAttr)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->removeAttributeNode(*localOldAttr)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8Element::getElementsByTagNameCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getElementsByTagName"); +v8::Handle<v8::Value> V8Element::getElementsByTagNameCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getElementsByTagName"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(*localName)); - v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(*localName)); + v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8Element::getAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getAttributeNS"); +v8::Handle<v8::Value> V8Element::getAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getAttributeNS"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(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<v8::Value> V8Element::setAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in setAttributeNS"); +v8::Handle<v8::Value> V8Element::setAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in setAttributeNS"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); - v8::String::AsciiValue localValue(args[2]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(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<v8::Value> V8Element::removeAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in removeAttributeNS"); +v8::Handle<v8::Value> V8Element::removeAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in removeAttributeNS"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(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<v8::Value> V8Element::getAttributeNodeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getAttributeNodeNS"); +v8::Handle<v8::Value> V8Element::getAttributeNodeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getAttributeNodeNS"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNodeNS(*localNamespaceURI, *localLocalName)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNodeNS(*localNamespaceURI, *localLocalName)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> 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<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - Arabica::DOM::Attr<std::string>* localNewAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); + Arabica::DOM::Attr<std::string>* localNewAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNodeNS(*localNewAttr)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNodeNS(*localNewAttr)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8Element::getElementsByTagNameNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getElementsByTagNameNS"); +v8::Handle<v8::Value> V8Element::getElementsByTagNameNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getElementsByTagNameNS"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); - v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); + v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8Element::hasAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in hasAttribute"); +v8::Handle<v8::Value> V8Element::hasAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in hasAttribute"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(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<v8::Value> V8Element::hasAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in hasAttributeNS"); +v8::Handle<v8::Value> V8Element::hasAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in hasAttributeNS"); - v8::Local<v8::Object> self = args.Holder(); - struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local<v8::Object> self = args.Holder(); + struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(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<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8Element::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; - - V8_DESTRUCTOR(V8ElementPrivate); - static bool hasInstance(v8::Handle<v8::Value>); - - static v8::Handle<v8::Value> getAttributeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> setAttributeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> removeAttributeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> getAttributeNodeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> setAttributeNodeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> removeAttributeNodeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> getElementsByTagNameCallback(const v8::Arguments&); - static v8::Handle<v8::Value> getAttributeNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> setAttributeNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> removeAttributeNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> getAttributeNodeNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> setAttributeNodeNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> getElementsByTagNameNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> hasAttributeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> hasAttributeNSCallback(const v8::Arguments&); - - static v8::Handle<v8::Value> tagNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Element")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - prototype->Set(v8::String::NewSymbol("getAttribute"), - v8::FunctionTemplate::New(V8Element::getAttributeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttribute"), - v8::FunctionTemplate::New(V8Element::setAttributeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeAttribute"), - v8::FunctionTemplate::New(V8Element::removeAttributeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getAttributeNode"), - v8::FunctionTemplate::New(V8Element::getAttributeNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttributeNode"), - v8::FunctionTemplate::New(V8Element::setAttributeNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeAttributeNode"), - v8::FunctionTemplate::New(V8Element::removeAttributeNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagName"), - v8::FunctionTemplate::New(V8Element::getElementsByTagNameCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getAttributeNS"), - v8::FunctionTemplate::New(V8Element::getAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttributeNS"), - v8::FunctionTemplate::New(V8Element::setAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeAttributeNS"), - v8::FunctionTemplate::New(V8Element::removeAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getAttributeNodeNS"), - v8::FunctionTemplate::New(V8Element::getAttributeNodeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttributeNodeNS"), - v8::FunctionTemplate::New(V8Element::setAttributeNodeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), - v8::FunctionTemplate::New(V8Element::getElementsByTagNameNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasAttribute"), - v8::FunctionTemplate::New(V8Element::hasAttributeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasAttributeNS"), - v8::FunctionTemplate::New(V8Element::hasAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8ElementPrivate { + V8DOM* dom; + Arabica::DOM::Element<std::string>* nativeObj; + }; + + V8_DESTRUCTOR(V8ElementPrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + static v8::Handle<v8::Value> getAttributeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> setAttributeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> removeAttributeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> getAttributeNodeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> setAttributeNodeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> removeAttributeNodeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> getElementsByTagNameCallback(const v8::Arguments&); + static v8::Handle<v8::Value> getAttributeNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> setAttributeNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> removeAttributeNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> getAttributeNodeNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> setAttributeNodeNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> getElementsByTagNameNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> hasAttributeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> hasAttributeNSCallback(const v8::Arguments&); + + static v8::Handle<v8::Value> tagNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Element")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + prototype->Set(v8::String::NewSymbol("getAttribute"), + v8::FunctionTemplate::New(V8Element::getAttributeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttribute"), + v8::FunctionTemplate::New(V8Element::setAttributeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttribute"), + v8::FunctionTemplate::New(V8Element::removeAttributeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNode"), + v8::FunctionTemplate::New(V8Element::getAttributeNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNode"), + v8::FunctionTemplate::New(V8Element::setAttributeNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttributeNode"), + v8::FunctionTemplate::New(V8Element::removeAttributeNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagName"), + v8::FunctionTemplate::New(V8Element::getElementsByTagNameCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNS"), + v8::FunctionTemplate::New(V8Element::getAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNS"), + v8::FunctionTemplate::New(V8Element::setAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttributeNS"), + v8::FunctionTemplate::New(V8Element::removeAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNodeNS"), + v8::FunctionTemplate::New(V8Element::getAttributeNodeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNodeNS"), + v8::FunctionTemplate::New(V8Element::setAttributeNodeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), + v8::FunctionTemplate::New(V8Element::getElementsByTagNameNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttribute"), + v8::FunctionTemplate::New(V8Element::hasAttributeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttributeNS"), + v8::FunctionTemplate::New(V8Element::hasAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8Entity::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Entity::Tmpl; - v8::Handle<v8::Value> V8Entity::publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8EntityPrivate* privData = V8DOM::toClassPtr<V8EntityPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Entity::publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8EntityPrivate* privData = V8DOM::toClassPtr<V8EntityPrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getPublicId().c_str()); - } + return v8::String::New(privData->nativeObj->getPublicId().c_str()); +} - v8::Handle<v8::Value> V8Entity::systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8EntityPrivate* privData = V8DOM::toClassPtr<V8EntityPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Entity::systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8EntityPrivate* privData = V8DOM::toClassPtr<V8EntityPrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getSystemId().c_str()); - } + return v8::String::New(privData->nativeObj->getSystemId().c_str()); +} - v8::Handle<v8::Value> V8Entity::notationNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8EntityPrivate* privData = V8DOM::toClassPtr<V8EntityPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Entity::notationNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8EntityPrivate* privData = V8DOM::toClassPtr<V8EntityPrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getNotationName().c_str()); - } - bool V8Entity::hasInstance(v8::Handle<v8::Value> value) { - return getTmpl()->HasInstance(value); - } + return v8::String::New(privData->nativeObj->getNotationName().c_str()); +} +bool V8Entity::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; - - V8_DESTRUCTOR(V8EntityPrivate); - static bool hasInstance(v8::Handle<v8::Value>); - - - static v8::Handle<v8::Value> publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> notationNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Entity")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("systemId"), V8Entity::systemIdAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("notationName"), V8Entity::notationNameAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8EntityPrivate { + V8DOM* dom; + Arabica::DOM::Entity<std::string>* nativeObj; + }; + + V8_DESTRUCTOR(V8EntityPrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + + static v8::Handle<v8::Value> publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> notationNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Entity")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("systemId"), V8Entity::systemIdAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("notationName"), V8Entity::notationNameAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8EntityReference::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8EntityReference::Tmpl; - bool V8EntityReference::hasInstance(v8::Handle<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8EntityReference::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; + struct V8EntityReferencePrivate { + V8DOM* dom; + Arabica::DOM::EntityReference<std::string>* nativeObj; + }; - V8_DESTRUCTOR(V8EntityReferencePrivate); - static bool hasInstance(v8::Handle<v8::Value>); + V8_DESTRUCTOR(V8EntityReferencePrivate); + static bool hasInstance(v8::Handle<v8::Value>); - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("EntityReference")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("EntityReference")); + tmpl->ReadOnlyPrototype(); - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + instance->SetInternalFieldCount(1); - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8NamedNodeMap::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8NamedNodeMap::Tmpl; - v8::Handle<v8::Value> V8NamedNodeMap::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8NamedNodeMap::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - return v8::Integer::New(privData->nativeObj->getLength()); - } - v8::Handle<v8::Value> 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<v8::Value> V8NamedNodeMap::getNamedItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getNamedItem"); - v8::Local<v8::Object> self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local<v8::Object> self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItem(*localName)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItem(*localName)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> 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<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localArg = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local<v8::Object> self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); + Arabica::DOM::Node<std::string>* localArg = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItem(*localArg)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItem(*localArg)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8NamedNodeMap::removeNamedItemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeNamedItem"); +v8::Handle<v8::Value> V8NamedNodeMap::removeNamedItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeNamedItem"); - v8::Local<v8::Object> self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + v8::Local<v8::Object> self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItem(*localName)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItem(*localName)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8NamedNodeMap::itemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in item"); +v8::Handle<v8::Value> V8NamedNodeMap::itemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in item"); - v8::Local<v8::Object> self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + v8::Local<v8::Object> self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8NamedNodeMap::getNamedItemNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getNamedItemNS"); +v8::Handle<v8::Value> V8NamedNodeMap::getNamedItemNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getNamedItemNS"); - v8::Local<v8::Object> self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local<v8::Object> self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItemNS(*localNamespaceURI, *localLocalName)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItemNS(*localNamespaceURI, *localLocalName)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> 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<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localArg = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + v8::Local<v8::Object> self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); + Arabica::DOM::Node<std::string>* localArg = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItemNS(*localArg)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItemNS(*localArg)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8NamedNodeMap::removeNamedItemNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in removeNamedItemNS"); +v8::Handle<v8::Value> V8NamedNodeMap::removeNamedItemNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in removeNamedItemNS"); - v8::Local<v8::Object> self = args.Holder(); - struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + v8::Local<v8::Object> self = args.Holder(); + struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItemNS(*localNamespaceURI, *localLocalName)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItemNS(*localNamespaceURI, *localLocalName)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8NamedNodeMap::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; - - V8_DESTRUCTOR(V8NamedNodeMapPrivate); - static bool hasInstance(v8::Handle<v8::Value>); - - static v8::Handle<v8::Value> getNamedItemCallback(const v8::Arguments&); - static v8::Handle<v8::Value> setNamedItemCallback(const v8::Arguments&); - static v8::Handle<v8::Value> removeNamedItemCallback(const v8::Arguments&); - static v8::Handle<v8::Value> itemCallback(const v8::Arguments&); - static v8::Handle<v8::Value> getNamedItemNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> setNamedItemNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> removeNamedItemNSCallback(const v8::Arguments&); - - static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("NamedNodeMap")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - prototype->Set(v8::String::NewSymbol("getNamedItem"), - v8::FunctionTemplate::New(V8NamedNodeMap::getNamedItemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setNamedItem"), - v8::FunctionTemplate::New(V8NamedNodeMap::setNamedItemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeNamedItem"), - v8::FunctionTemplate::New(V8NamedNodeMap::removeNamedItemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("item"), - v8::FunctionTemplate::New(V8NamedNodeMap::itemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getNamedItemNS"), - v8::FunctionTemplate::New(V8NamedNodeMap::getNamedItemNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setNamedItemNS"), - v8::FunctionTemplate::New(V8NamedNodeMap::setNamedItemNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeNamedItemNS"), - v8::FunctionTemplate::New(V8NamedNodeMap::removeNamedItemNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - - - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8NamedNodeMapPrivate { + V8DOM* dom; + Arabica::DOM::NamedNodeMap<std::string>* nativeObj; + }; + + V8_DESTRUCTOR(V8NamedNodeMapPrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + static v8::Handle<v8::Value> getNamedItemCallback(const v8::Arguments&); + static v8::Handle<v8::Value> setNamedItemCallback(const v8::Arguments&); + static v8::Handle<v8::Value> removeNamedItemCallback(const v8::Arguments&); + static v8::Handle<v8::Value> itemCallback(const v8::Arguments&); + static v8::Handle<v8::Value> getNamedItemNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> setNamedItemNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> removeNamedItemNSCallback(const v8::Arguments&); + + static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("NamedNodeMap")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + prototype->Set(v8::String::NewSymbol("getNamedItem"), + v8::FunctionTemplate::New(V8NamedNodeMap::getNamedItemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setNamedItem"), + v8::FunctionTemplate::New(V8NamedNodeMap::setNamedItemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeNamedItem"), + v8::FunctionTemplate::New(V8NamedNodeMap::removeNamedItemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("item"), + v8::FunctionTemplate::New(V8NamedNodeMap::itemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getNamedItemNS"), + v8::FunctionTemplate::New(V8NamedNodeMap::getNamedItemNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setNamedItemNS"), + v8::FunctionTemplate::New(V8NamedNodeMap::setNamedItemNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeNamedItemNS"), + v8::FunctionTemplate::New(V8NamedNodeMap::removeNamedItemNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + + + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8Node::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Node::Tmpl; - v8::Handle<v8::Value> V8Node::nodeNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Node::nodeNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getNodeName().c_str()); - } + return v8::String::New(privData->nativeObj->getNodeName().c_str()); +} - v8::Handle<v8::Value> V8Node::nodeValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Node::nodeValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(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<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNodeValue(value); - privData->nativeObj->setNodeValue(*localNodeValue); - } +void V8Node::nodeValueAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localNodeValue(value); + privData->nativeObj->setNodeValue(*localNodeValue); +} - v8::Handle<v8::Value> V8Node::nodeTypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Node::nodeTypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - return v8::Integer::New(privData->nativeObj->getNodeType()); - } + return v8::Integer::New(privData->nativeObj->getNodeType()); +} - v8::Handle<v8::Value> V8Node::parentNodeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Node::parentNodeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - if (!privData->nativeObj->getParentNode()) return v8::Undefined(); - Arabica::DOM::Node<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->getParentNode()); + if (!privData->nativeObj->getParentNode()) return v8::Undefined(); + Arabica::DOM::Node<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->getParentNode()); - v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); + v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<v8::Value> V8Node::childNodesAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); +} - - Arabica::DOM::NodeList<std::string>* arbaicaRet = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getChildNodes()); +v8::Handle<v8::Value> V8Node::childNodesAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - v8::Handle<v8::Function> arbaicaRetCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<std::string>* arbaicaRet = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getChildNodes()); - } + v8::Handle<v8::Function> arbaicaRetCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); - v8::Handle<v8::Value> V8Node::firstChildAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(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<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->getFirstChild()); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8NodeList::jsDestructor); + return arbaicaRetObj; - v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<v8::Value> V8Node::firstChildAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - } + if (!privData->nativeObj->getFirstChild()) return v8::Undefined(); + Arabica::DOM::Node<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->getFirstChild()); - v8::Handle<v8::Value> V8Node::lastChildAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); - if (!privData->nativeObj->getLastChild()) return v8::Undefined(); - Arabica::DOM::Node<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->getLastChild()); + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<v8::Value> V8Node::previousSiblingAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - - if (!privData->nativeObj->getPreviousSibling()) return v8::Undefined(); - Arabica::DOM::Node<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->getPreviousSibling()); - - v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<v8::Value> V8Node::nextSiblingAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Node::lastChildAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - if (!privData->nativeObj->getNextSibling()) return v8::Undefined(); - Arabica::DOM::Node<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNextSibling()); - - v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->getLastChild()); - } + v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); - v8::Handle<v8::Value> V8Node::ownerDocumentAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(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<std::string>* arbaicaRet = new Arabica::DOM::Document<std::string>(privData->nativeObj->getOwnerDocument()); + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; - v8::Handle<v8::Function> arbaicaRetCtor = V8Document::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<v8::Value> V8Node::previousSiblingAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - } + if (!privData->nativeObj->getPreviousSibling()) return v8::Undefined(); + Arabica::DOM::Node<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->getPreviousSibling()); - v8::Handle<v8::Value> V8Node::namespaceURIAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<v8::Value> V8Node::prefixAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(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<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localPrefix(value); - privData->nativeObj->setPrefix(*localPrefix); - } +v8::Handle<v8::Value> V8Node::nextSiblingAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - v8::Handle<v8::Value> V8Node::localNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + if (!privData->nativeObj->getNextSibling()) return v8::Undefined(); + Arabica::DOM::Node<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNextSibling()); - return v8::String::New(privData->nativeObj->getLocalName().c_str()); - } - v8::Handle<v8::Value> 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<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); - v8::Local<v8::Object> self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* localRefChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[1]->ToObject()->GetInternalField(0))->nativeObj; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->insertBefore(*localNewChild, *localRefChild)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8Node::ownerDocumentAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + if (!privData->nativeObj->getOwnerDocument()) return v8::Undefined(); + Arabica::DOM::Document<std::string>* arbaicaRet = new Arabica::DOM::Document<std::string>(privData->nativeObj->getOwnerDocument()); - } + v8::Handle<v8::Function> arbaicaRetCtor = V8Document::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); - v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* localOldChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[1]->ToObject()->GetInternalField(0))->nativeObj; + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Document::jsDestructor); + return arbaicaRetObj; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->replaceChild(*localNewChild, *localOldChild)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +} - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +v8::Handle<v8::Value> V8Node::namespaceURIAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(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<v8::Value> V8Node::prefixAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - } + return v8::String::New(privData->nativeObj->getPrefix().c_str()); +} - v8::Handle<v8::Value> 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<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localPrefix(value); + privData->nativeObj->setPrefix(*localPrefix); +} - v8::Local<v8::Object> self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localOldChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; +v8::Handle<v8::Value> V8Node::localNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeChild(*localOldChild)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + return v8::String::New(privData->nativeObj->getLocalName().c_str()); +} +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + Arabica::DOM::Node<std::string>* localRefChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[1]->ToObject()->GetInternalField(0))->nativeObj; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->insertBefore(*localNewChild, *localRefChild)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> 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<v8::Object> self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; +} - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->appendChild(*localNewChild)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + Arabica::DOM::Node<std::string>* localOldChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[1]->ToObject()->GetInternalField(0))->nativeObj; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->replaceChild(*localNewChild, *localOldChild)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8Node::hasChildNodesCallback(const v8::Arguments& args) { + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; - v8::Local<v8::Object> self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); +} - bool retVal = privData->nativeObj->hasChildNodes(); +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + Arabica::DOM::Node<std::string>* localOldChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - v8::Handle<v8::Value> V8Node::cloneNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in cloneNode"); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeChild(*localOldChild)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - v8::Local<v8::Object> self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(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<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->cloneNode(localDeep)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - v8::Handle<v8::Value> V8Node::normalizeCallback(const v8::Arguments& args) { + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->appendChild(*localNewChild)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - v8::Local<v8::Object> self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(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<v8::Value> V8Node::isSupportedCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in isSupported"); +} - v8::Local<v8::Object> self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localFeature(args[0]); - v8::String::AsciiValue localVersion(args[1]); +v8::Handle<v8::Value> V8Node::hasChildNodesCallback(const v8::Arguments& args) { - bool retVal = privData->nativeObj->isSupported(*localFeature, *localVersion); + v8::Local<v8::Object> self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - return v8::Boolean::New(retVal); - } + bool retVal = privData->nativeObj->hasChildNodes(); - v8::Handle<v8::Value> V8Node::hasAttributesCallback(const v8::Arguments& args) { + return v8::Boolean::New(retVal); +} - v8::Local<v8::Object> self = args.Holder(); - struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> 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<v8::Object> self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + bool localDeep = args[0]->ToBoolean()->BooleanValue(); - return v8::Boolean::New(retVal); - } + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->cloneNode(localDeep)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - bool V8Node::hasInstance(v8::Handle<v8::Value> 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<v8::Value> V8Node::normalizeCallback(const v8::Arguments& args) { + + v8::Local<v8::Object> self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + + privData->nativeObj->normalize(); + + return v8::Undefined(); +} + +v8::Handle<v8::Value> V8Node::isSupportedCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in isSupported"); + + v8::Local<v8::Object> self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(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<v8::Value> V8Node::hasAttributesCallback(const v8::Arguments& args) { + + v8::Local<v8::Object> self = args.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + + bool retVal = privData->nativeObj->hasAttributes(); + + return v8::Boolean::New(retVal); +} + +bool V8Node::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; - - V8_DESTRUCTOR(V8NodePrivate); - static bool hasInstance(v8::Handle<v8::Value>); - - static v8::Handle<v8::Value> insertBeforeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> replaceChildCallback(const v8::Arguments&); - static v8::Handle<v8::Value> removeChildCallback(const v8::Arguments&); - static v8::Handle<v8::Value> appendChildCallback(const v8::Arguments&); - static v8::Handle<v8::Value> hasChildNodesCallback(const v8::Arguments&); - static v8::Handle<v8::Value> cloneNodeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> normalizeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> isSupportedCallback(const v8::Arguments&); - static v8::Handle<v8::Value> hasAttributesCallback(const v8::Arguments&); - - static v8::Handle<v8::Value> nodeNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> nodeValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static void nodeValueAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> nodeTypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> parentNodeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> childNodesAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> firstChildAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> lastChildAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> previousSiblingAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> nextSiblingAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> attributesCustomAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> ownerDocumentAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> namespaceURIAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> prefixAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static void prefixAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> localNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Node")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("nodeValue"), V8Node::nodeValueAttrGetter, V8Node::nodeValueAttrSetter, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("nodeType"), V8Node::nodeTypeAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("parentNode"), V8Node::parentNodeAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("childNodes"), V8Node::childNodesAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("firstChild"), V8Node::firstChildAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("lastChild"), V8Node::lastChildAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("previousSibling"), V8Node::previousSiblingAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("nextSibling"), V8Node::nextSiblingAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("attributes"), V8Node::attributesCustomAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("ownerDocument"), V8Node::ownerDocumentAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("namespaceURI"), V8Node::namespaceURIAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("prefix"), V8Node::prefixAttrGetter, V8Node::prefixAttrSetter, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("localName"), V8Node::localNameAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - prototype->Set(v8::String::NewSymbol("insertBefore"), - v8::FunctionTemplate::New(V8Node::insertBeforeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("replaceChild"), - v8::FunctionTemplate::New(V8Node::replaceChildCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeChild"), - v8::FunctionTemplate::New(V8Node::removeChildCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("appendChild"), - v8::FunctionTemplate::New(V8Node::appendChildCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasChildNodes"), - v8::FunctionTemplate::New(V8Node::hasChildNodesCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("cloneNode"), - v8::FunctionTemplate::New(V8Node::cloneNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("normalize"), - v8::FunctionTemplate::New(V8Node::normalizeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("isSupported"), - v8::FunctionTemplate::New(V8Node::isSupportedCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasAttributes"), - v8::FunctionTemplate::New(V8Node::hasAttributesCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - - tmpl->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(3), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(3), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(4), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(4), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(5), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(5), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(6), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(6), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(7), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(7), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(8), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(8), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(9), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(9), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(10), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(10), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(11), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(11), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(12), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(12), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8NodePrivate { + V8DOM* dom; + Arabica::DOM::Node<std::string>* nativeObj; + }; + + V8_DESTRUCTOR(V8NodePrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + static v8::Handle<v8::Value> insertBeforeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> replaceChildCallback(const v8::Arguments&); + static v8::Handle<v8::Value> removeChildCallback(const v8::Arguments&); + static v8::Handle<v8::Value> appendChildCallback(const v8::Arguments&); + static v8::Handle<v8::Value> hasChildNodesCallback(const v8::Arguments&); + static v8::Handle<v8::Value> cloneNodeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> normalizeCallback(const v8::Arguments&); + static v8::Handle<v8::Value> isSupportedCallback(const v8::Arguments&); + static v8::Handle<v8::Value> hasAttributesCallback(const v8::Arguments&); + + static v8::Handle<v8::Value> nodeNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> nodeValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static void nodeValueAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> nodeTypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> parentNodeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> childNodesAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> firstChildAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> lastChildAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> previousSiblingAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> nextSiblingAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> attributesCustomAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> ownerDocumentAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> namespaceURIAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> prefixAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static void prefixAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> localNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Node")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nodeValue"), V8Node::nodeValueAttrGetter, V8Node::nodeValueAttrSetter, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nodeType"), V8Node::nodeTypeAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("parentNode"), V8Node::parentNodeAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("childNodes"), V8Node::childNodesAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("firstChild"), V8Node::firstChildAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("lastChild"), V8Node::lastChildAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("previousSibling"), V8Node::previousSiblingAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nextSibling"), V8Node::nextSiblingAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("attributes"), V8Node::attributesCustomAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("ownerDocument"), V8Node::ownerDocumentAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("namespaceURI"), V8Node::namespaceURIAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("prefix"), V8Node::prefixAttrGetter, V8Node::prefixAttrSetter, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("localName"), V8Node::localNameAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + prototype->Set(v8::String::NewSymbol("insertBefore"), + v8::FunctionTemplate::New(V8Node::insertBeforeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("replaceChild"), + v8::FunctionTemplate::New(V8Node::replaceChildCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeChild"), + v8::FunctionTemplate::New(V8Node::removeChildCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("appendChild"), + v8::FunctionTemplate::New(V8Node::appendChildCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasChildNodes"), + v8::FunctionTemplate::New(V8Node::hasChildNodesCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("cloneNode"), + v8::FunctionTemplate::New(V8Node::cloneNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("normalize"), + v8::FunctionTemplate::New(V8Node::normalizeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("isSupported"), + v8::FunctionTemplate::New(V8Node::isSupportedCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttributes"), + v8::FunctionTemplate::New(V8Node::hasAttributesCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + + tmpl->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(3), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(3), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(4), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(4), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(5), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(5), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(6), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(6), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(7), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(7), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(8), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(8), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(9), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(9), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(10), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(10), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(11), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(11), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(12), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(12), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8NodeList::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8NodeList::Tmpl; - v8::Handle<v8::Value> V8NodeList::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodeListPrivate* privData = V8DOM::toClassPtr<V8NodeListPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8NodeList::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodeListPrivate* privData = V8DOM::toClassPtr<V8NodeListPrivate >(self->GetInternalField(0)); - return v8::Integer::New(privData->nativeObj->getLength()); - } - v8::Handle<v8::Value> 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<v8::Value> V8NodeList::itemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in item"); - v8::Local<v8::Object> self = args.Holder(); - struct V8NodeListPrivate* privData = V8DOM::toClassPtr<V8NodeListPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + v8::Local<v8::Object> self = args.Holder(); + struct V8NodeListPrivate* privData = V8DOM::toClassPtr<V8NodeListPrivate >(self->GetInternalField(0)); + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8NodeList::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; + struct V8NodeListPrivate { + V8DOM* dom; + Arabica::DOM::NodeList<std::string>* nativeObj; + }; - V8_DESTRUCTOR(V8NodeListPrivate); - static bool hasInstance(v8::Handle<v8::Value>); + V8_DESTRUCTOR(V8NodeListPrivate); + static bool hasInstance(v8::Handle<v8::Value>); - static v8::Handle<v8::Value> itemCallback(const v8::Arguments&); + static v8::Handle<v8::Value> itemCallback(const v8::Arguments&); - static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("NodeList")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("NodeList")); + tmpl->ReadOnlyPrototype(); - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings - instance->SetAccessor(v8::String::NewSymbol("length"), V8NodeList::lengthAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(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::PropertyAttribute>(v8::DontDelete)); + instance->SetAccessor(v8::String::NewSymbol("length"), V8NodeList::lengthAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8NodeList::indexedPropertyCustomGetter, 0); + prototype->Set(v8::String::NewSymbol("item"), + v8::FunctionTemplate::New(V8NodeList::itemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8NodeSet::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8NodeSet::Tmpl; - v8::Handle<v8::Value> V8NodeSet::sizeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodeSetPrivate* privData = V8DOM::toClassPtr<V8NodeSetPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8NodeSet::sizeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodeSetPrivate* privData = V8DOM::toClassPtr<V8NodeSetPrivate >(self->GetInternalField(0)); - return v8::Integer::New(privData->nativeObj->size()); - } + return v8::Integer::New(privData->nativeObj->size()); +} - v8::Handle<v8::Value> V8NodeSet::emptyAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NodeSetPrivate* privData = V8DOM::toClassPtr<V8NodeSetPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8NodeSet::emptyAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NodeSetPrivate* privData = V8DOM::toClassPtr<V8NodeSetPrivate >(self->GetInternalField(0)); - return v8::Boolean::New(privData->nativeObj->empty()); - } - v8::Handle<v8::Value> V8NodeSet::toDocumentOrderCallback(const v8::Arguments& args) { + return v8::Boolean::New(privData->nativeObj->empty()); +} +v8::Handle<v8::Value> V8NodeSet::toDocumentOrderCallback(const v8::Arguments& args) { - v8::Local<v8::Object> self = args.Holder(); - struct V8NodeSetPrivate* privData = V8DOM::toClassPtr<V8NodeSetPrivate >(self->GetInternalField(0)); + v8::Local<v8::Object> self = args.Holder(); + struct V8NodeSetPrivate* privData = V8DOM::toClassPtr<V8NodeSetPrivate >(self->GetInternalField(0)); - privData->nativeObj->to_document_order(); + privData->nativeObj->to_document_order(); - return v8::Undefined(); - } + return v8::Undefined(); +} - bool V8NodeSet::hasInstance(v8::Handle<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8NodeSet::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; - - V8_DESTRUCTOR(V8NodeSetPrivate); - static bool hasInstance(v8::Handle<v8::Value>); - - static v8::Handle<v8::Value> toDocumentOrderCallback(const v8::Arguments&); - - static v8::Handle<v8::Value> sizeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> emptyAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("NodeSet")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("empty"), V8NodeSet::emptyAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - instance->SetIndexedPropertyHandler(V8NodeSet::indexedPropertyCustomGetter, 0); - prototype->Set(v8::String::NewSymbol("toDocumentOrder"), - v8::FunctionTemplate::New(V8NodeSet::toDocumentOrderCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - - - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8NodeSetPrivate { + V8DOM* dom; + Arabica::XPath::NodeSet<std::string>* nativeObj; + }; + + V8_DESTRUCTOR(V8NodeSetPrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + static v8::Handle<v8::Value> toDocumentOrderCallback(const v8::Arguments&); + + static v8::Handle<v8::Value> sizeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> emptyAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("NodeSet")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("empty"), V8NodeSet::emptyAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + instance->SetIndexedPropertyHandler(V8NodeSet::indexedPropertyCustomGetter, 0); + prototype->Set(v8::String::NewSymbol("toDocumentOrder"), + v8::FunctionTemplate::New(V8NodeSet::toDocumentOrderCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + + + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8Notation::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Notation::Tmpl; - v8::Handle<v8::Value> V8Notation::publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NotationPrivate* privData = V8DOM::toClassPtr<V8NotationPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Notation::publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NotationPrivate* privData = V8DOM::toClassPtr<V8NotationPrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getPublicId().c_str()); - } + return v8::String::New(privData->nativeObj->getPublicId().c_str()); +} - v8::Handle<v8::Value> V8Notation::systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8NotationPrivate* privData = V8DOM::toClassPtr<V8NotationPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8Notation::systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8NotationPrivate* privData = V8DOM::toClassPtr<V8NotationPrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getSystemId().c_str()); - } - bool V8Notation::hasInstance(v8::Handle<v8::Value> value) { - return getTmpl()->HasInstance(value); - } + return v8::String::New(privData->nativeObj->getSystemId().c_str()); +} +bool V8Notation::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; + struct V8NotationPrivate { + V8DOM* dom; + Arabica::DOM::Notation<std::string>* nativeObj; + }; - V8_DESTRUCTOR(V8NotationPrivate); - static bool hasInstance(v8::Handle<v8::Value>); + V8_DESTRUCTOR(V8NotationPrivate); + static bool hasInstance(v8::Handle<v8::Value>); - static v8::Handle<v8::Value> publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> systemIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Notation")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Notation")); + tmpl->ReadOnlyPrototype(); - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings - instance->SetAccessor(v8::String::NewSymbol("publicId"), V8Notation::publicIdAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("systemId"), V8Notation::systemIdAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetInternalFieldCount(1); + instance->SetAccessor(v8::String::NewSymbol("publicId"), V8Notation::publicIdAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("systemId"), V8Notation::systemIdAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8ProcessingInstruction::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8ProcessingInstruction::Tmpl; - v8::Handle<v8::Value> V8ProcessingInstruction::targetAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr<V8ProcessingInstructionPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8ProcessingInstruction::targetAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr<V8ProcessingInstructionPrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->getTarget().c_str()); - } + return v8::String::New(privData->nativeObj->getTarget().c_str()); +} - v8::Handle<v8::Value> V8ProcessingInstruction::dataAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr<V8ProcessingInstructionPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8ProcessingInstruction::dataAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr<V8ProcessingInstructionPrivate >(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<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr<V8ProcessingInstructionPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localData(value); - privData->nativeObj->setData(*localData); - } - bool V8ProcessingInstruction::hasInstance(v8::Handle<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +void V8ProcessingInstruction::dataAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr<V8ProcessingInstructionPrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localData(value); + privData->nativeObj->setData(*localData); +} +bool V8ProcessingInstruction::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; + struct V8ProcessingInstructionPrivate { + V8DOM* dom; + Arabica::DOM::ProcessingInstruction<std::string>* nativeObj; + }; - V8_DESTRUCTOR(V8ProcessingInstructionPrivate); - static bool hasInstance(v8::Handle<v8::Value>); + V8_DESTRUCTOR(V8ProcessingInstructionPrivate); + static bool hasInstance(v8::Handle<v8::Value>); - static v8::Handle<v8::Value> targetAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> dataAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static void dataAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> targetAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> dataAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static void dataAttrSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info); - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("ProcessingInstruction")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("ProcessingInstruction")); + tmpl->ReadOnlyPrototype(); - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings - instance->SetAccessor(v8::String::NewSymbol("target"), V8ProcessingInstruction::targetAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("data"), V8ProcessingInstruction::dataAttrGetter, V8ProcessingInstruction::dataAttrSetter, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetInternalFieldCount(1); + instance->SetAccessor(v8::String::NewSymbol("target"), V8ProcessingInstruction::targetAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("data"), V8ProcessingInstruction::dataAttrGetter, V8ProcessingInstruction::dataAttrSetter, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8SCXMLEvent::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8SCXMLEvent::Tmpl; - v8::Handle<v8::Value> V8SCXMLEvent::nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8SCXMLEvent::nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->name.c_str()); - } + return v8::String::New(privData->nativeObj->name.c_str()); +} - v8::Handle<v8::Value> V8SCXMLEvent::originAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8SCXMLEvent::originAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(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<v8::Value> V8SCXMLEvent::origintypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8SCXMLEvent::origintypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(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<v8::Value> V8SCXMLEvent::rawAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8SCXMLEvent::rawAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(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<v8::Value> V8SCXMLEvent::domAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8SCXMLEvent::domAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(self->GetInternalField(0)); - if (!privData->nativeObj->dom) return v8::Undefined(); - Arabica::DOM::Node<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->dom); + if (!privData->nativeObj->dom) return v8::Undefined(); + Arabica::DOM::Node<std::string>* arbaicaRet = new Arabica::DOM::Node<std::string>(privData->nativeObj->dom); - v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::New(arbaicaRetCtor->NewInstance()); + v8::Handle<v8::Function> arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> arbaicaRetObj = v8::Persistent<v8::Object>::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<v8::Value> V8SCXMLEvent::invokeidAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(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<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +v8::Handle<v8::Value> V8SCXMLEvent::invokeidAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(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<v8::Value> 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<v8::Value>); - - - static v8::Handle<v8::Value> typeCustomAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> originAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> origintypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> rawAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> domAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> sendidCustomAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> invokeidAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("SCXMLEvent")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("name"), V8SCXMLEvent::nameAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("origin"), V8SCXMLEvent::originAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("origintype"), V8SCXMLEvent::origintypeAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("raw"), V8SCXMLEvent::rawAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("dom"), V8SCXMLEvent::domAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("sendid"), V8SCXMLEvent::sendidCustomAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("invokeid"), V8SCXMLEvent::invokeidAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - - tmpl->Set(v8::String::NewSymbol("INTERNAL"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("INTERNAL"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("EXTERNAL"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("EXTERNAL"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - tmpl->Set(v8::String::NewSymbol("PLATFORM"), v8::Integer::New(3), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - prototype->Set(v8::String::NewSymbol("PLATFORM"), v8::Integer::New(3), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); - - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8SCXMLEventPrivate { + V8DOM* dom; + uscxml::Event* nativeObj; + }; + + V8_DESTRUCTOR(V8SCXMLEventPrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + + static v8::Handle<v8::Value> typeCustomAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> originAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> origintypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> rawAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> domAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> sendidCustomAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> invokeidAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("SCXMLEvent")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("name"), V8SCXMLEvent::nameAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("origin"), V8SCXMLEvent::originAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("origintype"), V8SCXMLEvent::origintypeAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("raw"), V8SCXMLEvent::rawAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("dom"), V8SCXMLEvent::domAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("sendid"), V8SCXMLEvent::sendidCustomAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("invokeid"), V8SCXMLEvent::invokeidAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + + tmpl->Set(v8::String::NewSymbol("INTERNAL"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("INTERNAL"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("EXTERNAL"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("EXTERNAL"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Set(v8::String::NewSymbol("PLATFORM"), v8::Integer::New(3), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + prototype->Set(v8::String::NewSymbol("PLATFORM"), v8::Integer::New(3), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8Text::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Text::Tmpl; - v8::Handle<v8::Value> V8Text::splitTextCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in splitText"); +v8::Handle<v8::Value> V8Text::splitTextCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in splitText"); - v8::Local<v8::Object> self = args.Holder(); - struct V8TextPrivate* privData = V8DOM::toClassPtr<V8TextPrivate >(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + v8::Local<v8::Object> self = args.Holder(); + struct V8TextPrivate* privData = V8DOM::toClassPtr<V8TextPrivate >(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->splitText(localOffset)); - v8::Handle<v8::Function> retCtor = V8Text::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->splitText(localOffset)); + v8::Handle<v8::Function> retCtor = V8Text::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8Text::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; + struct V8TextPrivate { + V8DOM* dom; + Arabica::DOM::Text<std::string>* nativeObj; + }; - V8_DESTRUCTOR(V8TextPrivate); - static bool hasInstance(v8::Handle<v8::Value>); + V8_DESTRUCTOR(V8TextPrivate); + static bool hasInstance(v8::Handle<v8::Value>); - static v8::Handle<v8::Value> splitTextCallback(const v8::Arguments&); + static v8::Handle<v8::Value> splitTextCallback(const v8::Arguments&); - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Text")); - tmpl->ReadOnlyPrototype(); + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Text")); + tmpl->ReadOnlyPrototype(); - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); - (void)prototype; // surpress unused warnings - - instance->SetInternalFieldCount(1); + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("splitText"), + v8::FunctionTemplate::New(V8Text::splitTextCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - tmpl->Inherit(V8CharacterData::getTmpl()); - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + + tmpl->Inherit(V8CharacterData::getTmpl()); + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<v8::FunctionTemplate> V8XPathResult::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8XPathResult::Tmpl; - v8::Handle<v8::Value> V8XPathResult::numberValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8XPathResult::numberValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); - return v8::Number::New(privData->nativeObj->asNumber()); - } + return v8::Number::New(privData->nativeObj->asNumber()); +} - v8::Handle<v8::Value> V8XPathResult::stringValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8XPathResult::stringValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); - return v8::String::New(privData->nativeObj->asString().c_str()); - } + return v8::String::New(privData->nativeObj->asString().c_str()); +} - v8::Handle<v8::Value> V8XPathResult::booleanValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { - v8::Local<v8::Object> self = info.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); +v8::Handle<v8::Value> V8XPathResult::booleanValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); - return v8::Boolean::New(privData->nativeObj->asBool()); - } - v8::Handle<v8::Value> V8XPathResult::asNodeSetCallback(const v8::Arguments& args) { + return v8::Boolean::New(privData->nativeObj->asBool()); +} +v8::Handle<v8::Value> V8XPathResult::asNodeSetCallback(const v8::Arguments& args) { - v8::Local<v8::Object> self = args.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + v8::Local<v8::Object> self = args.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); - Arabica::XPath::NodeSet<std::string>* retVal = new Arabica::XPath::NodeSet<std::string>(privData->nativeObj->asNodeSet()); - v8::Handle<v8::Function> retCtor = V8NodeSet::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::XPath::NodeSet<std::string>* retVal = new Arabica::XPath::NodeSet<std::string>(privData->nativeObj->asNodeSet()); + v8::Handle<v8::Function> retCtor = V8NodeSet::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8XPathResult::asBoolCallback(const v8::Arguments& args) { +v8::Handle<v8::Value> V8XPathResult::asBoolCallback(const v8::Arguments& args) { - v8::Local<v8::Object> self = args.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + v8::Local<v8::Object> self = args.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(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<v8::Value> V8XPathResult::asStringCallback(const v8::Arguments& args) { +v8::Handle<v8::Value> V8XPathResult::asStringCallback(const v8::Arguments& args) { - v8::Local<v8::Object> self = args.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + v8::Local<v8::Object> self = args.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(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<v8::Value> V8XPathResult::asNumberCallback(const v8::Arguments& args) { +v8::Handle<v8::Value> V8XPathResult::asNumberCallback(const v8::Arguments& args) { - v8::Local<v8::Object> self = args.Holder(); - struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + v8::Local<v8::Object> self = args.Holder(); + struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(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<v8::Value> value) { - return getTmpl()->HasInstance(value); - } +bool V8XPathResult::hasInstance(v8::Handle<v8::Value> 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<std::string>* nativeObj; - }; - - V8_DESTRUCTOR(V8XPathResultPrivate); - static bool hasInstance(v8::Handle<v8::Value>); - - static v8::Handle<v8::Value> asNodeSetCallback(const v8::Arguments&); - static v8::Handle<v8::Value> asBoolCallback(const v8::Arguments&); - static v8::Handle<v8::Value> asStringCallback(const v8::Arguments&); - static v8::Handle<v8::Value> asNumberCallback(const v8::Arguments&); - - static v8::Handle<v8::Value> numberValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> stringValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> booleanValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - static v8::Handle<v8::Value> singleNodeValueCustomAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); - - static v8::Persistent<v8::FunctionTemplate> Tmpl; - static v8::Handle<v8::FunctionTemplate> getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("XPathResult")); - tmpl->ReadOnlyPrototype(); - - v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); - v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("stringValue"), V8XPathResult::stringValueAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("booleanValue"), V8XPathResult::booleanValueAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("singleNodeValue"), V8XPathResult::singleNodeValueCustomAttrGetter, 0, - v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); - - prototype->Set(v8::String::NewSymbol("asNodeSet"), - v8::FunctionTemplate::New(V8XPathResult::asNodeSetCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("asBool"), - v8::FunctionTemplate::New(V8XPathResult::asBoolCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("asString"), - v8::FunctionTemplate::New(V8XPathResult::asStringCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("asNumber"), - v8::FunctionTemplate::New(V8XPathResult::asNumberCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - - - Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); - } - return Tmpl; - } + struct V8XPathResultPrivate { + V8DOM* dom; + Arabica::XPath::XPathValue<std::string>* nativeObj; + }; + + V8_DESTRUCTOR(V8XPathResultPrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + static v8::Handle<v8::Value> asNodeSetCallback(const v8::Arguments&); + static v8::Handle<v8::Value> asBoolCallback(const v8::Arguments&); + static v8::Handle<v8::Value> asStringCallback(const v8::Arguments&); + static v8::Handle<v8::Value> asNumberCallback(const v8::Arguments&); + + static v8::Handle<v8::Value> numberValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> stringValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> booleanValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> singleNodeValueCustomAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("XPathResult")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> 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::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("stringValue"), V8XPathResult::stringValueAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("booleanValue"), V8XPathResult::booleanValueAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("singleNodeValue"), V8XPathResult::singleNodeValueCustomAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + prototype->Set(v8::String::NewSymbol("asNodeSet"), + v8::FunctionTemplate::New(V8XPathResult::asNodeSetCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asBool"), + v8::FunctionTemplate::New(V8XPathResult::asBoolCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asString"), + v8::FunctionTemplate::New(V8XPathResult::asStringCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asNumber"), + v8::FunctionTemplate::New(V8XPathResult::asNumberCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + + + Tmpl = v8::Persistent<v8::FunctionTemplate>::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<DataModelImpl> SWIDataModel::create(InterpreterImpl* interpreter) { boost::shared_ptr<SWIDataModel> dm = boost::shared_ptr<SWIDataModel>(new SWIDataModel()); dm->_interpreter = interpreter; @@ -50,7 +50,7 @@ boost::shared_ptr<DataModelImpl> 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<std::string, PlTerm> vars = resolveAtoms(compound, orig); std::map<std::string, PlTerm>::iterator varIter = vars.begin(); while(varIter != vars.end()) { @@ -307,28 +307,28 @@ std::string SWIDataModel::evalAsString(const std::string& expr) { std::map<std::string, PlTerm> SWIDataModel::resolveAtoms(PlTerm& term, PlTerm& orig) { std::map<std::string, PlTerm> 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<std::string, PlTerm> 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<std::string, PlTerm> result = resolveAtoms(newTerm, newOrig); - atoms.insert(result.begin(), result.end()); - } - break; + break; } return atoms; } - + void SWIDataModel::assign(const Arabica::DOM::Element<std::string>& assignElem, const Arabica::DOM::Document<std::string>& doc, const std::string& content) { @@ -353,7 +353,7 @@ void SWIDataModel::assign(const Arabica::DOM::Element<std::string>& 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<std::string, PlTerm> 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<std::string>& node) { - } - void StartRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void PauseRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void ResumeRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void CancelRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void ClearContextRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void StatusRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void NewContextResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void PrepareResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void StartResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void PauseResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void ResumeResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void CancelResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void ClearContextResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void StatusResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void DoneNotificationElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void NewContextRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } - void ExtensionNotificationElement::enterElement(const Arabica::DOM::Node<std::string>& node) { - } + +void PrepareRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void StartRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void PauseRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void ResumeRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void CancelRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void ClearContextRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void StatusRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void NewContextResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void PrepareResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void StartResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void PauseResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void ResumeResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void CancelResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void ClearContextResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void StatusResponseElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void DoneNotificationElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void NewContextRequestElement::enterElement(const Arabica::DOM::Node<std::string>& node) { +} +void ExtensionNotificationElement::enterElement(const Arabica::DOM::Node<std::string>& 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<tthread::recursive_mutex> 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<InvokerImpl> 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 <uscxml/config.h> +#include "XHTMLInvoker.h" +#include <glog/logging.h> +#include <uscxml/plugins/ioprocessor/comet/CometIOProcessor.h> + +#ifdef BUILD_AS_PLUGINS +#include <Pluma/Connector.hpp> +#endif + +#if defined(__APPLE__) and defined(TARGET_OS_MAC) +#include <CoreFoundation/CFBundle.h> +#include <ApplicationServices/ApplicationServices.h> +#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<InvokerImpl> XHTMLInvoker::create(InterpreterImpl* interpreter) { + boost::shared_ptr<XHTMLInvoker> invoker = boost::shared_ptr<XHTMLInvoker>(new XHTMLInvoker()); + invoker->_interpreter = interpreter; +// _ioProc = interpreter->getFactory()->createIOProcessor("comet", interpreter); + return invoker; +} + +bool XHTMLInvoker::httpRecvRequest(const HTTPServer::Request& req) { + tthread::lock_guard<tthread::recursive_mutex> 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>(); + 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<tthread::recursive_mutex> 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<std::string> 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 <uscxml/Interpreter.h> + +#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<InvokerImpl> create(InterpreterImpl* interpreter); + + virtual std::set<std::string> getNames() { + std::set<std::string> 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<SendRequest> _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 <uscxml/Common.h> +#include "uscxml/plugins/ioprocessor/comet/CometIOProcessor.h" +#include "uscxml/Message.h" +#include <iostream> + +#include <string.h> + +#ifdef BUILD_AS_PLUGINS +#include <Pluma/Connector.hpp> +#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<IOProcessorImpl> CometIOProcessor::create(InterpreterImpl* interpreter) { + boost::shared_ptr<CometIOProcessor> io = boost::shared_ptr<CometIOProcessor>(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<tthread::recursive_mutex> 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<tthread::recursive_mutex> 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<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter); + + virtual std::set<std::string> getNames() { + std::set<std::string> 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<SendRequest> _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<IOProcessorImpl> 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<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter); - - virtual std::set<std::string> getNames() { - std::set<std::string> 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<std::string, std::pair<URL, SendRequest> > _sendRequests; - }; - - #ifdef BUILD_AS_PLUGINS - PLUMA_INHERIT_PROVIDER(MMIHTTPIOProcessor, IOProcessorImpl); - #endif + +class MMIHTTPIOProcessor : public BasicHTTPIOProcessor { +public: + MMIHTTPIOProcessor(); + virtual ~MMIHTTPIOProcessor(); + virtual boost::shared_ptr<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter); + + virtual std::set<std::string> getNames() { + std::set<std::string> 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<std::string, std::pair<URL, SendRequest> > _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<std::string> 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<std::string> 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<std::string> MMIEvent::getEventNode(Arabica::DOM::Node<std::string> node) { + if (!node) + return node; + + if (node.getNodeType() == Node_base::DOCUMENT_NODE) + node = Arabica::DOM::Document<std::string>(node).getDocumentElement(); + + // get the first element + while (node && node.getNodeType() != Node_base::ELEMENT_NODE) { + node = node.getNextSibling(); } - - Arabica::DOM::Node<std::string> MMIEvent::getEventNode(Arabica::DOM::Node<std::string> node) { - if (node.getNodeType() == Node_base::DOCUMENT_NODE) - node = Arabica::DOM::Document<std::string>(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<std::string> MMIEvent::toXML() const { Arabica::DOM::DOMImplementation<std::string> domFactory = Arabica::SimpleDOM::DOMImplementation<std::string>::getDOMImplementation(); Document<std::string> doc = domFactory.createDocument(nameSpace, "", 0); @@ -255,7 +258,7 @@ MMIEvent::operator Event() const { } return ev; } - + ContextualizedRequest ContextualizedRequest::fromXML(Arabica::DOM::Node<std::string> 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<std::string> node, InterpreterImpl* interpreter) { ContentRequest msg(ContextualizedRequest::fromXML(node, interpreter)); while (node) { @@ -424,5 +427,5 @@ StatusRequest StatusRequest::fromXML(Arabica::DOM::Node<std::string> 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<std::string> node); static Arabica::DOM::Node<std::string> getEventNode(Arabica::DOM::Node<std::string> node); - + virtual Arabica::DOM::Document<std::string> toXML() const; static MMIEvent fromXML(Arabica::DOM::Node<std::string> 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<std::string> 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<std::string> toXML() const; static ContextualizedRequest fromXML(Arabica::DOM::Node<std::string> 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<std::string> 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<std::string> 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<std::string> 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<std::string> 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<std::string> toXML() const; static StatusRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL); + InterpreterImpl* interpreter = NULL); operator Event() const; bool automaticUpdate; protected: @@ -207,7 +207,7 @@ public: virtual Arabica::DOM::Document<std::string> toXML() const; static ContentRequest fromXML(Arabica::DOM::Node<std::string> 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<std::string> 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<std::string> 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<std::string> toXML() const; static ExtensionNotification fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL); + InterpreterImpl* interpreter = NULL); operator Event() const; std::string name; protected: @@ -290,7 +290,7 @@ public: } virtual Arabica::DOM::Document<std::string> toXML() const; static StatusResponse fromXML(Arabica::DOM::Node<std::string> 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<std::string> toXML() const; StatusInfoResponse(const StatusResponse& father) : StatusResponse(father) {} static StatusInfoResponse fromXML(Arabica::DOM::Node<std::string> 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<std::string> 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<std::string> 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<std::string> 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<std::string> 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<std::string> 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<std::string> 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<std::string> 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<std::string> 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 <uscxml/Common.h> +#include "uscxml/plugins/ioprocessor/sample/SampleIOProcessor.h" +#include "uscxml/Message.h" +#include <iostream> + +#include <string.h> + +#ifdef BUILD_AS_PLUGINS +#include <Pluma/Connector.hpp> +#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<IOProcessorImpl> SampleIOProcessor::create(InterpreterImpl* interpreter) { + boost::shared_ptr<SampleIOProcessor> io = boost::shared_ptr<SampleIOProcessor>(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<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter); + + virtual std::set<std::string> getNames() { + std::set<std::string> 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<std::string, std::string> HTTPServer::mimeTypes; HTTPServer* HTTPServer::getInstance(int port) { // tthread::lock_guard<tthread::recursive_mutex> 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 <header> 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<tthread::recursive_mutex> 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<std::string, HTTPServlet*, comp_strsize_less> 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<std::string, HTTPServlet*, comp_strsize_less>::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<IOProcessorImpl> InterpreterServlet::create(InterpreterImpl* i return io; } -void InterpreterServlet::httpRecvRequest(const HTTPServer::Request& req) { +bool InterpreterServlet::httpRecvRequest(const HTTPServer::Request& req) { tthread::lock_guard<tthread::recursive_mutex> 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 @@ <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> - <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js"></script> - <script type="text/javascript"> - function createUUID() { - // http://www.ietf.org/rfc/rfc4122.txt - var s = []; - var hexDigits = "0123456789abcdef"; - for (var i = 0; i < 36; i++) { - s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); + // see http://stackoverflow.com/questions/1206937/javascript-domready + var domLoaded = function(callback) { + /* Internet Explorer */ + /*@cc_on + @if (@_win32 || @_win64) + document.write('<script id="ieScriptLoad" defer src="//:"><\/script>'); + document.getElementById('ieScriptLoad').onreadystatechange = function() { + if (this.readyState == 'complete') { + callback(); + } + }; + @end @*/ + /* Mozilla, Chrome, Opera */ + if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', callback, false); + return; + } + /* Safari, iCab, Konqueror */ + if (/KHTML|WebKit|iCab/i.test(navigator.userAgent)) { + var DOMLoadTimer = setInterval(function () { + if (/loaded|complete/i.test(document.readyState)) { + callback(); + clearInterval(DOMLoadTimer); + } + }, 10); + return; + } + /* Other web browsers */ + window.onload = callback; + }; + + </script> + <script type="text/javascript"> + + function CometSession(options) { + /** + * Support for two-channel asynchronous http communication + */ + for (var key in options) { + if (options.hasOwnProperty(key)) { + this[key] = options[key]; + } + } + var self = this; + + this.xhr = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0")); + this.cometPoll = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0")); + + this.createUUID = function() { + // http://www.ietf.org/rfc/rfc4122.txt + var s = []; + var hexDigits = "0123456789abcdef"; + for (var i = 0; i < 36; i++) { + s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); + } + s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 + s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 + s[8] = s[13] = s[18] = s[23] = "-"; + var uuid = s.join(""); + return uuid; + } + + this.longpoll = function() { + self.cometPoll.onreadystatechange = function() { + if (self.cometPoll.readyState === 4) { + if (self.cometPoll.status !== 200) { + self.longpoll(); + return; + } + self.onRcvd(self.cometPoll); + self.longpoll(); + } + }; + // use token until we have a context + self.cometPoll.open("GET", self.server + (self.query ? "?" + self.query : "")); + self.cometPoll.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + self.cometPoll.send(null); + }; + + this.post = function(data) { + self.xhr.open("POST", self.server + (self.query ? "?" + self.query : "")); + self.xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + self.xhr.send(data); + } } - s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 - s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 - s[8] = s[13] = s[18] = s[23] = "-"; - var uuid = s.join(""); - return uuid; - } + </script> + <script type="text/javascript"> - <script type="text/javascript"> - require(["dojo/on", "dojo/mouse", "dojo/domReady!", "dojo", "dojox/json/ref"], function(on, mouse, dom, dojo, ref) { + function MMISession(element, imURL, params) { + // copy all attributes passe as params + for (var key in params) { + if (params.hasOwnProperty(key)) { + this[key] = params[key]; + } + } + var self = this; - var element = dojo.byId("foo"); - - var mmiNS = "http://www.w3.org/2008/04/mmi-arch"; - var token = createUUID(); - var contextId; - var timeout="30000"; - var imURL = "${im.url}"; - - var xhr = dojo.require("dojo/_base/xhr"); - // initial new context request - xhr.post({ - url: imURL + "?token=" + token, - postData: - '<mmi:mmi xmlns:mmi="' + mmiNS + '" version="1.0">' + - '<mmi:NewContextRequest ' + - 'mmi:Source="HTML" ' + - 'mmi:Target="' + imURL + '" '+ - 'mmi:RequestID="' + token + '" />' + - '</mmi:mmi>', - handleAs:"xml", - headers:{ - "X-Requested-With": null, - "Content-Type": "application/xml", - }, - load: function(result) { - // scxml IM replied with 204 - longpoll via get - longpoll(); - } - }); - - var longpoll = function() { - xhr.get({ - // The URL to request - url: imURL + "?token=" + token, - handleAs:"xml", - headers:{ - "X-Requested-With": null, - "Content-Type": "application/xml", - }, - load: function(result) { - // IM had some event to send to us - element.innerHTML += (new XMLSerializer()).serializeToString(result).replace(/</gi, "<") + "<br />"; - var mmiEvent = result.documentElement.firstChild; + // initialize base class with onData handler + this.__proto__ = new CometSession({ + server: imURL, + onRcvd: function(data) { + var mmiEvent = data.responseXML.documentElement.firstChild; + var handler; + var replier; switch (mmiEvent.localName) { case "NewContextResponse": - newContextResponse(mmiEvent); + self.context = mmiEvent.getAttribute("Context"); + self.comet.query = "context=" + self.context; + break; + case "PrepareRequest": + handler = self.onPrepare; + replier = function(attrs) { sendMMIEvent("DoneNotification", attrs) }; break; case "StartRequest": - startRequest(mmiEvent); + handler = self.onStart; + replier = function(attrs) { sendMMIEvent("StartResponse", attrs) }; + break; + case "CancelRequest": + handler = self.onCancel; + replier = function(attrs) { sendMMIEvent("CancelResponse", attrs) }; + break; + case "PauseRequest": + handler = self.onPause; + replier = function(attrs) { sendMMIEvent("PauseResponse", attrs) }; + break; + case "ResumeRequest": + handler = self.onResume; + replier = function(attrs) { sendMMIEvent("ResumeResponse", attrs) }; break; + case "ClearContextRequest": + handler = self.onClearContext; + replier = function(attrs) { sendMMIEvent("ClearContextResponse", attrs) }; + break; + case "StatusRequest": + handler = self.onStatus; + replier = function(attrs) { sendMMIEvent("StatusResponse", attrs) }; + break; + case "ExtensionNotification": + handler = self.onExtension; + break; + } + if (typeof handler === "function") { + var rc = handler(mmiEvent); + if (typeof replier === "function") { + if (rc === false) { + replier({ Status: "Failure"}); + } else if (typeof rc === "object") { + replier(rc); + } else { + replier({ Status: "Success"}); + } + } } - longpoll(); } }); - } - - var eventToJSON = function(event) { - var seen = []; - return JSON.stringify(event, function(key, val) { - if (isNode(val)) { - return; + this.comet = this.__proto__; + + // get element as an HTML Node + if (typeof(element) === 'string') { + element = document.getElementById(element); + } + + // assign attributes + this.mmiNS = "http://www.w3.org/2008/04/mmi-arch"; + this.comet.query = "token=" + this.createUUID(); + this.element = element; + + this.init = function() { + sendMMIEvent("NewContextRequest"); + self.longpoll(); + } + + // helper function to determine whether something is a html node + var isNode = function(o){ + return ( + typeof Node === "object" ? o instanceof Node : + o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName==="string" + ); + } + + // helper function to determine whether something is a window + var isWindow = function(o){ + return ( + typeof Window === "object" ? o instanceof Window : + o && typeof o === "object" && typeof o.menubar === "object" + ); + } + + // serialize an object to be send + this.send = function(attr) { + // see also: https://raw.github.com/douglascrockford/JSON-js/master/cycle.js + var data = attr.Data; + // dispatch over thingy type here + if (typeof data === "object") { + var seen = []; + data = JSON.stringify(attr.Data, function(key, val) { + if (isNode(val)) { + // return a selection of attributes + return { + id: val.id, + tagName: val.tagName, + localName: val.localName, + }; + +/* + // return everything that is atomic - this is a lot with all the HTML inside + var nodeAttr = {}; + for (var key in val) { + if ( + key !== "outerHTML" && + val.hasOwnProperty(key) && + typeof val[key] !== "object" && + typeof val[key] !== "function" + ) { + nodeAttr[key] = val[key]; + } + } + return nodeAttr; +*/ + } + if (isWindow(val)) { + return; + } + if (typeof val === "object") { + if (seen.indexOf(val) >= 0) + return; + seen.push(val) + } + return val + }); + } - if (isWindow(val)) { - return; + attr.Data = data; + sendMMIEvent("ExtensionNotification", attr); + } + + // register event handler if not given per constructor + if(typeof this.onStart !== "function") { + this.onStart = function(mmiEvent) { + var content = mmiEvent.firstChild; + var fromStartRequest = document.importNode(content.firstChild, true); + self.element.appendChild(fromStartRequest); } - if (typeof val == "object") { - if (seen.indexOf(val) >= 0) - return; - seen.push(val) + } + if(typeof this.onStatus !== "function") { + this.onStatus = function(mmiEvent) { + return true; } - return val - }); - } - - var isNode = function(o){ - return ( - typeof Node === "object" ? o instanceof Node : - o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName==="string" - ); - } + } + if(typeof this.onPrepare !== "function") { + this.onPrepare = function(mmiEvent) { + return true; + } + } + if(typeof this.onCancel !== "function") { + this.onCancel = function(mmiEvent) { + return true; + } + } + if(typeof this.onPause !== "function") { + this.onPause = function(mmiEvent) { + return true; + } + } + if(typeof this.onResume !== "function") { + this.onResume = function(mmiEvent) { + return true; + } + } + if(typeof this.onExtension !== "function") { + this.onExtension = function(mmiEvent) { + return true; + } + } + if(typeof this.onClearContext !== "function") { + this.onClearContext = function(mmiEvent) { + return true; + } + } - var isWindow = function(o){ - return ( - typeof Window === "object" ? o instanceof Window : - o && typeof o === "object" && typeof o.menubar === "object" - ); - } - - var newContextResponse = function(event) { - contextId = event.getAttribute("Context"); - } - var startRequest = function(event) { - var content = event.firstChild; - console.log(content); - var fromStartRequest = document.importNode(content.firstChild,true); - element.appendChild(fromStartRequest); - } - - var sendExtensionNotification = function(event) { - console.log(event); - var data = eventToJSON(event); - console.log(data); - xhr.post({ - url: imURL + "?token=" + token, - postData: - '<mmi:mmi xmlns:mmi="' + mmiNS + '" version="1.0">' + - '<mmi:ExtensionNotification ' + - 'mmi:Source="HTML" ' + - 'mmi:Target="' + imURL + '" ' + - 'mmi:Context="' + contextId + '" ' + - 'mmi:RequestID="' + token + '">' + - '<mmi:Data>' + data + '</mmi:Data>' + - '</mmi:ExtensionNotification>' + - '</mmi:mmi>', - handleAs:"xml", - headers:{ - "X-Requested-With": null, - "Content-Type": "application/xml", - }, - load: function(result) { - // scxml IM replied with 204 - } - }); + if(typeof this.onDone !== "function") { + this.onDone = function(mmiEvent) { + return true; + } + } + + window.onbeforeunload=function(){ + this.onDone(); + sendMMIEvent("DoneNotification", attrs); + }; - } - - on(element, "click", sendExtensionNotification); - on(element, mouse.enter, sendExtensionNotification); - on(element, mouse.leave, sendExtensionNotification); - - }); + var sendMMIEvent = function(type, attrs) { + if (!attrs) + attrs = {}; + if (!attrs["Source"]) // default for Source + attrs["Source"] = "HTML"; + if (!attrs["Target"]) // default for Target + attrs["Target"] = self.imURL; + if (!attrs["RequestID"]) // default for RequestID + attrs["RequestID"] = self.createUUID(); + var mmiDocument = '<mmi:mmi xmlns:mmi="' + self.mmiNS + '" version="1.0">' + + '<mmi:' + type + ' '; + if (self.context) + mmiDocument += 'mmi:Context="' + self.context + '" '; + for (attr in attrs) { + if (attr === "Data") + continue; + if (attr === "Content") + continue; + mmiDocument += 'mmi:' + attr + '="' + attrs[attr] + '" '; + } + mmiDocument += '>'; + + if (attrs["Data"]) + mmiDocument += '<mmi:Data>' + "\n<![CDATA[\n" + attrs["Data"] + "\n]]>\n" + '</mmi:Data>'; + if (attrs["Content"]) + mmiDocument += '<mmi:Content>' + "\n<![CDATA[\n" + attrs["Content"] + "\n]]>\n" + '</mmi:Content>'; + + mmiDocument += '</mmi:' + type +'></mmi:mmi>', + self.post(mmiDocument); + } + + }; + + </script> + + <script type="text/javascript"> + var mmiSession; + domLoaded(function () { + mmiSession = new MMISession("foo", "${im.url}", { + onExtension : function(mmiEvent) { + console.log(mmiEvent); + } + }); + mmiSession.init(); + }); </script> + </head> <body class="tundra"> <div id="foo"></div> 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 @@ +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> + <script type="text/javascript"> + // see http://stackoverflow.com/questions/1206937/javascript-domready + var domLoaded = function(callback) { + /* Internet Explorer */ + /*@cc_on + @if (@_win32 || @_win64) + document.write('<script id="ieScriptLoad" defer src="//:"><\/script>'); + document.getElementById('ieScriptLoad').onreadystatechange = function() { + if (this.readyState == 'complete') { + var head= document.getElementsByTagName('head')[0]; + var script= document.createElement('script'); + script.type= 'text/javascript'; + script.src= 'http://wicked-good-xpath.googlecode.com/files/wgxpath.install.js'; + head.appendChild(script); + wgxpath.install(); + + // see http://stackoverflow.com/questions/1811116/ie-support-for-dom-importnode + document.importNode = function(node, allChildren) { + switch (node.nodeType) { + case document.ELEMENT_NODE: + var newNode = document.createElementNS(node.namespaceURI, node.nodeName); + if(node.attributes && node.attributes.length > 0) + for(var i = 0, il = node.attributes.length; i < il; i++) + newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i].nodeName)); + if(allChildren && node.childNodes && node.childNodes.length > 0) + for(var i = 0, il = node.childNodes.length; i < il; i++) + newNode.appendChild(document.importNode(node.childNodes[i], allChildren)); + return newNode; + break; + case document.TEXT_NODE: + case document.CDATA_SECTION_NODE: + case document.COMMENT_NODE: + return document.createTextNode(node.nodeValue); + break; + } + } + + callback(); + } + }; + @end @*/ + /* Mozilla, Chrome, Opera */ + if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', callback, false); + return; + } + /* Safari, iCab, Konqueror */ + if (/KHTML|WebKit|iCab/i.test(navigator.userAgent)) { + var DOMLoadTimer = setInterval(function () { + if (/loaded|complete/i.test(document.readyState)) { + callback(); + clearInterval(DOMLoadTimer); + } + }, 10); + return; + } + /* Other web browsers */ + window.onload = callback; + }; + + </script> + <script type="text/javascript"> + + function CometSession(options) { + /** + * Support for two-channel asynchronous http communication + */ + for (var key in options) { + if (options.hasOwnProperty(key)) { + this[key] = options[key]; + } + } + var self = this; + + this.xhr = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0")); + this.cometPoll = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0")); + + this.createUUID = function() { + // http://www.ietf.org/rfc/rfc4122.txt + var s = []; + var hexDigits = "0123456789abcdef"; + for (var i = 0; i < 36; i++) { + s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); + } + s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 + s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 + s[8] = s[13] = s[18] = s[23] = "-"; + var uuid = s.join(""); + return uuid; + } + + this.longpoll = function() { + self.cometPoll.onreadystatechange = function() { + if (self.cometPoll.readyState === 4) { + if (self.cometPoll.status !== 200) { + self.longpoll(); + return; + } + self.onRcvd(self.cometPoll); + self.longpoll(); + } + }; + // use token until we have a context + self.cometPoll.open("GET", self.server + (self.query ? "?" + self.query : "")); + self.cometPoll.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + self.cometPoll.setRequestHeader("Connection", "close"); + self.cometPoll.send(null); + }; + + this.post = function(name, data) { + self.xhr.open("POST", self.server + (self.query ? "?" + self.query : "")); + self.xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + self.xhr.setRequestHeader('X-SCXML-Name', name); + self.xhr.send(data); + } + + // serialize an object to be send + this.send = function(name, thing) { + var data; + // see also: https://raw.github.com/douglascrockford/JSON-js/master/cycle.js + // dispatch over thingy type here + if (typeof thing === "object") { + var seen = []; + // will not work on opera as thing is checked for cycles first + data = JSON.stringify(thing, function(key, val) { + if (isNode(val)) { + // return a selection of attributes + return { + id: val.id, + tagName: val.tagName, + localName: val.localName + }; + } + if (isWindow(val)) { + return; + } + if (typeof val === "object") { + if (seen.indexOf(val) >= 0) + return; + seen.push(val) + } + return val + }); + } else { + data = thing; + } + this.post(name, data); + } + + // helper function to determine whether something is a html node + var isNode = function(o){ + return ( + typeof Node === "object" ? o instanceof Node : + o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName==="string" + ); + } + + // helper function to determine whether something is a window + var isWindow = function(o){ + return ( + typeof Window === "object" ? o instanceof Window : + o && typeof o === "object" && typeof o.menubar === "object" + ); + } + + } + + </script> + + <script type="text/javascript"> + domLoaded(function () { + scxml = new CometSession({ + element: document.getElementById("${scxml.invokeId}"), + server: "${scxml.server}", + onRcvd : function(data) { + if (data.responseXML) { + var type = data.getResponseHeader("X-SCXML-Type") || "replacechildren"; + var domTarget = data.getResponseHeader("X-SCXML-XPath") || "/html/body"; + var domAttr = data.getResponseHeader("X-SCXML-Attr"); + var result = document.evaluate(domTarget, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); + + for (var i = 0, l = result.snapshotLength; i < l; i++) { + var item = result.snapshotItem(i); + var node = document.importNode(data.responseXML.firstChild, true); + switch (type) { + case "firstchild": + item.insertBefore(node, item.firstChild); + break; + case "lastchild": + item.appendChild(node); + break; + case "previoussibling": + item.parentNode.insertBefore(node, item); + break; + case "nextsibling": + item.parentNode.insertBefore(node, item.nextSibling); + break; + case "replace": + item.parentNode.replaceChild(node, item); + break; + case "delete": + item.parentNode.removeChild(item); + break; + case "addattribute": + item.setAttribute(domAttr, node); + break; + case "replacechildren": + while(item.hasChildNodes()) { + item.removeChild(item.firstChild); + } + item.appendChild(node); + default: + break; + } + } + } + } + }); + scxml.longpoll(); + }); + </script> + + </head> + <body></body> +</html> 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 @@ <state id="startmc"> <!-- invoke type="vxml" id="mc.vxml" / --> + <!-- invoke type="xhtml" id="mc.xhtml" / --> <!-- Idle here and wait for events --> <state id="idle"> @@ -52,7 +53,13 @@ <content> <mmi:StartRequest> <mmi:Content> - <html:button>Click Me</html:button> + <html:form onmouseover ="mmiSession.send({ Name: 'onmouseover', Data: arguments[0] })"> + First name: <html:input type="text" name="firstname" /><html:br /> + Last name: <html:input type="text" name="lastname" /> + <html:input + onclick="mmiSession.send({ Name: 'onsubmit', Data: arguments[0] })" + type="button" value="Submit" /> + </html:form> </mmi:Content> </mmi:StartRequest> </content> @@ -60,7 +67,7 @@ </transition> <transition event="mmi.extensionnotification" target="idle"> - <script>dump(_event)</script> + <!--script>dump(_event)</script --> </transition> </state> 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 @@ +<scxml datamodel="ecmascript" name="comet-test" + xmlns:html="http://www.w3.org/1999/xhtml" + xmlns="http://www.w3.org/2005/07/scxml"> + + <script src="http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js" /> + + <state id="start"> + <invoke type="xhtml" id="xhtml1"> + <!-- replacechildren (default), firstchild, lastchild, previoussibling, nextsibling, replace, delete, addattribute --> + <content type="replacechildren" xpath="/html/body"> + <html:form onmouseover="scxml.send('onmouseover', arguments[0])"> + First name1: <html:input type="text" name="firstname" /><html:br /> + Last name1: <html:input type="text" name="lastname" /> + <html:input onclick="scxml.send('onclick', arguments[0])" type="button" value="Submit" /> + </html:form> + </content> + </invoke> + + <state id="idle"> + <transition target="idle" event="onmouseover"> + <log expr="dump(_event)" /> + </transition> + <transition target="idle" event="onclick" cond="_event.origin=='xhtml1'"> + <send target="#_xhtml1"> + <content type="lastchild" xpath="/html/body"> + <html:p>Thank you!</html:p> + </content> + </send> + </transition> + </state> + + </state> +</scxml>
\ No newline at end of file diff --git a/test/src/scxml-test-framework-client.cpp b/test/src/scxml-test-framework-client.cpp index 0441c0e..8fbdf75 100644 --- a/test/src/scxml-test-framework-client.cpp +++ b/test/src/scxml-test-framework-client.cpp @@ -105,7 +105,7 @@ public: } - void httpRecvRequest(const uscxml::HTTPServer::Request& request) { + bool httpRecvRequest(const uscxml::HTTPServer::Request& request) { // uscxml::HTTPServer::Reply httpReply(request); // uscxml::HTTPServer::reply(httpReply); @@ -144,7 +144,7 @@ public: _interpreters[token] = std::make_pair(interpreter, request); interpreter.start(); } - return; + return true; } if(jsonReq.compound.find("event") != jsonReq.compound.end()) { @@ -160,7 +160,7 @@ public: _interpreters[token].second = request; _interpreters[token].first.receive(event); } - + return true; } void setURL(const std::string& url) { diff --git a/test/src/test-url.cpp b/test/src/test-url.cpp index 69951e4..69f9014 100644 --- a/test/src/test-url.cpp +++ b/test/src/test-url.cpp @@ -16,7 +16,9 @@ class TestServlet : public HTTPServlet { public:
TestServlet(bool adaptPath) : _canAdaptPath(adaptPath) {}
- void httpRecvRequest(const HTTPServer::Request& request) {};
+ bool httpRecvRequest(const HTTPServer::Request& request) {
+ return true;
+ };
bool canAdaptPath() {
return _canAdaptPath;
}
@@ -69,6 +71,9 @@ int main(int argc, char** argv) { URL exeUrl(exeName);
exeUrl.toAbsolute(baseUrl);
assert(canResolve(exeUrl.asString()));
+ std::cout << exeUrl.asString() << std::endl;
+ exeUrl.download(true);
+ assert(exeUrl.getInContent().length() > 0);
}
{
@@ -105,6 +110,11 @@ int main(int argc, char** argv) { }
{
+ Data data = Data::fromJSON("{\"shiftKey\":false,\"toElement\":{\"id\":\"\",\"localName\":\"body\"},\"clientY\":38,\"y\":38,\"x\":66,\"ctrlKey\":false,\"relatedTarget\":{\"id\":\"\",\"localName\":\"body\"},\"clientX\":66,\"screenY\":288,\"metaKey\":false,\"offsetX\":58,\"altKey\":false,\"offsetY\":30,\"fromElement\":{\"id\":\"foo\",\"localName\":\"div\"},\"screenX\":-1691,\"dataTransfer\":null,\"button\":0,\"pageY\":38,\"layerY\":38,\"pageX\":66,\"charCode\":0,\"which\":0,\"keyCode\":0,\"detail\":0,\"layerX\":66,\"returnValue\":true,\"timeStamp\":1371223991895,\"eventPhase\":2,\"target\":{\"id\":\"foo\",\"localName\":\"div\"},\"defaultPrevented\":false,\"srcElement\":{\"id\":\"foo\",\"localName\":\"div\"},\"type\":\"mouseout\",\"cancelable\":true,\"currentTarget\":{\"id\":\"foo\",\"localName\":\"div\"},\"bubbles\":true,\"cancelBubble\":false}");
+ std::cout << data << std::endl;
+ }
+
+ {
Data data = Data::fromJSON("asdf");
std::cout << data << std::endl;
}
|