diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-07-23 09:25:44 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-07-23 09:25:44 (GMT) |
commit | eb99c62e3d00f4ea5271f6dfc6401e3fcd5a5b90 (patch) | |
tree | c57585368b5855b7f71c5383d045d428a249ef8b | |
parent | 122285d16fd8ac9855c92519d48919bea36791b4 (diff) | |
download | uscxml-eb99c62e3d00f4ea5271f6dfc6401e3fcd5a5b90.zip uscxml-eb99c62e3d00f4ea5271f6dfc6401e3fcd5a5b90.tar.gz uscxml-eb99c62e3d00f4ea5271f6dfc6401e3fcd5a5b90.tar.bz2 |
Fixed setting intial config
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 56 | ||||
-rw-r--r-- | src/uscxml/Interpreter.cpp | 13 | ||||
-rw-r--r-- | src/uscxml/interpreter/InterpreterDraft6.cpp | 70 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp | 4 | ||||
-rw-r--r-- | test/CMakeLists.txt | 5 | ||||
-rw-r--r-- | test/samples/uscxml/test-initial-config.scxml | 58 | ||||
-rw-r--r-- | test/src/test-initial-config.cpp | 36 |
8 files changed, 191 insertions, 53 deletions
@@ -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<std::string>& 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<std::string>& no if (parser.parse(inputSource) && parser.getDocument()) { dom = parser.getDocument(); - std::cout << dom; + //std::cout << dom; Node<std::string> content = dom.getDocumentElement(); assert(content.getNodeType() == Node_base::ELEMENT_NODE); Node<std::string> 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<std::string> 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<std::string> 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<std::string> initialTransitions; - if (_userDefinedStartConfiguration.size() == 0) { + if (_userDefinedStartConfiguration.size() > 0) { + // we emulate entering a given configuration by creating a pseudo deep history + Element<std::string> 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<std::string> histStates; + for (int i = 0; i < _userDefinedStartConfiguration.size(); i++) { + histStates.push_back(getState(_userDefinedStartConfiguration[i])); + } + _historyValue[histId] = histStates; + + Element<std::string> initialElem = _document.createElementNS(_nsURL, "initial"); + initialElem.setAttribute("generated", "true"); + Element<std::string> 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<std::string> 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<std::string> initialStates; + // fetch per draft initialStates = getInitialStates(); - } - - assert(initialStates.size() > 0); - for (int i = 0; i < initialStates.size(); i++) { - Element<std::string> initialElem = _document.createElementNS(_nsURL, "initial"); - initialElem.setAttribute("generated", "true"); - Element<std::string> 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<std::string> initialElem = _document.createElementNS(_nsURL, "initial"); + initialElem.setAttribute("generated", "true"); + Element<std::string> 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<std::string> 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<std::string>& } 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<std::string>& 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 @@ +<scxml name="CuCo" version="0.9" xmlns="http://www.w3.org/2005/07/scxml"> + <parallel id="MAIN-PARALLEL"> + <state id="MAIN_STATE"> + <state id="1_PROPOSAL" initial="1_START"> + <state id="1_START"> + <onentry> + </onentry> + <transition event="event.role.system" target="SYSTEM_1.1_BEGIN"></transition> + <transition event="event.role.coordinator" target="COORDINATOR_1.1_BEGIN"></transition> + </state> + <state id="SYSTEM_1.1_ANNOUNCEMENT" initial="SYSTEM_1.1_BEGIN"> + <state id="SYSTEM_1.1.2_REMINDER_COORDINATOR-PREPARE-INFO"> + <onentry> + </onentry> + </state> + <state id="SYSTEM_1.1_BEGIN"> + <onentry> + + </onentry> + <transition cond="DATETIME_NOW == DATETIME_EVENT$REMINDER$1_PROPOSAL$ANNOUNCEMENT" event="event.datetime.reminder-2week-coordinator-prepare-info" target="SYSTEM_1.1.2_REMINDER_COORDINATOR-PREPARE-INFO"></transition> + </state> + </state> + <state id="COORDINATOR_1.1_ANNOUNCEMENT" initial="COORDINATOR_1.1_BEGIN"> + <state id="COORDINATOR_1.1_BEGIN"> + <onentry> + + </onentry> + <transition event="FLAG_REMINDER1 == TRUE" target="COORDINATOR_1.1.1_ANNOUNCEMENT-CONTENTS-VALIDATE"></transition> + </state> + <state id="COORDINATOR_1.1.1_ANNOUNCEMENT-CONTENTS-VALIDATE"></state> + </state> + </state> + </state> + <state id="finish_shortcut"> + <transition event="event.finish" target="finished"></transition> + </state> + <state id="ADMINISTRATIVE_TASKS"> + <state id="ADMINISTRATIVE_NON-HR-MANAGEMENT"> + <onentry> + + </onentry> + <transition event="event.administrative.next" target="ADMINISTRATIVE_NON-HR-MANAGEMENT_2"></transition> + </state> + <state id="ADMINISTRATIVE_NON-HR-MANAGEMENT_2"> + <onentry> + + </onentry> + </state> + </state> + <state id="COORDINATOR_TASKS"> + <state id="COORDINATOR_1"></state> + </state> + <state id="HR-MANAGER_TASKS"> + <state id="HR-MANAGER_MANAGE-HR"></state> + </state> + </parallel> + <final id="finished"></final> +</scxml> 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 <assert.h> +#include <boost/algorithm/string.hpp> +#include <iostream> + +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<std::string> 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 |