From 41d2e893c372efe02a5c53712fa996e57b4ffcd4 Mon Sep 17 00:00:00 2001
From: Alvise De Faveri <alvise.defaveri@skywarder.eu>
Date: Fri, 13 Mar 2020 21:14:39 +0100
Subject: [PATCH] [scripts] Update eventgen template files

* Add event and topics list
* Change name EventFunctions.cpp -> EventStrings.cpp
* Fix missing */
---
 ...tions.cpp.template => EventStrings.cpp.template} |  1 +
 scripts/eventgen/Events.h.template                  |  9 ++++++---
 scripts/eventgen/README.md                          |  2 +-
 scripts/eventgen/Topics.h.template                  |  7 ++++---
 scripts/eventgen/eventgen.py                        | 13 ++++++++-----
 5 files changed, 20 insertions(+), 12 deletions(-)
 rename scripts/eventgen/{EventFunctions.cpp.template => EventStrings.cpp.template} (99%)

diff --git a/scripts/eventgen/EventFunctions.cpp.template b/scripts/eventgen/EventStrings.cpp.template
similarity index 99%
rename from scripts/eventgen/EventFunctions.cpp.template
rename to scripts/eventgen/EventStrings.cpp.template
index 1611abafb..ac394d77a 100644
--- a/scripts/eventgen/EventFunctions.cpp.template
+++ b/scripts/eventgen/EventStrings.cpp.template
@@ -33,6 +33,7 @@
 #include "Topics.h"
 
 #include <map>
+using std::map;
 
 string getEventString(uint8_t event)
 {{
diff --git a/scripts/eventgen/Events.h.template b/scripts/eventgen/Events.h.template
index bd9cc2536..6ba4c21b2 100644
--- a/scripts/eventgen/Events.h.template
+++ b/scripts/eventgen/Events.h.template
@@ -32,22 +32,25 @@
 
 #include <cstdint>
 #include <string>
+#include <vector>
 
 #include "events/Event.h"
 #include "events/EventBroker.h"
-#include "EventClasses.h"
 #include "Topics.h"
 
 using std::string;
-using std::map;
 
 /**
- * Definition of all events signals.
+ * Definition of all events in the Homeone Board software
+ * Refer to section 5.1.1 of the Software Design Document.
+ */
 enum Events : uint8_t
 {{
 {enum_data}
 }};
 
+const std::vector<uint8_t> EVENT_LIST {{{event_list}}};
+
 /**
  * @brief Returns the name of the provided event
  *
diff --git a/scripts/eventgen/README.md b/scripts/eventgen/README.md
index 7bfb1c9b0..30ad5fed2 100644
--- a/scripts/eventgen/README.md
+++ b/scripts/eventgen/README.md
@@ -1,6 +1,6 @@
 # Events Generator Script
 
-This script generates Events.h, Topics.h and EventFunctions.cpp from a list of
+This script generates Events.h, Topics.h and EventStrings.cpp from a list of
 SCXML files representing the state machines of a project.
 
 To execute the script:
diff --git a/scripts/eventgen/Topics.h.template b/scripts/eventgen/Topics.h.template
index 2ce2c2c53..ca3f12884 100644
--- a/scripts/eventgen/Topics.h.template
+++ b/scripts/eventgen/Topics.h.template
@@ -32,8 +32,8 @@
 
 #include <stdint.h>
 #include <string>
+#include <vector>
 
-using std::map;
 using std::string;
 
 /**
@@ -44,11 +44,12 @@ enum Topics : uint8_t
 {enum_data}
 }};
 
+const std::vector<uint8_t> TOPIC_LIST {{{topic_list}}};
+
 /**
  * @brief Returns the name of the provided event
  *
  * @param event
  * @return string
  */
-string getTopicString(uint8_t topic);
-
+string getTopicString(uint8_t topic);
\ No newline at end of file
diff --git a/scripts/eventgen/eventgen.py b/scripts/eventgen/eventgen.py
index 9c36223a3..7d772986f 100755
--- a/scripts/eventgen/eventgen.py
+++ b/scripts/eventgen/eventgen.py
@@ -94,6 +94,7 @@ def parse_scxml(files):
 def generate_events(events, date):
     enum_str = ""
     event_map_str = ""
+    event_list_str = ""
 
     # generate string
     for e in events:
@@ -102,14 +103,14 @@ def generate_events(events, date):
             (" = EV_FIRST_SIGNAL" if e == events[0] else "") + endl
         event_map_str += "        {{ {event}, {string} }}{endl}".format(
             event=e, string='"' + e + '"', endl=endl)
+        event_list_str += e + (", " if e != events[-1] else "")
 
     # read template
     with open('Events.h.template', 'r') as template_file:
         template = template_file.read()
 
     # write template
-    template = template.format(date=date, enum_data=enum_str)
-
+    template = template.format(date=date, enum_data=enum_str, event_list=event_list_str)
     with open(join(OUTPUT_FOLDER, 'Events.h'), 'w') as header_file:
         header_file.write(template)
 
@@ -121,17 +122,19 @@ def generate_events(events, date):
 def generate_topics(topics, date):
     enum_str = ""
     topic_map_str = ""
+    topic_list_str = ""
 
     for t in topics:
         endl = ",\n" if t != topics[-1] else ""
         enum_str += "    " + t + endl
         topic_map_str += "        {{ {topics}, {string} }}{endl}".format(
             topics=t, string='"' + t + '"', endl=endl)
+        topic_list_str += t + (", " if t != topics[-1] else "")
 
     with open('Topics.h.template', 'r') as template_file:
         template = template_file.read()
 
-    template = template.format(date=date, enum_data=enum_str)
+    template = template.format(date=date, enum_data=enum_str, topic_list=topic_list_str)
 
     with open(join(OUTPUT_FOLDER, 'Topics.h'), 'w') as header_file:
         header_file.write(template)
@@ -142,12 +145,12 @@ def generate_topics(topics, date):
 # Generate EventFunctions.cpp
 #
 def generate_functions(event_map_str, topic_map_str, date):
-    with open('EventFunctions.cpp.template', 'r') as cpp_template_file:
+    with open('EventStrings.cpp.template', 'r') as cpp_template_file:
         cpp = cpp_template_file.read()
 
     cpp = cpp.format(date=date, event_map_data=event_map_str, topic_map_data=topic_map_str)
 
-    with open(join(OUTPUT_FOLDER, 'EventFunctions.cpp'), 'w') as cpp_file:
+    with open(join(OUTPUT_FOLDER, 'EventStrings.cpp'), 'w') as cpp_file:
         cpp_file.write(cpp)
 
 #
-- 
GitLab