firmware: implement canHandleBlob
Implement the canHandleBlob method. For any blob_id specific command
from the manager level, it'll ask each handler if they support that
blob_id before passing it down. The call is made against only the first
handler that responds in the affirmative.
If the client creates a new blob_id via an action, they are expected to
again enumerate the blobs to verify the operation -- although they don't
need to. Any action that creates or deletes a blob_id will update the
firmwares list.
Operations are single-threaded.
Change-Id: Id3cedb33013e59ea52a7878478557822bf29e33f
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index 0e26ab2..4c076de 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -1,5 +1,6 @@
#include "firmware_handler.hpp"
+#include <algorithm>
#include <cstdint>
#include <memory>
#include <string>
@@ -18,6 +19,11 @@
bool FirmwareBlobHandler::canHandleBlob(const std::string& path)
{
/* Check if the path is in our supported list (or active list). */
+ if (std::count(firmwares.begin(), firmwares.end(), path))
+ {
+ return true;
+ }
+
return false;
}
@@ -25,17 +31,13 @@
{
/*
* Grab the list of supported firmware.
- * If there's an open session, add that to this list.
+ *
+ * If there's an open firmware session, it'll already be present in the
+ * list as "/flash/active/image", and if the hash has started,
+ * "/flash/active/hash" regardless of mechanism. This is done in the open
+ * comamnd, no extra work is required here.
*/
- std::vector<std::string> blobs = baseFirmwares;
-
- /*
- * If there's an open firmware session, it'll add "/flash/active/image",
- * and if the hash has started, "/flash/active/hash" regardless of
- * mechanism.
- */
-
- return blobs;
+ return firmwares;
}
bool FirmwareBlobHandler::deleteBlob(const std::string& path)
diff --git a/firmware_handler.hpp b/firmware_handler.hpp
index f9a8983..05bd84d 100644
--- a/firmware_handler.hpp
+++ b/firmware_handler.hpp
@@ -22,13 +22,25 @@
class FirmwareBlobHandler : public GenericBlobInterface
{
public:
+ /**
+ * Create a FirmwareBlobHandler.
+ *
+ * @param[in] firmwares - list of blobs_ids to support.
+ * @param[in] transports - bitmask of transports to support.
+ */
static std::unique_ptr<GenericBlobInterface>
CreateFirmwareBlobHandler(const std::vector<std::string>& firmwares,
std::uint32_t transports);
+ /**
+ * Create a FirmwareBlobHandler.
+ *
+ * @param[in] firmwares - list of blobs_ids to support.
+ * @param[in] transports - bitmask of transports to support.
+ */
FirmwareBlobHandler(const std::vector<std::string>& firmwares,
std::uint32_t transports) :
- baseFirmwares(firmwares),
+ firmwares(firmwares),
transports(transports)
{
}
@@ -56,7 +68,7 @@
bool expire(uint16_t session) override;
private:
- std::vector<std::string> baseFirmwares;
+ std::vector<std::string> firmwares;
std::uint32_t transports;
};