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 | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 8 | #include <memory> |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 11 | #include <base/files/file_path.h> |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 12 | #include <base/macros.h> |
| 13 | #include <base/memory/weak_ptr.h> |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 14 | |
| 15 | #include "buffet/commands/command_dictionary.h" |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 16 | #include "buffet/commands/command_queue.h" |
| 17 | #include "buffet/commands/dbus_command_dispatcher.h" |
| 18 | |
| 19 | namespace chromeos { |
| 20 | namespace dbus_utils { |
| 21 | class ExportedObjectManager; |
| 22 | } // namespace dbus_utils |
| 23 | } // namespace chromeos |
| 24 | |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 25 | |
| 26 | namespace buffet { |
| 27 | |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 28 | class CommandInstance; |
| 29 | |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 30 | // CommandManager class that will have a list of all the device command |
| 31 | // schemas as well as the live command queue of pending command instances |
| 32 | // dispatched to the device. |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 33 | class CommandManager final { |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 34 | public: |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 35 | CommandManager(); |
| 36 | explicit CommandManager( |
| 37 | const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>& |
| 38 | object_manager); |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 39 | |
| 40 | // Get the command definitions for the device. |
| 41 | const CommandDictionary& GetCommandDictionary() const; |
| 42 | |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 43 | // Loads base/standard GCD command definitions. |
| 44 | // |json| is the full JSON schema of standard GCD commands. These commands |
| 45 | // are not necessarily supported by a particular device but rather |
| 46 | // all the standard commands defined by GCD standard for all known/supported |
| 47 | // device kinds. |
| 48 | // On success, returns true. Otherwise, |error| contains additional |
| 49 | // error information. |
| 50 | bool LoadBaseCommands(const base::DictionaryValue& json, |
Alex Vakulenko | 5f47206 | 2014-08-14 17:54:04 -0700 | [diff] [blame] | 51 | chromeos::ErrorPtr* error); |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 52 | |
| 53 | // Same as the overload above, but takes a path to a json file to read |
| 54 | // the base command definitions from. |
| 55 | bool LoadBaseCommands(const base::FilePath& json_file_path, |
Alex Vakulenko | 5f47206 | 2014-08-14 17:54:04 -0700 | [diff] [blame] | 56 | chromeos::ErrorPtr* error); |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 57 | |
| 58 | // Loads device command schema for particular category. |
| 59 | // See CommandDictionary::LoadCommands for detailed description of the |
| 60 | // parameters. |
| 61 | bool LoadCommands(const base::DictionaryValue& json, |
Alex Vakulenko | 5f47206 | 2014-08-14 17:54:04 -0700 | [diff] [blame] | 62 | const std::string& category, |
| 63 | chromeos::ErrorPtr* error); |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 64 | |
| 65 | // Same as the overload above, but takes a path to a json file to read |
| 66 | // the base command definitions from. Also, the command category is |
| 67 | // derived from file name (without extension). So, if the path points to |
| 68 | // "power_manager.json", the command category used will be "power_manager". |
| 69 | bool LoadCommands(const base::FilePath& json_file_path, |
Alex Vakulenko | 5f47206 | 2014-08-14 17:54:04 -0700 | [diff] [blame] | 70 | chromeos::ErrorPtr* error); |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 71 | |
Alex Vakulenko | c2bc9a4 | 2014-07-23 10:57:58 -0700 | [diff] [blame] | 72 | // Startup method to be called by buffet daemon at startup. |
| 73 | // Initializes the object and loads the standard GCD command |
Alex Vakulenko | e4efaaf | 2014-07-22 08:08:44 -0700 | [diff] [blame] | 74 | // dictionary as well as static vendor-provided command definitions for |
| 75 | // the current device. |
Alex Vakulenko | c2bc9a4 | 2014-07-23 10:57:58 -0700 | [diff] [blame] | 76 | void Startup(); |
Alex Vakulenko | e4efaaf | 2014-07-22 08:08:44 -0700 | [diff] [blame] | 77 | |
Anton Muhin | 5191e81 | 2014-10-30 17:49:48 +0400 | [diff] [blame] | 78 | // Adds a new command to the command queue. |
| 79 | void AddCommand(std::unique_ptr<CommandInstance> command_instance); |
| 80 | |
| 81 | // Finds a command by the command |id|. Returns nullptr if the command with |
| 82 | // the given |id| is not found. The returned pointer should not be persisted |
| 83 | // for a long period of time. |
| 84 | CommandInstance* FindCommand(const std::string& id) const; |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 85 | |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 86 | private: |
Alex Vakulenko | fd44869 | 2014-07-22 07:46:53 -0700 | [diff] [blame] | 87 | CommandDictionary base_dictionary_; // Base/std command definitions/schemas. |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 88 | CommandDictionary dictionary_; // Command definitions/schemas. |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 89 | CommandQueue command_queue_; |
| 90 | DBusCommandDispacher command_dispatcher_; |
Alex Vakulenko | e4efaaf | 2014-07-22 08:08:44 -0700 | [diff] [blame] | 91 | |
Alex Vakulenko | 7c36b67 | 2014-07-16 14:50:58 -0700 | [diff] [blame] | 92 | DISALLOW_COPY_AND_ASSIGN(CommandManager); |
| 93 | }; |
| 94 | |
| 95 | } // namespace buffet |
| 96 | |
| 97 | #endif // BUFFET_COMMANDS_COMMAND_MANAGER_H_ |