OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // Defines the PlatformReader base class. It provides a default file reading |
| 6 // implementation that pulls in the contents of the given platform_file_path. |
| 7 // This content is passed to a subclass-defined Process() helper which will |
| 8 // return an int. This int should map to the anonymous enum in the |
| 9 // PlatformReader class or to an extension to that enum in the subclass. |
| 10 #ifndef CROS_BOOT_MODE_PLATFORM_READER_H_ |
| 11 #define CROS_BOOT_MODE_PLATFORM_READER_H_ |
| 12 |
| 13 #include <sys/types.h> |
| 14 #include <string> |
| 15 |
| 16 #include "helpers.h" |
| 17 |
| 18 namespace cros_boot_mode { |
| 19 |
| 20 class PlatformReader { |
| 21 public: |
| 22 enum { kUnsupported = -1 }; // All subclasses should extend this enum. |
| 23 PlatformReader(); |
| 24 virtual ~PlatformReader(); |
| 25 // Provides a default file reader which then calls an override-able |
| 26 // function for processing. Initialize must leave the class in a usable |
| 27 // state even on failure. |
| 28 virtual void Initialize(); |
| 29 |
| 30 // To be provided by the implementation |
| 31 |
| 32 // The name of the concrete class. |
| 33 virtual const char *name() const = 0; |
| 34 // c_str() should return the conversion of the given enum to a lowercase |
| 35 // char array with no spaces. |
| 36 virtual const char *c_str() const = 0; |
| 37 // max_size should return the maximum size that will be read. |
| 38 virtual size_t max_size() const = 0; |
| 39 // default_platform_file_path should return the char array of the |
| 40 // path to the file to be processed. |
| 41 virtual const char *default_platform_file_path() const = 0; |
| 42 // Called from initialize over the contents of the platform file. It |
| 43 // should return an int that matches either kUnsupported or an extension |
| 44 // of the anonymous enum. If the file does not exist, cannot be read, |
| 45 // or exceeds the max_size(), Process will be called with (buf, 0) arguments. |
| 46 virtual int Process(const char *file_contents, size_t length) = 0; |
| 47 |
| 48 // Accessors for the private value. |
| 49 // These are largely used for internal references, but kept in public |
| 50 // to allow for direct unit testing. |
| 51 virtual int value() const { |
| 52 return value_; |
| 53 } |
| 54 virtual void set_value(int value) { |
| 55 value_ = value; |
| 56 } |
| 57 |
| 58 virtual const char *platform_file_path() const; |
| 59 virtual void set_platform_file_path(const char *path) { |
| 60 platform_file_path_ = path; |
| 61 } |
| 62 |
| 63 private: |
| 64 int value_; |
| 65 const char *platform_file_path_; |
| 66 }; |
| 67 |
| 68 } // namespace cros_boot_mode |
| 69 #endif // CROS_BOOT_MODE_PLATFORM_READER_H_ |
OLD | NEW |