Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 1 | // Copyright 2014 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 | #ifndef BUFFET_COMMANDS_COMMAND_MANAGER_H_ |
| 6 | #define BUFFET_COMMANDS_COMMAND_MANAGER_H_ |
| 7 | |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 10 | #include <base/basictypes.h> |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 11 | #include <base/files/file_path.h> |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 12 | |
| 13 | #include "buffet/commands/command_dictionary.h" |
| 14 | |
| 15 | namespace buffet { |
| 16 | |
| 17 | // CommandManager class that will have a list of all the device command |
| 18 | // schemas as well as the live command queue of pending command instances |
| 19 | // dispatched to the device. |
| 20 | class CommandManager { |
| 21 | public: |
| 22 | CommandManager() = default; |
| 23 | |
| 24 | // Get the command definitions for the device. |
| 25 | const CommandDictionary& GetCommandDictionary() const; |
| 26 | |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 27 | // Loads base/standard GCD command definitions. |
| 28 | // |json| is the full JSON schema of standard GCD commands. These commands |
| 29 | // are not necessarily supported by a particular device but rather |
| 30 | // all the standard commands defined by GCD standard for all known/supported |
| 31 | // device kinds. |
| 32 | // On success, returns true. Otherwise, |error| contains additional |
| 33 | // error information. |
| 34 | bool LoadBaseCommands(const base::DictionaryValue& json, |
| 35 | ErrorPtr* error); |
| 36 | |
| 37 | // Same as the overload above, but takes a path to a json file to read |
| 38 | // the base command definitions from. |
| 39 | bool LoadBaseCommands(const base::FilePath& json_file_path, |
| 40 | ErrorPtr* error); |
| 41 | |
| 42 | // Loads device command schema for particular category. |
| 43 | // See CommandDictionary::LoadCommands for detailed description of the |
| 44 | // parameters. |
| 45 | bool LoadCommands(const base::DictionaryValue& json, |
| 46 | const std::string& category, ErrorPtr* error); |
| 47 | |
| 48 | // Same as the overload above, but takes a path to a json file to read |
| 49 | // the base command definitions from. Also, the command category is |
| 50 | // derived from file name (without extension). So, if the path points to |
| 51 | // "power_manager.json", the command category used will be "power_manager". |
| 52 | bool LoadCommands(const base::FilePath& json_file_path, |
| 53 | ErrorPtr* error); |
| 54 | |
Alex Vakulenko | c2bc9a4 | 2014-07-23 10:57:58 -0700 | [diff] [blame] | 55 | // Startup method to be called by buffet daemon at startup. |
| 56 | // Initializes the object and loads the standard GCD command |
Alex Vakulenko | e4efaaf | 2014-07-22 08:08:44 -0700 | [diff] [blame] | 57 | // dictionary as well as static vendor-provided command definitions for |
| 58 | // the current device. |
Alex Vakulenko | c2bc9a4 | 2014-07-23 10:57:58 -0700 | [diff] [blame] | 59 | void Startup(); |
Alex Vakulenko | e4efaaf | 2014-07-22 08:08:44 -0700 | [diff] [blame] | 60 | |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 61 | private: |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 62 | // Helper function to load a JSON file that is expected to be |
| 63 | // an object/dictionary. In case of error, returns empty unique ptr and fills |
| 64 | // in error details in |error|. |
| 65 | std::unique_ptr<const base::DictionaryValue> LoadJsonDict( |
| 66 | const base::FilePath& json_file_path, ErrorPtr* error); |
| 67 | |
| 68 | CommandDictionary base_dictionary_; // Base/std command definitions/schemas. |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 69 | CommandDictionary dictionary_; // Command definitions/schemas. |
Alex Vakulenko | e4efaaf | 2014-07-22 08:08:44 -0700 | [diff] [blame] | 70 | |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 71 | DISALLOW_COPY_AND_ASSIGN(CommandManager); |
| 72 | }; |
| 73 | |
| 74 | } // namespace buffet |
| 75 | |
| 76 | #endif // BUFFET_COMMANDS_COMMAND_MANAGER_H_ |