Skip to content

Commit 3e6ebc1

Browse files
committed
Fix status update
1 parent 5ec0a20 commit 3e6ebc1

7 files changed

Lines changed: 102 additions & 21 deletions

command/source/CommandExecutionsEvent.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ namespace Aws
1010
namespace Iotcommand
1111
{
1212

13-
void CommandExecutionsEvent::LoadFromObject(CommandExecutionsEvent &val, const Aws::Crt::JsonView &doc) {}
13+
void CommandExecutionsEvent::LoadFromObject(CommandExecutionsEvent &val, const Aws::Crt::JsonView &doc)
14+
{
15+
(void)val;
16+
(void)doc;
17+
}
1418

15-
void CommandExecutionsEvent::SerializeToObject(Aws::Crt::JsonObject &object) const {}
19+
void CommandExecutionsEvent::SerializeToObject(Aws::Crt::JsonObject &object) const
20+
{
21+
(void)object;
22+
}
1623

1724
CommandExecutionsEvent::CommandExecutionsEvent(const Crt::JsonView &doc)
1825
{

command/source/CommandExecutionsSubscriptionRequest.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ namespace Aws
1414
CommandExecutionsSubscriptionRequest &val,
1515
const Aws::Crt::JsonView &doc)
1616
{
17+
(void)val;
18+
(void)doc;
1719
}
1820

19-
void CommandExecutionsSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const {}
21+
void CommandExecutionsSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const
22+
{
23+
(void)object;
24+
}
2025

2126
CommandExecutionsSubscriptionRequest::CommandExecutionsSubscriptionRequest(const Crt::JsonView &doc)
2227
{

command/source/IotCommandClientV2.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,27 @@ namespace Aws
121121

122122
Aws::Crt::StringStream subscriptionTopicStream0;
123123
subscriptionTopicStream0 << "$aws/commands/" << *request.DeviceType << "/" << *request.DeviceId
124-
<< "/executions/" << *request.ExecutionId << "/response/+/json";
124+
<< "/executions/" << *request.ExecutionId << "/response/accepted/json";
125125
Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str();
126126

127-
struct aws_byte_cursor subscriptionTopicFilters[1] = {
127+
Aws::Crt::StringStream subscriptionTopicStream1;
128+
subscriptionTopicStream1 << "$aws/commands/" << *request.DeviceType << "/" << *request.DeviceId
129+
<< "/executions/" << *request.ExecutionId << "/response/rejected/json";
130+
Aws::Crt::String subscriptionTopic1 = subscriptionTopicStream1.str();
131+
132+
struct aws_byte_cursor subscriptionTopicFilters[2] = {
128133
Aws::Crt::ByteCursorFromString(subscriptionTopic0),
134+
Aws::Crt::ByteCursorFromString(subscriptionTopic1),
129135
};
130136

131137
Aws::Crt::StringStream responsePathTopicAcceptedStream;
132-
responsePathTopicAcceptedStream << publishTopic << "/accepted";
138+
responsePathTopicAcceptedStream << "$aws/commands/" << *request.DeviceType << "/" << *request.DeviceId
139+
<< "/executions/" << *request.ExecutionId << "/response/accepted/json";
133140
Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str();
134141

135142
Aws::Crt::StringStream responsePathTopicRejectedStream;
136-
responsePathTopicRejectedStream << publishTopic << "/rejected";
143+
responsePathTopicRejectedStream << "$aws/commands/" << *request.DeviceType << "/" << *request.DeviceId
144+
<< "/executions/" << *request.ExecutionId << "/response/rejected/json";
137145
Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str();
138146

139147
struct aws_mqtt_request_operation_response_path responsePaths[2];
@@ -150,7 +158,7 @@ namespace Aws
150158
struct aws_mqtt_request_operation_options options;
151159
AWS_ZERO_STRUCT(options);
152160
options.subscription_topic_filters = subscriptionTopicFilters;
153-
options.subscription_topic_filter_count = 1;
161+
options.subscription_topic_filter_count = 2;
154162
options.response_paths = responsePaths;
155163
options.response_path_count = 2;
156164
options.publish_topic = Aws::Crt::ByteCursorFromString(publishTopic);
@@ -259,6 +267,7 @@ namespace Aws
259267
topicStream << "$aws/commands/" << *request.DeviceType << "/" << *request.DeviceId
260268
<< "/executions/+/request/json";
261269
Aws::Crt::String topic = topicStream.str();
270+
262271
return ServiceStreamingOperation<CommandExecutionsEvent>::Create(
263272
m_allocator, m_bindingClient, topic, options);
264273
}

command/source/UpdateCommandExecutionRequest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ namespace Aws
1414
UpdateCommandExecutionRequest &val,
1515
const Aws::Crt::JsonView &doc)
1616
{
17+
(void)val;
18+
(void)doc;
19+
1720
if (doc.ValueExists("status"))
1821
{
1922
val.Status = CommandStatusMarshaller::FromString(doc.GetString("status"));
@@ -22,6 +25,8 @@ namespace Aws
2225

2326
void UpdateCommandExecutionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const
2427
{
28+
(void)object;
29+
2530
if (Status)
2631
{
2732
object.WithString("status", CommandStatusMarshaller::ToString(*Status));

command/source/UpdateCommandExecutionResponse.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ namespace Aws
1414
UpdateCommandExecutionResponse &val,
1515
const Aws::Crt::JsonView &doc)
1616
{
17+
(void)val;
18+
(void)doc;
19+
1720
if (doc.ValueExists("timestamp"))
1821
{
1922
val.Timestamp = doc.GetDouble("timestamp");
@@ -22,6 +25,8 @@ namespace Aws
2225

2326
void UpdateCommandExecutionResponse::SerializeToObject(Aws::Crt::JsonObject &object) const
2427
{
28+
(void)object;
29+
2530
if (Timestamp)
2631
{
2732
object.WithDouble("timestamp", Timestamp->SecondsWithMSPrecision());

command/source/V2ServiceError.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ namespace Aws
1212

1313
void V2ServiceError::LoadFromObject(V2ServiceError &val, const Aws::Crt::JsonView &doc)
1414
{
15+
(void)val;
16+
(void)doc;
17+
1518
if (doc.ValueExists("code"))
1619
{
1720
val.Code = RejectedErrorCodeMarshaller::FromString(doc.GetString("code"));
@@ -30,6 +33,8 @@ namespace Aws
3033

3134
void V2ServiceError::SerializeToObject(Aws::Crt::JsonObject &object) const
3235
{
36+
(void)object;
37+
3338
if (Code)
3439
{
3540
object.WithString("code", RejectedErrorCodeMarshaller::ToString(*Code));

samples/command/v2/main.cpp

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <aws/iotcommand/CommandExecutionsEvent.h>
1010
#include <aws/iotcommand/CommandExecutionsSubscriptionRequest.h>
1111
#include <aws/iotcommand/IotCommandClientV2.h>
12+
#include <aws/iotcommand/UpdateCommandExecutionRequest.h>
13+
#include <aws/iotcommand/UpdateCommandExecutionResponse.h>
14+
#include <aws/iotcommand/V2ServiceError.h>
1215

1316
#include <algorithm>
1417
#include <cinttypes>
@@ -70,6 +73,8 @@ static void s_onSubscriptionStatusEvent(uint64_t id, Aws::Iot::RequestResponse::
7073
Aws::Crt::ErrorDebugString(event.GetErrorCode()));
7174
}
7275

76+
void updateExecution(const Aws::Crt::String &executionId) {}
77+
7378
int main(int argc, char *argv[])
7479
{
7580
/************************ Setup ****************************/
@@ -109,21 +114,61 @@ int main(int argc, char *argv[])
109114

110115
context.m_protocolClient->Start();
111116

112-
Aws::Iotcommand::CommandExecutionsSubscriptionRequest request;
113-
request.DeviceType = "things";
114-
request.DeviceId = "laptop_test_0001";
115-
116-
Aws::Iot::RequestResponse::StreamingOperationOptions<Aws::Iotcommand::CommandExecutionsEvent> options;
117-
options.WithStreamHandler([](CommandExecutionsEvent &&event)
118-
{ fprintf(stdout, "Got new event %s\n", event.ExecutionId->c_str()); });
119-
uint32_t streamId = 8;
120-
options.WithSubscriptionStatusEventHandler([streamId](Aws::Iot::RequestResponse::SubscriptionStatusEvent &&event)
121-
{ s_onSubscriptionStatusEvent(streamId, std::move(event)); });
117+
Aws::Crt::String executionId;
122118

123-
auto operation = context.m_commandClient->CreateCommandExecutionsStream(request, options);
124-
operation->Open();
119+
{
120+
std::promise<void> executionIdPromise;
121+
Aws::Iotcommand::CommandExecutionsSubscriptionRequest request;
122+
request.DeviceType = "things";
123+
request.DeviceId = "laptop_test_0001";
124+
125+
Aws::Iot::RequestResponse::StreamingOperationOptions<Aws::Iotcommand::CommandExecutionsEvent> options;
126+
options.WithStreamHandler(
127+
[&executionIdPromise, &executionId](CommandExecutionsEvent &&event)
128+
{
129+
fprintf(stdout, "==== Got new event %s\n", event.ExecutionId->c_str());
130+
executionId = *event.ExecutionId;
131+
executionIdPromise.set_value();
132+
});
133+
uint32_t streamId = 8;
134+
options.WithSubscriptionStatusEventHandler(
135+
[streamId](Aws::Iot::RequestResponse::SubscriptionStatusEvent &&event)
136+
{ s_onSubscriptionStatusEvent(streamId, std::move(event)); });
137+
138+
auto operation = context.m_commandClient->CreateCommandExecutionsStream(request, options);
139+
operation->Open();
140+
141+
fprintf(stdout, "==== waiting for a command\n");
142+
executionIdPromise.get_future().wait();
143+
fprintf(stdout, "==== received new command\n");
144+
}
125145

126-
std::this_thread::sleep_for(std::chrono::seconds(20));
146+
{
147+
std::promise<void> updatePromise;
148+
Aws::Iotcommand::UpdateCommandExecutionRequest request;
149+
request.DeviceType = "things";
150+
request.DeviceId = "laptop_test_0001";
151+
request.ExecutionId = executionId;
152+
request.Status = Aws::Iotcommand::CommandStatus::SUCCEEDED;
153+
context.m_commandClient->UpdateCommandExecution(
154+
request,
155+
[&updatePromise](Aws::Iotcommand::UpdateCommandExecutionResult &&result)
156+
{
157+
if (result.IsSuccess())
158+
{
159+
fprintf(stdout, "========= Success\n");
160+
}
161+
else
162+
{
163+
fprintf(stdout, "========= Error: code %d\n", result.GetError().GetErrorCode());
164+
}
165+
updatePromise.set_value();
166+
});
167+
168+
fprintf(stdout, "==== waiting for update\n");
169+
updatePromise.get_future().wait();
170+
fprintf(stdout, "==== updated\n");
171+
}
127172

128173
return 0;
129174
}

0 commit comments

Comments
 (0)