buffet: load standard GCD command definitions in CommandManager Changed CommandManager to load the base command definitions and use it as a base schema for loading device-specific commands and make sure device vendors are not redefining standard commands in breaking manner. BUG=chromium:374861 TEST=USE=buffet P2_TEST_FILTER="buffet::*" FEATURES=test emerge-link platform2 Change-Id: I5f2d5500bc90ef918a8a6df1242bdd1fe3b78615 Reviewed-on: https://chromium-review.googlesource.com/209175 Tested-by: Alex Vakulenko <avakulenko@chromium.org> Reviewed-by: Christopher Wiley <wiley@chromium.org> Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/command_manager.h b/buffet/commands/command_manager.h index 1700712..64037b8 100644 --- a/buffet/commands/command_manager.h +++ b/buffet/commands/command_manager.h
@@ -5,7 +5,10 @@ #ifndef BUFFET_COMMANDS_COMMAND_MANAGER_H_ #define BUFFET_COMMANDS_COMMAND_MANAGER_H_ +#include <string> + #include <base/basictypes.h> +#include <base/files/file_path.h> #include "buffet/commands/command_dictionary.h" @@ -21,7 +24,42 @@ // Get the command definitions for the device. const CommandDictionary& GetCommandDictionary() const; + // Loads base/standard GCD command definitions. + // |json| is the full JSON schema of standard GCD commands. These commands + // are not necessarily supported by a particular device but rather + // all the standard commands defined by GCD standard for all known/supported + // device kinds. + // On success, returns true. Otherwise, |error| contains additional + // error information. + bool LoadBaseCommands(const base::DictionaryValue& json, + ErrorPtr* error); + + // Same as the overload above, but takes a path to a json file to read + // the base command definitions from. + bool LoadBaseCommands(const base::FilePath& json_file_path, + ErrorPtr* error); + + // Loads device command schema for particular category. + // See CommandDictionary::LoadCommands for detailed description of the + // parameters. + bool LoadCommands(const base::DictionaryValue& json, + const std::string& category, ErrorPtr* error); + + // Same as the overload above, but takes a path to a json file to read + // the base command definitions from. Also, the command category is + // derived from file name (without extension). So, if the path points to + // "power_manager.json", the command category used will be "power_manager". + bool LoadCommands(const base::FilePath& json_file_path, + ErrorPtr* error); + private: + // Helper function to load a JSON file that is expected to be + // an object/dictionary. In case of error, returns empty unique ptr and fills + // in error details in |error|. + std::unique_ptr<const base::DictionaryValue> LoadJsonDict( + const base::FilePath& json_file_path, ErrorPtr* error); + + CommandDictionary base_dictionary_; // Base/std command definitions/schemas. CommandDictionary dictionary_; // Command definitions/schemas. DISALLOW_COPY_AND_ASSIGN(CommandManager); };