blob: 88b551a4e04719875196beef9b1be37590affc71 [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 Vakulenko95110752014-09-03 16:27:21 -07008#include <memory>
Alex Vakulenkofd448692014-07-22 07:46:53 -07009#include <string>
10
Alex Vakulenkofd448692014-07-22 07:46:53 -070011#include <base/files/file_path.h>
Alex Vakulenko95110752014-09-03 16:27:21 -070012#include <base/macros.h>
13#include <base/memory/weak_ptr.h>
Alex Vakulenko7c36b672014-07-16 14:50:58 -070014
15#include "buffet/commands/command_dictionary.h"
Alex Vakulenko95110752014-09-03 16:27:21 -070016#include "buffet/commands/command_queue.h"
17#include "buffet/commands/dbus_command_dispatcher.h"
18
19namespace chromeos {
20namespace dbus_utils {
21class ExportedObjectManager;
22} // namespace dbus_utils
23} // namespace chromeos
24
Alex Vakulenko7c36b672014-07-16 14:50:58 -070025
26namespace buffet {
27
Alex Vakulenko95110752014-09-03 16:27:21 -070028class CommandInstance;
29
Alex Vakulenko7c36b672014-07-16 14:50:58 -070030// 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 Vakulenko95110752014-09-03 16:27:21 -070033class CommandManager final {
Alex Vakulenko7c36b672014-07-16 14:50:58 -070034 public:
Alex Vakulenko95110752014-09-03 16:27:21 -070035 CommandManager();
36 explicit CommandManager(
37 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
38 object_manager);
Alex Vakulenko7c36b672014-07-16 14:50:58 -070039
40 // Get the command definitions for the device.
41 const CommandDictionary& GetCommandDictionary() const;
42
Alex Vakulenkofd448692014-07-22 07:46:53 -070043 // 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 Vakulenko5f472062014-08-14 17:54:04 -070051 chromeos::ErrorPtr* error);
Alex Vakulenkofd448692014-07-22 07:46:53 -070052
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 Vakulenko5f472062014-08-14 17:54:04 -070056 chromeos::ErrorPtr* error);
Alex Vakulenkofd448692014-07-22 07:46:53 -070057
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 Vakulenko5f472062014-08-14 17:54:04 -070062 const std::string& category,
63 chromeos::ErrorPtr* error);
Alex Vakulenkofd448692014-07-22 07:46:53 -070064
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 Vakulenko5f472062014-08-14 17:54:04 -070070 chromeos::ErrorPtr* error);
Alex Vakulenkofd448692014-07-22 07:46:53 -070071
Alex Vakulenkoc2bc9a42014-07-23 10:57:58 -070072 // Startup method to be called by buffet daemon at startup.
73 // Initializes the object and loads the standard GCD command
Alex Vakulenkoe4efaaf2014-07-22 08:08:44 -070074 // dictionary as well as static vendor-provided command definitions for
75 // the current device.
Alex Vakulenkoc2bc9a42014-07-23 10:57:58 -070076 void Startup();
Alex Vakulenkoe4efaaf2014-07-22 08:08:44 -070077
Anton Muhin5191e812014-10-30 17:49:48 +040078 // 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 Vakulenko95110752014-09-03 16:27:21 -070085
Alex Vakulenko7c36b672014-07-16 14:50:58 -070086 private:
Alex Vakulenkofd448692014-07-22 07:46:53 -070087 CommandDictionary base_dictionary_; // Base/std command definitions/schemas.
Alex Vakulenko7c36b672014-07-16 14:50:58 -070088 CommandDictionary dictionary_; // Command definitions/schemas.
Alex Vakulenko95110752014-09-03 16:27:21 -070089 CommandQueue command_queue_;
90 DBusCommandDispacher command_dispatcher_;
Alex Vakulenkoe4efaaf2014-07-22 08:08:44 -070091
Alex Vakulenko7c36b672014-07-16 14:50:58 -070092 DISALLOW_COPY_AND_ASSIGN(CommandManager);
93};
94
95} // namespace buffet
96
97#endif // BUFFET_COMMANDS_COMMAND_MANAGER_H_