Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced xerces deps and new transition callback and new xerces-c #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions contrib/cmake/BuildXercesC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ if(MSVC)
endif()

externalproject_add(xerces-c
URL http://www.apache.org/dist/xerces/c/3/sources/xerces-c-3.1.4.tar.gz
URL_MD5 21bb097b711a513275379b59757cba4c
URL http://www.apache.org/dist/xerces/c/3/sources/xerces-c-3.2.1.tar.gz
URL_MD5 fe951ca5d93713db31b026fab2d042d7
BUILD_IN_SOURCE 1
PREFIX ${CMAKE_BINARY_DIR}/deps/xerces-c
CONFIGURE_COMMAND ""
Expand All @@ -51,15 +51,15 @@ if(MSVC)
${CMAKE_COMMAND} -E make_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release &&
${CMAKE_COMMAND} -E make_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug &&
${CMAKE_COMMAND} -E copy_directory Build/${XERCESC_BUILD_PATH_SUFFIX}/${VC_VERSION}/Release/ ${CMAKE_BINARY_DIR}/deps/xerces-c/lib/ &&
${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/deps/xerces-c/lib/xerces-c_3_1.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/ &&
${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/deps/xerces-c/lib/xerces-c_3_1.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/ &&
${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/deps/xerces-c/lib/xerces-c_3_1.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ &&
${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/deps/xerces-c/lib/xerces-c_3_2.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/ &&
${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/deps/xerces-c/lib/xerces-c_3_2.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/ &&
${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/deps/xerces-c/lib/xerces-c_3_2.dll ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ &&
${CMAKE_COMMAND} -E copy_directory src/ ${CMAKE_BINARY_DIR}/deps/xerces-c/include/
)
else()
externalproject_add(xerces-c
URL http://www.apache.org/dist/xerces/c/3/sources/xerces-c-3.1.4.tar.gz
URL_MD5 21bb097b711a513275379b59757cba4c
URL http://www.apache.org/dist/xerces/c/3/sources/xerces-c-3.2.1.tar.gz
URL_MD5 fe951ca5d93713db31b026fab2d042d7
BUILD_IN_SOURCE 0
PREFIX ${CMAKE_BINARY_DIR}/deps/xerces-c
CONFIGURE_COMMAND
Expand Down
10 changes: 8 additions & 2 deletions contrib/cmake/FindUSCXML.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ else()
ENV USCXML_LIB_DIR
)
if (USCXML_LIBRARY_RELEASE)
list(APPEND USCXML_LIBRARIES optimized USCXML_LIBRARY_RELEASE)
list(APPEND USCXML_LIBRARIES optimized ${USCXML_LIBRARY_RELEASE})
endif()
endif()

Expand All @@ -73,7 +73,13 @@ else()
ENV USCXML_LIB_DIR
)
if ("${USCXML_LIBRARY_DEBUG}")
list(APPEND USCXML_LIBRARIES debug USCXML_LIBRARY_DEBUG)
list(APPEND USCXML_LIBRARIES debug ${USCXML_LIBRARY_DEBUG})
else()
# on unices, we can add release as debug
if (USCXML_LIBRARY_RELEASE)
list(APPEND USCXML_LIBRARIES debug ${USCXML_LIBRARY_RELEASE})
endif()

endif()
endif()

Expand Down
11 changes: 8 additions & 3 deletions examples/cpp/library/lambdas/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
cmake_minimum_required(VERSION 2.8.6)
project(simple-scxml)
project(lambda-scxml)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/local/share/uscxml/cmake/")
find_package(USCXML REQUIRED)

# message(FATAL_ERROR "USCXML_LIBRARIES: ${USCXML_LIBRARIES}")


include_directories(${USCXML_INCLUDE_DIR})
add_executable(simple main.cpp)
target_link_libraries(simple ${USCXML_LIBRARIES})
add_executable(lambdas main.cpp)
target_link_libraries(lambdas ${USCXML_LIBRARIES})
36 changes: 31 additions & 5 deletions examples/cpp/library/lambdas/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,39 @@

int main(int argc, char *argv[])
{
if (argc < 2) {
std::cerr << "Expected URL with SCXML document as first argument" << std::endl;
return -1;
}
std::string scxmlURL("https://raw.githubusercontent.com/tklab-tud/uscxml/master/test/w3c/null/test436.scxml");

uscxml::Interpreter sc = uscxml::Interpreter::fromURL(argv[1]);
uscxml::Interpreter sc = uscxml::Interpreter::fromURL(scxmlURL);
uscxml::InterpreterState state;

sc.on().enterState([](const std::string& sessionId,
const std::string& stateName,
const xercesc_3_1::DOMElement* state) {
std::cout << "Entered " << stateName << std::endl;
});

sc.on().exitState([](const std::string& sessionId,
const std::string& stateName,
const xercesc_3_1::DOMElement* state) {
std::cout << "Exited " << stateName << std::endl;
});

sc.on().transition([](const std::string& sessionId,
const std::string& targetList,
const xercesc_3_1::DOMElement* transition) {
std::cout << "Transition to " << targetList << std::endl;
});

sc.on().completion([](const std::string& sessionId){
std::cout << "Completed!" << std::endl;
});

sc.on().executeContent([](const std::string& sessionId,
const xercesc_3_1::DOMElement* element){
std::cout << "Executing content" << std::endl;

});

while ((state = sc.step()) != uscxml::USCXML_FINISHED) {
}

Expand Down
4 changes: 3 additions & 1 deletion examples/cpp/library/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
cmake_minimum_required(VERSION 2.8.6)
project(simple-scxml)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/local/share/uscxml/cmake/")
find_package(USCXML REQUIRED)


include_directories(${USCXML_INCLUDE_DIR})
add_executable(simple main.cpp)
target_link_libraries(simple ${USCXML_LIBRARIES})
4 changes: 2 additions & 2 deletions src/bindings/swig/wrapped/WrappedInterpreterMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void WrappedInterpreterMonitor::afterUninvoking(const std::string& sessionId, co
afterUninvoking(DOMUtils::xPathForNode(invoker), invokeId, ss.str());
}

void WrappedInterpreterMonitor::beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) {
void WrappedInterpreterMonitor::beforeTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition) {
XERCESC_NS::DOMElement* sourceState = getSourceState(transition);
const XERCESC_NS::DOMElement* root = DOMUtils::getNearestAncestor(transition, "scxml");

Expand All @@ -93,7 +93,7 @@ void WrappedInterpreterMonitor::beforeTakingTransition(const std::string& sessio
beforeTakingTransition(DOMUtils::xPathForNode(transition), ATTR_CAST(sourceState, kXMLCharId), targets, ss.str());
}

void WrappedInterpreterMonitor::afterTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) {
void WrappedInterpreterMonitor::afterTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition) {
XERCESC_NS::DOMElement* sourceState = getSourceState(transition);
const XERCESC_NS::DOMElement* root = DOMUtils::getNearestAncestor(transition, "scxml");

Expand Down
2 changes: 2 additions & 0 deletions src/bindings/swig/wrapped/WrappedInterpreterMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ class WrappedInterpreterMonitor : public InterpreterMonitor {


void beforeTakingTransition(const std::string& sessionId,
const std::string& targetList,
const XERCESC_NS::DOMElement* transition);
virtual void beforeTakingTransition(const std::string& xpath,
const std::string& source,
const std::list<std::string>& targets,
const std::string& transitionXML) {}

void afterTakingTransition(const std::string& sessionId,
const std::string& targetList,
const XERCESC_NS::DOMElement* transition);
virtual void afterTakingTransition(const std::string& xpath,
const std::string& source,
Expand Down
4 changes: 3 additions & 1 deletion src/uscxml/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ static void printNodeSet(Logger& logger, const std::list<XERCESC_NS::DOMElement*

std::recursive_mutex StateTransitionMonitor::_mutex;

void StateTransitionMonitor::beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) {
void StateTransitionMonitor::beforeTakingTransition(const std::string& sessionId,
const std::string& targetList,
const XERCESC_NS::DOMElement* transition) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
LOG(_logger, USCXML_VERBATIM) << "Transition: " << uscxml::DOMUtils::xPathForNode(transition) << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/uscxml/debug/Breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ bool Breakpoint::matches(Interpreter interpreter, const Breakpoint& other) const
return true;
}

}
}
5 changes: 2 additions & 3 deletions src/uscxml/debug/Breakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
#include <string> // for string
#include "uscxml/Common.h" // for USCXML_API
#include "uscxml/Interpreter.h"
//#include "DOM/Element.hpp" // for Element
#include "uscxml/messages/Data.h" // for Data

// forward declare
namespace XERCESC_NS {
class DOMElement;
class DOMNode;
}

namespace uscxml {
Expand Down Expand Up @@ -77,7 +76,7 @@ class USCXML_API Breakpoint {
Subject subject;
Action action;

const XERCESC_NS::DOMElement* element = NULL;
const XERCESC_NS::DOMNode* element = NULL;

std::string invokeId;
std::string invokeType;
Expand Down
6 changes: 3 additions & 3 deletions src/uscxml/debug/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

#include "uscxml/debug/Debugger.h"
#include "uscxml/util/DOM.h"
#include "uscxml/util/Predicates.h"
#include "uscxml/util/DOM.h"
#include "uscxml/debug/DebugSession.h"

namespace uscxml {
Expand Down Expand Up @@ -90,10 +90,10 @@ std::list<Breakpoint> Debugger::getQualifiedTransBreakpoints(const std::string&
return breakpoints;
}

void Debugger::beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) {
void Debugger::beforeTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition) {
handleTransition(sessionId, transition, Breakpoint::BEFORE);
}
void Debugger::afterTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) {
void Debugger::afterTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition) {
handleTransition(sessionId, transition, Breakpoint::AFTER);
}
void Debugger::beforeExecutingContent(const std::string& sessionId, const XERCESC_NS::DOMElement* execContent) {
Expand Down
4 changes: 2 additions & 2 deletions src/uscxml/debug/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class USCXML_API Debugger : public InterpreterMonitor {
virtual void afterExecutingContent(const std::string& sessionId, const XERCESC_NS::DOMElement* execContent);
virtual void beforeUninvoking(const std::string& sessionId, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid);
virtual void afterUninvoking(const std::string& sessionId, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid);
virtual void beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition);
virtual void afterTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition);
virtual void beforeTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition);
virtual void afterTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition);
virtual void beforeEnteringState(const std::string& sessionId, const std::string& stateName, const XERCESC_NS::DOMElement* state);
virtual void afterEnteringState(const std::string& sessionId, const std::string& stateName, const XERCESC_NS::DOMElement* state);
virtual void beforeInvoking(const std::string& sessionId, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid);
Expand Down
21 changes: 17 additions & 4 deletions src/uscxml/interpreter/FastMicroStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,10 @@ InterpreterState FastMicroStep::step(size_t blockMs) {
i = _transSet.find_first();
while(i != boost::dynamic_bitset<BITSET_BLOCKTYPE>::npos) {
if ((USCXML_GET_TRANS(i).type & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL)) == 0) {
USCXML_MONITOR_CALLBACK1(monitors, beforeTakingTransition, USCXML_GET_TRANS(i).element);
USCXML_MONITOR_CALLBACK2(monitors,
beforeTakingTransition,
(HAS_ATTR(USCXML_GET_TRANS(i).element, kXMLCharTarget) ? ATTR(USCXML_GET_TRANS(i).element, kXMLCharTarget) : ""),
USCXML_GET_TRANS(i).element);

if (USCXML_GET_TRANS(i).onTrans != NULL) {

Expand All @@ -1190,7 +1193,11 @@ InterpreterState FastMicroStep::step(size_t blockMs) {
}
}

USCXML_MONITOR_CALLBACK1(monitors, afterTakingTransition, USCXML_GET_TRANS(i).element);
USCXML_MONITOR_CALLBACK2(monitors,
afterTakingTransition,
(HAS_ATTR(USCXML_GET_TRANS(i).element, kXMLCharTarget) ? ATTR(USCXML_GET_TRANS(i).element, kXMLCharTarget) : ""),
USCXML_GET_TRANS(i).element);


}
i = _transSet.find_next(i);
Expand Down Expand Up @@ -1249,7 +1256,10 @@ InterpreterState FastMicroStep::step(size_t blockMs) {
if unlikely((USCXML_GET_TRANS(j).type & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL)) &&
USCXML_GET_STATE(USCXML_GET_TRANS(j).source).parent == i) {

USCXML_MONITOR_CALLBACK1(monitors, beforeTakingTransition, USCXML_GET_TRANS(j).element);
USCXML_MONITOR_CALLBACK2(monitors,
beforeTakingTransition,
(HAS_ATTR(USCXML_GET_TRANS(j).element, kXMLCharTarget) ? ATTR(USCXML_GET_TRANS(j).element, kXMLCharTarget) : ""),
USCXML_GET_TRANS(j).element);

/* call executable content in transition */
if (USCXML_GET_TRANS(j).onTrans != NULL) {
Expand All @@ -1260,7 +1270,10 @@ InterpreterState FastMicroStep::step(size_t blockMs) {
}
}

USCXML_MONITOR_CALLBACK1(monitors, afterTakingTransition, USCXML_GET_TRANS(j).element);
USCXML_MONITOR_CALLBACK2(monitors,
afterTakingTransition,
(HAS_ATTR(USCXML_GET_TRANS(j).element, kXMLCharTarget) ? ATTR(USCXML_GET_TRANS(j).element, kXMLCharTarget) : ""),
USCXML_GET_TRANS(j).element);
}

j = _transSet.find_next(j);
Expand Down
15 changes: 11 additions & 4 deletions src/uscxml/interpreter/InterpreterMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ class USCXML_API InterpreterMonitor {
const std::string& invokeid) {}

virtual void beforeTakingTransition(const std::string& sessionId,
const std::string& targetList,
const XERCESC_NS::DOMElement* transition) {}
virtual void afterTakingTransition(const std::string& sessionId,
const std::string& targetList,
const XERCESC_NS::DOMElement* transition) {}

virtual void beforeEnteringState(const std::string& sessionId,
Expand Down Expand Up @@ -134,7 +136,7 @@ class USCXML_API StateTransitionMonitor : public uscxml::InterpreterMonitor {
StateTransitionMonitor(std::string prefix = "") : _logPrefix(prefix) {}
virtual ~StateTransitionMonitor() {}

virtual void beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition);
virtual void beforeTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition);
virtual void beforeExecutingContent(const std::string& sessionId, const XERCESC_NS::DOMElement* element);
virtual void onStableConfiguration(const std::string& sessionId);
virtual void beforeProcessingEvent(const std::string& sessionId, const uscxml::Event& event);
Expand Down Expand Up @@ -198,6 +200,7 @@ class USCXML_API LambdaMonitor : public InterpreterMonitor {
}

void transition(std::function<void (const std::string& sessionId,
const std::string& targetList,
const XERCESC_NS::DOMElement* transition)> callback,
bool after = false) {
if (after) {
Expand Down Expand Up @@ -278,8 +281,10 @@ class USCXML_API LambdaMonitor : public InterpreterMonitor {
const std::string& invokeid)> _afterUninvoking;

std::function<void (const std::string& sessionId,
const std::string& targetList,
const XERCESC_NS::DOMElement* transition)> _beforeTakingTransition;
std::function<void (const std::string& sessionId,
const std::string& targetList,
const XERCESC_NS::DOMElement* transition)> _afterTakingTransition;

std::function<void (const std::string& sessionId,
Expand Down Expand Up @@ -357,14 +362,16 @@ class USCXML_API LambdaMonitor : public InterpreterMonitor {
}

void beforeTakingTransition(const std::string& sessionId,
const XERCESC_NS::DOMElement* transition) {
const std::string& targetList,
const XERCESC_NS::DOMElement* transition) {
if (_beforeTakingTransition)
_beforeTakingTransition(sessionId, transition);
_beforeTakingTransition(sessionId, targetList, transition);
}
void afterTakingTransition(const std::string& sessionId,
const std::string& targetList,
const XERCESC_NS::DOMElement* transition) {
if (_afterTakingTransition)
_afterTakingTransition(sessionId, transition);
_afterTakingTransition(sessionId, targetList, transition);
}

void beforeEnteringState(const std::string& sessionId,
Expand Down
Loading