diff options
Diffstat (limited to 'src/uscxml')
-rw-r--r-- | src/uscxml/debug/Breakpoint.cpp | 20 | ||||
-rw-r--r-- | src/uscxml/debug/Breakpoint.h | 4 | ||||
-rw-r--r-- | src/uscxml/debug/Debugger.cpp | 4 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp | 47 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h | 17 |
5 files changed, 50 insertions, 42 deletions
diff --git a/src/uscxml/debug/Breakpoint.cpp b/src/uscxml/debug/Breakpoint.cpp index 58cf295..df5dd61 100644 --- a/src/uscxml/debug/Breakpoint.cpp +++ b/src/uscxml/debug/Breakpoint.cpp @@ -93,11 +93,11 @@ Breakpoint::Breakpoint(const Data& data) { if (data.hasKey("stateId")) stateId = data["stateId"].atom; - if (data.hasKey("transSource")) - transSource = data["transSource"].atom; + if (data.hasKey("transSourceId")) + transSourceId = data["transSourceId"].atom; - if (data.hasKey("transTarget")) - transTarget = data["transTarget"].atom; + if (data.hasKey("transTargetId")) + transTargetId = data["transTargetId"].atom; } @@ -183,11 +183,11 @@ Data Breakpoint::toData() const { if (stateId.length() > 0) data.compound["stateId"] = Data(stateId, Data::VERBATIM); - if (transSource.length() > 0) - data.compound["transSource"] = Data(transSource, Data::VERBATIM); + if (transSourceId.length() > 0) + data.compound["transSourceId"] = Data(transSourceId, Data::VERBATIM); - if (transTarget.length() > 0) - data.compound["transTarget"] = Data(transTarget, Data::VERBATIM); + if (transTargetId.length() > 0) + data.compound["transTargetId"] = Data(transTargetId, Data::VERBATIM); if (condition.length() > 0) data.compound["condition"] = Data(condition, Data::VERBATIM); @@ -241,11 +241,11 @@ bool Breakpoint::matches(Interpreter interpreter, const Breakpoint& other) const return Interpreter::isMember(other.element, nodes); } - if(transSource.length() > 0 && transSource != other.transSource) { + if(transSourceId.length() > 0 && transSourceId != other.transSourceId) { return false; } - if(transTarget.length() > 0 && transTarget != other.transTarget) { + if(transTargetId.length() > 0 && transTargetId != other.transTargetId) { return false; } diff --git a/src/uscxml/debug/Breakpoint.h b/src/uscxml/debug/Breakpoint.h index cd6fea5..157a56d 100644 --- a/src/uscxml/debug/Breakpoint.h +++ b/src/uscxml/debug/Breakpoint.h @@ -79,8 +79,8 @@ public: std::string executableXPath; std::string stateId; - std::string transSource; - std::string transTarget; + std::string transSourceId; + std::string transTargetId; std::string condition; }; diff --git a/src/uscxml/debug/Debugger.cpp b/src/uscxml/debug/Debugger.cpp index 3a19228..4fe677c 100644 --- a/src/uscxml/debug/Debugger.cpp +++ b/src/uscxml/debug/Debugger.cpp @@ -74,8 +74,8 @@ std::list<Breakpoint> getQualifiedTransBreakpoints(Interpreter interpreter, cons Breakpoint bp = breakpointTemplate; // copy base as template bp.element = transition; - bp.transSource = ATTR(source, "id"); - bp.transTarget = ATTR(target, "id"); + bp.transSourceId = ATTR(source, "id"); + bp.transTargetId = ATTR(target, "id"); bp.subject = Breakpoint::TRANSITION; breakpoints.push_back(bp); diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index 23c6e1a..5e66c68 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -42,16 +42,9 @@ catch (PlException plex) { \ e.data.compound["cause"] = (char*)plex; \ throw e; \ } \ - -// this might evolve into multi-threaded prolog, but no need for now -#define SET_PL_CONTEXT \ -_dmPtr = this; #define PL_MODULE \ _interpreter.getSessionId().c_str() \ - -#define UNSET_PL_ENGINE(dm) \ -PL_set_engine(NULL, NULL); #define SET_PL_ENGINE(dm) \ assert(_swiEngines.find(dm) != _swiEngines.end()); \ @@ -116,8 +109,6 @@ boost::shared_ptr<DataModelImpl> SWIDataModel::create(InterpreterImpl* interpret NULL }; - PL_engine_t engine; - if (!PL_is_initialised(NULL, NULL)) { if(!PL_initialise(argc,av)) { LOG(ERROR) << "Error intializing prolog engine"; @@ -125,7 +116,7 @@ boost::shared_ptr<DataModelImpl> SWIDataModel::create(InterpreterImpl* interpret return boost::shared_ptr<DataModelImpl>(); } - PL_set_engine(PL_ENGINE_CURRENT, &engine); + PL_set_engine(PL_ENGINE_CURRENT, &_engine); // load SWI XML parser try { @@ -147,16 +138,16 @@ boost::shared_ptr<DataModelImpl> 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"; - engine = PL_create_engine(NULL); +// engine = PL_create_engine(NULL); } - assert(engine); - _swiEngines[dm.get()] = engine; - _dmPtr = dm.get(); +// assert(engine); +// _swiEngines[dm.get()] = engine; +// _dmPtr = dm.get(); - int rc = PL_set_engine(engine, NULL); - assert(rc == PL_ENGINE_SET); - (void)rc; +// int rc = PL_set_engine(engine, NULL); +// assert(rc == PL_ENGINE_SET); +// (void)rc; _plModule = boost::replace_all_copy(interpreter->getSessionId(), "-", ""); boost::replace_all(_plModule, "0", "g"); @@ -195,6 +186,7 @@ boost::shared_ptr<DataModelImpl> SWIDataModel::create(InterpreterImpl* interpret // the in predicate PlRegister("user", "in", 1, SWIDataModel::inPredicate); + PL_set_engine(NULL, NULL); return dm; } RETHROW_PLEX_AS_EVENT; @@ -243,8 +235,8 @@ void SWIDataModel::initialize() { } void SWIDataModel::setEvent(const Event& event) { - - SET_PL_CONTEXT; + SWIEngineLock engineLock; + // remove old event try { PlCall("retractall(event(_))"); @@ -430,7 +422,7 @@ void SWIDataModel::assertFromData(const Data& data, const std::string& expr, siz #endif Data SWIDataModel::getStringAsData(const std::string& content) { - SET_PL_CONTEXT + SWIEngineLock engineLock; try { PlCompound compound(content.c_str()); PlCompound orig(content.c_str()); @@ -616,13 +608,13 @@ PlTerm SWIDataModel::dataAsTerm(Data data) { } bool SWIDataModel::validate(const std::string& location, const std::string& schema) { - SET_PL_CONTEXT + SWIEngineLock engineLock; // std::cout << "SWIDataModel::validate" << std::endl; return true; } uint32_t SWIDataModel::getLength(const std::string& expr) { - SET_PL_CONTEXT + SWIEngineLock engineLock; try { PlCompound compound(expr.c_str()); PlTermv termv(compound.arity()); @@ -642,7 +634,7 @@ void SWIDataModel::setForeach(const std::string& item, const std::string& array, const std::string& index, uint32_t iteration) { - SET_PL_CONTEXT + SWIEngineLock engineLock; try { PlCompound compound(array.c_str()); PlCompound orig(array.c_str()); @@ -673,7 +665,7 @@ void SWIDataModel::setForeach(const std::string& item, } void SWIDataModel::eval(const Element<std::string>& scriptElem, const std::string& expr) { - SET_PL_CONTEXT + SWIEngineLock engineLock; try { if (scriptElem && HAS_ATTR(scriptElem, "type") && iequals(ATTR(scriptElem, "type"), "query")) { evalAsBool(expr); @@ -690,7 +682,7 @@ bool SWIDataModel::evalAsBool(const std::string& expr) { } bool SWIDataModel::evalAsBool(const Arabica::DOM::Node<std::string>& node, const std::string& expr) { - SET_PL_CONTEXT + SWIEngineLock engineLock; try { PlCompound compound(expr.c_str()); PlTermv termv(compound.arity()); @@ -705,7 +697,7 @@ bool SWIDataModel::evalAsBool(const Arabica::DOM::Node<std::string>& node, const } std::string SWIDataModel::evalAsString(const std::string& expr) { - SET_PL_CONTEXT + SWIEngineLock engineLock; try { PlCompound compound(expr.c_str()); @@ -755,7 +747,6 @@ std::string SWIDataModel::evalAsString(const std::string& expr) { // this is similar to http://etalis.googlecode.com/svn/eEtalis/src/term.c std::map<std::string, PlTerm> SWIDataModel::resolveAtoms(PlTerm& term, PlTerm& orig) { - SET_PL_CONTEXT try { std::map<std::string, PlTerm> atoms; switch (orig.type()) { @@ -788,7 +779,7 @@ std::map<std::string, PlTerm> SWIDataModel::resolveAtoms(PlTerm& term, PlTerm& o void SWIDataModel::assign(const Element<std::string>& assignElem, const Node<std::string>& node, const std::string& content) { - SET_PL_CONTEXT + SWIEngineLock engineLock; try { std::string expr = content; std::string predicate; diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h index 75e2d74..d52dd24 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h @@ -34,6 +34,22 @@ namespace uscxml { class SWIDataModel : public DataModelImpl { public: + class SWIEngineLock { + public: + SWIEngineLock() { + isLocked = false; + int rc = PL_set_engine(PL_ENGINE_MAIN, NULL); + if (rc == PL_ENGINE_SET) { + isLocked = true; + } + } + ~SWIEngineLock() { + if (isLocked) + PL_set_engine(NULL, NULL); + } + bool isLocked; + }; + SWIDataModel(); virtual ~SWIDataModel(); virtual boost::shared_ptr<DataModelImpl> create(InterpreterImpl* interpreter); @@ -106,6 +122,7 @@ protected: std::string _plModule; std::string _name; std::string _sessionId; + PL_engine_t _engine; }; #ifdef BUILD_AS_PLUGINS |