Add Id to Trigger

Currently, Trigger is using Name as unique identifier. By adding Id, we
can be compliant with redfish specification:
- Id will be used as unique identifier
- Name will be used as human readable, non-unique name

AddTrigger dbus method is now requiring both id and name. Each of them
can be passed as empty string and the service will fill them with
correct values. If only id is an empty string, name will be used to
generate its value.

Dbus object path and persistent storage filename are now be based on id,
instead of name.

Added validation for AddTrigger:
- correct characters in id
- max id length

Added Name property for Trigger object, which can be modified from dbus.

Testing done:
- Unit test added and passing
- Trigger was added using dbus, without errors
- Id generation is working properly
- Name property is accessible and writable from dbus

Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: Ibb553586eaf51943044c93a35bc0725e6ef67ce9
diff --git a/src/trigger_manager.hpp b/src/trigger_manager.hpp
index c3acd36..4837062 100644
--- a/src/trigger_manager.hpp
+++ b/src/trigger_manager.hpp
@@ -3,6 +3,7 @@
 #include "interfaces/report_manager.hpp"
 #include "interfaces/trigger_factory.hpp"
 #include "interfaces/trigger_manager.hpp"
+#include "trigger.hpp"
 
 #include <sdbusplus/asio/object_server.hpp>
 
@@ -30,10 +31,15 @@
     std::unique_ptr<sdbusplus::asio::dbus_interface> managerIface;
     std::vector<std::unique_ptr<interfaces::Trigger>> triggers;
 
-    void verifyAddTrigger(const std::string& triggerName);
+    void verifyAddTrigger(const std::string& triggerId,
+                          const std::string& triggerName) const;
+    std::string generateId(const std::string& prefix,
+                           const std::string& triggerName) const;
+    static void verifyTriggerIdLength(const std::string& triggerId);
+    static void verifyIdCharacters(const std::string& triggerId);
 
     interfaces::Trigger&
-        addTrigger(const std::string& triggerName,
+        addTrigger(const std::string& triggerId, const std::string& triggerName,
                    const std::vector<std::string>& triggerActions,
                    const std::vector<LabeledSensorInfo>& labeledSensors,
                    const std::vector<std::string>& reportNames,
@@ -42,8 +48,15 @@
 
   public:
     static constexpr size_t maxTriggers{TELEMETRY_MAX_TRIGGERS};
+    static constexpr size_t maxTriggerIdLength{
+        TELEMETRY_MAX_DBUS_PATH_LENGTH -
+        std::string_view(Trigger::triggerDir).length()};
     static constexpr const char* triggerManagerIfaceName =
         "xyz.openbmc_project.Telemetry.TriggerManager";
     static constexpr const char* triggerManagerPath =
         "/xyz/openbmc_project/Telemetry/Triggers";
+
+    static constexpr std::string_view allowedCharactersInId =
+        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_/";
+    static constexpr const char* triggerNameDefault = "Trigger";
 };