Rename Complete::SetResults to Command::Complete
This name better represents the fact that the call sets command state
into terminal "done".
Change-Id: I50f0931f1300336eb4bca971b6a9a6719726dc5e
BUG:24267885
Reviewed-on: https://weave-review.googlesource.com/1275
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/libweave/examples/ubuntu/main.cc b/libweave/examples/ubuntu/main.cc
index 3e54adf..b9f0806 100644
--- a/libweave/examples/ubuntu/main.cc
+++ b/libweave/examples/ubuntu/main.cc
@@ -125,7 +125,7 @@
base::DictionaryValue result;
result.SetString("_greeting", "Hello " + name);
- cmd->SetResults(result, nullptr);
+ cmd->Complete(result, nullptr);
LOG(INFO) << cmd->GetName() << " command finished: " << result;
LOG(INFO) << "New state: " << *device_->GetState();
}
@@ -162,7 +162,7 @@
if (cmd_value != cur_state) {
UpdateLedState();
}
- cmd->SetResults({}, nullptr);
+ cmd->Complete({}, nullptr);
return;
}
weave::ErrorPtr error;
@@ -183,7 +183,7 @@
led_status_[led_index] = ~led_status_[led_index];
UpdateLedState();
- cmd->SetResults({}, nullptr);
+ cmd->Complete({}, nullptr);
return;
}
weave::ErrorPtr error;
diff --git a/libweave/include/weave/command.h b/libweave/include/weave/command.h
index 1df24b8..583cd68 100644
--- a/libweave/include/weave/command.h
+++ b/libweave/include/weave/command.h
@@ -56,12 +56,11 @@
virtual bool SetProgress(const base::DictionaryValue& progress,
ErrorPtr* error) = 0;
+ // Sets command into terminal "done" state.
// Updates the command results. The |results| should match the schema.
// Returns false if |results| value is incorrect.
- // Sets command into terminal "done" state.
- // TODO(vitalybuka): Rename to Complete.
- virtual bool SetResults(const base::DictionaryValue& results,
- ErrorPtr* error) = 0;
+ virtual bool Complete(const base::DictionaryValue& results,
+ ErrorPtr* error) = 0;
// Sets command into paused state.
// This is not terminal state. Command can be resumed with |SetProgress| call.
diff --git a/libweave/include/weave/test/mock_command.h b/libweave/include/weave/test/mock_command.h
index 93fe1c2..98fd1b5 100644
--- a/libweave/include/weave/test/mock_command.h
+++ b/libweave/include/weave/test/mock_command.h
@@ -30,7 +30,7 @@
MOCK_CONST_METHOD0(MockGetResults, const std::string&());
MOCK_CONST_METHOD0(GetError, const Error*());
MOCK_METHOD2(SetProgress, bool(const base::DictionaryValue&, ErrorPtr*));
- MOCK_METHOD2(SetResults, bool(const base::DictionaryValue&, ErrorPtr*));
+ MOCK_METHOD2(Complete, bool(const base::DictionaryValue&, ErrorPtr*));
MOCK_METHOD1(Pause, bool(ErrorPtr*));
MOCK_METHOD2(SetError, bool(const Error*, ErrorPtr*));
MOCK_METHOD2(Abort, bool(const Error*, ErrorPtr*));
diff --git a/libweave/src/base_api_handler.cc b/libweave/src/base_api_handler.cc
index 5d69b58..2ed7613 100644
--- a/libweave/src/base_api_handler.cc
+++ b/libweave/src/base_api_handler.cc
@@ -81,7 +81,7 @@
device_info_->UpdateBaseConfig(auth_scope, discovery_enabled,
pairing_enabled);
- command->SetResults({}, nullptr);
+ command->Complete({}, nullptr);
}
void BaseApiHandler::OnConfigChanged(const Settings& settings) {
@@ -113,7 +113,7 @@
parameters->GetString("location", &location);
device_info_->UpdateDeviceInfo(name, description, location);
- command->SetResults({}, nullptr);
+ command->Complete({}, nullptr);
}
} // namespace weave
diff --git a/libweave/src/commands/cloud_command_proxy_unittest.cc b/libweave/src/commands/cloud_command_proxy_unittest.cc
index c5863b6..3c7692f 100644
--- a/libweave/src/commands/cloud_command_proxy_unittest.cc
+++ b/libweave/src/commands/cloud_command_proxy_unittest.cc
@@ -148,7 +148,7 @@
TEST_F(CloudCommandProxyTest, ImmediateUpdate) {
const char expected[] = "{'state':'done'}";
EXPECT_CALL(cloud_updater_, UpdateCommand(kCmdID, MatchJson(expected), _, _));
- command_instance_->SetResults({}, nullptr);
+ command_instance_->Complete({}, nullptr);
task_runner_.RunOnce();
}
@@ -156,7 +156,7 @@
// Simulate that the current device state has changed.
current_state_update_id_ = 20;
// No command update is expected here.
- command_instance_->SetResults({}, nullptr);
+ command_instance_->Complete({}, nullptr);
// Still no command update here...
callbacks_.Notify(19);
// Now we should get the update...
@@ -241,7 +241,7 @@
EXPECT_TRUE(command_instance_->SetProgress(
*CreateDictionaryValue("{'status': 'busy'}"), nullptr));
current_state_update_id_ = 22;
- command_instance_->SetResults({}, nullptr);
+ command_instance_->Complete({}, nullptr);
// Device state #20 updated.
base::Closure on_success;
@@ -280,7 +280,7 @@
EXPECT_TRUE(command_instance_->SetProgress(
*CreateDictionaryValue("{'status': 'busy'}"), nullptr));
current_state_update_id_ = 22;
- command_instance_->SetResults({}, nullptr);
+ command_instance_->Complete({}, nullptr);
// Device state 20-21 updated.
base::Closure on_success;
@@ -309,7 +309,7 @@
EXPECT_TRUE(command_instance_->SetProgress(
*CreateDictionaryValue("{'status': 'busy'}"), nullptr));
current_state_update_id_ = 22;
- command_instance_->SetResults({}, nullptr);
+ command_instance_->Complete({}, nullptr);
// Device state 30 updated.
const char expected[] = R"({
@@ -328,9 +328,8 @@
*CreateDictionaryValue("{'status': 'busy'}"), nullptr));
EXPECT_TRUE(command_instance_->SetProgress(
*CreateDictionaryValue("{'status': 'finished'}"), nullptr));
- EXPECT_TRUE(command_instance_->SetResults(
- *CreateDictionaryValue("{'sum': 30}"), nullptr));
- command_instance_->SetResults({}, nullptr);
+ EXPECT_TRUE(command_instance_->Complete(*CreateDictionaryValue("{'sum': 30}"),
+ nullptr));
const char expected[] = R"({
'progress': {'status':'finished'},
@@ -354,7 +353,7 @@
// As soon as we change the command, the update to the server should be sent.
const char expected[] = "{'state':'done'}";
EXPECT_CALL(cloud_updater_, UpdateCommand(kCmdID, MatchJson(expected), _, _));
- command_instance_->SetResults({}, nullptr);
+ command_instance_->Complete({}, nullptr);
task_runner_.RunOnce();
}
@@ -367,7 +366,7 @@
CreateCommandInstance();
// No command updates right now.
- command_instance_->SetResults({}, nullptr);
+ command_instance_->Complete({}, nullptr);
// Only when the state #20 is published we should update the command
const char expected[] = "{'state':'done'}";
diff --git a/libweave/src/commands/command_instance.cc b/libweave/src/commands/command_instance.cc
index ac56eac..46aeb79 100644
--- a/libweave/src/commands/command_instance.cc
+++ b/libweave/src/commands/command_instance.cc
@@ -135,8 +135,8 @@
return true;
}
-bool CommandInstance::SetResults(const base::DictionaryValue& results,
- ErrorPtr* error) {
+bool CommandInstance::Complete(const base::DictionaryValue& results,
+ ErrorPtr* error) {
if (!command_definition_)
return ReportDestroyedError(error);
ObjectPropType obj_prop_type;
diff --git a/libweave/src/commands/command_instance.h b/libweave/src/commands/command_instance.h
index 5c8e80e..c3d29fd 100644
--- a/libweave/src/commands/command_instance.h
+++ b/libweave/src/commands/command_instance.h
@@ -63,8 +63,7 @@
const Error* GetError() const override;
bool SetProgress(const base::DictionaryValue& progress,
ErrorPtr* error) override;
- bool SetResults(const base::DictionaryValue& results,
- ErrorPtr* error) override;
+ bool Complete(const base::DictionaryValue& results, ErrorPtr* error) override;
bool Pause(ErrorPtr* error) override;
bool SetError(const Error* command_error, ErrorPtr* error) override;
bool Abort(const Error* command_error, ErrorPtr* error) override;
diff --git a/libweave/src/commands/command_instance_unittest.cc b/libweave/src/commands/command_instance_unittest.cc
index f65353e..5288f36 100644
--- a/libweave/src/commands/command_instance_unittest.cc
+++ b/libweave/src/commands/command_instance_unittest.cc
@@ -80,7 +80,7 @@
dict_.FindCommand("robot.speak"), params};
EXPECT_TRUE(
- instance.SetResults(*CreateDictionaryValue("{'foo': 239}"), nullptr));
+ instance.Complete(*CreateDictionaryValue("{'foo': 239}"), nullptr));
EXPECT_EQ("", instance.GetID());
EXPECT_EQ("robot.speak", instance.GetName());
@@ -209,8 +209,8 @@
EXPECT_TRUE(instance->SetProgress(*CreateDictionaryValue("{'progress': 15}"),
nullptr));
instance->SetID("testId");
- EXPECT_TRUE(instance->SetResults(*CreateDictionaryValue("{'testResult': 17}"),
- nullptr));
+ EXPECT_TRUE(instance->Complete(*CreateDictionaryValue("{'testResult': 17}"),
+ nullptr));
json->MergeDictionary(CreateDictionaryValue(R"({
'id': 'testId',
diff --git a/libweave/src/device_registration_info_unittest.cc b/libweave/src/device_registration_info_unittest.cc
index 84ee33a..cfd5b86 100644
--- a/libweave/src/device_registration_info_unittest.cc
+++ b/libweave/src/device_registration_info_unittest.cc
@@ -565,7 +565,7 @@
nullptr));
}
-TEST_F(DeviceRegistrationInfoUpdateCommandTest, SetResults) {
+TEST_F(DeviceRegistrationInfoUpdateCommandTest, Complete) {
EXPECT_CALL(http_client_,
MockSendRequest(
http::kPatch, command_url_,
@@ -576,8 +576,8 @@
base::DictionaryValue json;
return ReplyWithJson(200, json);
})));
- EXPECT_TRUE(command_->SetResults(*CreateDictionaryValue("{'status': 'Ok'}"),
- nullptr));
+ EXPECT_TRUE(
+ command_->Complete(*CreateDictionaryValue("{'status': 'Ok'}"), nullptr));
}
TEST_F(DeviceRegistrationInfoUpdateCommandTest, Cancel) {