Remove hard-coded check for standard command definitions
Libweave will contain only definition of standard commands it will
handle itself, updateBaseConfiguration and updateDeviceInfo.
BUG:25304415
Change-Id: I926b2e1e6324d3181a22cc7131368bdbb9214d61
Reviewed-on: https://weave-review.googlesource.com/1425
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/libweave/libweave.gypi b/libweave/libweave.gypi
index f65eda7..c32e99b 100644
--- a/libweave/libweave.gypi
+++ b/libweave/libweave.gypi
@@ -18,7 +18,6 @@
'src/commands/prop_values.cc',
'src/commands/schema_constants.cc',
'src/commands/schema_utils.cc',
- 'src/commands/standard_definitions.cc',
'src/config.cc',
'src/data_encoding.cc',
'src/device_manager.cc',
diff --git a/libweave/src/base_api_handler.cc b/libweave/src/base_api_handler.cc
index 5cebb87..c3aa616 100644
--- a/libweave/src/base_api_handler.cc
+++ b/libweave/src/base_api_handler.cc
@@ -39,8 +39,24 @@
device->AddCommandDefinitionsFromJson(R"({
"base": {
- "updateBaseConfiguration": {},
- "updateDeviceInfo": {}
+ "updateBaseConfiguration": {
+ "minimalRole": "manager",
+ "parameters": {
+ "localDiscoveryEnabled": "boolean",
+ "localAnonymousAccessMaxRole": [ "none", "viewer", "user" ],
+ "localPairingEnabled": "boolean"
+ },
+ "results": {}
+ },
+ "updateDeviceInfo": {
+ "minimalRole": "manager",
+ "parameters": {
+ "description": "string",
+ "name": "string",
+ "location": "string"
+ },
+ "results": {}
+ }
}
})");
diff --git a/libweave/src/base_api_handler_unittest.cc b/libweave/src/base_api_handler_unittest.cc
index 565c6aa..a025e44 100644
--- a/libweave/src/base_api_handler_unittest.cc
+++ b/libweave/src/base_api_handler_unittest.cc
@@ -35,7 +35,6 @@
.WillRepeatedly(Return(true));
command_manager_ = std::make_shared<CommandManager>();
- command_manager_->Startup();
state_manager_ = std::make_shared<StateManager>(&mock_state_change_queue_);
@@ -106,6 +105,47 @@
int command_id_{0};
};
+TEST_F(BaseApiHandlerTest, Initialization) {
+ auto command_defs =
+ command_manager_->GetCommandDictionary().GetCommandsAsJson(
+ [](const CommandDefinition* def) { return true; }, true, nullptr);
+
+ auto expected = R"({
+ "base": {
+ "updateBaseConfiguration": {
+ "minimalRole": "manager",
+ "parameters": {
+ "localAnonymousAccessMaxRole": {
+ "enum": [ "none", "viewer", "user" ],
+ "type": "string"
+ },
+ "localDiscoveryEnabled": {
+ "type": "boolean"
+ },
+ "localPairingEnabled": {
+ "type": "boolean"
+ }
+ }
+ },
+ "updateDeviceInfo": {
+ "minimalRole": "manager",
+ "parameters": {
+ "description": {
+ "type": "string"
+ },
+ "location": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ })";
+ EXPECT_JSON_EQ(expected, *command_defs);
+}
+
TEST_F(BaseApiHandlerTest, UpdateBaseConfiguration) {
const Settings& settings = dev_reg_->GetSettings();
diff --git a/libweave/src/commands/command_manager.cc b/libweave/src/commands/command_manager.cc
index 595613f..75d8295 100644
--- a/libweave/src/commands/command_manager.cc
+++ b/libweave/src/commands/command_manager.cc
@@ -9,7 +9,6 @@
#include <weave/error.h>
#include "src/commands/schema_constants.h"
-#include "src/commands/standard_definitions.h"
#include "src/utils.h"
namespace weave {
@@ -27,22 +26,9 @@
return dictionary_;
}
-bool CommandManager::LoadStandardCommands(const base::DictionaryValue& dict,
- ErrorPtr* error) {
- return standard_dictionary_.LoadCommands(dict, nullptr, error);
-}
-
-bool CommandManager::LoadStandardCommands(const std::string& json,
- ErrorPtr* error) {
- std::unique_ptr<const base::DictionaryValue> dict = LoadJsonDict(json, error);
- if (!dict)
- return false;
- return LoadStandardCommands(*dict, error);
-}
-
bool CommandManager::LoadCommands(const base::DictionaryValue& dict,
ErrorPtr* error) {
- bool result = dictionary_.LoadCommands(dict, &standard_dictionary_, error);
+ bool result = dictionary_.LoadCommands(dict, nullptr, error);
for (const auto& cb : on_command_changed_)
cb.Run();
return result;
@@ -56,13 +42,6 @@
return LoadCommands(*dict, error);
}
-void CommandManager::Startup() {
- LOG(INFO) << "Initializing CommandManager.";
-
- // Load global standard GCD command dictionary.
- CHECK(LoadStandardCommands(kStandardCommandDefs, nullptr));
-}
-
void CommandManager::AddCommand(
std::unique_ptr<CommandInstance> command_instance) {
command_queue_.Add(std::move(command_instance));
diff --git a/libweave/src/commands/command_manager.h b/libweave/src/commands/command_manager.h
index ee8aa69..7cc8907 100644
--- a/libweave/src/commands/command_manager.h
+++ b/libweave/src/commands/command_manager.h
@@ -44,15 +44,6 @@
// Returns the command definitions for the device.
const CommandDictionary& GetCommandDictionary() const;
- // Loads standard GCD command definitions.
- // |dict| is the full JSON schema of standard GCD commands. These commands
- // are not necessarily supported by a particular device but rather
- // all the standard commands defined by GCD standard for all known/supported
- // device kinds.
- // On success, returns true. Otherwise, |error| contains additional
- // error information.
- bool LoadStandardCommands(const base::DictionaryValue& dict, ErrorPtr* error);
-
// Same as the overload above, but takes a path to a json file to read
// the base command definitions from.
bool LoadStandardCommands(const std::string& json, ErrorPtr* error);
@@ -66,10 +57,6 @@
bool LoadCommands(const std::string& json,
ErrorPtr* error);
- // Startup method to be called by buffet daemon at startup.
- // Initializes standard GCD command dictionary.
- void Startup();
-
// Adds a new command to the command queue.
void AddCommand(std::unique_ptr<CommandInstance> command_instance);
@@ -84,8 +71,7 @@
ErrorPtr* error);
private:
- CommandDictionary standard_dictionary_; // Standard command definitions.
- CommandDictionary dictionary_; // Registered definitions.
+ CommandDictionary dictionary_; // Registered definitions.
CommandQueue command_queue_;
std::vector<base::Callback<void()>> on_command_changed_;
uint32_t next_command_id_{0};
diff --git a/libweave/src/commands/command_manager_unittest.cc b/libweave/src/commands/command_manager_unittest.cc
index ff8c5d8..bbdd7ac 100644
--- a/libweave/src/commands/command_manager_unittest.cc
+++ b/libweave/src/commands/command_manager_unittest.cc
@@ -63,12 +63,6 @@
EXPECT_TRUE(manager.GetCommandDictionary().IsEmpty());
}
-TEST(CommandManager, LoadStandardCommandsJSON) {
- CommandManager manager;
- auto json = CreateDictionaryValue(kTestBaseCommands);
- EXPECT_TRUE(manager.LoadStandardCommands(*json, nullptr));
-}
-
TEST(CommandManager, LoadCommandsDict) {
CommandManager manager;
auto json = CreateDictionaryValue(kTestVendorCommands);
@@ -77,20 +71,6 @@
TEST(CommandManager, LoadCommandsJson) {
CommandManager manager;
- // Load some standard command definitions first.
- auto json = CreateDictionaryValue(R"({
- 'base': {
- 'reboot': {
- 'parameters': {'delay': 'integer'},
- 'results': {}
- },
- 'shutdown': {
- 'parameters': {},
- 'results': {}
- }
- }
- })");
- manager.LoadStandardCommands(*json, nullptr);
// Load device-supported commands.
auto json_str = R"({
@@ -115,7 +95,6 @@
TEST(CommandManager, ShouldLoadStandardAndTestDefinitions) {
CommandManager manager;
- manager.Startup();
ASSERT_TRUE(manager.LoadCommands(kTestVendorCommands, nullptr));
ASSERT_TRUE(manager.LoadCommands(kTestTestCommands, nullptr));
EXPECT_EQ(3, manager.GetCommandDictionary().GetSize());
diff --git a/libweave/src/commands/standard_definitions.cc b/libweave/src/commands/standard_definitions.cc
deleted file mode 100644
index 4c20984..0000000
--- a/libweave/src/commands/standard_definitions.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2015 The Weave Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "src/commands/standard_definitions.h"
-
-namespace weave {
-
-const char kStandardCommandDefs[] = R"({
- "base": {
- "updateBaseConfiguration": {
- "minimalRole": "manager",
- "parameters": {
- "localDiscoveryEnabled": "boolean",
- "localAnonymousAccessMaxRole": [ "none", "viewer", "user" ],
- "localPairingEnabled": "boolean"
- },
- "results": {}
- },
- "reboot": {
- "minimalRole": "user",
- "parameters": {},
- "results": {}
- },
- "identify": {
- "minimalRole": "user",
- "parameters": {},
- "results": {}
- },
- "updateDeviceInfo": {
- "minimalRole": "manager",
- "parameters": {
- "description": "string",
- "name": "string",
- "location": "string"
- },
- "results": {}
- }
- }
-})";
-
-} // namespace weave
diff --git a/libweave/src/commands/standard_definitions.h b/libweave/src/commands/standard_definitions.h
deleted file mode 100644
index 9c9f3e1..0000000
--- a/libweave/src/commands/standard_definitions.h
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2015 The Weave Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef LIBWEAVE_SRC_COMMANDS_STANDARD_DEFINITIONS_H_
-#define LIBWEAVE_SRC_COMMANDS_STANDARD_DEFINITIONS_H_
-
-namespace weave {
-
-extern const char kStandardCommandDefs[];
-
-} // namespace weave
-
-#endif // LIBWEAVE_SRC_COMMANDS_STANDARD_DEFINITIONS_H_
diff --git a/libweave/src/device_manager.cc b/libweave/src/device_manager.cc
index 1b21961..c0b8e9a 100644
--- a/libweave/src/device_manager.cc
+++ b/libweave/src/device_manager.cc
@@ -34,7 +34,6 @@
provider::Wifi* wifi,
provider::Bluetooth* bluetooth) {
command_manager_ = std::make_shared<CommandManager>();
- command_manager_->Startup();
state_change_queue_.reset(new StateChangeQueue(kMaxStateChangeQueueSize));
state_manager_ = std::make_shared<StateManager>(state_change_queue_.get());
diff --git a/libweave/src/device_registration_info_unittest.cc b/libweave/src/device_registration_info_unittest.cc
index a07ea40..91b8ff5 100644
--- a/libweave/src/device_registration_info_unittest.cc
+++ b/libweave/src/device_registration_info_unittest.cc
@@ -350,21 +350,6 @@
}
TEST_F(DeviceRegistrationInfoTest, RegisterDevice) {
- auto json_base = CreateDictionaryValue(R"({
- 'base': {
- 'reboot': {
- 'parameters': {'delay': 'integer'},
- 'minimalRole': 'user',
- 'results': {}
- },
- 'shutdown': {
- 'parameters': {},
- 'minimalRole': 'user',
- 'results': {}
- }
- }
- })");
- EXPECT_TRUE(command_manager_->LoadStandardCommands(*json_base, nullptr));
auto json_cmds = CreateDictionaryValue(R"({
'base': {
'reboot': {
diff --git a/libweave/src/states/state_manager.cc b/libweave/src/states/state_manager.cc
index 268dd04..fe6e669 100644
--- a/libweave/src/states/state_manager.cc
+++ b/libweave/src/states/state_manager.cc
@@ -7,7 +7,6 @@
#include <base/logging.h>
#include <base/values.h>
-#include "src/commands/standard_definitions.h"
#include "src/json_error_codes.h"
#include "src/states/error_codes.h"
#include "src/states/state_change_queue_interface.h"