buffet: Add command_def filtering by command visibility
When updating cloud or local client with the device's CDD make sure
to send only the command definitions that are available to particular
client (local vs cloud).
Also made it possible to subscribe to command definition change notifications
for more than one listener (using base::CallbackList) so that both the local
and cloud adapters can notify the respective clients about command visibility
changes (the actual API to change the command visibility is coming in a
follow-up CL).
BUG=brillo:797
TEST=`FEATURES=test emerge-link buffet`
Change-Id: I6bec36633ababcb534012abad2c37a3502d8faf4
Reviewed-on: https://chromium-review.googlesource.com/266209
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/commands/command_dictionary.h b/buffet/commands/command_dictionary.h
index db68c8a..52e1a10 100644
--- a/buffet/commands/command_dictionary.h
+++ b/buffet/commands/command_dictionary.h
@@ -7,6 +7,7 @@
#include <map>
#include <memory>
+#include <set>
#include <string>
#include <vector>
@@ -57,12 +58,18 @@
const CommandDictionary* base_commands,
chromeos::ErrorPtr* error);
// Converts all the command definitions to a JSON object for CDD/Device
- // draft. |full_schema| specifies whether full command definitions must
- // be generated (true) for CDD or only overrides from the base schema (false).
+ // draft.
+ // |filter| is a predicate used to filter out the command definitions to
+ // be returned by this method. Only command definitions for which the
+ // predicate returns true will be included in the resulting JSON.
+ // |full_schema| specifies whether full command definitions must be generated
+ // (true) for CDD or only overrides from the base schema (false).
// Returns empty unique_ptr in case of an error and fills in the additional
// error details in |error|.
std::unique_ptr<base::DictionaryValue> GetCommandsAsJson(
- bool full_schema, chromeos::ErrorPtr* error) const;
+ const std::function<bool(const CommandDefinition*)>& filter,
+ bool full_schema,
+ chromeos::ErrorPtr* error) const;
// Returns the number of command definitions in the dictionary.
size_t GetSize() const { return definitions_.size(); }
// Checks if the dictionary has no command definitions.