Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alfred2g committed Dec 10, 2023
1 parent 54b6aa3 commit 430a80b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions servicetests/tests/ShadowUpdate/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,23 @@ int main(int argc, char *argv[])
{
if (cmdData.input_shadowName.empty())
{
/*
std::promise<void> gotResponse;
subscribeShadowUpdatedValue(
cmdData.input_thingName,
cmdData.input_shadowProperty,
cmdData.input_shadowValue,
shadowClient,
gotResponse);
*/

changeShadowValue(
cmdData.input_thingName, cmdData.input_shadowProperty, cmdData.input_shadowValue, shadowClient);

/*
std::future_status status = gotResponse.get_future().wait_for(std::chrono::seconds(5));
if (status == std::future_status::timeout)
{
fprintf(stderr, "Shadow update document timedout\n");
exit(-1);
}
*/
}
else
{
Expand Down Expand Up @@ -296,15 +292,15 @@ int main(int argc, char *argv[])
std::this_thread::sleep_for(std::chrono::milliseconds(500));

if (cmdData.input_mqtt_version == 5UL)
{ // mqtt5
{ // mqtt5
// Disconnect
if (client5->Stop() == true)
{
connectionClosedPromise.get_future().wait();
}
}
else
{ // mqtt3
{ // mqtt3
// Disconnect
if (connection->Disconnect() == true)
{
Expand Down Expand Up @@ -337,20 +333,20 @@ void subscribeShadowUpdatedValue(
};

/* verify updated shadow */
auto handler = [&gotResponse, &property] (ShadowUpdatedEvent *event, int ioErr) {
auto handler = [&gotResponse, &property](ShadowUpdatedEvent *event, int ioErr) {
if (ioErr == AWS_OP_ERR)
{
fprintf(stderr, "handler lambda error\n");
exit(-1);
}
if (event)
{
String value = event->Previous->State->Reported->View().GetString(property);
String value1 = event->Previous->State->Reported->View().GetString(property);
String value2 = event->Previous->State->Desired->View().GetString(property);
String value3 = event->Current->State->Reported->View().GetString(property);
String value4 = event->Current->State->Desired->View().GetString(property);

fprintf(stdout, "previous reported Value 1 %s\n", value.c_str());
fprintf(stdout, "previous reported Value 1 %s\n", value1.c_str());
fprintf(stdout, "previous desired Value 2 %s\n", value2.c_str());

fprintf(stdout, "current reported Value 3 %s\n", value3.c_str());
Expand All @@ -362,7 +358,8 @@ void subscribeShadowUpdatedValue(
/* subscribe to event updates */
ShadowUpdatedSubscriptionRequest requestUpdate;
requestUpdate.ThingName = thingName;
shadowClient->SubscribeToShadowUpdatedEvents(requestUpdate, AWS_MQTT_QOS_AT_LEAST_ONCE, handler, std::move(publishCompleted));
shadowClient->SubscribeToShadowUpdatedEvents(
requestUpdate, AWS_MQTT_QOS_AT_LEAST_ONCE, std::move(handler), std::move(publishCompleted));
shadowCompletedPromise.get_future().get();
}

Expand Down Expand Up @@ -416,7 +413,8 @@ void subscribeNamedShadowUpdatedValue(
NamedShadowUpdatedSubscriptionRequest requestUpdate;
requestUpdate.ThingName = thingName;
requestUpdate.ShadowName = shadowName;
shadowClient->SubscribeToNamedShadowUpdatedEvents(requestUpdate, AWS_MQTT_QOS_AT_LEAST_ONCE, handler, std::move(publishCompleted));
shadowClient->SubscribeToNamedShadowUpdatedEvents(
requestUpdate, AWS_MQTT_QOS_AT_LEAST_ONCE, handler, std::move(publishCompleted));
shadowCompletedPromise.get_future().get();
}

Expand Down

0 comments on commit 430a80b

Please sign in to comment.