diff options
author | Hung-Te Lin <hungte@chromium.org> | 2010-06-02 18:13:47 -0700 |
---|---|---|
committer | Hung-Te Lin <hungte@chromium.org> | 2010-06-02 18:13:47 -0700 |
commit | 21ef1a3678854cf1a0ff63a6548305a3df2ecec3 (patch) | |
tree | 59c58c4c220be16404e4c4fc09ff52a38071f50c /utility/include/gbb_utility.h | |
parent | b8976b6d448de9d95f1f97ac0b0c1933f4050121 (diff) | |
download | vboot-21ef1a3678854cf1a0ff63a6548305a3df2ecec3.tar.gz |
Refine gbb_utility for better maintainance
* now -g (get mode) becomes default
* properties are now managed in a more generalized way so adding new property would be more easy
Review URL: http://codereview.chromium.org/2549001
Diffstat (limited to 'utility/include/gbb_utility.h')
-rw-r--r-- | utility/include/gbb_utility.h | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/utility/include/gbb_utility.h b/utility/include/gbb_utility.h index 70a45275..021eb80f 100644 --- a/utility/include/gbb_utility.h +++ b/utility/include/gbb_utility.h @@ -13,6 +13,14 @@ namespace vboot_reference { class GoogleBinaryBlockUtil { public: + // enumerate of available data fields + enum PROPINDEX { + PROP_HWID, // hardware id + PROP_ROOTKEY, // root key + PROP_BMPFV, // bitmap FV + PROP_RANGE, // indicator of valid property range + }; + GoogleBinaryBlockUtil(); ~GoogleBinaryBlockUtil(); @@ -24,22 +32,27 @@ class GoogleBinaryBlockUtil { // return true on success. bool save_to_file(const char *filename); - // getters and setters of properties in GBB - bool set_hwid(const char *hwid); // hwid is NUL-terminated. + // retrieve the value of a property from GBB data. + // return the property value. + std::string get_property(PROPINDEX i) const; + + // overwrite a property in GBB data. + // return true on success. + bool set_property(PROPINDEX i, const std::string &value); + + // get a readable name by a property index. + // return the name for valid properties, otherwise unexpected empty string. + std::string get_property_name(PROPINDEX i) const; + + // quick getters and setters of known properties in GBB + bool set_hwid(const char *hwid); // NOTE: hwid is NUL-terminated. bool set_rootkey(const std::string &value); bool set_bmpfv(const std::string &value); - std::string get_hwid() const { return get_property(PROP_HWID); } + std::string get_hwid() const { return get_property(PROP_HWID); } std::string get_rootkey() const { return get_property(PROP_ROOTKEY); } - std::string get_bmpfv() const { return get_property(PROP_BMPFV); } + std::string get_bmpfv() const { return get_property(PROP_BMPFV); } private: - // enumerate of available data fields - enum PROPINDEX { - PROP_HWID, // hardware id - PROP_ROOTKEY, // root key - PROP_BMPFV, // bitmap FV - }; - // clear all cached data and initialize to original state void initialize(); @@ -52,17 +65,12 @@ class GoogleBinaryBlockUtil { bool load_gbb_header(const std::string &image, long offset, GoogleBinaryBlockHeader *phdr) const; - // retrieve a property from GBB data. - // return the property value. - std::string get_property(PROPINDEX i) const; - - // overwrite a property in GBB data. - // return true on success. - bool set_property(PROPINDEX i, const std::string &value); - - // find the size and offset information for given property - // return true if the offset and size are assign to *poffset and *psize. - bool find_property(PROPINDEX i, uint32_t *poffset, uint32_t *psize) const; + // find the size, offset, and name information for given property. + // return true if the offset and size are assign to *poffset and *psize; + // if pname is not NULL, *pname will hold a pointer to a readable name. + // return false if the property index is invalid. + bool find_property(PROPINDEX i, uint32_t *poffset, uint32_t *psize, + const char **pname) const; GoogleBinaryBlockHeader header_; // copy of GBB header from image std::string file_content_; // complete image file content |