blob: d3f9a34510d133129c309f15048258e2cae6ffce [file] [log] [blame]
Alex Vakulenko7c36b672014-07-16 14:50:58 -07001// 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 Vakulenkofd448692014-07-22 07:46:53 -07008#include <string>
9
Alex Vakulenko7c36b672014-07-16 14:50:58 -070010#include <base/basictypes.h>
Alex Vakulenkofd448692014-07-22 07:46:53 -070011#include <base/files/file_path.h>
Alex Vakulenko7c36b672014-07-16 14:50:58 -070012
13#include "buffet/commands/command_dictionary.h"
14
15namespace 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.
20class CommandManager {
21 public:
22 CommandManager() = default;
23
24 // Get the command definitions for the device.
25 const CommandDictionary& GetCommandDictionary() const;
26
Alex Vakulenkofd448692014-07-22 07:46:53 -070027 // 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,
Alex Vakulenko5f472062014-08-14 17:54:04 -070035 chromeos::ErrorPtr* error);
Alex Vakulenkofd448692014-07-22 07:46:53 -070036
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,
Alex Vakulenko5f472062014-08-14 17:54:04 -070040 chromeos::ErrorPtr* error);
Alex Vakulenkofd448692014-07-22 07:46:53 -070041
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,
Alex Vakulenko5f472062014-08-14 17:54:04 -070046 const std::string& category,
47 chromeos::ErrorPtr* error);
Alex Vakulenkofd448692014-07-22 07:46:53 -070048
49 // Same as the overload above, but takes a path to a json file to read
50 // the base command definitions from. Also, the command category is
51 // derived from file name (without extension). So, if the path points to
52 // "power_manager.json", the command category used will be "power_manager".
53 bool LoadCommands(const base::FilePath& json_file_path,
Alex Vakulenko5f472062014-08-14 17:54:04 -070054 chromeos::ErrorPtr* error);
Alex Vakulenkofd448692014-07-22 07:46:53 -070055
Alex Vakulenkoc2bc9a42014-07-23 10:57:58 -070056 // Startup method to be called by buffet daemon at startup.
57 // Initializes the object and loads the standard GCD command
Alex Vakulenkoe4efaaf2014-07-22 08:08:44 -070058 // dictionary as well as static vendor-provided command definitions for
59 // the current device.
Alex Vakulenkoc2bc9a42014-07-23 10:57:58 -070060 void Startup();
Alex Vakulenkoe4efaaf2014-07-22 08:08:44 -070061
Alex Vakulenko7c36b672014-07-16 14:50:58 -070062 private:
Alex Vakulenkofd448692014-07-22 07:46:53 -070063 // Helper function to load a JSON file that is expected to be
64 // an object/dictionary. In case of error, returns empty unique ptr and fills
65 // in error details in |error|.
66 std::unique_ptr<const base::DictionaryValue> LoadJsonDict(
Alex Vakulenko5f472062014-08-14 17:54:04 -070067 const base::FilePath& json_file_path, chromeos::ErrorPtr* error);
Alex Vakulenkofd448692014-07-22 07:46:53 -070068
69 CommandDictionary base_dictionary_; // Base/std command definitions/schemas.
Alex Vakulenko7c36b672014-07-16 14:50:58 -070070 CommandDictionary dictionary_; // Command definitions/schemas.
Alex Vakulenkoe4efaaf2014-07-22 08:08:44 -070071
Alex Vakulenko7c36b672014-07-16 14:50:58 -070072 DISALLOW_COPY_AND_ASSIGN(CommandManager);
73};
74
75} // namespace buffet
76
77#endif // BUFFET_COMMANDS_COMMAND_MANAGER_H_