hiomap: Implement ack

Change-Id: Ia3a3cfed6fe2dba8c92645444f50fcd227f130c9
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/hiomap.cpp b/hiomap.cpp
index faedaa2..e7f688a 100644
--- a/hiomap.cpp
+++ b/hiomap.cpp
@@ -432,6 +432,40 @@
     return IPMI_CC_OK;
 }
 
+static ipmi_ret_t hiomap_ack(ipmi_request_t request, ipmi_response_t response,
+                             ipmi_data_len_t data_len, ipmi_context_t context)
+{
+    struct hiomap *ctx = static_cast<struct hiomap *>(context);
+
+    if (*data_len < 1)
+    {
+        return IPMI_CC_REQ_DATA_LEN_INVALID;
+    }
+
+    uint8_t *reqdata = (uint8_t *)request;
+    auto m = ctx->bus->new_method_call(HIOMAPD_SERVICE, HIOMAPD_OBJECT,
+                                       HIOMAPD_IFACE_V2, "Ack");
+    auto acked = reqdata[0];
+    m.append(acked);
+
+    try
+    {
+        auto reply = ctx->bus->call(m);
+
+        /* Update our cache: Necessary because the signals do not carry a value
+         */
+        ctx->bmc_events &= ~acked;
+
+        *data_len = 0;
+    }
+    catch (const exception::SdBusError &e)
+    {
+        return hiomap_xlate_errno(e.get_errno());
+    }
+
+    return IPMI_CC_OK;
+}
+
 static const hiomap_command hiomap_commands[] = {
     [0] = NULL, /* 0 is an invalid command ID */
     [1] = hiomap_reset,
@@ -442,6 +476,7 @@
     [6] = hiomap_create_write_window,
     [7] = hiomap_mark_dirty,
     [8] = hiomap_flush,
+    [9] = hiomap_ack,
 };
 
 /* FIXME: Define this in the "right" place, wherever that is */