bugfix: load handlers and use factory symbol
Use a predefined factory symbol to build each handler after loading the
library.
Change-Id: I0369c6e46a57c2e8533409d8b06eb74a3962434c
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/example/example.cpp b/example/example.cpp
index 929e4d1..cc36e88 100644
--- a/example/example.cpp
+++ b/example/example.cpp
@@ -181,11 +181,17 @@
void setupExampleHandler()
{
- auto* manager = getBlobManager();
- if (!manager->registerHandler(std::make_unique<ExampleBlobHandler>()))
- {
- log<level::ERR>("Failed to register Example Handler");
- }
+ // You don't need to do anything in the constructor.
}
} // namespace blobs
+
+/**
+ * This method is required by the blob manager.
+ *
+ * It is called to grab a handler for registering the blob handler instance.
+ */
+std::unique_ptr<blobs::GenericBlobInterface> createHandler()
+{
+ return std::make_unique<blobs::ExampleBlobHandler>();
+}
diff --git a/example/example.hpp b/example/example.hpp
index a85c275..335eade 100644
--- a/example/example.hpp
+++ b/example/example.hpp
@@ -1,10 +1,25 @@
#pragma once
#include <blobs-ipmid/blobs.hpp>
+#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This method must be declared as extern C for blob manager to lookup the
+ * symbol.
+ */
+std::unique_ptr<blobs::GenericBlobInterface> createHandler();
+
+#ifdef __cplusplus
+}
+#endif
+
namespace blobs
{