Skip to content

Updated DeviceDefender task interface changes #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Aug 3, 2021
Merged

Updated DeviceDefender task interface changes #305

merged 19 commits into from
Aug 3, 2021

Conversation

DavidOgunsAWS
Copy link
Contributor

Issue #, if available:

Description of changes:

  • These changes are downstream of these changes: Custom metrics awslabs/aws-c-iot#48 and remain in draft until it is pushed and given a pre-release tag
  • The interface to start a DeviceDefender task has been updated for better safety and extensibility to include custom metrics. This device SDK needed updates to adhere to the new interface
  • No functionality for custom metrics has been added yet

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@DavidOgunsAWS DavidOgunsAWS marked this pull request as ready for review July 28, 2021 22:27
}

ReportTask::ReportTask(ReportTask &&toMove) noexcept
: OnTaskCancelled(std::move(toMove.OnTaskCancelled)), cancellationUserdata(toMove.cancellationUserdata),
m_allocator(toMove.m_allocator), m_status(toMove.m_status), m_taskConfig(std::move(toMove.m_taskConfig)),
m_owningTask(toMove.m_owningTask), m_lastError(toMove.m_lastError)
m_owningTask(toMove.m_owningTask), m_lastError(toMove.m_lastError),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this constructor necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. It was already there so I made adjustments as necessary rather than figure out if it was safe to delete.

toMove.m_allocator = nullptr;
toMove.m_taskConfig = m_taskConfig;
toMove.m_owningTask = m_owningTask;
m_owningTask = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right to me. Why are we pushing things back into the thing we're moving out of?

For example here are several side-affect sequences, neither of which seem correct:

m_taskConfig(std::move(toMove.m_taskConfig))
toMove.m_taskConfig = m_taskConfig;

m_owningTask(toMove.m_owningTask) // copy
toMove.m_owningTask = m_owningTask // does nothing
m_owningTask = nullptr; // why?
toMove.m_owningTask = nullptr;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted this entire function

Copy link
Contributor

@graebm graebm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix & ship

Comment on lines 47 to 49
m_lastError =
aws_iotdevice_defender_config_create(&m_taskConfig, allocator, &thingNameCursor, reportFormat);
if (AWS_OP_SUCCESS == m_lastError)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial: it's a little weird to save the AWS_OP_ result in the same variable that's supposed to hold an AWS_ERROR_. They're conceptually two different types, even if they both happen to be ints

consider either

if (aws_iotdevice_defender_config_create(...) == AWS_OP_SUCCESS)

or

int result = aws_iotdevice_defender_config_create(...);
if (result == AWS_OP_SUCESS)
    ...

}

ReportTask::ReportTask(ReportTask &&toMove) noexcept
: OnTaskCancelled(std::move(toMove.OnTaskCancelled)), cancellationUserdata(toMove.cancellationUserdata),
m_allocator(toMove.m_allocator), m_status(toMove.m_status), m_taskConfig(std::move(toMove.m_taskConfig)),
m_owningTask(toMove.m_owningTask), m_lastError(toMove.m_lastError)
m_owningTask(toMove.m_owningTask), m_lastError(toMove.m_lastError),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you want to support move operations? It's a lot of subtle stuff that can accidentally go wrong. And if we ever need to pass a pointer to the C++ class down into C as user_data then then move is illegal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't, but after evaluating that callback_userdata is given a value of this, it's clear that a move after that won't be valid. This class has to be non-copyable, non-moveable. Making the adjustments

&m_owningTask,
this->m_taskConfig,
m_mqttConnection->GetUnderlyingConnection(),
aws_event_loop_group_get_next_loop(m_eventLoopGroup.GetUnderlyingHandle())))
{
this->m_lastError = aws_last_error();
aws_raise_error(this->m_lastError);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial: there's no point in re-raising the error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

}
}
return AWS_OP_SUCCESS;
return return_code;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, if the first if statement fails, we'll end up returning AWS_OP_ERR without having ever raised an error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Raising AWS_ERROR_INVALID_STATE in this situation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants