Add helper method to resolve a log object path

Add a helper method to resolve a previously generated
log entry which can be used by other services in conjunction
with the `lg2::commit` API.

Change-Id: Ia1582177b51ca2f0bfecae98f999b5b8f2f61c93
Signed-off-by: Amithash Prasasd <amithash@meta.com>
diff --git a/README.md b/README.md
index 0537825..25c6af8 100644
--- a/README.md
+++ b/README.md
@@ -72,6 +72,13 @@
     "NUMBER_OF_LOGS", count));
 ```
 
+The above function will return the object path of the created log entry. This
+log-entry can be resolved with the helper `lg2::resolve` fuction.
+
+```cpp
+lg2::resolve(logPath);
+```
+
 There are two other, but now deprecated, methods to creating event logs in
 OpenBMC code. The first makes use of the systemd journal to store metadata
 needed for the log, and the second is a plain D-Bus method call.
diff --git a/lib/include/phosphor-logging/commit.hpp b/lib/include/phosphor-logging/commit.hpp
index d3b291c..fa65077 100644
--- a/lib/include/phosphor-logging/commit.hpp
+++ b/lib/include/phosphor-logging/commit.hpp
@@ -16,6 +16,16 @@
 auto commit(sdbusplus::exception::generated_event_base&& e)
     -> sdbusplus::message::object_path;
 
+/** Resolve an existing event/error.
+ *
+ *  @param logPath - The object path of the event to resolve.
+ *  @return None.
+ *
+ *  Note: Similar to elog(), this will use the default dbus connection to
+ *  perform the operation.
+ */
+void resolve(const sdbusplus::message::object_path& logPath);
+
 /** Commit a generated event/error (using async context).
  *
  *  @param ctx - The async context to use.
@@ -25,4 +35,15 @@
 auto commit(sdbusplus::async::context& ctx,
             sdbusplus::exception::generated_event_base&& e)
     -> sdbusplus::async::task<sdbusplus::message::object_path>;
+
+/** Resolve an existing event/error (using async context).
+ *
+ *  @param ctx - The async context to use.
+ *  @param logPath - The object path of the event to resolve.
+ *  @return None
+ */
+auto resolve(sdbusplus::async::context& ctx,
+             const sdbusplus::message::object_path& logPath)
+    -> sdbusplus::async::task<>;
+
 } // namespace lg2
diff --git a/lib/lg2_commit.cpp b/lib/lg2_commit.cpp
index 6916bf5..a35b91e 100644
--- a/lib/lg2_commit.cpp
+++ b/lib/lg2_commit.cpp
@@ -142,6 +142,20 @@
     return {};
 }
 
+void resolve(const sdbusplus::message::object_path& logPath)
+{
+    if constexpr (LG2_COMMIT_DBUS)
+    {
+        using details::Entry;
+
+        auto b = sdbusplus::bus::new_default();
+        auto m = b.new_method_call(Entry::default_service, logPath.str.c_str(),
+                                   "org.freedesktop.DBus.Properties", "Set");
+        m.append(Entry::interface, "Resolved", std::variant<bool>(true));
+        auto reply = b.call(m);
+    }
+}
+
 auto commit(sdbusplus::async::context& ctx,
             sdbusplus::exception::generated_event_base&& t)
     -> sdbusplus::async::task<sdbusplus::message::object_path>
@@ -164,4 +178,21 @@
     co_return {};
 }
 
+auto resolve(sdbusplus::async::context& ctx,
+             const sdbusplus::message::object_path& logPath)
+    -> sdbusplus::async::task<>
+{
+    using details::Entry;
+
+    if constexpr (LG2_COMMIT_DBUS)
+    {
+        std::string path = logPath.str;
+        co_await Entry(ctx)
+            .service(Entry::default_service)
+            .path(path)
+            .resolved(true);
+    }
+    co_return;
+}
+
 } // namespace lg2