privetd: Implement /privet/v3/commandDefs
Buffet exposes D-Bus property CommandDefs.
Privetd reads commands from buffet using D-Bus in CloudDelegate.
Buffet will update property if definitions changed. Still there is no Buffet
codepath which changes commad definitions after loading.
BUG=brillo:426
TEST=unittest
Change-Id: I18dac0f87325257fa31c0fe3e0c883a9ed40e4c7
Reviewed-on: https://chromium-review.googlesource.com/261611
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/commands/command_manager.cc b/buffet/commands/command_manager.cc
index 78e0dee..afdd518 100644
--- a/buffet/commands/command_manager.cc
+++ b/buffet/commands/command_manager.cc
@@ -47,7 +47,11 @@
bool CommandManager::LoadCommands(const base::DictionaryValue& json,
const std::string& category,
chromeos::ErrorPtr* error) {
- return dictionary_.LoadCommands(json, category, &base_dictionary_, error);
+ bool result =
+ dictionary_.LoadCommands(json, category, &base_dictionary_, error);
+ if (!on_command_defs_changed_.is_null())
+ on_command_defs_changed_.Run();
+ return result;
}
bool CommandManager::LoadCommands(const base::FilePath& json_file_path,
diff --git a/buffet/commands/command_manager.h b/buffet/commands/command_manager.h
index f176cad..8088e26 100644
--- a/buffet/commands/command_manager.h
+++ b/buffet/commands/command_manager.h
@@ -37,7 +37,12 @@
const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
object_manager);
- // Get the command definitions for the device.
+ // Sets callback which is called when command definitions is changed.
+ void SetOnCommandDefChanged(const base::Closure& on_command_defs_changed) {
+ on_command_defs_changed_ = on_command_defs_changed;
+ }
+
+ // Returns the command definitions for the device.
const CommandDictionary& GetCommandDictionary() const;
// Loads base/standard GCD command definitions.
@@ -91,6 +96,7 @@
CommandDictionary dictionary_; // Command definitions/schemas.
CommandQueue command_queue_;
DBusCommandDispacher command_dispatcher_;
+ base::Closure on_command_defs_changed_;
DISALLOW_COPY_AND_ASSIGN(CommandManager);
};