Update elog gen script to support the dbus specified errors

This work is in prep for running this python script against the
errors defined in the phosphor-dbus-interfaces repo

Change-Id: I85e6f612a5935391deaedc74aab06ca023c15703
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/elog-gen-template.mako.hpp b/elog-gen-template.mako.hpp
index 8461f70..cb7137d 100644
--- a/elog-gen-template.mako.hpp
+++ b/elog-gen-template.mako.hpp
@@ -15,7 +15,16 @@
 {
 
     % for a in errors:
-namespace _${errors[a]}
+<%
+    namespaces = errors[a].split('.')
+    classname = namespaces.pop()
+%>\
+    % for s in namespaces:
+namespace ${s}
+{
+    % endfor
+
+namespace _${classname}
 {
     % for b in meta[a]:
 struct ${b}
@@ -28,19 +37,23 @@
 };
     % endfor
 
-}  // namespace _${errors[a]}
+}  // namespace _${classname}
 <% meta_string = ', '.join(meta[a]) %>
-struct ${errors[a]}
+struct ${classname}
 {
-    static constexpr auto err_code = "xyz.openbmc_project.logging.${errors[a]}";
+    static constexpr auto err_code = "${errors[a]}";
     static constexpr auto err_msg = "${error_msg[errors[a]]}";
     static constexpr auto L = level::${error_lvl[errors[a]]};
     % for b in meta[a]:
-    using ${b} = _${errors[a]}::${b};
+    using ${b} = _${classname}::${b};
     % endfor
     using metadata_types = std::tuple<${meta_string}>;
 };
 
+% for s in reversed(namespaces):
+} // namespace ${s}
+% endfor
+
     % endfor
 
 } // namespace logging
diff --git a/elog-gen.py b/elog-gen.py
index 25f40f0..c94e1b4 100755
--- a/elog-gen.py
+++ b/elog-gen.py
@@ -38,17 +38,15 @@
 
     # see elog.yaml for reference
     ifile = yaml.safe_load(open(i_elog_yaml))
-    err_count = 0;
-    for i in ifile['SW'].keys():
-        # Grab the main error
-        errors[err_count] = i
-        # Grab it's sub-items
-        prop = ifile['SW'][i]
-        error_msg[i] = prop['msg']
-        error_lvl[i] = prop['level']
+    err_count = 0
+    for i in ifile['error-codes']:
+        # Grab the main error and it's info
+        errors[err_count] = i['name']
+        error_msg[i['name']] = i['msg']
+        error_lvl[i['name']] = i['level']
         tmp_meta = []
         # grab all the meta data fields and info
-        for j in prop['meta']:
+        for j in i['meta']:
             str_short = j['str'].split('=')[0]
             tmp_meta.append(str_short)
             meta_data[str_short] = {}
@@ -60,11 +58,11 @@
 
     # Debug
     # for i in errors:
-    #    print "ERROR: " + errors[i]
-    #    print " MSG:  " + error_msg[errors[i]]
-    #    print " LVL:  " + error_lvl[errors[i]]
-    #    print " META: "
-    #    print meta[i]
+    #   print "ERROR: " + errors[i]
+    #   print " MSG:  " + error_msg[errors[i]]
+    #   print " LVL:  " + error_lvl[errors[i]]
+    #   print " META: "
+    #   print meta[i]
 
     # Load the mako template and call it with the required data
     mytemplate = Template(filename=i_input_mako)
@@ -79,21 +77,21 @@
     parser = OptionParser()
 
     parser.add_option("-e", "--elog", dest="elog_yaml", default="elog.yaml",
-                      help="input error yaml file to parse");
+                      help="input error yaml file to parse")
 
     parser.add_option("-m", "--mako", dest="elog_mako",
                       default="elog-gen-template.mako.hpp",
-                      help="input mako template file to use");
+                      help="input mako template file to use")
 
     parser.add_option("-o", "--output", dest="output_hpp",
                       default="elog-gen.hpp",
-                      help="output hpp to generate, elog-gen.hpp is default");
+                      help="output hpp to generate, elog-gen.hpp is default")
 
     (options, args) = parser.parse_args(i_args)
 
     if (not (os.path.isfile(options.elog_yaml))):
         print "Can not find input yaml file " + options.elog_yaml
-        exit(1);
+        exit(1)
 
     gen_elog_hpp(options.elog_yaml, options.elog_mako,
                  options.output_hpp)
diff --git a/elog.yaml b/elog.yaml
index 0dd21e3..17cf1e0 100644
--- a/elog.yaml
+++ b/elog.yaml
@@ -1,22 +1,22 @@
----
-SW:
-    FILE_NOT_FOUND:
-        msg: "A required file was not found"
-        level: INFO
-        meta:
-            - str: "ERRNUM=0x%.4X"
-              type: int
-            - str: FILE_PATH=%s
-              type: const char*
-            - str: FILE_NAME=%s
-              type: const char*
-    GETSCOM:
-        msg: "Getscom call failed"
-        level: ERR
-        meta:
+error-codes:
+    - name: org.freedesktop.DBus.Error.FileNotFound
+      msg: "A required file was not found"
+      level: INFO
+      meta:
+        - str: "ERRNUM=0x%.4X"
+          type: int
+        - str: FILE_PATH=%s
+          type: const char *
+        - str: FILE_NAME=%s
+          type: const char *
+
+    - name: xyz.openbmc_project.Hwsv.Error.Scom
+      msg: "Getscom call failed"
+      level: ERR
+      meta:
             - str: DEV_ADDR=0x%.8X
               type: int
             - str: DEV_ID=%u
               type: int
             - str: DEV_NAME=%s
