pldmd: implement a new handler registration scheme

Implement a PLDM request handler registration scheme that requires
handlers to be C++ objects rather than plain functions. This was needed
for a couple of reasons:

- Perform specific actions at the PLDM daemon startup (that's when the
  handlers are loaded).
- Share data across PLDM request messages (for eg FRU/BIOS tables),
  without having to resort to globals and statics.

Tested:
- existing unit tests still pass
- added tests for the new registration scheme

Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Change-Id: I1cf1c0a6fccd15da54f08120e61a5f256df6bc36
diff --git a/libpldmresponder/base.hpp b/libpldmresponder/base.hpp
index a6e5abd..519bff2 100644
--- a/libpldmresponder/base.hpp
+++ b/libpldmresponder/base.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include "handler.hpp"
+
 #include <stdint.h>
 
 #include <vector>
@@ -8,51 +10,67 @@
 
 namespace pldm
 {
-
-using Type = uint8_t;
-
-using Response = std::vector<uint8_t>;
-
 namespace responder
 {
-
 namespace base
 {
-/** @brief Register handlers for command from the base spec
- */
-void registerHandlers();
+
+class Handler : public CmdHandler
+{
+  public:
+    Handler()
+    {
+        handlers.emplace(PLDM_GET_PLDM_TYPES,
+                         [this](const pldm_msg* request, size_t payloadLength) {
+                             return this->getPLDMTypes(request, payloadLength);
+                         });
+        handlers.emplace(PLDM_GET_PLDM_COMMANDS, [this](const pldm_msg* request,
+                                                        size_t payloadLength) {
+            return this->getPLDMCommands(request, payloadLength);
+        });
+        handlers.emplace(PLDM_GET_PLDM_VERSION, [this](const pldm_msg* request,
+                                                       size_t payloadLength) {
+            return this->getPLDMVersion(request, payloadLength);
+        });
+        handlers.emplace(PLDM_GET_TID,
+                         [this](const pldm_msg* request, size_t payloadLength) {
+                             return this->getTID(request, payloadLength);
+                         });
+    }
+
+    /** @brief Handler for getPLDMTypes
+     *
+     *  @param[in] request - Request message payload
+     *  @param[in] payload_length - Request message payload length
+     *  @param[return] Response - PLDM Response message
+     */
+    Response getPLDMTypes(const pldm_msg* request, size_t payloadLength);
+
+    /** @brief Handler for getPLDMCommands
+     *
+     *  @param[in] request - Request message payload
+     *  @param[in] payload_length - Request message payload length
+     *  @param[return] Response - PLDM Response message
+     */
+    Response getPLDMCommands(const pldm_msg* request, size_t payloadLength);
+
+    /** @brief Handler for getPLDMCommands
+     *
+     *  @param[in] request - Request message payload
+     *  @param[in] payload_length - Request message payload length
+     *  @param[return] Response - PLDM Response message
+     */
+    Response getPLDMVersion(const pldm_msg* request, size_t payloadLength);
+
+    /** @brief Handler for getTID
+     *
+     *  @param[in] request - Request message payload
+     *  @param[in] payload_length - Request message payload length
+     *  @param[return] Response - PLDM Response message
+     */
+    Response getTID(const pldm_msg* request, size_t payloadLength);
+};
+
 } // namespace base
-
-/** @brief Handler for getPLDMTypes
- *
- *  @param[in] request - Request message payload
- *  @param[in] payload_length - Request message payload length
- *  @param[return] Response - PLDM Response message
- */
-Response getPLDMTypes(const pldm_msg* request, size_t payloadLength);
-
-/** @brief Handler for getPLDMCommands
- *
- *  @param[in] request - Request message payload
- *  @param[in] payload_length - Request message payload length
- *  @param[return] Response - PLDM Response message
- */
-Response getPLDMCommands(const pldm_msg* request, size_t payloadLength);
-
-/** @brief Handler for getPLDMCommands
- *
- *  @param[in] request - Request message payload
- *  @param[in] payload_length - Request message payload length
- *  @param[return] Response - PLDM Response message
- */
-Response getPLDMVersion(const pldm_msg* request, size_t payloadLength);
-
-/** @brief Handler for getTID
- *
- *  @param[in] request - Request message payload
- *  @param[in] payload_length - Request message payload length
- *  @param[return] Response - PLDM Response message
- */
-Response getTID(const pldm_msg* request, size_t payloadLength);
 } // namespace responder
 } // namespace pldm