From 3df6c9c6630f3b3b9b0876ae5bc8f2d12a15b253 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Thu, 1 Aug 2013 14:55:04 +0200 Subject: Bug fixes and version bump - New calendar invoker - Fixed memory leaks with JavaScriptCore - Compiles on windows again - Beautified source code indentation --- CMakeLists.txt | 14 +- config.h.in | 1 + contrib/cmake/FindLIBICAL.cmake | 33 +- contrib/dom/scripts/CodeGeneratorArabicaJSC.pm | 12 +- contrib/local/beautifyCode.sh | 2 + contrib/local/compress_and_upload_deps.sh | 1 - src/bindings/swig/java/uscxml.i | 7 + src/bindings/swig/php/uscxml.i | 2 + src/uscxml/Factory.cpp | 18 +- src/uscxml/Factory.h | 10 +- src/uscxml/Interpreter.cpp | 28 +- src/uscxml/Interpreter.h | 13 +- src/uscxml/NameSpacingParser.h | 2 +- src/uscxml/URL.cpp | 25 +- src/uscxml/URL.h | 3 + src/uscxml/interpreter/InterpreterDraft6.cpp | 4 +- .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 59 ++- .../ecmascript/JavaScriptCore/JSCDataModel.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCAttr.cpp | 10 +- .../JavaScriptCore/dom/JSCCharacterData.cpp | 6 +- .../ecmascript/JavaScriptCore/dom/JSCDOM.cpp | 5 + .../ecmascript/JavaScriptCore/dom/JSCDOM.h | 2 +- .../JavaScriptCore/dom/JSCDocumentType.cpp | 20 +- .../ecmascript/JavaScriptCore/dom/JSCElement.cpp | 7 +- .../ecmascript/JavaScriptCore/dom/JSCEntity.cpp | 15 +- .../ecmascript/JavaScriptCore/dom/JSCNode.cpp | 25 +- .../ecmascript/JavaScriptCore/dom/JSCNotation.cpp | 10 +- .../dom/JSCProcessingInstruction.cpp | 10 +- .../JavaScriptCore/dom/JSCSCXMLEvent.cpp | 34 +- .../JavaScriptCore/dom/JSCSCXMLEventCustom.cpp | 10 +- .../JavaScriptCore/dom/JSCXPathResult.cpp | 6 +- .../datamodel/ecmascript/v8/V8DataModel.cpp | 2 +- .../plugins/datamodel/null/NULLDataModel.cpp | 2 +- src/uscxml/plugins/datamodel/null/NULLDataModel.h | 2 +- .../plugins/datamodel/prolog/swi/SWIDataModel.cpp | 20 +- .../plugins/datamodel/prolog/swi/SWIDataModel.h | 4 +- .../plugins/datamodel/xpath/XPathDataModel.cpp | 2 +- .../plugins/datamodel/xpath/XPathDataModel.h | 2 +- src/uscxml/plugins/invoker/CMakeLists.txt | 21 + .../plugins/invoker/calendar/CalendarInvoker.cpp | 583 +++++++++++++++++++++ .../plugins/invoker/calendar/CalendarInvoker.h | 39 ++ .../plugins/invoker/location/LocationInvoker.cpp | 44 -- .../plugins/invoker/location/LocationInvoker.h | 40 -- src/uscxml/plugins/invoker/miles/SpatialAudio.cpp | 6 +- src/uscxml/plugins/invoker/umundo/JSON.pb.h | 458 ++++++++-------- .../plugins/invoker/umundo/UmundoInvoker.cpp | 22 +- src/uscxml/plugins/invoker/umundo/UmundoInvoker.h | 2 +- .../plugins/invoker/vxml/VoiceXMLInvoker.cpp | 2 +- src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp | 10 +- test/samples/uscxml/test-calendar.scxml | 93 ++++ test/src/test-arabica-parsing.cpp | 6 +- test/src/test-datamodel.cpp | 4 +- 52 files changed, 1308 insertions(+), 452 deletions(-) delete mode 100644 src/uscxml/plugins/invoker/location/LocationInvoker.cpp delete mode 100644 src/uscxml/plugins/invoker/location/LocationInvoker.h create mode 100644 test/samples/uscxml/test-calendar.scxml diff --git a/CMakeLists.txt b/CMakeLists.txt index ad02a49..685c010 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 "5") +SET(USCXML_VERSION_PATCH "6") SET(USCXML_VERSION ${USCXML_VERSION_MAJOR}.${USCXML_VERSION_MINOR}.${USCXML_VERSION_PATCH}) # build type has to be set before the project definition4 @@ -397,6 +397,13 @@ if (NOT WIN32) set(XML_LIBRARIES ${LIBXML2_LIBRARIES}) list (APPEND USCXML_CORE_LIBS "dl") list (APPEND USCXML_CORE_LIBS "pthread") + if (APPLE) + find_library(CORELOCATION_LIBRARY CoreLocation) + if (CORELOCATION_LIBRARY AND OFF) + list (APPEND USCXML_OPT_LIBS ${CORELOCATION_LIBRARY}/CoreLocation) + set(CORELOCATION_FOUND ON) + endif() + endif() if (IOS) find_library(COREFOUNDATION_LIBRARY CoreFoundation) list (APPEND USCXML_CORE_LIBS ${COREFOUNDATION_LIBRARY}/CoreFoundation) @@ -505,10 +512,13 @@ if (FFMPEG_FOUND) include_directories (${FFMPEG_INCLUDE_DIR}) endif() +set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SHARED}) find_package(LIBICAL) if (LIBICAL_FOUND) - include_directories (${LIBICAL_INCLUDE_DIR}) + include_directories (${LIBICAL_INCLUDE_DIR}) + list (APPEND USCXML_OPT_LIBS ${LIBICAL_LIBRARIES}) endif() +set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_STATIC}) if (WIN32) diff --git a/config.h.in b/config.h.in index d45d185..52cfcdc 100644 --- a/config.h.in +++ b/config.h.in @@ -65,6 +65,7 @@ #cmakedefine FFMPEG_FOUND #cmakedefine OPENSCENEGRAPH_FOUND #cmakedefine PROTOBUF_FOUND +#cmakedefine CORELOCATION_FOUND /** Header files we found */ #cmakedefine HAS_UNISTD_H diff --git a/contrib/cmake/FindLIBICAL.cmake b/contrib/cmake/FindLIBICAL.cmake index 652a4df..a0cfe43 100644 --- a/contrib/cmake/FindLIBICAL.cmake +++ b/contrib/cmake/FindLIBICAL.cmake @@ -10,23 +10,42 @@ FIND_PATH(LIBICAL_INCLUDE_DIR libical/ical.h ) FIND_LIBRARY(LIBICAL_LIBRARY_RELEASE - NAMES ical + NAMES ical libical libical-static ) if (LIBICAL_LIBRARY_RELEASE) - list(APPEND LIBICAL_LIBRARY optimized ${LIBICAL_LIBRARY_RELEASE}) + list(APPEND LIBICAL_LIBRARIES optimized ${LIBICAL_LIBRARY_RELEASE}) endif() FIND_LIBRARY(LIBICAL_LIBRARY_DEBUG - NAMES ical_d + NAMES ical_d libical_d libical-static_d ) if (LIBICAL_LIBRARY_DEBUG) - list(APPEND LIBICAL_LIBRARY debug ${LIBICAL_LIBRARY_DEBUG}) + list(APPEND LIBICAL_LIBRARIES debug ${LIBICAL_LIBRARY_DEBUG}) else() if (UNIX) - list(APPEND LIBICAL_LIBRARY debug ${LIBICAL_LIBRARY_RELEASE}) + list(APPEND LIBICAL_LIBRARIES debug ${LIBICAL_LIBRARY_RELEASE}) endif() endif() +FIND_LIBRARY(LIBICALSS_LIBRARY_RELEASE + NAMES icalss libicalss libicalss-static +) +if (LIBICALSS_LIBRARY_RELEASE) + list(APPEND LIBICAL_LIBRARIES optimized ${LIBICALSS_LIBRARY_RELEASE}) +endif() + +FIND_LIBRARY(LIBICALSS_LIBRARY_DEBUG + NAMES icalss_d libicalss_d libicalss-static_d +) +if (LIBICALSS_LIBRARY_DEBUG) + list(APPEND LIBICAL_LIBRARIES debug ${LIBICALSS_LIBRARY_DEBUG}) +else() + if (UNIX) + list(APPEND LIBICAL_LIBRARIES debug ${LIBICALSS_LIBRARY_RELEASE}) + endif() +endif() + + INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBICAL DEFAULT_MSG LIBICAL_LIBRARY LIBICAL_INCLUDE_DIR) -MARK_AS_ADVANCED(LIBICAL_LIBRARY LIBICAL_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBICAL DEFAULT_MSG LIBICAL_LIBRARIES LIBICAL_INCLUDE_DIR) +MARK_AS_ADVANCED(LIBICAL_LIBRARIES LIBICAL_INCLUDE_DIR) diff --git a/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm b/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm index 2de92a9..cc8debb 100644 --- a/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm +++ b/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm @@ -349,8 +349,11 @@ END push(@implContent, "\n return JSValueMakeUndefined(ctx);"); } push(@implContent, <nativeObj->${wrapperGetter}.c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; END } elsif($JSCType eq "Number") { push(@implContent, "\n return JSValueMakeNumber(ctx, privData->nativeObj->${wrapperGetter});\n"); @@ -387,7 +390,9 @@ END if ($JSCType eq "String") { push(@implContent, "\n JSStringRef jscString = JSStringCreateWithUTF8CString(" . $constant->value . ");". - "\n return JSValueMakeString(ctx, jscString);\n"); + "\n JSValueRef retVal = JSValueMakeString(ctx, jscString);". + "\n JSStringRelease(jscString);". + "\n return retVal;\n"); } elsif($JSCType eq "Number") { push(@implContent, "\n return JSValueMakeNumber(ctx, " . $constant->value . ");\n"); } elsif($JSCType eq "Boolean") { @@ -633,7 +638,8 @@ sub NativeToHandle return ("\n JSValueRef ${paramName} = JSValueMakeUndefined(ctx);") if ($nativeType eq "void"); return ( "\n JSStringRef jscString = JSStringCreateWithUTF8CString(${nativeName}.c_str());". - "\n JSValueRef ${paramName} = JSValueMakeString(ctx, jscString);" + "\n JSValueRef ${paramName} = JSValueMakeString(ctx, jscString);". + "\n JSStringRelease(jscString);" ) if ($nativeType eq "std::string"); die($nativeType); diff --git a/contrib/local/beautifyCode.sh b/contrib/local/beautifyCode.sh index d6f4c11..487fa40 100755 --- a/contrib/local/beautifyCode.sh +++ b/contrib/local/beautifyCode.sh @@ -9,6 +9,8 @@ ME=`basename $0` DIR="$( cd "$( dirname "$0" )" && pwd )" CWD=`pwd` +find ${DIR}/../../ -name ".DS_Store" -exec rm {} \; + astyle \ --style=java \ --indent=tab \ diff --git a/contrib/local/compress_and_upload_deps.sh b/contrib/local/compress_and_upload_deps.sh index 4ab1918..3cc9684 100755 --- a/contrib/local/compress_and_upload_deps.sh +++ b/contrib/local/compress_and_upload_deps.sh @@ -31,7 +31,6 @@ cd ../prebuilt ssh ${USCXML_PREBUILT_HOST} mkdir -p ${USCXML_PREBUILT_PATH}/${VERSION} PLATFORMS=`find . -maxdepth 1 -type d -regex ./[^\.].*` -PLATFORMS="ios" for FILE in ${PLATFORMS}; do PLATFORM=`basename $FILE` if [ "$PLATFORM" != "include" ]; then diff --git a/src/bindings/swig/java/uscxml.i b/src/bindings/swig/java/uscxml.i index 760846c..ee7133c 100644 --- a/src/bindings/swig/java/uscxml.i +++ b/src/bindings/swig/java/uscxml.i @@ -19,6 +19,11 @@ %ignore operator!=; %ignore operator<; %ignore operator=; +%ignore operator[]; +%ignore operator std::list; +%ignore operator std::string; +%ignore operator std::map; + //************************************************** // This ends up in the generated wrapper code @@ -39,6 +44,8 @@ using namespace uscxml; %ignore uscxml::SCXMLParser; %ignore uscxml::InterpreterImpl; +%ignore uscxml::Interpreter::getDelayQueue(); + //*********************************************** // Parse the header file to generate wrappers //*********************************************** diff --git a/src/bindings/swig/php/uscxml.i b/src/bindings/swig/php/uscxml.i index f51309f..8500bfe 100644 --- a/src/bindings/swig/php/uscxml.i +++ b/src/bindings/swig/php/uscxml.i @@ -53,6 +53,8 @@ void*** tsrm_ls; // Beautify interpreter class //*********************************************** +%ignore uscxml::Interpreter::getDelayQueue(); + %extend uscxml::Interpreter { std::vector getConfiguration() { std::vector config; diff --git a/src/uscxml/Factory.cpp b/src/uscxml/Factory.cpp index 0d5f401..b8bf60a 100644 --- a/src/uscxml/Factory.cpp +++ b/src/uscxml/Factory.cpp @@ -49,6 +49,10 @@ # include "uscxml/plugins/invoker/calendar/CalendarInvoker.h" # endif +# ifdef CORELOCATION_FOUND +# include "uscxml/plugins/invoker/location/CoreLocation/LocationInvoker.h" +# endif + # ifdef V8_FOUND # include "uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h" # endif @@ -134,8 +138,9 @@ Factory::Factory() { #ifdef MILES_FOUND { - MilesSessionInvoker* invoker = new MilesSessionInvoker(); - registerInvoker(invoker); + // eats 8MB of RAM! +// MilesSessionInvoker* invoker = new MilesSessionInvoker(); +// registerInvoker(invoker); } { SpatialAudio* invoker = new SpatialAudio(); @@ -150,6 +155,13 @@ Factory::Factory() { } #endif +#ifdef LIBICAL_FOUND + { + CalendarInvoker* invoker = new CalendarInvoker(); + registerInvoker(invoker); + } +#endif + #ifdef OPENSCENEGRAPH_FOUND { OSGInvoker* invoker = new OSGInvoker(); @@ -448,7 +460,7 @@ size_t DataModelImpl::replaceExpressions(std::string& content) { } if (replacements) content = ss.str(); - + return replacements; } diff --git a/src/uscxml/Factory.h b/src/uscxml/Factory.h index 58002fe..3ddd9ad 100644 --- a/src/uscxml/Factory.h +++ b/src/uscxml/Factory.h @@ -15,7 +15,7 @@ namespace uscxml { inline bool isnan(double x) { - return x != x; + return x != x; } // see http://stackoverflow.com/questions/228005/alternative-to-itoa-for-converting-integer-to-string-c @@ -259,7 +259,7 @@ public: virtual Data getStringAsData(const std::string& content) = 0; size_t replaceExpressions(std::string& content); - + // foreach virtual uint32_t getLength(const std::string& expr) = 0; virtual void setForeach(const std::string& item, @@ -270,8 +270,8 @@ public: virtual void popContext() = 0; virtual void eval(const Arabica::DOM::Element& scriptElem, - const std::string& expr) = 0; - + const std::string& expr) = 0; + virtual std::string evalAsString(const std::string& expr) = 0; virtual bool evalAsBool(const std::string& expr) = 0; @@ -333,7 +333,7 @@ public: } virtual void eval(const Arabica::DOM::Element& scriptElem, - const std::string& expr) { + const std::string& expr) { return _impl->eval(scriptElem, expr); } virtual std::string evalAsString(const std::string& expr) { diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 4e33c8b..77c6805 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -473,9 +473,9 @@ void InterpreterImpl::processDOMorText(const Arabica::DOM::Node& no std::auto_ptr ssPtr(ss); Arabica::SAX::InputSource inputSource; inputSource.setByteStream(ssPtr); - + // parser.setFeature(Arabica::SAX::FeatureNames().external_general, true); - + if (parser.parse(inputSource) && parser.getDocument()) { dom = parser.getDocument(); //std::cout << dom; @@ -498,7 +498,7 @@ void InterpreterImpl::processDOMorText(const Arabica::DOM::Node& no Node child = node.getFirstChild(); while(child) { - if (child.getNodeType() == Node_base::TEXT_NODE) { + if (child.getNodeType() == Node_base::TEXT_NODE || child.getNodeType() == Node_base::CDATA_SECTION_NODE) { std::string trimmed = child.getNodeValue(); boost::trim(trimmed); if (trimmed.length() > 0) @@ -515,8 +515,13 @@ void InterpreterImpl::processDOMorText(const Arabica::DOM::Node& no // we need to import the parent - to support xpath test150 Node newNode = dom.importNode(child.getParentNode(), true); dom.appendChild(newNode); - } else if(child && child.getNodeType() == Node_base::TEXT_NODE) { - text = child.getNodeValue(); + } else if(child && (child.getNodeType() == Node_base::TEXT_NODE || child.getNodeType() == Node_base::CDATA_SECTION_NODE)) { + while(child) { + if ((child.getNodeType() == Node_base::TEXT_NODE || child.getNodeType() == Node_base::CDATA_SECTION_NODE)) { + text += child.getNodeValue(); + } + child = child.getNextSibling(); + } } else { LOG(ERROR) << LOCALNAME(node) << " has neither text nor element children."; } @@ -638,7 +643,7 @@ void InterpreterImpl::send(const Arabica::DOM::Node& element) { } if (delay.size() > 0) { boost::trim(delay); - + NumAttr delayAttr(delay); if (boost::iequals(delayAttr.unit, "ms")) { sendReq.delayMs = strTo(delayAttr.value); @@ -1076,7 +1081,7 @@ void InterpreterImpl::executeContent(const Arabica::DOM::Node& cont CATCH_AND_DISTRIBUTE("Syntax error in expr attribute of log element:") } else { if (logElem.hasAttribute("label")) - std::cout << std::endl; + std::cout << std::endl; } } else if (boost::iequals(TAGNAME(content), _xmlNSPrefix + "assign")) { // --- ASSIGN -------------------------- @@ -1131,9 +1136,14 @@ void InterpreterImpl::executeContent(const Arabica::DOM::Node& cont } else { if (content.hasChildNodes()) { // search for the text node with the actual script - if (content.getFirstChild().getNodeType() == Node_base::TEXT_NODE) { + std::string scriptContent; + for (Node child = content.getFirstChild(); child; child = child.getNextSibling()) { + if (child.getNodeType() == Node_base::TEXT_NODE || child.getNodeType() == Node_base::CDATA_SECTION_NODE) + scriptContent += child.getNodeValue(); + } + if (scriptContent.size() > 0) { try { - _dataModel.eval((Element)content, content.getFirstChild().getNodeValue()); + _dataModel.eval((Element)content, scriptContent); } CATCH_AND_DISTRIBUTE("Syntax error while executing script element") } diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index 56454db..d0da78f 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -188,6 +188,10 @@ public: return _sessionId; } + DelayedEventQueue* getDelayQueue() { + return _sendQueue; + } + const std::map& getIOProcessors() { return _ioProcessors; } @@ -204,7 +208,7 @@ public: bool hasLegalConfiguration(); bool isLegalConfiguration(const Arabica::XPath::NodeSet&); bool isLegalConfiguration(const std::vector&); - + static bool isState(const Arabica::DOM::Node& state); static bool isPseudoState(const Arabica::DOM::Node& state); static bool isTransitionTarget(const Arabica::DOM::Node& elem); @@ -215,12 +219,12 @@ public: static bool isParallel(const Arabica::DOM::Node& state); static bool isCompound(const Arabica::DOM::Node& state); static bool isDescendant(const Arabica::DOM::Node& s1, const Arabica::DOM::Node& s2); - + static std::vector tokenizeIdRefs(const std::string& idRefs); static std::string spaceNormalize(const std::string& text); bool isInEmbeddedDocument(const Arabica::DOM::Node& node); - bool isInitial(const Arabica::DOM::Node& state); + bool isInitial(const Arabica::DOM::Node& state); Arabica::XPath::NodeSet getInitialStates(Arabica::DOM::Node state = Arabica::DOM::Node()); static Arabica::XPath::NodeSet getChildStates(const Arabica::DOM::Node& state); static Arabica::DOM::Node getParentState(const Arabica::DOM::Node& element); @@ -484,6 +488,9 @@ public: const std::string& getSessionId() { return _impl->getSessionId(); } + DelayedEventQueue* getDelayQueue() { + return _impl->getDelayQueue(); + } const std::map& getIOProcessors() { return _impl->getIOProcessors(); diff --git a/src/uscxml/NameSpacingParser.h b/src/uscxml/NameSpacingParser.h index 50cc260..47dd9eb 100644 --- a/src/uscxml/NameSpacingParser.h +++ b/src/uscxml/NameSpacingParser.h @@ -12,7 +12,7 @@ class ScriptEntityResolver : public Arabica::SAX::EntityResolver { return is; } }; - + class NameSpacingParser : public Arabica::SAX2DOM::Parser { public: NameSpacingParser(); diff --git a/src/uscxml/URL.cpp b/src/uscxml/URL.cpp index 45aba88..ac947d7 100644 --- a/src/uscxml/URL.cpp +++ b/src/uscxml/URL.cpp @@ -8,7 +8,6 @@ #ifdef _WIN32 #include #include -#include #include #include #define getcwd _getcwd @@ -25,6 +24,30 @@ namespace uscxml { +std::string URL::tmpDir() { + // try hard to find a temporary directory + const char* tmpDir = NULL; + if (tmpDir == NULL) + tmpDir = getenv("TMPDIR"); + if (tmpDir == NULL) + tmpDir = getenv("TMP"); + if (tmpDir == NULL) + tmpDir = getenv("TEMP"); + if (tmpDir == NULL) + tmpDir = getenv("USERPROFILE"); + if (tmpDir == NULL) + tmpDir = "/tmp/"; + + char* tmpl = (char*)malloc(strlen(tmpDir) + 11); + char* writePtr = tmpl; + memcpy(writePtr, tmpDir, strlen(tmpDir)); + writePtr += strlen(tmpDir); + memcpy(writePtr, "scxmlXXXXXX", 11); + writePtr += 11; + tmpl[writePtr - tmpl] = 0; + return tmpl; +} + URLImpl::URLImpl(const std::string& url) : _handle(NULL), _uri(url), _isDownloaded(false), _hasFailed(false) { std::stringstream ss(_uri.path()); std::string item; diff --git a/src/uscxml/URL.h b/src/uscxml/URL.h index 402666f..bb33a7c 100644 --- a/src/uscxml/URL.h +++ b/src/uscxml/URL.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "uscxml/concurrency/tinythread.h" @@ -219,6 +220,8 @@ public: return _impl->asString(); } + static std::string tmpDir(); + friend class URLFetcher; friend std::ostream & operator<<(std::ostream &stream, const URL& p); diff --git a/src/uscxml/interpreter/InterpreterDraft6.cpp b/src/uscxml/interpreter/InterpreterDraft6.cpp index b3e76bd..9140d17 100644 --- a/src/uscxml/interpreter/InterpreterDraft6.cpp +++ b/src/uscxml/interpreter/InterpreterDraft6.cpp @@ -91,7 +91,7 @@ void InterpreterDraft6::interpret() { histStates.push_back(getState(_userDefinedStartConfiguration[i])); } _historyValue[histId] = histStates; - + Element initialElem = _document.createElementNS(_nsURL, "initial"); initialElem.setAttribute("generated", "true"); Element transitionElem = _document.createElementNS(_nsURL, "transition"); @@ -119,7 +119,7 @@ void InterpreterDraft6::interpret() { } } } - + assert(initialTransitions.size() > 0); enterStates(initialTransitions); // _mutex.unlock(); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 1326fb9..33746a5 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -15,7 +15,7 @@ namespace uscxml { using namespace Arabica::XPath; using namespace Arabica::DOM; - + #ifdef BUILD_AS_PLUGINS PLUMA_CONNECTOR bool connect(pluma::Host& host) { @@ -25,19 +25,28 @@ bool connect(pluma::Host& host) { #endif JSCDataModel::JSCDataModel() { + _dom = NULL; + _ctx = NULL; +} + +JSCDataModel::~JSCDataModel() { + if (_dom) + delete _dom; + if (_ctx) + JSGlobalContextRelease(_ctx); } #if 0 typedef struct { int version; /* current (and only) version is 0 */ JSClassAttributes attributes; - + const char* className; JSClassRef parentClass; - + const JSStaticValue* staticValues; const JSStaticFunction* staticFunctions; - + JSObjectInitializeCallback initialize; JSObjectFinalizeCallback finalize; JSObjectHasPropertyCallback hasProperty; @@ -51,7 +60,7 @@ typedef struct { JSObjectConvertToTypeCallback convertToType; } JSClassDefinition; #endif - + // functions need to be objects to hold private data in JSC JSClassDefinition JSCDataModel::jsInClassDef = { 0, 0, "In", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, jsIn, 0, 0, 0 }; JSClassDefinition JSCDataModel::jsPrintClassDef = { 0, 0, "print", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, jsPrint, 0, 0, 0 }; @@ -113,7 +122,10 @@ boost::shared_ptr JSCDataModel::create(InterpreterImpl* interpret JSObjectRef documentObject = JSObjectMake(dm->_ctx, JSCDocument::getTmpl(), privData); JSObjectRef globalObject = JSContextGetGlobalObject(dm->_ctx); - JSObjectSetProperty(dm->_ctx, globalObject, JSStringCreateWithUTF8CString("document"), documentObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL); + JSStringRef documentName = JSStringCreateWithUTF8CString("document"); + + JSObjectSetProperty(dm->_ctx, globalObject, documentName, documentObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL); + JSStringRelease(documentName); } dm->eval(Element(), "_x = {};"); @@ -121,10 +133,6 @@ boost::shared_ptr JSCDataModel::create(InterpreterImpl* interpret return dm; } -JSCDataModel::~JSCDataModel() { - JSGlobalContextRelease(_ctx); -} - void JSCDataModel::pushContext() { } @@ -138,7 +146,7 @@ void JSCDataModel::setEvent(const Event& event) { JSObjectRef eventObj = JSObjectMake(_ctx, JSCSCXMLEvent::getTmpl(), privData); JSObjectRef globalObject = JSContextGetGlobalObject(_ctx); - + JSValueRef exception = NULL; if (event.dom) { @@ -199,8 +207,9 @@ void JSCDataModel::setEvent(const Event& event) { handleException(exception); } } - - JSObjectSetProperty(_ctx, globalObject, JSStringCreateWithUTF8CString("_event"), eventObj, kJSPropertyAttributeDontDelete, &exception); + JSStringRef eventName = JSStringCreateWithUTF8CString("_event"); + JSObjectSetProperty(_ctx, globalObject, eventName, eventObj, kJSPropertyAttributeDontDelete, &exception); + JSStringRelease(eventName); if (exception) handleException(exception); @@ -365,7 +374,7 @@ bool JSCDataModel::isDeclared(const std::string& expr) { } void JSCDataModel::eval(const Element& scriptElem, - const std::string& expr) { + const std::string& expr) { evalAsValue(expr); } @@ -511,7 +520,9 @@ JSValueRef JSCDataModel::jsPrint(JSContextRef ctx, JSObjectRef function, JSObjec char* buffer = new char[maxSize]; JSStringGetUTF8CString(stringRef, buffer, maxSize); + JSStringRelease(stringRef); std::string msg(buffer); + free(buffer); std::cout << msg; } @@ -532,7 +543,10 @@ JSValueRef JSCDataModel::jsIn(JSContextRef ctx, JSObjectRef function, JSObjectRe char* buffer = new char[maxSize]; JSStringGetUTF8CString(stringRef, buffer, maxSize); + JSStringRelease(stringRef); std::string stateName(buffer); + free(buffer); + if (Interpreter::isMember(INSTANCE->_interpreter->getState(stateName), INSTANCE->_interpreter->getConfiguration())) { continue; } @@ -579,31 +593,31 @@ void JSCDataModel::jsIOProcessorListProps(JSContextRef ctx, JSObjectRef object, JSStringRef ioProcName = JSStringCreateWithUTF8CString(ioProcIter->first.c_str()); JSPropertyNameAccumulatorAddName(propertyNames, ioProcName); ioProcIter++; - } + } } - + bool JSCDataModel::jsInvokerHasProp(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { JSCDataModel* INSTANCE = (JSCDataModel*)JSObjectGetPrivate(object); std::map invokers = INSTANCE->_interpreter->getInvokers(); - + size_t maxSize = JSStringGetMaximumUTF8CStringSize(propertyName); char buffer[maxSize]; JSStringGetUTF8CString(propertyName, buffer, maxSize); std::string prop(buffer); - + return invokers.find(prop) != invokers.end(); } JSValueRef JSCDataModel::jsInvokerGetProp(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { JSCDataModel* INSTANCE = (JSCDataModel*)JSObjectGetPrivate(object); std::map invokers = INSTANCE->_interpreter->getInvokers(); - + size_t maxSize = JSStringGetMaximumUTF8CStringSize(propertyName); char buffer[maxSize]; JSStringGetUTF8CString(propertyName, buffer, maxSize); std::string prop(buffer); - + if (invokers.find(prop) != invokers.end()) { return INSTANCE->getDataAsValue(invokers.find(prop)->second.getDataModelVariables()); } @@ -613,13 +627,14 @@ JSValueRef JSCDataModel::jsInvokerGetProp(JSContextRef ctx, JSObjectRef object, void JSCDataModel::jsInvokerListProps(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames) { JSCDataModel* INSTANCE = (JSCDataModel*)JSObjectGetPrivate(object); std::map invokers = INSTANCE->_interpreter->getInvokers(); - + std::map::const_iterator invokerIter = invokers.begin(); while(invokerIter != invokers.end()) { JSStringRef invokeName = JSStringCreateWithUTF8CString(invokerIter->first.c_str()); JSPropertyNameAccumulatorAddName(propertyNames, invokeName); + JSStringRelease(invokeName); invokerIter++; - } + } } } \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index 9e70a8f..c5e9587 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -43,7 +43,7 @@ public: virtual void popContext(); virtual void eval(const Arabica::DOM::Element& scriptElem, - const std::string& expr); + const std::string& expr); virtual std::string evalAsString(const std::string& expr); virtual bool evalAsBool(const std::string& expr); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp index 4de0efa..6ceb642 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp @@ -22,8 +22,11 @@ JSStaticFunction JSCAttr::staticFunctions[] = { JSValueRef JSCAttr::nameAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCAttrPrivate* privData = (struct JSCAttrPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getName().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } @@ -36,8 +39,11 @@ JSValueRef JSCAttr::specifiedAttrGetter(JSContextRef ctx, JSObjectRef object, JS JSValueRef JSCAttr::valueAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCAttrPrivate* privData = (struct JSCAttrPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getValue().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp index 46dbdae..c7ce20a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp @@ -24,8 +24,11 @@ JSStaticFunction JSCCharacterData::staticFunctions[] = { JSValueRef JSCCharacterData::dataAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getData().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } @@ -68,6 +71,7 @@ JSValueRef JSCCharacterData::substringDataCallback(JSContextRef ctx, JSObjectRef JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); return jscRetVal; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp index bd66f8c..1b5aaef 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp @@ -4,7 +4,12 @@ namespace Arabica { namespace DOM { JSCDOM::JSCDOM() { + xpath = NULL; +} +JSCDOM::~JSCDOM() { + if (xpath) + delete(xpath); } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h index 2cd30f6..e2b8a4d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h @@ -17,7 +17,7 @@ namespace DOM { class JSCDOM { public: JSCDOM(); - virtual ~JSCDOM() { }; + virtual ~JSCDOM(); Arabica::XPath::XPath* xpath; }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp index 07bfbc1..954f748 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp @@ -24,8 +24,11 @@ JSStaticFunction JSCDocumentType::staticFunctions[] = { JSValueRef JSCDocumentType::nameAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCDocumentTypePrivate* privData = (struct JSCDocumentTypePrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getName().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } @@ -65,22 +68,31 @@ JSValueRef JSCDocumentType::notationsAttrGetter(JSContextRef ctx, JSObjectRef ob JSValueRef JSCDocumentType::publicIdAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCDocumentTypePrivate* privData = (struct JSCDocumentTypePrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getPublicId().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCDocumentType::systemIdAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCDocumentTypePrivate* privData = (struct JSCDocumentTypePrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getSystemId().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCDocumentType::internalSubsetAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCDocumentTypePrivate* privData = (struct JSCDocumentTypePrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getInternalSubset().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp index aa4b242..ce77091 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp @@ -35,8 +35,11 @@ JSStaticFunction JSCElement::staticFunctions[] = { JSValueRef JSCElement::tagNameAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getTagName().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCElement::getAttributeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { @@ -63,6 +66,7 @@ JSValueRef JSCElement::getAttributeCallback(JSContextRef ctx, JSObjectRef functi JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); return jscRetVal; } @@ -276,6 +280,7 @@ JSValueRef JSCElement::getAttributeNSCallback(JSContextRef ctx, JSObjectRef func JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); return jscRetVal; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.cpp index 9466f27..6b51ad0 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.cpp @@ -20,22 +20,31 @@ JSStaticFunction JSCEntity::staticFunctions[] = { JSValueRef JSCEntity::publicIdAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCEntityPrivate* privData = (struct JSCEntityPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getPublicId().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCEntity::systemIdAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCEntityPrivate* privData = (struct JSCEntityPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getSystemId().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCEntity::notationNameAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCEntityPrivate* privData = (struct JSCEntityPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getNotationName().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp index fc7513b..0e84442 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp @@ -53,15 +53,21 @@ JSStaticFunction JSCNode::staticFunctions[] = { JSValueRef JSCNode::nodeNameAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getNodeName().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCNode::nodeValueAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getNodeValue().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } @@ -207,15 +213,21 @@ JSValueRef JSCNode::ownerDocumentAttrGetter(JSContextRef ctx, JSObjectRef object JSValueRef JSCNode::namespaceURIAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getNamespaceURI().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCNode::prefixAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getPrefix().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } @@ -235,8 +247,11 @@ bool JSCNode::prefixAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRe JSValueRef JSCNode::localNameAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getLocalName().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCNode::ELEMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.cpp index 35cdc61..8ea57ff 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.cpp @@ -19,15 +19,21 @@ JSStaticFunction JSCNotation::staticFunctions[] = { JSValueRef JSCNotation::publicIdAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCNotationPrivate* privData = (struct JSCNotationPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getPublicId().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCNotation::systemIdAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCNotationPrivate* privData = (struct JSCNotationPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getSystemId().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp index 037af1b..d60c39b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp @@ -19,15 +19,21 @@ JSStaticFunction JSCProcessingInstruction::staticFunctions[] = { JSValueRef JSCProcessingInstruction::targetAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCProcessingInstructionPrivate* privData = (struct JSCProcessingInstructionPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getTarget().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCProcessingInstruction::dataAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCProcessingInstructionPrivate* privData = (struct JSCProcessingInstructionPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->getData().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp index 9b6f34f..de3a93f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp @@ -7,19 +7,18 @@ namespace DOM { JSClassRef JSCSCXMLEvent::Tmpl; JSStaticValue JSCSCXMLEvent::staticValues[] = { + { "type", typeCustomAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "name", nameAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "origin", originAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "origintype", origintypeAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "raw", rawAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "invokeid", invokeidAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "dom", domAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "origintype", origintypeAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - - { "type", typeCustomAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "sendid", sendidCustomAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "invokeid", invokeidAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, - { "INTERNAL", INTERNALConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum }, - { "EXTERNAL", EXTERNALConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum }, - { "PLATFORM", PLATFORMConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum }, + { "INTERNAL", INTERNALConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "EXTERNAL", EXTERNALConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "PLATFORM", PLATFORMConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; @@ -29,8 +28,11 @@ JSStaticFunction JSCSCXMLEvent::staticFunctions[] = { JSValueRef JSCSCXMLEvent::nameAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCSCXMLEventPrivate* privData = (struct JSCSCXMLEventPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->name.c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } @@ -40,7 +42,9 @@ JSValueRef JSCSCXMLEvent::originAttrGetter(JSContextRef ctx, JSObjectRef object, if (privData->nativeObj->origin.length() == 0) return JSValueMakeUndefined(ctx); JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->origin.c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } @@ -50,7 +54,9 @@ JSValueRef JSCSCXMLEvent::origintypeAttrGetter(JSContextRef ctx, JSObjectRef obj if (privData->nativeObj->origintype.length() == 0) return JSValueMakeUndefined(ctx); JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->origintype.c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } @@ -60,7 +66,9 @@ JSValueRef JSCSCXMLEvent::rawAttrGetter(JSContextRef ctx, JSObjectRef object, JS if (privData->nativeObj->raw.length() == 0) return JSValueMakeUndefined(ctx); JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->raw.c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } @@ -87,7 +95,9 @@ JSValueRef JSCSCXMLEvent::invokeidAttrGetter(JSContextRef ctx, JSObjectRef objec if (privData->nativeObj->invokeid.length() == 0) return JSValueMakeUndefined(ctx); JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->invokeid.c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCSCXMLEvent::INTERNALConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp index de81244..1033034 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp @@ -21,8 +21,10 @@ JSValueRef JSCSCXMLEvent::typeCustomAttrGetter(JSContextRef ctx, JSObjectRef thi stringRef = JSStringCreateWithUTF8CString("undefined"); break; } - - return JSValueMakeString(ctx, stringRef); + + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } JSValueRef JSCSCXMLEvent::sendidCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { @@ -33,7 +35,9 @@ JSValueRef JSCSCXMLEvent::sendidCustomAttrGetter(JSContextRef ctx, JSObjectRef t return JSValueMakeUndefined(ctx); } else { stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->sendid.c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp index 4ac7d17..69b7969 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp @@ -32,8 +32,11 @@ JSValueRef JSCXPathResult::numberValueAttrGetter(JSContextRef ctx, JSObjectRef o JSValueRef JSCXPathResult::stringValueAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCXPathResultPrivate* privData = (struct JSCXPathResultPrivate*)JSObjectGetPrivate(object); + JSStringRef stringRef = JSStringCreateWithUTF8CString(privData->nativeObj->asString().c_str()); - return JSValueMakeString(ctx, stringRef); + JSValueRef retVal = JSValueMakeString(ctx, stringRef); + JSStringRelease(stringRef); + return retVal; } @@ -81,6 +84,7 @@ JSValueRef JSCXPathResult::asStringCallback(JSContextRef ctx, JSObjectRef functi JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); return jscRetVal; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 2eb41db..f912455 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -174,7 +174,7 @@ void V8DataModel::setEvent(const Event& event) { nameListIter++; } } - if (eventCopy.data > 0) { + if (eventCopy.data) { eventObj->Set(v8::String::New("data"), getDataAsValue(eventCopy.data)); // set data part of _event } else { // test 343 / test 488 diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp index 53eaffa..e351b1d 100644 --- a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp +++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp @@ -62,7 +62,7 @@ void NULLDataModel::setForeach(const std::string& item, } void NULLDataModel::eval(const Arabica::DOM::Element& scriptElem, - const std::string& expr) { + const std::string& expr) { } bool NULLDataModel::isDeclared(const std::string& expr) { diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.h b/src/uscxml/plugins/datamodel/null/NULLDataModel.h index 924bc8c..b86c01c 100644 --- a/src/uscxml/plugins/datamodel/null/NULLDataModel.h +++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.h @@ -55,7 +55,7 @@ public: virtual bool isDeclared(const std::string& expr); virtual void eval(const Arabica::DOM::Element& scriptElem, - const std::string& expr); + const std::string& expr); virtual std::string evalAsString(const std::string& expr); virtual bool evalAsBool(const std::string& expr); virtual double evalAsNumber(const std::string& expr); diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index 462b661..a52af4b 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -13,7 +13,7 @@ _dmPtr = this; #define PL_MODULE \ _interpreter.getSessionId().c_str() \ - + #define UNSET_PL_ENGINE(dm) \ PL_set_engine(NULL, NULL); @@ -49,7 +49,7 @@ SWIDataModel::~SWIDataModel() { _swiEngines.erase(this); } } - + boost::shared_ptr SWIDataModel::create(InterpreterImpl* interpreter) { boost::shared_ptr dm = boost::shared_ptr(new SWIDataModel()); dm->_interpreter = interpreter; @@ -76,18 +76,18 @@ boost::shared_ptr SWIDataModel::create(InterpreterImpl* interpret } else { LOG(WARNING) << "Instantiating more than one SWI prolog datamodel will lead to weird effects as I cannot seperate the environments"; } - + PL_set_engine(PL_ENGINE_CURRENT, &engine); - + // load SWI XML parser try { PlCall("use_module", PlCompound("library", PlTerm("sgml"))); } catch (PlException plex) { - + LOG(ERROR) << "Cannot load prolog sgml module - make sure you have it installed in your prolog runtime: " << (char*)plex; throw plex; } - + // load json parser try { PlCall("use_module", PlCompound("library", PlTerm("http/json"))); @@ -100,11 +100,11 @@ boost::shared_ptr SWIDataModel::create(InterpreterImpl* interpret } else { engine = PL_create_engine(NULL); } - + assert(engine); - _swiEngines[dm.get()] = engine; + _swiEngines[dm.get()] = engine; _dmPtr = dm.get(); - + int rc = PL_set_engine(engine, NULL); assert(rc == PL_ENGINE_SET); @@ -119,7 +119,7 @@ boost::shared_ptr SWIDataModel::create(InterpreterImpl* interpret boost::replace_all(_plModule, "7", "n"); boost::replace_all(_plModule, "8", "o"); boost::replace_all(_plModule, "9", "p"); - + // use atoms for double quoted PlCall("set_prolog_flag(double_quotes,atom)."); diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h index b4532cf..123e938 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h @@ -52,8 +52,8 @@ public: virtual void init(const std::string& location, const Data& data); virtual void eval(const Arabica::DOM::Element& scriptElem, - const std::string& expr); - + const std::string& expr); + virtual bool isDeclared(const std::string& expr); virtual Data getStringAsData(const std::string& content); diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp index 1f6a7cc..c38aef3 100644 --- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp +++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp @@ -300,7 +300,7 @@ bool XPathDataModel::isValidIdentifier(const std::string& identifier) { void XPathDataModel::eval(const Arabica::DOM::Element& scriptElem, - const std::string& expr) { + const std::string& expr) { XPathValue result = _xpath.evaluate_expr(expr, _doc); } diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h index 761661a..240c62c 100644 --- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h +++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h @@ -87,7 +87,7 @@ public: virtual void popContext(); virtual void eval(const Arabica::DOM::Element& scriptElem, - const std::string& expr); + const std::string& expr); virtual void assign(const Arabica::DOM::Element& assignElem, const Arabica::DOM::Document& doc, const std::string& content); diff --git a/src/uscxml/plugins/invoker/CMakeLists.txt b/src/uscxml/plugins/invoker/CMakeLists.txt index 67d356a..4f13aaf 100644 --- a/src/uscxml/plugins/invoker/CMakeLists.txt +++ b/src/uscxml/plugins/invoker/CMakeLists.txt @@ -147,6 +147,27 @@ if (LIBICAL_FOUND) endif() +# location invoker + +if (CORELOCATION_LIBRARY AND OFF) + file(GLOB_RECURSE LOCATION_INVOKER + location/CoreLocation/*.cpp + location/CoreLocation/*.mm + location/CoreLocation/*.h + ) + source_group("Invoker\\location" FILES ${LOCATION_INVOKER}) + if (BUILD_AS_PLUGINS) + add_library( + invoker_location SHARED + ${LOCATION_INVOKER}) + target_link_libraries(invoker_location uscxml) + set_target_properties(invoker_location PROPERTIES FOLDER "Plugin Invoker") + else() + list (APPEND USCXML_FILES ${LOCATION_INVOKER}) + endif() +endif() + + # UMUNDO invoker if (UMUNDO_FOUND) diff --git a/src/uscxml/plugins/invoker/calendar/CalendarInvoker.cpp b/src/uscxml/plugins/invoker/calendar/CalendarInvoker.cpp index 7ea3fc3..947c86c 100644 --- a/src/uscxml/plugins/invoker/calendar/CalendarInvoker.cpp +++ b/src/uscxml/plugins/invoker/calendar/CalendarInvoker.cpp @@ -16,14 +16,42 @@ bool connect(pluma::Host& host) { #endif CalendarInvoker::CalendarInvoker() { + _icalSet = NULL; + _icalComp = NULL; } CalendarInvoker::~CalendarInvoker() { + tthread::lock_guard lock(_mutex); + std::set::iterator _eventIdIter = _eventIds.begin(); + while(_eventIdIter != _eventIds.end()) { + _interpreter->getDelayQueue()->cancelEvent(*_eventIdIter); + _eventIds.erase(_eventIdIter++); + + } + + std::map::iterator eventIter = _events.begin(); + while(eventIter != _events.end()) { + delete eventIter->second; + eventIter++; + } + + if (_icalComp) + icalcomponent_free(_icalComp); }; boost::shared_ptr CalendarInvoker::create(InterpreterImpl* interpreter) { boost::shared_ptr invoker = boost::shared_ptr(new CalendarInvoker()); invoker->_interpreter = interpreter; + + icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); + +// invoker->_calFile = URL::tmpFile(); +// invoker->_icalSet = icalfileset_new(invoker->_calFile.c_str()); + +// if (!invoker->_icalSet) { +// LOG(WARNING) << "Could not create new ical fileset: " << icalerror_perror(); +// } + return invoker; } @@ -33,12 +61,567 @@ Data CalendarInvoker::getDataModelVariables() { } void CalendarInvoker::send(const SendRequest& req) { + tthread::lock_guard lock(_mutex); } void CalendarInvoker::cancel(const std::string sendId) { + tthread::lock_guard lock(_mutex); + std::set::iterator _eventIdIter = _eventIds.begin(); + while(_eventIdIter != _eventIds.end()) { + _interpreter->getDelayQueue()->cancelEvent(*_eventIdIter); + _eventIds.erase(_eventIdIter++); + } } void CalendarInvoker::invoke(const InvokeRequest& req) { + tthread::lock_guard lock(_mutex); + + _icalComp = addIcal(req.content); +// dumpComponent(_icalComp); + setupEvents(_icalComp); + +} + +icalcomponent* CalendarInvoker::addIcal(const std::string& icalString) { + + icalcomponent* root = icalparser_parse_string(icalString.c_str()); + if (!root) { + LOG(WARNING) << "Could not parse ical data: " << icalerror_perror(); + return NULL; + } +// icalerrorenum err; +// err = icalset_add_component(_icalSet, root); +// icalfileset_commit(_icalSet); + + return root; +} + +void CalendarInvoker::setupEvents(icalcomponent* comp) { +// dumpComponent(comp); + + switch (icalcomponent_isa(comp)) { + case ICAL_VCALENDAR_COMPONENT: + case ICAL_XROOT_COMPONENT: + break; + case ICAL_VALARM_COMPONENT: { + break; + } + case ICAL_VEVENT_COMPONENT: { + // event to map + CalendarEvent* event = new CalendarEvent(comp); + _events[toStr((uintptr_t)event)] = event; + queueEvent(event); + break; + } + default: +// dumpComponent(comp); + break; + } + + icalcomponent* child = icalcomponent_get_first_component(comp, ICAL_ANY_COMPONENT); + while(child) { + setupEvents(child); + child = icalcomponent_get_next_component(comp, ICAL_ANY_COMPONENT); + } + +} + +void CalendarInvoker::queueEvent(CalendarEvent* event) { + if (_events.find(toStr((uintptr_t)event)) == _events.end()) { + _events[toStr((uintptr_t)event)] = event; + } + time_t now = time(NULL); + struct icaltime_span span; + + if (event->_nextSpan.start > 0) { + span = event->getNextDuration(event->_nextSpan.start + 1); + } else { + span = event->getNextDuration(now); + } + +#if 0 + if (span.end > 0) { + std::cout << "\t\t" << ctime(&span.start); + std::cout << "\t\t" << ctime(&span.end); + span = event->getNextDuration(span.end); + } +#endif + + if (span.start <= 0 || span.end <= 0) { + event->_nextSpan.start = 0; + event->_nextSpan.end = 0; + return; + } + + int beginSecs = span.start - now; + int endSecs = span.end - now; + + if (beginSecs > endSecs) { + LOG(WARNING) << "Event ends before it starts"; + return; + } + + event->_nextSpan = span; + + std::string beginEventId = event->getId() + "." + toStr(span.start) + ".started"; + std::string endEventId = event->getId() + "." + toStr(span.end) + ".ended"; + +#if 1 + beginSecs = 1; + endSecs = 2; +#endif + if (beginSecs > 0) { + _interpreter->getDelayQueue()->addEvent(beginEventId, CalendarInvoker::raiseEvent, beginSecs * 1000, this); + _eventIds.insert(beginEventId); + } else { + raiseEvent(this, beginEventId); + } + _interpreter->getDelayQueue()->addEvent(endEventId, CalendarInvoker::raiseEvent, endSecs * 1000, this); + _eventIds.insert(endEventId); + +} + +void CalendarInvoker::raiseEvent(void* userdata, const std::string eventId) { + CalendarInvoker* INSTANCE = (CalendarInvoker*)userdata; + tthread::lock_guard lock(INSTANCE->_mutex); + + std::string address = eventId.substr(0, eventId.find_first_of(".")); + + if (INSTANCE->_events.find(address) == INSTANCE->_events.end()) { + LOG(WARNING) << "No such event: " << eventId; + return; + } + + if(INSTANCE->_eventIds.find(eventId) != INSTANCE->_eventIds.end()) { + INSTANCE->_eventIds.erase(eventId); + } + + CalendarEvent* calEvent = INSTANCE->_events[address]; + Event event; + + event.data = *calEvent; + if (boost::ends_with(eventId, ".started")) { + event.name = "event.started." + calEvent->getId(); + assert(!calEvent->_active); + calEvent->_active = true; + } else { + event.name = "event.ended." + calEvent->getId(); + assert(calEvent->_active); + calEvent->_active = false; + } + INSTANCE->returnEvent(event); + + // event ended, reschedule next event + if (boost::ends_with(eventId, ".ended")) + INSTANCE->queueEvent(calEvent); } +/** + * Get the next duration for this event starting no earlier + * than the given time. + */ +icaltime_span CalendarEvent::getNextDuration(time_t time) { + if (!_icalComp) + return icaltime_span_new(icaltime_null_time(), icaltime_null_time(), 0); + + // see icalcomponent_foreach_recurrence + icalproperty *rrule; + + icaltimetype calTime = icaltime_from_timet_with_zone(time, 0, 0); + + // actual occurence, without reocurrence + if (!icalproperty_recurrence_is_excluded(_icalComp, &_dtstart, &_dtend)) { + if (icaltime_compare(_dtstart, calTime) >= 0) { + // start is still in the future + return icaltime_span_new(_dtstart, _dtend, 0); + } + } + + icaltime_span recDur = icaltime_span_new(icaltime_null_time(), icaltime_null_time(), 0); + + // iterate all rrules + for (rrule = icalcomponent_get_first_property(_icalComp, ICAL_RRULE_PROPERTY); + rrule != NULL; + rrule = icalcomponent_get_next_property(_icalComp, ICAL_RRULE_PROPERTY)) { + + struct icalrecurrencetype recurType = icalproperty_get_rrule(rrule); + icalrecur_iterator *ritr; + struct icaltimetype rtime; + + // do we have an old iterator that has not yet passed time? + if (_recIters.find(rrule) != _recIters.end()) { + if (_recIters[rrule].second > time) { + icalrecur_iterator_free(_recIters[rrule].first); + _recIters[rrule].first = icalrecur_iterator_new(recurType, _dtstart); + + // skip initial non-reoccurence + if(_recIters[rrule].first) + rtime = icalrecur_iterator_next(_recIters[rrule].first); + + } + ritr = _recIters[rrule].first; + } else { + // create a new iterator for this rrule + _recIters[rrule] = std::make_pair(icalrecur_iterator_new(recurType, _dtstart), 0); + ritr = _recIters[rrule].first; + } + +// std::cout << icalrecurrencetype_as_string(&recurType) << std::endl; + + while (ritr) { + rtime = icalrecur_iterator_next(ritr); + +#if 0 + time_t tt = icaltime_as_timet(rtime); + std::cout << "\t\t" << ctime(&tt); +#endif + + if (icaltime_is_null_time(rtime)) { + // remove iterator + icalrecur_iterator_free(_recIters[rrule].first); + _recIters.erase(rrule); + break; // for next rule + } + _recIters[rrule].second = icaltime_as_timet(rtime); + + if (icaltime_compare(rtime, calTime) < 0) + continue; // until we are after given time + + if (icalproperty_recurrence_is_excluded(_icalComp, &_dtstart, &rtime)) + continue; + + icaltime_span thisDur = icaltime_span_new(rtime, rtime, 1); + thisDur.end += _dtduration; + + if (recDur.start == 0 || thisDur.start < recDur.start) { + // update soonest reoccurence with the one from this rule + recDur = thisDur; + } + break; // we are after the event + } + } + return recDur; +} + +CalendarEvent::~CalendarEvent() { + std::map >::iterator recItersIter = _recIters.begin(); + while(recItersIter != _recIters.end()) { + icalrecur_iterator_free(recItersIter->second.first); + recItersIter++; + } +} + +CalendarEvent::CalendarEvent(icalcomponent* icalComp) { + _nextSpan.start = 0; + _nextSpan.end = 0; + _icalComp = NULL; + _active = false; + + + _dtstart = icalcomponent_get_dtstart(icalComp); + _dtend = icalcomponent_get_dtend(icalComp); + + if (!icaltime_is_valid_time(_dtstart)) { + LOG(WARNING) << "Start of event not a valid time"; + return; + } + + if (!icaltime_is_valid_time(_dtend)) { + LOG(WARNING) << "End of event not a valid time"; + return; + } + + _dtduration = icaldurationtype_as_int(icaltime_subtract(_dtend, _dtstart)); + + if (_dtduration <= 0) { + LOG(WARNING) << "Event has negative or zero duration"; + return; + } + + _icalComp = icalComp; + + // initialize all iterators - not really needed anymore + for (icalproperty* rrule = icalcomponent_get_first_property(_icalComp, ICAL_RRULE_PROPERTY); + rrule != NULL; + rrule = icalcomponent_get_next_property(_icalComp, ICAL_RRULE_PROPERTY)) { + + struct icalrecurrencetype recurType = icalproperty_get_rrule(rrule); + icalrecur_iterator *ritr = icalrecur_iterator_new(recurType, _dtstart); + + _recIters[rrule] = std::make_pair(ritr, 0); + } + + +} + +CalendarEvent::operator Data() { + Data data; + data = CalendarInvoker::toData(_icalComp); + return data; +} + +Data CalendarInvoker::toData(icalcomponent* comp) { + Data data; + data.compound["kind"] = Data(icalcomponent_kind_to_string(icalcomponent_isa(comp)), Data::VERBATIM); + + // iterate all properties + icalproperty* prop = icalcomponent_get_first_property(comp, ICAL_ANY_PROPERTY); + while(prop) { + std::string propName = icalproperty_kind_to_string(icalproperty_isa(prop)); + boost::to_lower(propName); + +#if 0 + // iterate all parameters + icalparameter* para = icalproperty_get_first_parameter(prop, ICAL_ANY_PARAMETER); + while(para) { + std::string paraName = icalparameter_kind_to_string(icalparameter_isa(para)); + + switch(icalparameter_get_value(para)) { + case ICAL_VALUE_X: + data.compound[propName].compound[paraName] = Data(icalparameter_get_x(para), Data::VERBATIM); + break; + case ICAL_VALUE_BOOLEAN: + case ICAL_VALUE_BINARY: + case ICAL_VALUE_DATE: + case ICAL_VALUE_DURATION: + case ICAL_VALUE_FLOAT: + case ICAL_VALUE_INTEGER: + case ICAL_VALUE_PERIOD: + case ICAL_VALUE_RECUR: + case ICAL_VALUE_TEXT: + case ICAL_VALUE_URI: + case ICAL_VALUE_ERROR: + case ICAL_VALUE_DATETIME: + case ICAL_VALUE_UTCOFFSET: + case ICAL_VALUE_CALADDRESS: + case ICAL_VALUE_NONE: + data.compound[propName].compound[paraName] = Data("", Data::VERBATIM); + break; + } + + para = icalproperty_get_next_parameter(prop, ICAL_ANY_PARAMETER); + } + data.compound[propName].compound["value"] = Data(icalproperty_get_value_as_string(prop), Data::VERBATIM); +#endif +#if 0 + data.compound[propName] = Data(icalproperty_as_ical_string(prop), Data::VERBATIM); +#endif + data.compound[propName] = Data(icalproperty_get_value_as_string(prop), Data::VERBATIM); + + prop = icalcomponent_get_next_property(comp, ICAL_ANY_PROPERTY); + } + + + icalcomponent* child = icalcomponent_get_first_component(comp, ICAL_ANY_COMPONENT); + while(child) { + data.compound["childs"].array.push_back(toData(child)); + child = icalcomponent_get_next_component(comp, ICAL_ANY_COMPONENT); + } + + return data; +} + +void CalendarInvoker::dumpComponent(icalcomponent* comp) { + std::cout << icalcomponent_kind_to_string(icalcomponent_isa(comp)) << std::endl; + + struct icaltimetype start, end; + time_t tt; + + icalproperty *startProp = icalcomponent_get_first_property(comp, ICAL_DTSTART_PROPERTY); + if (startProp) { + start = icalproperty_get_dtstart(startProp); + } + + icalproperty *endProp = icalcomponent_get_first_property(comp, ICAL_DTEND_PROPERTY); + if (endProp) { + end = icalproperty_get_dtend(endProp); + } + + icalproperty *prop = icalcomponent_get_first_property(comp, ICAL_ANY_PROPERTY); + + while(prop) { + std::cout << "\t" << icalproperty_kind_to_string(icalproperty_isa(prop)) << std::endl; + switch (icalproperty_isa(prop)) { + case ICAL_ANY_PROPERTY: + case ICAL_ACKNOWLEDGED_PROPERTY: + case ICAL_ACTION_PROPERTY: + case ICAL_ALLOWCONFLICT_PROPERTY: + case ICAL_ATTACH_PROPERTY: + case ICAL_ATTENDEE_PROPERTY: + case ICAL_CALID_PROPERTY: + case ICAL_CALMASTER_PROPERTY: + case ICAL_CALSCALE_PROPERTY: + case ICAL_CAPVERSION_PROPERTY: + case ICAL_CARLEVEL_PROPERTY: + case ICAL_CARID_PROPERTY: + case ICAL_CATEGORIES_PROPERTY: + case ICAL_CLASS_PROPERTY: + case ICAL_CMD_PROPERTY: + case ICAL_COMMENT_PROPERTY: + case ICAL_COMPLETED_PROPERTY: + case ICAL_COMPONENTS_PROPERTY: + case ICAL_CONTACT_PROPERTY: + case ICAL_CREATED_PROPERTY: + case ICAL_CSID_PROPERTY: + case ICAL_DATEMAX_PROPERTY: + case ICAL_DATEMIN_PROPERTY: + case ICAL_DECREED_PROPERTY: + case ICAL_DEFAULTCHARSET_PROPERTY: + case ICAL_DEFAULTLOCALE_PROPERTY: + case ICAL_DEFAULTTZID_PROPERTY: + case ICAL_DEFAULTVCARS_PROPERTY: + case ICAL_DENY_PROPERTY: + break; + case ICAL_DESCRIPTION_PROPERTY: + std::cout << "\t\t" << icalproperty_get_description(prop) << std::endl; + break; + case ICAL_DTEND_PROPERTY: { + end = icalproperty_get_dtend(prop); + tt = icaltime_as_timet(start); + std::cout << "\t\t" << ctime(&tt) << std::endl; + break; + } + case ICAL_DTSTAMP_PROPERTY: + break; + case ICAL_DTSTART_PROPERTY: { + start = icalproperty_get_dtstart(prop); + tt = icaltime_as_timet(start); + std::cout << "\t\t" << ctime(&tt) << std::endl; + break; + } + case ICAL_DUE_PROPERTY: + case ICAL_DURATION_PROPERTY: + case ICAL_EXDATE_PROPERTY: + case ICAL_EXPAND_PROPERTY: + case ICAL_EXRULE_PROPERTY: + case ICAL_FREEBUSY_PROPERTY: + case ICAL_GEO_PROPERTY: + case ICAL_GRANT_PROPERTY: + case ICAL_ITIPVERSION_PROPERTY: + case ICAL_LASTMODIFIED_PROPERTY: + case ICAL_LOCATION_PROPERTY: + case ICAL_MAXCOMPONENTSIZE_PROPERTY: + case ICAL_MAXDATE_PROPERTY: + case ICAL_MAXRESULTS_PROPERTY: + case ICAL_MAXRESULTSSIZE_PROPERTY: + case ICAL_METHOD_PROPERTY: + case ICAL_MINDATE_PROPERTY: + case ICAL_MULTIPART_PROPERTY: + case ICAL_NAME_PROPERTY: + case ICAL_ORGANIZER_PROPERTY: + case ICAL_OWNER_PROPERTY: + case ICAL_PERCENTCOMPLETE_PROPERTY: + case ICAL_PERMISSION_PROPERTY: + case ICAL_PRIORITY_PROPERTY: + case ICAL_PRODID_PROPERTY: + case ICAL_QUERY_PROPERTY: + case ICAL_QUERYLEVEL_PROPERTY: + case ICAL_QUERYID_PROPERTY: + case ICAL_QUERYNAME_PROPERTY: + case ICAL_RDATE_PROPERTY: + case ICAL_RECURACCEPTED_PROPERTY: + case ICAL_RECUREXPAND_PROPERTY: + case ICAL_RECURLIMIT_PROPERTY: + case ICAL_RECURRENCEID_PROPERTY: + case ICAL_RELATEDTO_PROPERTY: + case ICAL_RELCALID_PROPERTY: + case ICAL_REPEAT_PROPERTY: + case ICAL_REQUESTSTATUS_PROPERTY: + case ICAL_RESOURCES_PROPERTY: + case ICAL_RESTRICTION_PROPERTY: + break; + case ICAL_RRULE_PROPERTY: { + // struct icaltimetype start = icaltime_from_timet(1,0); + // struct icaltimetype start = icalproperty_get_dtstart(icalcomponent_get_first_property(comp,ICAL_DTSTART_PROPERTY)); + + // struct icaltimetype end = icaltime_today(); + struct icalrecurrencetype recur = icalproperty_get_rrule(prop); + struct icaltimetype next; + + icalrecur_iterator* ritr; + for(ritr = icalrecur_iterator_new(recur,start), + next = icalrecur_iterator_next(ritr); + !icaltime_is_null_time(next); + next = icalrecur_iterator_next(ritr)) { + + tt = icaltime_as_timet(next); + printf(" %s",ctime(&tt )); + + } + icalrecur_iterator_free(ritr); + + break; + } + case ICAL_SCOPE_PROPERTY: + case ICAL_SEQUENCE_PROPERTY: + case ICAL_STATUS_PROPERTY: + case ICAL_STORESEXPANDED_PROPERTY: + case ICAL_SUMMARY_PROPERTY: + case ICAL_TARGET_PROPERTY: + case ICAL_TRANSP_PROPERTY: + case ICAL_TRIGGER_PROPERTY: + case ICAL_TZID_PROPERTY: + case ICAL_TZNAME_PROPERTY: + case ICAL_TZOFFSETFROM_PROPERTY: + case ICAL_TZOFFSETTO_PROPERTY: + case ICAL_TZURL_PROPERTY: + case ICAL_UID_PROPERTY: + case ICAL_URL_PROPERTY: + case ICAL_VERSION_PROPERTY: + case ICAL_X_PROPERTY: + case ICAL_XLICCLASS_PROPERTY: + case ICAL_XLICCLUSTERCOUNT_PROPERTY: + case ICAL_XLICERROR_PROPERTY: + case ICAL_XLICMIMECHARSET_PROPERTY: + case ICAL_XLICMIMECID_PROPERTY: + case ICAL_XLICMIMECONTENTTYPE_PROPERTY: + case ICAL_XLICMIMEENCODING_PROPERTY: + case ICAL_XLICMIMEFILENAME_PROPERTY: + case ICAL_XLICMIMEOPTINFO_PROPERTY: + case ICAL_NO_PROPERTY: + break; + } + prop = icalcomponent_get_next_property(comp, ICAL_ANY_PROPERTY); + } + + switch (icalcomponent_isa(comp)) { + case ICAL_NO_COMPONENT: + case ICAL_ANY_COMPONENT: + break; + case ICAL_XROOT_COMPONENT: { + icalcomponent* child = icalcomponent_get_first_component(comp, ICAL_ANY_COMPONENT); + while(child) { + dumpComponent(child); + child = icalcomponent_get_next_component(comp, ICAL_ANY_COMPONENT); + } + break; + } + case ICAL_XATTACH_COMPONENT: + case ICAL_VEVENT_COMPONENT: + case ICAL_VTODO_COMPONENT: + case ICAL_VJOURNAL_COMPONENT: + case ICAL_VCALENDAR_COMPONENT: + case ICAL_VAGENDA_COMPONENT: + case ICAL_VFREEBUSY_COMPONENT: + case ICAL_VALARM_COMPONENT: + case ICAL_XAUDIOALARM_COMPONENT: + case ICAL_XDISPLAYALARM_COMPONENT: + case ICAL_XEMAILALARM_COMPONENT: + case ICAL_XPROCEDUREALARM_COMPONENT: + case ICAL_VTIMEZONE_COMPONENT: + case ICAL_XSTANDARD_COMPONENT: + case ICAL_XDAYLIGHT_COMPONENT: + case ICAL_X_COMPONENT: + case ICAL_VSCHEDULE_COMPONENT: + case ICAL_VQUERY_COMPONENT: + case ICAL_VREPLY_COMPONENT: + case ICAL_VCAR_COMPONENT: + case ICAL_VCOMMAND_COMPONENT: + case ICAL_XLICINVALID_COMPONENT: + case ICAL_XLICMIMEPART_COMPONENT: + break; + } +} + + } \ No newline at end of file diff --git a/src/uscxml/plugins/invoker/calendar/CalendarInvoker.h b/src/uscxml/plugins/invoker/calendar/CalendarInvoker.h index 45dc8d0..3faf570 100644 --- a/src/uscxml/plugins/invoker/calendar/CalendarInvoker.h +++ b/src/uscxml/plugins/invoker/calendar/CalendarInvoker.h @@ -2,6 +2,10 @@ #define CALENDARINVOKER_H_W09J90F0 #include +extern "C" { +# include +# include +} #ifdef BUILD_AS_PLUGINS #include "uscxml/plugins/Plugins.h" @@ -9,6 +13,25 @@ namespace uscxml { +class CalendarEvent { +public: + CalendarEvent(icalcomponent* _icalComp); + ~CalendarEvent(); + icalcomponent* _icalComp; + icaltime_span _nextSpan; + bool _active; + struct icaltimetype _dtstart, _dtend; + time_t _dtduration; + + icaltime_span getNextDuration(time_t time); + std::string getId() { + return toStr((uintptr_t)this); + } + + std::map > _recIters; + operator Data(); +}; + class CalendarInvoker : public InvokerImpl { public: CalendarInvoker(); @@ -27,7 +50,23 @@ public: virtual void cancel(const std::string sendId); virtual void invoke(const InvokeRequest& req); + static void raiseEvent(void* userdata, const std::string eventId); + static Data toData(icalcomponent* comp); protected: + icalcomponent* addIcal(const std::string& icalString); + void setupEvents(icalcomponent* comp); + void queueEvent(CalendarEvent* event); + + void dumpComponent(icalcomponent* comp); + + tthread::recursive_mutex _mutex; + + std::string _calFile; + icalset* _icalSet; + icalcomponent* _icalComp; + + std::set _eventIds; + std::map _events; }; #ifdef BUILD_AS_PLUGINS diff --git a/src/uscxml/plugins/invoker/location/LocationInvoker.cpp b/src/uscxml/plugins/invoker/location/LocationInvoker.cpp deleted file mode 100644 index 9aeb6b4..0000000 --- a/src/uscxml/plugins/invoker/location/LocationInvoker.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "LocationInvoker.h" -#include - -#ifdef BUILD_AS_PLUGINS -#include -#endif - -namespace uscxml { - -#ifdef BUILD_AS_PLUGINS -PLUMA_CONNECTOR -bool connect(pluma::Host& host) { - host.add( new LocationInvokerProvider() ); - return true; -} -#endif - -LocationInvoker::LocationInvoker() { -} - -LocationInvoker::~LocationInvoker() { -}; - -boost::shared_ptr LocationInvoker::create(InterpreterImpl* interpreter) { - boost::shared_ptr invoker = boost::shared_ptr(new LocationInvoker()); - invoker->_interpreter = interpreter; - return invoker; -} - -Data LocationInvoker::getDataModelVariables() { - Data data; - return data; -} - -void LocationInvoker::send(const SendRequest& req) { -} - -void LocationInvoker::cancel(const std::string sendId) { -} - -void LocationInvoker::invoke(const InvokeRequest& req) { -} - -} \ No newline at end of file diff --git a/src/uscxml/plugins/invoker/location/LocationInvoker.h b/src/uscxml/plugins/invoker/location/LocationInvoker.h deleted file mode 100644 index 2eb4833..0000000 --- a/src/uscxml/plugins/invoker/location/LocationInvoker.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef LOCATIONINVOKER_H_W09J90F0 -#define LOCATIONINVOKER_H_W09J90F0 - -#include - -#ifdef BUILD_AS_PLUGINS -#include "uscxml/plugins/Plugins.h" -#endif - -namespace uscxml { - -class LocationInvoker : public InvokerImpl { -public: - LocationInvoker(); - virtual ~LocationInvoker(); - virtual boost::shared_ptr create(InterpreterImpl* interpreter); - - virtual std::set getNames() { - std::set names; - names.insert("location"); - names.insert("http://uscxml.tk.informatik.tu-darmstadt.de/#location"); - return names; - } - - virtual Data getDataModelVariables(); - virtual void send(const SendRequest& req); - virtual void cancel(const std::string sendId); - virtual void invoke(const InvokeRequest& req); - -protected: -}; - -#ifdef BUILD_AS_PLUGINS -PLUMA_INHERIT_PROVIDER(LocationInvoker, InvokerImpl); -#endif - -} - - -#endif /* end of include guard: LOCATIONINVOKER_H_W09J90F0 */ diff --git a/src/uscxml/plugins/invoker/miles/SpatialAudio.cpp b/src/uscxml/plugins/invoker/miles/SpatialAudio.cpp index 298b15f..fb91e40 100644 --- a/src/uscxml/plugins/invoker/miles/SpatialAudio.cpp +++ b/src/uscxml/plugins/invoker/miles/SpatialAudio.cpp @@ -70,11 +70,11 @@ void SpatialAudio::send(const SendRequest& req) { miles_audio_device_control(MILES_AUDIO_IO_OPENAL, _audioDev, MILES_AUDIO_DEVICE_CTRL_SET_POSITION, _pos); - + char* buffer = (char*)malloc(_audioDev->chunk_size); // skip wav header _dataStream.seekg(44); - + while(_dataStream.readsome(buffer, _audioDev->chunk_size) != 0) { int written = 0; while(written < _audioDev->chunk_size) { @@ -187,7 +187,7 @@ void SpatialAudio::getPosFromParams(const std::multimap& - compound() const; - inline ::google::protobuf::RepeatedPtrField< ::JSONProto >* - mutable_compound(); - - // optional string key = 2; - inline bool has_key() const; - inline void clear_key(); - static const int kKeyFieldNumber = 2; - inline const ::std::string& key() const; - inline void set_key(const ::std::string& value); - inline void set_key(const char* value); - inline void set_key(const char* value, size_t size); - inline ::std::string* mutable_key(); - inline ::std::string* release_key(); - inline void set_allocated_key(::std::string* key); - - // optional string atom = 3; - inline bool has_atom() const; - inline void clear_atom(); - static const int kAtomFieldNumber = 3; - inline const ::std::string& atom() const; - inline void set_atom(const ::std::string& value); - inline void set_atom(const char* value); - inline void set_atom(const char* value, size_t size); - inline ::std::string* mutable_atom(); - inline ::std::string* release_atom(); - inline void set_allocated_atom(::std::string* atom); - - // optional bool verbatim = 4; - inline bool has_verbatim() const; - inline void clear_verbatim(); - static const int kVerbatimFieldNumber = 4; - inline bool verbatim() const; - inline void set_verbatim(bool value); - - // @@protoc_insertion_point(class_scope:JSONProto) - private: - inline void set_has_key(); - inline void clear_has_key(); - inline void set_has_atom(); - inline void clear_has_atom(); - inline void set_has_verbatim(); - inline void clear_has_verbatim(); - - ::google::protobuf::UnknownFieldSet _unknown_fields_; - - ::google::protobuf::RepeatedPtrField< ::JSONProto > compound_; - ::std::string* key_; - ::std::string* atom_; - bool verbatim_; - - mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(4 + 31) / 32]; - - friend void protobuf_AddDesc_JSON_2eproto(); - friend void protobuf_AssignDesc_JSON_2eproto(); - friend void protobuf_ShutdownFile_JSON_2eproto(); - - void InitAsDefaultInstance(); - static JSONProto* default_instance_; +public: + JSONProto(); + virtual ~JSONProto(); + + JSONProto(const JSONProto& from); + + inline JSONProto& operator=(const JSONProto& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const JSONProto& default_instance(); + + void Swap(JSONProto* other); + + // implements Message ---------------------------------------------- + + JSONProto* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const JSONProto& from); + void MergeFrom(const JSONProto& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { + return _cached_size_; + } +private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; +public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .JSONProto compound = 1; + inline int compound_size() const; + inline void clear_compound(); + static const int kCompoundFieldNumber = 1; + inline const ::JSONProto& compound(int index) const; + inline ::JSONProto* mutable_compound(int index); + inline ::JSONProto* add_compound(); + inline const ::google::protobuf::RepeatedPtrField< ::JSONProto >& + compound() const; + inline ::google::protobuf::RepeatedPtrField< ::JSONProto >* + mutable_compound(); + + // optional string key = 2; + inline bool has_key() const; + inline void clear_key(); + static const int kKeyFieldNumber = 2; + inline const ::std::string& key() const; + inline void set_key(const ::std::string& value); + inline void set_key(const char* value); + inline void set_key(const char* value, size_t size); + inline ::std::string* mutable_key(); + inline ::std::string* release_key(); + inline void set_allocated_key(::std::string* key); + + // optional string atom = 3; + inline bool has_atom() const; + inline void clear_atom(); + static const int kAtomFieldNumber = 3; + inline const ::std::string& atom() const; + inline void set_atom(const ::std::string& value); + inline void set_atom(const char* value); + inline void set_atom(const char* value, size_t size); + inline ::std::string* mutable_atom(); + inline ::std::string* release_atom(); + inline void set_allocated_atom(::std::string* atom); + + // optional bool verbatim = 4; + inline bool has_verbatim() const; + inline void clear_verbatim(); + static const int kVerbatimFieldNumber = 4; + inline bool verbatim() const; + inline void set_verbatim(bool value); + + // @@protoc_insertion_point(class_scope:JSONProto) +private: + inline void set_has_key(); + inline void clear_has_key(); + inline void set_has_atom(); + inline void clear_has_atom(); + inline void set_has_verbatim(); + inline void clear_has_verbatim(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::google::protobuf::RepeatedPtrField< ::JSONProto > compound_; + ::std::string* key_; + ::std::string* atom_; + bool verbatim_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(4 + 31) / 32]; + + friend void protobuf_AddDesc_JSON_2eproto(); + friend void protobuf_AssignDesc_JSON_2eproto(); + friend void protobuf_ShutdownFile_JSON_2eproto(); + + void InitAsDefaultInstance(); + static JSONProto* default_instance_; }; // =================================================================== @@ -167,189 +169,189 @@ class JSONProto : public ::google::protobuf::Message { // repeated .JSONProto compound = 1; inline int JSONProto::compound_size() const { - return compound_.size(); + return compound_.size(); } inline void JSONProto::clear_compound() { - compound_.Clear(); + compound_.Clear(); } inline const ::JSONProto& JSONProto::compound(int index) const { - return compound_.Get(index); + return compound_.Get(index); } inline ::JSONProto* JSONProto::mutable_compound(int index) { - return compound_.Mutable(index); + return compound_.Mutable(index); } inline ::JSONProto* JSONProto::add_compound() { - return compound_.Add(); + return compound_.Add(); } inline const ::google::protobuf::RepeatedPtrField< ::JSONProto >& JSONProto::compound() const { - return compound_; + return compound_; } inline ::google::protobuf::RepeatedPtrField< ::JSONProto >* JSONProto::mutable_compound() { - return &compound_; + return &compound_; } // optional string key = 2; inline bool JSONProto::has_key() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return (_has_bits_[0] & 0x00000002u) != 0; } inline void JSONProto::set_has_key() { - _has_bits_[0] |= 0x00000002u; + _has_bits_[0] |= 0x00000002u; } inline void JSONProto::clear_has_key() { - _has_bits_[0] &= ~0x00000002u; + _has_bits_[0] &= ~0x00000002u; } inline void JSONProto::clear_key() { - if (key_ != &::google::protobuf::internal::kEmptyString) { - key_->clear(); - } - clear_has_key(); + if (key_ != &::google::protobuf::internal::kEmptyString) { + key_->clear(); + } + clear_has_key(); } inline const ::std::string& JSONProto::key() const { - return *key_; + return *key_; } inline void JSONProto::set_key(const ::std::string& value) { - set_has_key(); - if (key_ == &::google::protobuf::internal::kEmptyString) { - key_ = new ::std::string; - } - key_->assign(value); + set_has_key(); + if (key_ == &::google::protobuf::internal::kEmptyString) { + key_ = new ::std::string; + } + key_->assign(value); } inline void JSONProto::set_key(const char* value) { - set_has_key(); - if (key_ == &::google::protobuf::internal::kEmptyString) { - key_ = new ::std::string; - } - key_->assign(value); + set_has_key(); + if (key_ == &::google::protobuf::internal::kEmptyString) { + key_ = new ::std::string; + } + key_->assign(value); } inline void JSONProto::set_key(const char* value, size_t size) { - set_has_key(); - if (key_ == &::google::protobuf::internal::kEmptyString) { - key_ = new ::std::string; - } - key_->assign(reinterpret_cast(value), size); + set_has_key(); + if (key_ == &::google::protobuf::internal::kEmptyString) { + key_ = new ::std::string; + } + key_->assign(reinterpret_cast(value), size); } inline ::std::string* JSONProto::mutable_key() { - set_has_key(); - if (key_ == &::google::protobuf::internal::kEmptyString) { - key_ = new ::std::string; - } - return key_; + set_has_key(); + if (key_ == &::google::protobuf::internal::kEmptyString) { + key_ = new ::std::string; + } + return key_; } inline ::std::string* JSONProto::release_key() { - clear_has_key(); - if (key_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = key_; - key_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } + clear_has_key(); + if (key_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = key_; + key_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } } inline void JSONProto::set_allocated_key(::std::string* key) { - if (key_ != &::google::protobuf::internal::kEmptyString) { - delete key_; - } - if (key) { - set_has_key(); - key_ = key; - } else { - clear_has_key(); - key_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - } + if (key_ != &::google::protobuf::internal::kEmptyString) { + delete key_; + } + if (key) { + set_has_key(); + key_ = key; + } else { + clear_has_key(); + key_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + } } // optional string atom = 3; inline bool JSONProto::has_atom() const { - return (_has_bits_[0] & 0x00000004u) != 0; + return (_has_bits_[0] & 0x00000004u) != 0; } inline void JSONProto::set_has_atom() { - _has_bits_[0] |= 0x00000004u; + _has_bits_[0] |= 0x00000004u; } inline void JSONProto::clear_has_atom() { - _has_bits_[0] &= ~0x00000004u; + _has_bits_[0] &= ~0x00000004u; } inline void JSONProto::clear_atom() { - if (atom_ != &::google::protobuf::internal::kEmptyString) { - atom_->clear(); - } - clear_has_atom(); + if (atom_ != &::google::protobuf::internal::kEmptyString) { + atom_->clear(); + } + clear_has_atom(); } inline const ::std::string& JSONProto::atom() const { - return *atom_; + return *atom_; } inline void JSONProto::set_atom(const ::std::string& value) { - set_has_atom(); - if (atom_ == &::google::protobuf::internal::kEmptyString) { - atom_ = new ::std::string; - } - atom_->assign(value); + set_has_atom(); + if (atom_ == &::google::protobuf::internal::kEmptyString) { + atom_ = new ::std::string; + } + atom_->assign(value); } inline void JSONProto::set_atom(const char* value) { - set_has_atom(); - if (atom_ == &::google::protobuf::internal::kEmptyString) { - atom_ = new ::std::string; - } - atom_->assign(value); + set_has_atom(); + if (atom_ == &::google::protobuf::internal::kEmptyString) { + atom_ = new ::std::string; + } + atom_->assign(value); } inline void JSONProto::set_atom(const char* value, size_t size) { - set_has_atom(); - if (atom_ == &::google::protobuf::internal::kEmptyString) { - atom_ = new ::std::string; - } - atom_->assign(reinterpret_cast(value), size); + set_has_atom(); + if (atom_ == &::google::protobuf::internal::kEmptyString) { + atom_ = new ::std::string; + } + atom_->assign(reinterpret_cast(value), size); } inline ::std::string* JSONProto::mutable_atom() { - set_has_atom(); - if (atom_ == &::google::protobuf::internal::kEmptyString) { - atom_ = new ::std::string; - } - return atom_; + set_has_atom(); + if (atom_ == &::google::protobuf::internal::kEmptyString) { + atom_ = new ::std::string; + } + return atom_; } inline ::std::string* JSONProto::release_atom() { - clear_has_atom(); - if (atom_ == &::google::protobuf::internal::kEmptyString) { - return NULL; - } else { - ::std::string* temp = atom_; - atom_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - return temp; - } + clear_has_atom(); + if (atom_ == &::google::protobuf::internal::kEmptyString) { + return NULL; + } else { + ::std::string* temp = atom_; + atom_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + return temp; + } } inline void JSONProto::set_allocated_atom(::std::string* atom) { - if (atom_ != &::google::protobuf::internal::kEmptyString) { - delete atom_; - } - if (atom) { - set_has_atom(); - atom_ = atom; - } else { - clear_has_atom(); - atom_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); - } + if (atom_ != &::google::protobuf::internal::kEmptyString) { + delete atom_; + } + if (atom) { + set_has_atom(); + atom_ = atom; + } else { + clear_has_atom(); + atom_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + } } // optional bool verbatim = 4; inline bool JSONProto::has_verbatim() const { - return (_has_bits_[0] & 0x00000008u) != 0; + return (_has_bits_[0] & 0x00000008u) != 0; } inline void JSONProto::set_has_verbatim() { - _has_bits_[0] |= 0x00000008u; + _has_bits_[0] |= 0x00000008u; } inline void JSONProto::clear_has_verbatim() { - _has_bits_[0] &= ~0x00000008u; + _has_bits_[0] &= ~0x00000008u; } inline void JSONProto::clear_verbatim() { - verbatim_ = false; - clear_has_verbatim(); + verbatim_ = false; + clear_has_verbatim(); } inline bool JSONProto::verbatim() const { - return verbatim_; + return verbatim_; } inline void JSONProto::set_verbatim(bool value) { - set_has_verbatim(); - verbatim_ = value; + set_has_verbatim(); + verbatim_ = value; } diff --git a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp index 081842f..bbfdabd 100644 --- a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp +++ b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp @@ -59,12 +59,12 @@ void UmundoInvoker::send(const SendRequest& req) { LOG(ERROR) << "Cannot transform content to data object per datamodel"; return; } - + std::string type; if (req.params.find("type") != req.params.end()) { // we are supposed to build a typed object type = req.params.find("type")->second; - + const google::protobuf::Message* protoMsg = umundo::PBSerializer::getProto(type); if (protoMsg == NULL) { LOG(ERROR) << "No type '" << type << "' is known, pass a directory with proto .desc files via types param when invoking"; @@ -76,7 +76,7 @@ void UmundoInvoker::send(const SendRequest& req) { LOG(ERROR) << "Cannot create message from JSON - not sending"; return; } - + if (!_isService) { // add all s11n properties _pub->prepareMsg(&msg, type, pbMsg); @@ -90,12 +90,12 @@ void UmundoInvoker::send(const SendRequest& req) { void* rv = NULL; stub->callStubMethod(req.name, pbMsg, type, rv, ""); protobufToData(event.data, *(const google::protobuf::Message*)rv); - + event.name = _invokeId + ".reply." + req.name; event.origin = msg.getMeta("um.channel"); event.origintype = "umundo"; event.type = Event::EXTERNAL; - + returnEvent(event); svcIter++; } @@ -116,7 +116,7 @@ void UmundoInvoker::send(const SendRequest& req) { LOG(ERROR) << "Cannot invoke services with untyped JSON"; return; } - + } } catch (Event e) { LOG(ERROR) << "Syntax error when invoking umundo:" << std::endl << e << std::endl; @@ -125,7 +125,7 @@ void UmundoInvoker::send(const SendRequest& req) { } else { LOG(ERROR) << "Required JSON object in content" << std::endl; return; - } + } } void UmundoInvoker::cancel(const std::string sendId) { @@ -187,7 +187,7 @@ void UmundoInvoker::invoke(const InvokeRequest& req) { _pub->setGreeter(this); _sub->registerType("JSON", new JSONProto()); - + _node->addPublisher(*_pub); _node->addSubscriber(*_sub); @@ -237,7 +237,7 @@ void UmundoInvoker::receive(void* object, umundo::Message* msg) { if (object != NULL) { if (msg->getMeta().find("um.s11n.type") != msg->getMeta().end() && - boost::equals(msg->getMeta().find("um.s11n.type")->second, "JSON")) { + boost::equals(msg->getMeta().find("um.s11n.type")->second, "JSON")) { jsonbufToData(event.data, *(JSONProto*)object); } else { protobufToData(event.data, *(const google::protobuf::Message*)object); @@ -349,7 +349,7 @@ bool UmundoInvoker::jsonbufToData(Data& data, const JSONProto& json) { data.type = Data::INTERPRETED; } } - + return true; } @@ -485,7 +485,7 @@ bool UmundoInvoker::dataToJSONbuf(JSONProto* msg, Data& data) { } else if (!data.array.empty()) { const google::protobuf::FieldDescriptor* fieldDesc = desc->FindFieldByName("compound"); - std::list::iterator arrayIter = data.array.begin(); + std::list::iterator arrayIter = data.array.begin(); while(arrayIter != data.array.end()) { JSONProto* arrayMsg = (JSONProto*)reflect->AddMessage(msg, fieldDesc); dataToJSONbuf(arrayMsg, *arrayIter); diff --git a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h index 4d81e79..c013a52 100644 --- a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h +++ b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.h @@ -18,7 +18,7 @@ namespace uscxml { class Interpreter; - class UmundoInvoker : public InvokerImpl, public umundo::TypedReceiver, public umundo::ResultSet, public umundo::TypedGreeter { +class UmundoInvoker : public InvokerImpl, public umundo::TypedReceiver, public umundo::ResultSet, public umundo::TypedGreeter { public: UmundoInvoker(); virtual ~UmundoInvoker(); diff --git a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp index a18be8e..ddca2eb 100644 --- a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp @@ -61,7 +61,7 @@ void VoiceXMLInvoker::send(const SendRequest& req) { domSS << req.getFirstDOMElement(); start.content = domSS.str(); _interpreter->getDataModel().replaceExpressions(start.content); - + start.requestId = "asdf"; start.source = "asdf"; start.target = "umundo://mmi/jvoicexml"; diff --git a/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp index 4e2c01a..82e0a48 100644 --- a/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp @@ -92,7 +92,7 @@ bool XHTMLInvoker::httpRecvRequest(const HTTPServer::Request& req) { } else if(_invokeReq.data) { ss << _invokeReq.data; content = ss.str(); - } else if (_invokeReq.content.length() > 0){ + } else if (_invokeReq.content.length() > 0) { content = _invokeReq.content; } else { URL templateURL("templates/xhtml-invoker.html"); @@ -100,10 +100,10 @@ bool XHTMLInvoker::httpRecvRequest(const HTTPServer::Request& req) { templateURL.download(true); content = templateURL.getInContent(); } - + _interpreter->getDataModel().replaceExpressions(content); reply.content = content; - + // application/xhtml+xml reply.headers["Content-Type"] = "text/html; charset=utf-8"; // reply.headers["Content-Type"] = "application/xhtml+xml; charset=utf-8"; @@ -140,7 +140,7 @@ void XHTMLInvoker::send(const SendRequest& req) { if (json) { reqCopy.data = json; } - + if (!_longPoll) { _outQueue.push_back(reqCopy); return; @@ -154,7 +154,7 @@ void XHTMLInvoker::reply(const SendRequest& req, const HTTPServer::Request& long // is there JSON in the content? std::string content = req.content; - + if (req.dom) { std::stringstream ss; Arabica::DOM::Node content = req.dom.getDocumentElement(); diff --git a/test/samples/uscxml/test-calendar.scxml b/test/samples/uscxml/test-calendar.scxml new file mode 100644 index 0000000..a031d55 --- /dev/null +++ b/test/samples/uscxml/test-calendar.scxml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/src/test-arabica-parsing.cpp b/test/src/test-arabica-parsing.cpp index 2a09dd6..24c58ae 100644 --- a/test/src/test-arabica-parsing.cpp +++ b/test/src/test-arabica-parsing.cpp @@ -22,7 +22,7 @@ int main(int argc, char** argv) { Arabica::SAX2DOM::Parser domParser; Arabica::SAX::CatchErrorHandler errorHandler; domParser.setErrorHandler(errorHandler); - + if(!domParser.parse(inputSource)) { std::cout << errorHandler.errors(); return -1; @@ -33,11 +33,11 @@ int main(int argc, char** argv) { { Arabica::SAX::InputSource inputSource; inputSource.setSystemId("/Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/arabica/test-arabica-parsing.xml"); - + Arabica::SAX2DOM::Parser domParser; Arabica::SAX::CatchErrorHandler errorHandler; domParser.setErrorHandler(errorHandler); - + if(!domParser.parse(inputSource)) { std::cout << errorHandler.errors(); return -1; diff --git a/test/src/test-datamodel.cpp b/test/src/test-datamodel.cpp index 77f0851..b0ed107 100644 --- a/test/src/test-datamodel.cpp +++ b/test/src/test-datamodel.cpp @@ -18,7 +18,7 @@ int main(int argc, char** argv) { WSADATA wsaData; WSAStartup(MAKEWORD(2, 2), &wsaData); #endif - + DataModel dm(Factory::getInstance()->createDataModel("ecmascript", NULL)); dm.evalAsString("var foo = 12"); @@ -61,7 +61,7 @@ int main(int argc, char** argv) { std::cout << content << std::endl; assert(boost::equals(content, "${bar}")); } - + { std::string content = "There are ${bar} monkeys! Really ${foo} monkeys!"; int rplc = dm.replaceExpressions(content); -- cgit v0.12