From 3c8927390ed740715602edb99b8da7014e123ff4 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 18 Jun 2018 09:44:33 -0700 Subject: updater: Add SourceInfo::{ReadAll,DumpBuffer,Overlaps}. Bug: 112151972 Test: Run recovery_unit_test on marlin. Change-Id: Ica2a7b3c768f5d8ca5d591a9560bca9f8ed847c5 --- updater/include/private/commands.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'updater/include/private/commands.h') diff --git a/updater/include/private/commands.h b/updater/include/private/commands.h index 85b52883b..521289780 100644 --- a/updater/include/private/commands.h +++ b/updater/include/private/commands.h @@ -16,6 +16,9 @@ #pragma once +#include + +#include #include #include #include @@ -111,6 +114,23 @@ class SourceInfo { } } + // Reads all the data specified by this SourceInfo object into the given 'buffer', by calling the + // given readers. Caller needs to specify the block size for the represented blocks. The given + // buffer needs to be sufficiently large. Otherwise it returns false. 'block_reader' and + // 'stash_reader' read the specified data into the given buffer (guaranteed to be large enough) + // respectively. The readers should return 0 on success, or -1 on error. + bool ReadAll( + std::vector* buffer, size_t block_size, + const std::function*)>& block_reader, + const std::function*)>& stash_reader) const; + + // Whether this SourceInfo overlaps with the given TargetInfo object. + bool Overlaps(const TargetInfo& target) const; + + // Dumps the hashes in hex for the given buffer that's loaded from this SourceInfo object + // (excluding the stashed blocks which are handled separately). + void DumpBuffer(const std::vector& buffer, size_t block_size) const; + const std::string& hash() const { return hash_; } @@ -334,6 +354,10 @@ class Command { return hash_tree_info_; } + size_t block_size() const { + return block_size_; + } + constexpr explicit operator bool() const { return type_ != Type::LAST; } @@ -377,6 +401,8 @@ class Command { StashInfo stash_; // The hash_tree info. Only meaningful for COMPUTE_HASH_TREE. HashTreeInfo hash_tree_info_; + // The unit size of each block to be used in this command. + size_t block_size_{ 4096 }; }; std::ostream& operator<<(std::ostream& os, const Command& command); -- cgit v1.2.3