Build FRU table lazily

The FRU table is created when the PLDM daemon starts and depends on
BMC inventory collection to populate it completely. There is no D-Bus
signal or target that PLDM daemon can rely on to figure completion of
inventory. This can cause some of the inventory to not show up in the
FRU table if the inventory collection is not complete when the PLDM
daemon starts.

An easy solution to this problem is to do the FRU table creation
lazily. The FRU table will be created when the FRU commands or Get PDR
command is handled the first time. The entity association PDR's are
created when the FRU table is built. So Get PDR commands expects the
building of the FRU table as a pre condition.

Tested:

Ensured FRU table is created when the GetFRURecordTableMetadata,
GetFRURecordTable and GetPDR command is handled by the PLDM daemon the
first time. Next time already built table is returned for the FRU
commands.

Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Change-Id: I0deb723f30a30a667d0e80c9f9f6aced5ab23a67
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index b2912bc..fa1c89c 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -186,13 +186,16 @@
     Invoker invoker{};
     invoker.registerHandler(PLDM_BASE, std::make_unique<base::Handler>());
     invoker.registerHandler(PLDM_BIOS, std::make_unique<bios::Handler>());
+    auto fruHandler = std::make_unique<fru::Handler>(
+        FRU_JSONS_DIR, pdrRepo.get(), entityTree.get());
+    // FRU table is built lazily when a FRU command or Get PDR command is
+    // handled. To enable building FRU table, the FRU handler is passed to the
+    // Platform handler.
     invoker.registerHandler(PLDM_PLATFORM,
                             std::make_unique<platform::Handler>(
                                 PDR_JSONS_DIR, EVENTS_JSONS_DIR, pdrRepo.get(),
-                                hostPDRHandler.get()));
-    invoker.registerHandler(
-        PLDM_FRU, std::make_unique<fru::Handler>(FRU_JSONS_DIR, pdrRepo.get(),
-                                                 entityTree.get()));
+                                hostPDRHandler.get(), fruHandler.get()));
+    invoker.registerHandler(PLDM_FRU, std::move(fruHandler));
 
 #ifdef OEM_IBM
     invoker.registerHandler(PLDM_OEM, std::make_unique<oem_ibm::Handler>());