From f4cbdb0292c5505bed8c8b69c8a559596267eda5 Mon Sep 17 00:00:00 2001 From: rlm Date: Thu, 4 Jul 2019 10:10:19 +0200 Subject: implementation of tascxml:result action in c transformer Change-Id: Ic858e887d644d564a4e0a2c2b275732678649e49 --- src/uscxml/transform/ChartToC.cpp | 86 ++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 11 deletions(-) mode change 100644 => 100755 src/uscxml/transform/ChartToC.cpp diff --git a/src/uscxml/transform/ChartToC.cpp b/src/uscxml/transform/ChartToC.cpp old mode 100644 new mode 100755 index a52cf5e..08ea1a0 --- a/src/uscxml/transform/ChartToC.cpp +++ b/src/uscxml/transform/ChartToC.cpp @@ -710,6 +710,7 @@ void ChartToC::writeTypes(std::ostream& stream) { stream << "typedef struct uscxml_elem_assign uscxml_elem_assign;" << std::endl; stream << "typedef struct uscxml_elem_donedata uscxml_elem_donedata;" << std::endl; stream << "typedef struct uscxml_elem_foreach uscxml_elem_foreach;" << std::endl; + stream << "typedef struct uscxml_elem_tascxml_result uscxml_elem_tascxml_result;" << std::endl; stream << std::endl; stream << "typedef void* (*dequeue_internal_t)(const uscxml_ctx* ctx);" << std::endl; @@ -733,6 +734,7 @@ void ChartToC::writeTypes(std::ostream& stream) { stream << "typedef int (*exec_content_cancel_t)(const uscxml_ctx* ctx, const char* sendid, const char* sendidexpr);" << std::endl; stream << "typedef int (*exec_content_finalize_t)(const uscxml_ctx* ctx, const uscxml_elem_invoke* invoker, const void* event);" << std::endl; stream << "typedef int (*exec_content_script_t)(const uscxml_ctx* ctx, const char* src, const char* content);" << std::endl; + stream << "typedef int (*exec_content_tascxml_result_t)(const uscxml_ctx* ctx, const uscxml_elem_tascxml_result* result);" << std::endl; stream << std::endl; stream << "/**" << std::endl; @@ -885,6 +887,20 @@ void ChartToC::writeTypes(std::ostream& stream) { stream << std::endl; stream << "/**" << std::endl; + stream << " * All information pertaining to a element" << std::endl; + stream << " */" << std::endl; + stream << "struct uscxml_elem_tascxml_result {" << std::endl; + stream << " const char* verdict;" << std::endl; + stream << " const char* timestamp;" << std::endl; + stream << " const char* teststep;" << std::endl; + stream << " const char* description;" << std::endl; + stream << " const char* resultid;" << std::endl; + stream << " const char* requirementid;" << std::endl; + stream << " const char* currentvalue;" << std::endl; + stream << "};" << std::endl; + stream << std::endl; + + stream << "/**" << std::endl; stream << " * Represents an instance of a state-chart at runtime/" << std::endl; stream << " */" << std::endl; stream << "struct uscxml_ctx {" << std::endl; @@ -905,16 +921,17 @@ void ChartToC::writeTypes(std::ostream& stream) { stream << " is_true_t is_true;" << std::endl; stream << " raise_done_event_t raise_done_event;" << std::endl; stream << std::endl; - stream << " exec_content_log_t exec_content_log;" << std::endl; - stream << " exec_content_raise_t exec_content_raise;" << std::endl; - stream << " exec_content_send_t exec_content_send;" << std::endl; - stream << " exec_content_foreach_init_t exec_content_foreach_init;" << std::endl; - stream << " exec_content_foreach_next_t exec_content_foreach_next;" << std::endl; - stream << " exec_content_foreach_done_t exec_content_foreach_done;" << std::endl; - stream << " exec_content_assign_t exec_content_assign;" << std::endl; - stream << " exec_content_init_t exec_content_init;" << std::endl; - stream << " exec_content_cancel_t exec_content_cancel;" << std::endl; - stream << " exec_content_script_t exec_content_script;" << std::endl; + stream << " exec_content_log_t exec_content_log;" << std::endl; + stream << " exec_content_raise_t exec_content_raise;" << std::endl; + stream << " exec_content_send_t exec_content_send;" << std::endl; + stream << " exec_content_foreach_init_t exec_content_foreach_init;" << std::endl; + stream << " exec_content_foreach_next_t exec_content_foreach_next;" << std::endl; + stream << " exec_content_foreach_done_t exec_content_foreach_done;" << std::endl; + stream << " exec_content_assign_t exec_content_assign;" << std::endl; + stream << " exec_content_init_t exec_content_init;" << std::endl; + stream << " exec_content_cancel_t exec_content_cancel;" << std::endl; + stream << " exec_content_script_t exec_content_script;" << std::endl; + stream << " exec_content_tascxml_result_t exec_content_tascxml_result;" << std::endl; stream << std::endl; stream << " invoke_t invoke;" << std::endl; stream << "};" << std::endl; @@ -1391,6 +1408,16 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ stream << padding << " return USCXML_ERR_MISSING_CALLBACK;" << std::endl; stream << padding << "}" << std::endl; + } else if(TAGNAME(elem) == "tascxml:result") { + stream << padding; + stream << "if likely(ctx->exec_content_tascxml_result != NULL) {" << std::endl; + stream << padding; + stream << " if ((ctx->exec_content_tascxml_result(ctx, &" << _prefix << "_elem_tascxml_results[" << ATTR(elem, X("documentOrder")) << "]"; + stream << ")) != USCXML_ERR_OK) return err;" << std::endl; + stream << padding << "} else {" << std::endl; + stream << padding << " return USCXML_ERR_MISSING_CALLBACK;" << std::endl; + stream << padding << "}" << std::endl; + } else { LOGD(USCXML_VERBATIM) << "writeExecContent unsupported element: '" << TAGNAME(elem) << "'" << std::endl << *elem << std::endl; assert(false); @@ -1690,7 +1717,7 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << "};" << std::endl; stream << std::endl; } - + std::list sends = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "send" }, _scxml); if (sends.size() > 0) { _hasElement.insert("send"); @@ -1769,6 +1796,43 @@ void ChartToC::writeElementInfo(std::ostream& stream) { stream << std::endl; } + static const X kXMLCharVerdict = X("verdict"); + static const X kXMLCharTimestamp = X("timestamp"); + static const X kXMLCharTestStep = X("teststep"); + static const X kXMLCharDescription = X("description"); + static const X kXMLCharResultId = X("resultid"); + static const X kXMLChaRequirementId = X("requirementid"); + static const X kXMLCharCurrentVaue = X("currentvalue"); + std::list tascxmlresults = DOMUtils::inDocumentOrder({ "tascxml:result" }, _scxml); + if (tascxmlresults.size() > 0) { + _hasElement.insert("result"); + stream << "static const uscxml_elem_tascxml_result " << _prefix << "_elem_tascxml_results[" << tascxmlresults.size() << "] = {" << std::endl; + size_t i = 0; + for (auto iter = tascxmlresults.begin(); iter != tascxmlresults.end(); iter++, i++) { + DOMElement* tascxmlresult = *iter; + stream << " { "; + stream << std::endl << " /* verdict */ "; + stream << (HAS_ATTR(tascxmlresult, kXMLCharVerdict) ? "\"" + escape(ATTR(tascxmlresult, kXMLCharVerdict)) + "\"" : "NULL") << ", "; + stream << std::endl << " /* timestamp */ "; + stream << (HAS_ATTR(tascxmlresult, kXMLCharTimestamp) ? "\"" + escape(ATTR(tascxmlresult, kXMLCharTimestamp)) + "\"" : "NULL") << ", "; + stream << std::endl << " /* teststep */ "; + stream << (HAS_ATTR(tascxmlresult, kXMLCharTestStep) ? "\"" + escape(ATTR(tascxmlresult, kXMLCharTestStep)) + "\"" : "NULL") << ", "; + stream << std::endl << " /* description */ "; + stream << (HAS_ATTR(tascxmlresult, kXMLCharDescription) ? "\"" + escape(ATTR(tascxmlresult, kXMLCharDescription)) + "\"" : "NULL") << ", "; + stream << std::endl << " /* resultid */ "; + stream << (HAS_ATTR(tascxmlresult, kXMLCharResultId) ? "\"" + escape(ATTR(tascxmlresult, kXMLCharResultId)) + "\"" : "NULL") << ", "; + stream << std::endl << " /* requirementid */ "; + stream << (HAS_ATTR(tascxmlresult, kXMLChaRequirementId) ? "\"" + escape(ATTR(tascxmlresult, kXMLChaRequirementId)) + "\"" : "NULL") << ", "; + stream << std::endl << " /* currentvalue */ "; + stream << (HAS_ATTR(tascxmlresult, kXMLCharCurrentVaue) ? "\"" + escape(ATTR(tascxmlresult, kXMLCharCurrentVaue)) + "\"" : "NULL"); + + stream << std::endl << " }" << (i + 1 < tascxmlresults.size() ? ",": "") << std::endl; + tascxmlresult->setAttribute(X("documentOrder"), X(toStr(i))); + } + stream << "};" << std::endl; + stream << std::endl; + } + std::list donedatas = DOMUtils::inDocumentOrder({ XML_PREFIX(_scxml).str() + "donedata" }, _scxml); stream << "static const uscxml_elem_donedata " << _prefix << "_elem_donedatas[" << donedatas.size() + 1 << "] = {" << std::endl; stream << " /* source, content, contentexpr, params */" << std::endl; -- cgit v0.12