From 0e0b1e365842f62c714247c32692606d0ec7b21a Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Sun, 8 Jan 2017 23:06:33 +0100 Subject: Introduced WITH_CACHE_FILES build option (defaults to true) --- CMakeLists.txt | 1 + config.h.in | 1 + src/uscxml/interpreter/FastMicroStep.cpp | 43 +++++++++++++++++++++--------- src/uscxml/interpreter/InterpreterImpl.cpp | 6 ++++- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11a391c..b06de8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,6 +202,7 @@ OPTION(BUILD_BINDING_CSHARP "Build language bindings for CSharp" ON) OPTION(BUILD_BINDING_PYTHON "Build language bindings for Python" ON) OPTION(BUILD_BINDING_PHP "Build language bindings for PHP" OFF) +OPTION(WITH_CACHE_FILES "Support for caching data in temporary files" ON) ################################################# # Dependent Libraries diff --git a/config.h.in b/config.h.in index 2990f30..cdead01 100644 --- a/config.h.in +++ b/config.h.in @@ -59,6 +59,7 @@ #cmakedefine SWI_BINARY "@SWI_BINARY@" /** whether we want some feature */ +#cmakedefine WITH_CACHE_FILES #cmakedefine WITH_INV_SCXML #cmakedefine WITH_INV_DIRMON diff --git a/src/uscxml/interpreter/FastMicroStep.cpp b/src/uscxml/interpreter/FastMicroStep.cpp index e41e9f7..149ccb4 100644 --- a/src/uscxml/interpreter/FastMicroStep.cpp +++ b/src/uscxml/interpreter/FastMicroStep.cpp @@ -197,11 +197,12 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { _xmlPrefix = std::string(_xmlPrefix) + ":"; } - bool withCache = !envVarIsTrue("USCXML_NOCACHE_FILES"); - - resortStates(_scxml, _xmlPrefix); + resortStates(_scxml, _xmlPrefix); - Data& cache = _callbacks->getCache().compound["FastMicroStep"]; +#ifdef WITH_CACHE_FILES + bool withCache = !envVarIsTrue("USCXML_NOCACHE_FILES"); + Data& cache = _callbacks->getCache().compound["FastMicroStep"]; +#endif /** -- All things states -- */ @@ -252,6 +253,7 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { auto endState = cache.compound["states"].array.end(); for (i = 0; i < _states.size(); i++) { +#ifdef WITH_CACHE_FILES Data* cachedState = NULL; if (withCache) { if (currState != endState) { @@ -262,6 +264,7 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { cachedState = &(*cache.compound["states"].array.rbegin()); } } +#endif // collect states with an id attribute if (HAS_ATTR(_states[i]->element, "id")) { _stateIds[ATTR(_states[i]->element, "id")] = i; @@ -314,10 +317,12 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { } // establish the states' completion +#ifdef WITH_CACHE_FILES if (withCache && cachedState->compound.find("completion") != cachedState->compound.end()) { _states[i]->completion = fromBase64(cachedState->compound["completion"]); } else { - std::list completion = getCompletion(_states[i]->element); +#endif + std::list completion = getCompletion(_states[i]->element); for (j = 0; j < _states.size(); j++) { if (!completion.empty() && _states[j]->element == completion.front()) { _states[i]->completion[j] = true; @@ -327,10 +332,12 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { } } assert(completion.size() == 0); +#ifdef WITH_CACHE_FILES if (withCache) cachedState->compound["completion"] = Data(toBase64(_states[i]->completion)); } - // this is set when establishing the completion +#endif + // this is set when establishing the completion if (_states[i]->element->getUserData(X("hasHistoryChild")) == _states[i]) { _states[i]->type |= USCXML_STATE_HAS_HISTORY; } @@ -381,6 +388,7 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { for (i = 0; i < _transitions.size(); i++) { +#ifdef WITH_CACHE_FILES Data* cachedTrans = NULL; if (withCache) { if (currTrans != endTrans) { @@ -391,13 +399,17 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { cachedTrans = &(*cache.compound["transitions"].array.rbegin()); } } +#endif + // establish the transitions' exit set assert(_transitions[i]->element != NULL); +#ifdef WITH_CACHE_FILES if (withCache && cachedTrans->compound.find("exitset") != cachedTrans->compound.end()) { _transitions[i]->exitSet = fromBase64(cachedTrans->compound["exitset"]); } else { - std::list exitList = getExitSetCached(_transitions[i]->element, _scxml); +#endif + std::list exitList = getExitSetCached(_transitions[i]->element, _scxml); for (j = 0; j < _states.size(); j++) { if (!exitList.empty() && _states[j]->element == exitList.front()) { @@ -409,15 +421,19 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { } assert(exitList.size() == 0); +#ifdef WITH_CACHE_FILES if (withCache) cachedTrans->compound["exitset"] = Data(toBase64(_transitions[i]->exitSet)); } +#endif // establish the transitions' conflict set +#ifdef WITH_CACHE_FILES if (withCache && cachedTrans->compound.find("conflicts") != cachedTrans->compound.end()) { _transitions[i]->conflicts = fromBase64(cachedTrans->compound["conflicts"]); } else { - for (j = i; j < _transitions.size(); j++) { +#endif + for (j = i; j < _transitions.size(); j++) { if (conflictsCached(_transitions[i]->element, _transitions[j]->element, _scxml)) { _transitions[i]->conflicts[j] = true; } else { @@ -430,26 +446,29 @@ void FastMicroStep::init(XERCESC_NS::DOMElement* scxml) { for (j = 0; j < i; j++) { _transitions[i]->conflicts[j] = _transitions[j]->conflicts[i]; } +#ifdef WITH_CACHE_FILES if (withCache) cachedTrans->compound["conflicts"] = Data(toBase64(_transitions[i]->conflicts)); } - +#endif // establish the transitions' target set +#ifdef WITH_CACHE_FILES if (withCache && cachedTrans->compound.find("target") != cachedTrans->compound.end()) { _transitions[i]->target = fromBase64(cachedTrans->compound["target"]); } else { - std::list targets = tokenize(ATTR(_transitions[i]->element, "target")); +#endif + std::list targets = tokenize(ATTR(_transitions[i]->element, "target")); for (auto tIter = targets.begin(); tIter != targets.end(); tIter++) { if (_stateIds.find(*tIter) != _stateIds.end()) { _transitions[i]->target[_stateIds[*tIter]] = true; } } +#ifdef WITH_CACHE_FILES if (withCache) cachedTrans->compound["target"] = Data(toBase64(_transitions[i]->target)); - } - +#endif // the transition's source State* uscxmlState = (State*)(_transitions[i]->element->getParentNode()->getUserData(X("uscxmlState"))); _transitions[i]->source = uscxmlState->documentOrder; diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp index 8762b95..f9da040 100644 --- a/src/uscxml/interpreter/InterpreterImpl.cpp +++ b/src/uscxml/interpreter/InterpreterImpl.cpp @@ -110,6 +110,7 @@ InterpreterImpl::~InterpreterImpl() { // assert(_invokers.size() == 0); // ::xercesc_3_1::XMLPlatformUtils::Terminate(); +#ifdef WITH_CACHE_FILES if (!envVarIsTrue("USCXML_NOCACHE_FILES")) { // save our cache std::string sharedTemp = URL::getTempDir(true); @@ -119,6 +120,7 @@ InterpreterImpl::~InterpreterImpl() { dataFS.close(); } } +#endif } void InterpreterImpl::cancel() { @@ -179,6 +181,7 @@ void InterpreterImpl::init() { setupDOM(); +#ifdef WITH_CACHE_FILES if (!envVarIsTrue("USCXML_NOCACHE_FILES")) { // try to open chached data from resource directory std::string sharedTemp = URL::getTempDir(true); @@ -205,7 +208,8 @@ void InterpreterImpl::init() { _cache.compound["InterpreterImpl"].compound["baseURL"] = Data(std::string(_baseURL)); _cache.compound["InterpreterImpl"].compound["md5"] = Data(_md5); } - +#endif + // register io processors std::map ioProcs = _factory->getIOProcessors(); for (auto ioProcIter = ioProcs.begin(); ioProcIter != ioProcs.end(); ioProcIter++) { -- cgit v0.12