Update generator at latest low level binding
authorRomain Forlot <romain.forlot@iot.bzh>
Tue, 6 Jun 2017 08:18:08 +0000 (10:18 +0200)
committerRomain Forlot <romain.forlot@iot.bzh>
Tue, 6 Jun 2017 08:18:08 +0000 (10:18 +0200)
- renaming configuration to application
- make message_set as a vector of shared_ptr
- Setting up object parent in graphs at application object instanciation

Change-Id: Ib33103d5cebbd9381375d2832582a25ae0f9f199
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
CAN-config-generator/src/main.cpp
CAN-config-generator/tests/generated.cpp

index 5f2e28f..d30428e 100644 (file)
@@ -109,7 +109,7 @@ template <>
 std::ostream& operator<<(std::ostream& o, const generator<openxc::message_set>& v)\r
 {\r
        o       << v.line_prefix_\r
-               << "can_message_set_t{"\r
+               << "{std::make_shared<can_message_set_t>(can_message_set_t{"\r
                << "0,"\r
                << gen(v.v_.name()) << ",\n"\r
                << "\t\t\t{ // beginning can_message_definition_ vector\n"\r
@@ -118,7 +118,7 @@ std::ostream& operator<<(std::ostream& o, const generator<openxc::message_set>&
                << "\t\t\t{ // beginning diagnostic_messages_ vector\n"\r
                << gen(v.v_.diagnostic_messages(),"\t\t\t") << "\n"\r
                << "\t\t\t} // end diagnostic_messages_ vector\n"\r
-               << "\t\t} // end can_message_set entry\n";\r
+               << "\t\t})} // end can_message_set entry\n";\r
        return o;\r
 }\r
 \r
@@ -208,25 +208,44 @@ std::ostream& operator<<(std::ostream& o, const generator<openxc::diagnostic_mes
        return o;\r
 }\r
 \r
-/// @brief Generate the configuration code.\r
+/// @brief Generate the application code.\r
 /// @param[in] header Content to be inserted as a header.\r
 /// @param[in] footer Content to be inserted as a footer.\r
-/// @param[in] message_set Configuration read from the json file.\r
+/// @param[in] message_set application read from the json file.\r
 /// @param[in] out Stream to write on.\r
 void generate(const std::string& header, const std::string& footer, const openxc::message_set& message_set, std::ostream& out)\r
 {\r
-       out << "#include \"configuration.hpp\"\n"\r
+       out << "#include \"application.hpp\"\n"\r
                << "#include \"../can/can-decoder.hpp\"\n\n";\r
 \r
        if (header.size()) out << header << "\n";\r
 \r
-       out     << "configuration_t::configuration_t()\n"\r
+       out     << "application_t::application_t()\n"\r
                << "    : can_bus_manager_{utils::config_parser_t{\"/etc/dev-mapping.conf\"}}\n"\r
                << "    , can_message_set_{\n"\r
                << gen(message_set, "\t\t")\r
                << "\t} // end can_message_set vector\n"\r
-               << "{}\n\n"\r
-               << "const std::string configuration_t::get_diagnostic_bus() const\n"\r
+               << "{\n"\r
+               << "    for(auto& cms: can_message_set_)\n"\r
+               << "    {\n"\r
+               << "            std::vector<std::shared_ptr<can_message_definition_t> >& can_messages_definition = cms->get_can_message_definition();\n"\r
+               << "            for(auto& cmd : can_messages_definition)\n"\r
+               << "            {\n"\r
+               << "                    cmd->set_parent(cms.get());\n"\r
+               << "                    std::vector<std::shared_ptr<can_signal_t> >& can_signals = cmd->get_can_signals();\n"\r
+               << "                    for(auto& sig: can_signals)\n"\r
+               << "                    {\n"\r
+               << "                            sig->set_parent(cmd.get());\n"\r
+               << "                    }\n"\r
+               << "            }\n\n"\r
+               << "            std::vector<std::shared_ptr<diagnostic_message_t> >& diagnostic_messages = cms->get_diagnostic_messages();\n"\r
+               << "            for(auto& dm : diagnostic_messages)\n"\r
+               << "            {\n"\r
+               << "                    dm->set_parent(cms.get());\n"\r
+               << "            }\n"\r
+               << "    }\n"\r
+               << "            }\n\n"\r
+               << "const std::string application_t::get_diagnostic_bus() const\n"\r
                << "{\n";\r
 \r
                std::string active_bus = "";\r
@@ -286,11 +305,11 @@ nlohmann::json read_json(const std::string& file)
 // function that show the help information\r
 void showhelpinfo(char *s)\r
 {\r
-std::cout<<"Usage:   "<<s<<" <-m inpout.json> [-o configuration-generated.cpp]"<< std::endl;\r
+std::cout<<"Usage:   "<<s<<" <-m inpout.json> [-o application-generated.cpp]"<< std::endl;\r
 std::cout<<"option:  "<<"-m  input.json : JSON file describing CAN messages and signals"<< std::endl;\r
 std::cout<<"         "<<"-h header.cpp : header source file insert at the beginning of generated file"<< std::endl;\r
 std::cout<<"         "<<"-f footer.cpp : footer source file append to generated file."<< std::endl;\r
-std::cout<<"         "<<"-o configuration-generated.cpp : output source file. Name has to be configuration-generated.cpp"<< std::endl;\r
+std::cout<<"         "<<"-o application-generated.cpp : output source file. Name has to be application-generated.cpp"<< std::endl;\r
 }\r
 \r
 /// @brief Entry point.\r
index e8bb5c9..9768860 100644 (file)
@@ -1,4 +1,4 @@
-#include "configuration.hpp"
+#include "application.hpp"
 #include "can/can-decoder.hpp"
 
 
@@ -28,7 +28,7 @@ void myLooper() {
 
 // <<<<< handlers.cpp <<<<<
 
-configuration_t::configuration_t()
+application_t::application_t()
        : can_message_set_{0, "example", 2, 2, 7, 1, 3}
        , can_message_definition_
        {