-              type: const char*
\ No newline at end of file
+              type: const char*
diff --git a/logging_test.cpp b/logging_test.cpp
index c5f622c..6c7d343 100644
--- a/logging_test.cpp
+++ b/logging_test.cpp
@@ -75,29 +75,36 @@
     const char *test_string = "/tmp/test_string/";
     try
     {
-        elog<FILE_NOT_FOUND>(FILE_NOT_FOUND::ERRNUM(number),
-                             FILE_NOT_FOUND::FILE_PATH(test_string),
-                             FILE_NOT_FOUND::FILE_NAME("elog_test_3.txt"));
+        elog<org::freedesktop::DBus::Error::FileNotFound>(
+                org::freedesktop::DBus::Error::FileNotFound::
+                    ERRNUM(number),
+                org::freedesktop::DBus::Error::FileNotFound::
+                    FILE_PATH(test_string),
+                org::freedesktop::DBus::Error::FileNotFound::
+                    FILE_NAME("elog_test_3.txt"));
     }
-    catch (elogException<FILE_NOT_FOUND>& e)
+    catch (elogException<org::freedesktop::DBus::Error::FileNotFound>& e)
     {
         std::cout << "elog exception caught: " << e.what() << std::endl;
     }
 
+    // Reduce our error namespaces
+    using namespace org::freedesktop::DBus::Error;
+
     // Now read back and verify our data made it into the journal
     std::stringstream stream;
     stream << std::hex << number;
-    rc = validate_journal(FILE_NOT_FOUND::ERRNUM::str_short,
+    rc = validate_journal(FileNotFound::ERRNUM::str_short,
                           std::string(stream.str()).c_str());
     if(rc)
         return(rc);
 
-    rc = validate_journal(FILE_NOT_FOUND::FILE_PATH::str_short,
+    rc = validate_journal(FileNotFound::FILE_PATH::str_short,
                           test_string);
     if(rc)
         return(rc);
 
-    rc = validate_journal(FILE_NOT_FOUND::FILE_NAME::str_short,
+    rc = validate_journal(FileNotFound::FILE_NAME::str_short,
                           "elog_test_3.txt");
     if(rc)
         return(rc);
@@ -106,9 +113,9 @@
     number = 0x9876;
     try
     {
-        elog<FILE_NOT_FOUND>(FILE_NOT_FOUND::ERRNUM(number),
-                             prev_entry<FILE_NOT_FOUND::FILE_PATH>(),
-                             FILE_NOT_FOUND::FILE_NAME("elog_test_4.txt"));
+        elog<FileNotFound>(FileNotFound::ERRNUM(number),
+                             prev_entry<FileNotFound::FILE_PATH>(),
+                             FileNotFound::FILE_NAME("elog_test_4.txt"));
     }
     catch (elogExceptionBase& e)
     {
@@ -118,18 +125,18 @@
     // Now read back and verify our data made it into the journal
     stream.str("");
     stream << std::hex << number;
-    rc = validate_journal(FILE_NOT_FOUND::ERRNUM::str_short,
+    rc = validate_journal(FileNotFound::ERRNUM::str_short,
                           std::string(stream.str()).c_str());
     if(rc)
         return(rc);
 
     // This should just be equal to what we put in test 3
-    rc = validate_journal(FILE_NOT_FOUND::FILE_PATH::str_short,
+    rc = validate_journal(FileNotFound::FILE_PATH::str_short,
                           test_string);
     if(rc)
         return(rc);
 
-    rc = validate_journal(FILE_NOT_FOUND::FILE_NAME::str_short,
+    rc = validate_journal(FileNotFound::FILE_NAME::str_short,
                           "elog_test_4.txt");
     if(rc)
         return(rc);
@@ -137,13 +144,13 @@
     // Compile fail tests
 
     // Simple test to prove we fail to compile due to missing param
-    //elog<FILE_NOT_FOUND>(FILE_NOT_FOUND::ERRNUM(1),
-    //                     FILE_NOT_FOUND::FILE_PATH("test"));
+    //elog<FileNotFound>(FileNotFound::ERRNUM(1),
+    //                   FileNotFound::FILE_PATH("test"));
 
     // Simple test to prove we fail to compile due to invalid param
-    //elog<FILE_NOT_FOUND>(FILE_NOT_FOUND::ERRNUM(1),
-    //                     FILE_NOT_FOUND::FILE_PATH("test"),
-    //                     FILE_NOT_FOUND::FILE_NAME(1));
+    //elog<FileNotFound>(FileNotFound::ERRNUM(1),
+    //                   FileNotFound::FILE_PATH("test"),
+    //                   FileNotFound::FILE_NAME(1));
 
     return 0;
 }