blob: 1199892e70c6db49864b5897573153effcc7c5e3 [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,
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 Vakulenkoc2bc9a42014-07-23 10:57:58 -070055 // Startup method to be called by buffet daemon at startup.
56 // Initializes the object and loads the standard GCD command
Alex Vakulenkoe4efaaf2014-07-22 08:08:44 -070057 // dictionary as well as static vendor-provided command definitions for
58 // the current device.
Alex Vakulenkoc2bc9a42014-07-23 10:57:58 -070059 void Startup();
Alex Vakulenkoe4efaaf2014-07-22 08:08:44 -070060
Alex Vakulenko7c36b672014-07-16 14:50:58 -070061 private:
Alex Vakulenkofd448692014-07-22 07:46:53 -070062 // 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 Vakulenko7c36b672014-07-16 14:50:58 -070069 CommandDictionary dictionary_; // Command definitions/schemas.
Alex Vakulenkoe4efaaf2014-07-22 08:08:44 -070070
Alex Vakulenko7c36b672014-07-16 14:50:58 -070071 DISALLOW_COPY_AND_ASSIGN(CommandManager);
72};
73
74} // namespace buffet
75
76#endif // BUFFET_COMMANDS_COMMAND_MANAGER_H_