New developments ahead
authorAndre EBERSOLD <andre.ebersold@siemens.com>
Fri, 3 Feb 2023 14:48:49 +0000 (15:48 +0100)
committerAndre EBERSOLD <andre.ebersold@siemens.com>
Fri, 3 Feb 2023 14:48:49 +0000 (15:48 +0100)
  Started code for http element support
  Started source tree for reqif parsing

src/tasks/http.cpp [new file with mode: 0644]
src/tasks/http.h [new file with mode: 0644]
src/xml/reqif/CMakeLists.txt [new file with mode: 0644]
src/xml/reqif/element_factory.cpp [new file with mode: 0644]
src/xml/reqif/element_factory.h [new file with mode: 0644]

diff --git a/src/tasks/http.cpp b/src/tasks/http.cpp
new file mode 100644 (file)
index 0000000..2c5b19a
--- /dev/null
@@ -0,0 +1,90 @@
+#include <antcc/common.h>
+#include <tasks/http.h>
+
+
+/**
+ * Attributes supported by exec
+ */
+antcc::xml::element_attributes<http> http::gAttr[] = 
+{
+  {"method",&http::setMethod}
+  , {"url",&http::setUrl}
+  , {"status",&http::setStatus}
+  , {"contentType",&http::setContentType}
+  , {NULL,NULL}
+}; 
+
+
+http::http()
+{
+}
+
+http::~http()
+{
+}
+
+antcc::task::eStatus 
+http::execute()
+{
+    eStatus l_return = EXEC_FAILED;
+    std::string _name;
+    std::string l_unless;
+    if (getResolvedAttribute("method",l_unless))
+    {
+        std::string l_prop;
+
+        if (getProject().getProperty(l_unless,l_prop))
+        {
+            l_return = EXEC_SUCCESS;
+
+        } else {
+            getProject().log(*this,eINFO,"unless %s ",l_prop.c_str());
+       }
+    }
+    if ( (l_return == EXEC_FAILED) && getResolvedAttribute("message",_name))
+    {
+        getProject().log(*this,eINFO,_name);
+    } else
+    {
+        ANTCC_LOG_DEBUG("http::%s  success condition is met"
+            ,__FUNCTION__);
+    }
+    return l_return;
+}
+
+///
+bool 
+http::addAttribute(const std::string &_name,const std::string &_v)  
+{
+    bool l_ok = false;
+    if  ( (l_ok = antElement::addAttribute<http>(this,http::gAttr,_name,_v)) == true)
+    {
+        antElement::addAttribute(_name,_v);
+    }
+    return l_ok;
+}
+///
+void 
+http::setMethod(const std::string &s)
+{
+  m_Method = s;
+}
+///
+void 
+http::setUrl(const std::string &s)
+{
+  m_Url = s;
+}
+///
+void 
+http::setContent(const std::string &s)
+{
+  m_Content = s;
+}
+///
+void 
+http::setContentType(const std::string &s)
+{
+  m_ContentType = s;
+}
+
diff --git a/src/tasks/http.h b/src/tasks/http.h
new file mode 100644 (file)
index 0000000..2220b32
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef __TASK_HTTP_H__
+#define __TASK_HTTP_H__
+
+
+/**
+ * @brief This tag sets one or multiple proproties for the
+ * project. The properties once set cannot be changed anymore.
+ *
+ */
+class http : public antcc::task
+{
+    public:
+        ///
+        http() ;
+        ///
+        virtual ~http();
+        ///
+        virtual eStatus execute() ;
+    private:
+        template <typename C> 
+        friend  struct element_attributes; 
+        ///
+        ///
+        virtual bool addAttribute(const std::string &_name,const std::string &_v)  ;
+        ///
+        void setUrl(const std::string &s);
+        ///
+        void setMethod(const std::string &s);
+        ///
+        void setContent(const std::string &s);
+        ///
+        void setContentType(const std::string &s);
+    private:
+        std::string m_Content;
+        std::string m_ContentType;
+        std::string m_Method;
+        std::string m_Url;
+        static ::antcc::xml::element_attributes<http> gAttr []; 
+};
+
+
+
+#endif
+/* vim:et:sw=4:ts=4:list: */
diff --git a/src/xml/reqif/CMakeLists.txt b/src/xml/reqif/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9a68836
--- /dev/null
@@ -0,0 +1,73 @@
+PROJECT(libreqifparser)
+
+INCLUDE_DIRECTORIES(${libreqifparser_SOURCE_DIR})
+INCLUDE_DIRECTORIES(/usr/local/include)
+# Check with BOOTSTRAP_expat too
+IF(NOT WIN32)
+  FIND_PACKAGE(EXPAT REQUIRED)
+ELSE(NOT WIN32)
+  #    C:\Tools\Expat 2.2.10\Source\lib
+  SET(EXPAT_INCLUDE_DIR "c:/Tools/Expat 2.2.10/Source/lib" CACHE STRING "Expat include dir")
+  SET(EXPAT_LIBRARY "c:/Tools/Expat 2.2.10/Bin/libexpat.lib" CACHE STRING "Expat library")
+  INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
+ENDIF(NOT WIN32)
+
+INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
+
+ADD_LIBRARY(reqif_parser STATIC 
+               document.cpp
+                ant_elements_parser.cpp 
+                ant_elements_parser_root.cpp 
+               element_factory.cpp
+               )
+
+TARGET_LINK_LIBRARIES(reqif_parser  ${EXPAT_LIBRARY})
+EXPORT(TARGETS reqif_parser FILE libxsdLibraries.cmake)
+
+IF (0)
+INSTALL(TARGETS libxsd
+        EXPORT libxsd
+        ARCHIVE
+        DESTINATION lib
+        COMPONENT   Libraries)
+INSTALL(EXPORT libxsd DESTINATION lib)
+
+INSTALL(TARGETS xsdd
+        EXPORT xsdd
+        ARCHIVE
+        DESTINATION lib
+        COMPONENT   Libraries)
+INSTALL(EXPORT xsdd DESTINATION lib)
+
+INSTALL(FILES
+        ${libxsd_SOURCE_DIR}/document_expat.cpp
+        ${libxsd_SOURCE_DIR}/elements.cpp
+        ${libxsd_SOURCE_DIR}/parser.cpp
+        DESTINATION lib/src
+        COMPONENT   Headers
+    )
+INSTALL(FILES 
+        ${libxsd_SOURCE_DIR}/../include/xsd/xsd.h
+        DESTINATION include/xsd
+        COMPONENT   Headers
+        )
+INSTALL(FILES 
+        ${libxsd_SOURCE_DIR}/../include/xsd/parser/parser.h
+        ${libxsd_SOURCE_DIR}/../include/xsd/parser/elements.h
+        ${libxsd_SOURCE_DIR}/../include/xsd/parser/document.h
+#        ${libxsd_SOURCE_DIR}/../include/xsd/parser/xml-schema.h
+        DESTINATION include/xsd/parser
+        COMPONENT   Headers
+        )
+INSTALL(FILES 
+        ${libxsd_SOURCE_DIR}/../include/xsd/parser/expat/elements.h
+        DESTINATION include/xsd/parser/expat
+        COMPONENT   Headers
+        )
+
+INSTALL(FILES 
+        ${libxsd_SOURCE_DIR}/../include/xmlSerialize.h
+        DESTINATION include/
+        COMPONENT   Headers
+        )
+ENDIF(0)
diff --git a/src/xml/reqif/element_factory.cpp b/src/xml/reqif/element_factory.cpp
new file mode 100644 (file)
index 0000000..2443b3a
--- /dev/null
@@ -0,0 +1,46 @@
+#include <ios>
+#include <iostream>
+#include <antcc/config.h>
+#include <logger.h>
+#include <reqif/element_factory.h>
+#include <reqif/elements.h>
+
+namespace reqif {
+
+ElementFactory::ElementFactory()
+{
+}
+
+ElementFactory::~ElementFactory()
+{
+}
+
+ElementFactory &ElementFactory::get()
+{
+  static ElementFactory instance;
+  return instance;
+}
+
+
+Element* ElementFactory::orderElement(const char* typeName)
+{
+  auto it = m_generators.find(typeName);
+  if ( it != m_generators.end()) {
+    ANTCC_PARSER_DEBUG("ElementFactory::orderElement %s",typeName);
+    Element *_elt = it->second(typeName);
+    _elt->setName(typeName);
+    return _elt;
+  }
+  ANTCC_LOG_ERROR("antElementFactory::orderElement <%s> failed not found ",typeName);
+  return nullptr;
+}
+
+bool ElementFactory::registerGenerator(
+                        const char* typeName,
+                        const ElementGenerator& funcCreate)
+{
+  ANTCC_LOG_DEBUG("antElementFactory::registerGenerator %s",typeName);
+  return m_generators.insert(std::make_pair(typeName,funcCreate)).second;
+}
+
+}
diff --git a/src/xml/reqif/element_factory.h b/src/xml/reqif/element_factory.h
new file mode 100644 (file)
index 0000000..83c5eb7
--- /dev/null
@@ -0,0 +1,79 @@
+#pragma once
+#include <string>
+#include <unordered_map>
+#ifdef N_WIN32
+#ifdef BUILD_DLL
+#define DLL_INTERFACE __declspec(dllexport)
+#else
+#define DLL_INTERFACE __declspec(dllimport)
+#endif
+#else
+#define DLL_INTERFACE
+#endif
+namespace reqif {
+
+struct Element;
+typedef Element*(*ElementGenerator)(const char *_typeName);
+class ElementFactory
+{
+public:
+    DLL_INTERFACE static ElementFactory& get();
+    DLL_INTERFACE Element* orderElement(const char* typeName);
+    DLL_INTERFACE bool registerGenerator(
+                            const char* typeName,
+                            const ElementGenerator& funcCreate);
+private:
+    ElementFactory();
+    ElementFactory(const ElementFactory&);
+    ~ElementFactory();
+    std::unordered_map<std::string, ElementGenerator> m_generators;
+};
+
+template <typename T>
+class ElementFactoryRegistration
+{
+  private:
+    static Element *create(const char *_id)
+    {
+        return new T() ;
+    }
+  public:
+    ElementFactoryRegistration(const char *id) 
+    {
+      ElementFactory::get().registerGenerator(
+        id
+        ,ElementFactoryRegistration<T>::create );
+    }
+};
+
+template <typename T>
+class LibElementFactoryRegistration
+{
+  private:
+    static Element *create(const char *_name)
+    {
+        return new T(_name) ;
+    }
+  public:
+    LibElementFactoryRegistration(const char *id) 
+    {
+      ElementFactory::get().registerGenerator(
+        id
+        ,LibElementFactoryRegistration<T>::create );
+    }
+};
+
+/**
+ * How to use registration
+ * in antElements cpp file simply create an object
+ * antElementFactoryRegistration<property> _Property("property");
+ * should do the trick
+ */
+} //end reqif