From eb99c62e3d00f4ea5271f6dfc6401e3fcd5a5b90 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Tue, 23 Jul 2013 11:25:44 +0200 Subject: Fixed setting intial config --- .gitignore | 2 + CMakeLists.txt | 56 ++++++++++------- src/uscxml/Interpreter.cpp | 13 ++-- src/uscxml/interpreter/InterpreterDraft6.cpp | 70 +++++++++++++++------- .../plugins/datamodel/xpath/XPathDataModel.cpp | 4 +- test/CMakeLists.txt | 5 ++ test/samples/uscxml/test-initial-config.scxml | 58 ++++++++++++++++++ test/src/test-initial-config.cpp | 36 +++++++++++ 8 files changed, 191 insertions(+), 53 deletions(-) create mode 100644 test/samples/uscxml/test-initial-config.scxml create mode 100644 test/src/test-initial-config.cpp diff --git a/.gitignore b/.gitignore index 649e14d..8a1e4e8 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ package/windows* *.tgz *.class + +/package/* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ba758f..a776753 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,13 @@ if (CMAKE_CROSSCOMPILING AND ANDROID_ABI) set(CMAKE_SYSTEM_VERSION ${ANDROID_NATIVE_API_LEVEL}) endif() +if (CMAKE_CROSSCOMPILING) + if (IOS) + add_definitions(-DTARGET_OS_IPHONE) + elseif(IOSSIM) + add_definitions(-DTARGET_IPHONE_SIMULATOR) + endif() +endif() # # Setting the CMAKE_FIND_ROOT_PATH to a list of directories will cause all CMake modules # to look in these directories in addition to the system search paths: @@ -211,7 +218,7 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") # order of arguments of gcc matters again # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") add_definitions(-fPIC) - add_definitions(-Wunreachable-code) + #add_definitions(-Wunreachable-code) if (CMAKE_BUILD_TYPE MATCHES ".*Deb.*" AND ENABLE_GCOV) # when not building for debug # coverage information @@ -610,34 +617,37 @@ else() target_link_libraries(uscxml ${USCXML_OPT_LIBS} ${USCXML_CORE_LIBS}) endif() -add_executable(uscxml-browser apps/uscxml-browser.cpp ${PROJECT_SOURCE_DIR}/contrib/src/getopt/XGetopt.cpp) -target_link_libraries(uscxml-browser uscxml) -set_target_properties(uscxml-browser PROPERTIES FOLDER "Apps") -install_executable(TARGETS uscxml-browser COMPONENT tools) +if (NOT CMAKE_CROSSCOMPILING) + add_executable(uscxml-browser apps/uscxml-browser.cpp ${PROJECT_SOURCE_DIR}/contrib/src/getopt/XGetopt.cpp) + target_link_libraries(uscxml-browser uscxml) + set_target_properties(uscxml-browser PROPERTIES FOLDER "Apps") + install_executable(TARGETS uscxml-browser COMPONENT tools) -if (PROTOBUF_FOUND) - file(GLOB W3C-MMI-COMMON ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/*.cpp ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/*.h) + if (PROTOBUF_FOUND) + file(GLOB W3C-MMI-COMMON ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/*.cpp ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/*.h) - file(GLOB_RECURSE W3C-MMI-IM ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/im/*.cpp ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/im/*.h) - add_executable(uscxml-interaction-manager ${W3C-MMI-IM} ${W3C-MMI-COMMON}) - target_link_libraries(uscxml-interaction-manager uscxml) - set_target_properties(uscxml-interaction-manager PROPERTIES FOLDER "Apps") - install_executable(TARGETS uscxml-interaction-manager COMPONENT tools) + file(GLOB_RECURSE W3C-MMI-IM ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/im/*.cpp ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/im/*.h) + add_executable(uscxml-interaction-manager ${W3C-MMI-IM} ${W3C-MMI-COMMON}) + target_link_libraries(uscxml-interaction-manager uscxml) + set_target_properties(uscxml-interaction-manager PROPERTIES FOLDER "Apps") + install_executable(TARGETS uscxml-interaction-manager COMPONENT tools) - file(GLOB_RECURSE W3C-MMI-MC ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/mc/*.cpp ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/mc/*.h) - add_executable(uscxml-modality-component ${W3C-MMI-MC} ${W3C-MMI-COMMON}) - target_link_libraries(uscxml-modality-component uscxml) - set_target_properties(uscxml-modality-component PROPERTIES FOLDER "Apps") - install_executable(TARGETS uscxml-modality-component COMPONENT tools) -endif() + file(GLOB_RECURSE W3C-MMI-MC ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/mc/*.cpp ${PROJECT_SOURCE_DIR}/apps/w3c-mmi/mc/*.h) + add_executable(uscxml-modality-component ${W3C-MMI-MC} ${W3C-MMI-COMMON}) + target_link_libraries(uscxml-modality-component uscxml) + set_target_properties(uscxml-modality-component PROPERTIES FOLDER "Apps") + install_executable(TARGETS uscxml-modality-component COMPONENT tools) + endif() -if (BUILD_TESTS) - add_subdirectory(test) + if (BUILD_TESTS) + add_subdirectory(test) + endif() + + if (NOT WIN32) + add_subdirectory(src/bindings) + endif() endif() -if (NOT WIN32) - add_subdirectory(src/bindings) -endif() ############################################################ # Header Files diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 8c1b4a6..f36e6b2 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -382,12 +382,12 @@ void InterpreterImpl::normalize(Arabica::DOM::Element& scxml) { } void InterpreterImpl::receiveInternal(const Event& event) { - std::cout << _name << " receiveInternal: " << event.name << std::endl; + //std::cout << _name << " receiveInternal: " << event.name << std::endl; _internalQueue.push_back(event); } void InterpreterImpl::receive(const Event& event, bool toFront) { - std::cout << _name << " receive: " << event.name << std::endl; + //std::cout << _name << " receive: " << event.name << std::endl; if (toFront) { _externalQueue.push_front(event); } else { @@ -478,7 +478,7 @@ void InterpreterImpl::processDOMorText(const Arabica::DOM::Node& no if (parser.parse(inputSource) && parser.getDocument()) { dom = parser.getDocument(); - std::cout << dom; + //std::cout << dom; Node content = dom.getDocumentElement(); assert(content.getNodeType() == Node_base::ELEMENT_NODE); Node container = dom.createElement("container"); @@ -1704,7 +1704,7 @@ void InterpreterImpl::setCmdLineOptions(int argc, char** argv) { */ bool InterpreterImpl::hasLegalConfiguration() { -#if 0 +#if VERBOSE std::cout << "Checking whether {"; std::string seperator; for (int i = 0; i < _configuration.size(); i++) { @@ -1757,8 +1757,10 @@ bool InterpreterImpl::hasLegalConfiguration() { for (int i = 0; i < _configuration.size(); i++) { if (!isAtomic(_configuration[i]) && !isParallel(_configuration[i])) { bool foundChildState = false; + //std::cout << _configuration[i] << std::endl; NodeSet childs = getChildStates(_configuration[i]); for (int j = 0; j < childs.size(); j++) { + //std::cout << childs[j] << std::endl; if (isMember(childs[j], _configuration)) { if (foundChildState) return false; @@ -1775,8 +1777,9 @@ bool InterpreterImpl::hasLegalConfiguration() { if (isParallel(_configuration[i])) { NodeSet childs = getChildStates(_configuration[i]); for (int j = 0; j < childs.size(); j++) { - if (!isMember(childs[j], _configuration) && !isHistory(childs[j])) + if (!isMember(childs[j], _configuration) && !isHistory(childs[j])) { return false; + } } } } diff --git a/src/uscxml/interpreter/InterpreterDraft6.cpp b/src/uscxml/interpreter/InterpreterDraft6.cpp index 915eba5..abea1ae 100644 --- a/src/uscxml/interpreter/InterpreterDraft6.cpp +++ b/src/uscxml/interpreter/InterpreterDraft6.cpp @@ -78,33 +78,48 @@ void InterpreterDraft6::interpret() { NodeSet initialTransitions; - if (_userDefinedStartConfiguration.size() == 0) { + if (_userDefinedStartConfiguration.size() > 0) { + // we emulate entering a given configuration by creating a pseudo deep history + Element initHistory = _document.createElementNS(_nsURL, "history"); + initHistory.setAttribute("id", getUUID()); + initHistory.setAttribute("type", "deep"); + _scxml.insertBefore(initHistory, _scxml.getFirstChild()); + + std::string histId = ATTR(initHistory, "id"); + NodeSet histStates; + for (int i = 0; i < _userDefinedStartConfiguration.size(); i++) { + 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"); + transitionElem.setAttribute("target", histId); + initialElem.appendChild(transitionElem); + _scxml.appendChild(initialElem); + initialTransitions.push_back(transitionElem); + + } else { // try to get initial transition form initial element initialTransitions = _xpath.evaluate("/" + _xpathPrefix + "initial/" + _xpathPrefix + "transition", _scxml).asNodeSet(); - } - - if (initialTransitions.size() == 0) { - Arabica::XPath::NodeSet initialStates; - if (_userDefinedStartConfiguration.size() > 0) { - // otherwise use user supplied config - initialStates = getStates(_userDefinedStartConfiguration); - } else { - // or fetch per draft + if (initialTransitions.size() == 0) { + Arabica::XPath::NodeSet initialStates; + // fetch per draft initialStates = getInitialStates(); - } - - assert(initialStates.size() > 0); - for (int i = 0; i < initialStates.size(); i++) { - Element initialElem = _document.createElementNS(_nsURL, "initial"); - initialElem.setAttribute("generated", "true"); - Element transitionElem = _document.createElementNS(_nsURL, "transition"); - transitionElem.setAttribute("target", ATTR(initialStates[i], "id")); - initialElem.appendChild(transitionElem); - _scxml.appendChild(initialElem); - initialTransitions.push_back(transitionElem); + assert(initialStates.size() > 0); + for (int i = 0; i < initialStates.size(); i++) { + Element initialElem = _document.createElementNS(_nsURL, "initial"); + initialElem.setAttribute("generated", "true"); + Element transitionElem = _document.createElementNS(_nsURL, "transition"); + transitionElem.setAttribute("target", ATTR(initialStates[i], "id")); + initialElem.appendChild(transitionElem); + _scxml.appendChild(initialElem); + initialTransitions.push_back(transitionElem); + } } } - + assert(initialTransitions.size() > 0); enterStates(initialTransitions); // _mutex.unlock(); @@ -228,12 +243,13 @@ void InterpreterDraft6::mainEventLoop() { if (_dataModel && boost::iequals(_currEvent.name, "cancel.invoke." + _sessionId)) break; - if (_dataModel) + if (_dataModel) { try { _dataModel.setEvent(_currEvent); } catch (Event e) { LOG(ERROR) << "Syntax error while setting external event:" << std::endl << e << std::endl; } + } for (unsigned int i = 0; i < _configuration.size(); i++) { NodeSet invokes = filterChildElements(_xmlNSPrefix + "invoke", _configuration[i]); for (unsigned int j = 0; j < invokes.size(); j++) { @@ -824,6 +840,14 @@ void InterpreterDraft6::enterStates(const Arabica::XPath::NodeSet& } statesToEnter.to_document_order(); +#if VERBOSE + std::cout << "States to enter: "; + for (int i = 0; i < statesToEnter.size(); i++) { + std::cout << ATTR(statesToEnter[i], "id") << ", "; + } + std::cout << std::endl; +#endif + monIter = _monitors.begin(); while(monIter != _monitors.end()) { try { diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp index 6b2f039..1de9c1b 100644 --- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp +++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp @@ -725,7 +725,7 @@ NodeSetVariableResolver::resolveVariable(const std::string& namepaceUri, if(n == _variables.end()) { throw Event("error.execution"); } -#if 1 +#if VERBOSE std::cout << std::endl << "Getting " << name << ":" << std::endl; for (int i = 0; i < n->second.size(); i++) { std::cout << n->second[i].getNodeType() << " | " << n->second[i] << std::endl; @@ -736,7 +736,7 @@ NodeSetVariableResolver::resolveVariable(const std::string& namepaceUri, } void NodeSetVariableResolver::setVariable(const std::string& name, const NodeSet& value) { -#if 1 +#if VERBOSE std::cout << std::endl << "Setting " << name << ":" << std::endl; for (int i = 0; i < value.size(); i++) { std::cout << value[i].getNodeType() << " | " << value[i] << std::endl; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ba332c2..983e179 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -63,6 +63,11 @@ target_link_libraries(test-url uscxml) add_test(test-url ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-url) set_target_properties(test-url PROPERTIES FOLDER "Tests") +# add_executable(test-initial-config src/test-initial-config.cpp) +# target_link_libraries(test-initial-config uscxml) +# add_test(test-url ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-initial-config ${CMAKE_SOURCE_DIR}/test/samples/uscxml/test-initial-config.scxml) +# set_target_properties(test-initial-config PROPERTIES FOLDER "Tests") + add_executable(test-datamodel src/test-datamodel.cpp) target_link_libraries(test-datamodel uscxml) add_test(test-datamodel ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-datamodel) diff --git a/test/samples/uscxml/test-initial-config.scxml b/test/samples/uscxml/test-initial-config.scxml new file mode 100644 index 0000000..cac0b8a --- /dev/null +++ b/test/samples/uscxml/test-initial-config.scxml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/src/test-initial-config.cpp b/test/src/test-initial-config.cpp new file mode 100644 index 0000000..dcba84d --- /dev/null +++ b/test/src/test-initial-config.cpp @@ -0,0 +1,36 @@ +#include "uscxml/Message.h" +#include "uscxml/Interpreter.h" +#include +#include +#include + +using namespace uscxml; +using namespace boost; + + +int main(int argc, char** argv) { +#ifdef _WIN32 + WSADATA wsaData; + WSAStartup(MAKEWORD(2, 2), &wsaData); +#endif + + if (argc != 2) { + std::cerr << "Expected path to test-initial-config.scxml" << std::endl; + exit(EXIT_FAILURE); + } + + std::string test = argv[1]; + + { + Interpreter interpreter = Interpreter::fromURI(test); + std::vector states; + states.push_back("finish_shortcut"); + states.push_back("ADMINISTRATIVE_NON-HR-MANAGEMENT"); + states.push_back("HR-MANAGER_MANAGE-HR"); + states.push_back("SYSTEM_1.1_BEGIN"); + states.push_back("COORDINATOR_1"); + interpreter.setConfiguration(states); + interpreter.interpret(); + } + +} \ No newline at end of file -- cgit v0.12