Skip to content

Code Format Update #798

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 2 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ on:
jobs:
clang-format:

runs-on: ubuntu-latest
runs-on: ubuntu-24.04 # latest

steps:
- name: Checkout Sources
uses: actions/checkout@v1
- name: Checkout Sources
uses: actions/checkout@v4

- name: clang-format lint
uses: DoozyX/[email protected]
with:
# List of extensions to check
extensions: cpp,h
clangFormatVersion: 11.1.0
- name: clang-format lint
run: |
./format-check.py
38 changes: 25 additions & 13 deletions devicedefender/source/DeviceDefender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Aws
public:
Crt::Allocator *m_allocator;

virtual ~CustomMetricBase(){};
virtual ~CustomMetricBase() {};
};

/**
Expand Down Expand Up @@ -97,9 +97,10 @@ namespace Aws
CustomMetricNumberList *metric = (CustomMetricNumberList *)data;
Crt::Vector<double> function_data = Crt::Vector<double>();
int returnValue = metric->m_metricFunction(&function_data);
std::for_each(function_data.begin(), function_data.end(), [output](double &i) {
aws_array_list_push_back(output, &i);
});
std::for_each(
function_data.begin(),
function_data.end(),
[output](double &i) { aws_array_list_push_back(output, &i); });
return returnValue;
}

Expand All @@ -116,10 +117,14 @@ namespace Aws
CustomMetricStringList *metric = (CustomMetricStringList *)data;
Crt::Vector<Crt::String> function_data = Crt::Vector<Crt::String>();
int returnValue = metric->m_metricFunction(&function_data);
std::for_each(function_data.begin(), function_data.end(), [output, metric](Crt::String &i) {
aws_string *tmp_str = aws_string_new_from_c_str(metric->m_allocator, i.c_str());
aws_array_list_push_back(output, &tmp_str);
});
std::for_each(
function_data.begin(),
function_data.end(),
[output, metric](Crt::String &i)
{
aws_string *tmp_str = aws_string_new_from_c_str(metric->m_allocator, i.c_str());
aws_array_list_push_back(output, &tmp_str);
});
return returnValue;
}

Expand All @@ -134,10 +139,14 @@ namespace Aws
CustomMetricIpList *metric = (CustomMetricIpList *)data;
Crt::Vector<Crt::String> function_data = Crt::Vector<Crt::String>();
int returnValue = metric->m_metricFunction(&function_data);
std::for_each(function_data.begin(), function_data.end(), [output, metric](Crt::String &i) {
aws_string *tmp_str = aws_string_new_from_c_str(metric->m_allocator, i.c_str());
aws_array_list_push_back(output, &tmp_str);
});
std::for_each(
function_data.begin(),
function_data.end(),
[output, metric](Crt::String &i)
{
aws_string *tmp_str = aws_string_new_from_c_str(metric->m_allocator, i.c_str());
aws_array_list_push_back(output, &tmp_str);
});
return returnValue;
}

Expand Down Expand Up @@ -184,7 +193,10 @@ namespace Aws
}
}

ReportTaskStatus ReportTask::GetStatus() noexcept { return this->m_status; }
ReportTaskStatus ReportTask::GetStatus() noexcept
{
return this->m_status;
}

int ReportTask::StartTask() noexcept
{
Expand Down
110 changes: 62 additions & 48 deletions devicedefender/tests/DeviceDefenderMetricsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ static int s_TestDeviceDefenderCustomMetricSuccess(Aws::Crt::Allocator *allocato
std::condition_variable cv;
bool taskStopped = false;

auto onCancelled = [&](void *a) -> void {
auto onCancelled = [&](void *a) -> void
{
auto *data = reinterpret_cast<bool *>(a);
*data = true;
taskStopped = true;
Expand All @@ -60,7 +61,8 @@ static int s_TestDeviceDefenderCustomMetricSuccess(Aws::Crt::Allocator *allocato

// ================
// Add the custom metrics
std::function<int(double *)> local_metric_number_func = [](double *output) {
std::function<int(double *)> local_metric_number_func = [](double *output)
{
*output = 10;
return AWS_OP_SUCCESS;
};
Expand All @@ -69,32 +71,35 @@ static int s_TestDeviceDefenderCustomMetricSuccess(Aws::Crt::Allocator *allocato
task->RegisterCustomMetricNumber("CustomNumberTwo", std::move(global_metric_number_func_ref));

std::function<int(Aws::Crt::Vector<double> *)> local_metric_number_list_func =
[](Aws::Crt::Vector<double> *output) {
output->push_back(101);
output->push_back(102);
output->push_back(103);
return AWS_OP_SUCCESS;
};
[](Aws::Crt::Vector<double> *output)
{
output->push_back(101);
output->push_back(102);
output->push_back(103);
return AWS_OP_SUCCESS;
};
task->RegisterCustomMetricNumberList("CustomNumberList", std::move(local_metric_number_list_func));

std::function<int(Aws::Crt::Vector<Aws::Crt::String> *)> local_metric_str_list_func =
[](Aws::Crt::Vector<Aws::Crt::String> *output) {
output->push_back("One Fish");
output->push_back("Two Fish");
output->push_back("Red Fish");
output->push_back("Blue Fish");
return AWS_OP_SUCCESS;
};
[](Aws::Crt::Vector<Aws::Crt::String> *output)
{
output->push_back("One Fish");
output->push_back("Two Fish");
output->push_back("Red Fish");
output->push_back("Blue Fish");
return AWS_OP_SUCCESS;
};
task->RegisterCustomMetricStringList("CustomStringList", std::move(local_metric_str_list_func));

std::function<int(Aws::Crt::Vector<Aws::Crt::String> *)> local_metric_ip_list_func =
[](Aws::Crt::Vector<Aws::Crt::String> *output) {
output->push_back("192.0.2.0");
output->push_back("198.51.100.0");
output->push_back("203.0.113.0");
output->push_back("233.252.0.0");
return AWS_OP_SUCCESS;
};
[](Aws::Crt::Vector<Aws::Crt::String> *output)
{
output->push_back("192.0.2.0");
output->push_back("198.51.100.0");
output->push_back("203.0.113.0");
output->push_back("233.252.0.0");
return AWS_OP_SUCCESS;
};
task->RegisterCustomMetricIpAddressList("CustomIPList", std::move(local_metric_ip_list_func));

// ================
Expand Down Expand Up @@ -146,7 +151,8 @@ static int s_TestDeviceDefenderCustomMetricFail(Aws::Crt::Allocator *allocator,
std::condition_variable cv;
bool taskStopped = false;

auto onCancelled = [&](void *a) -> void {
auto onCancelled = [&](void *a) -> void
{
auto *data = reinterpret_cast<bool *>(a);
*data = true;
taskStopped = true;
Expand All @@ -162,7 +168,8 @@ static int s_TestDeviceDefenderCustomMetricFail(Aws::Crt::Allocator *allocator,
std::shared_ptr<Aws::Iotdevicedefenderv1::ReportTask> task = taskBuilder.Build();

// Add the error custom metric
std::function<int(double *)> number_metric_func = [](double *output) {
std::function<int(double *)> number_metric_func = [](double *output)
{
*output = 10;
return AWS_OP_ERR;
};
Expand Down Expand Up @@ -220,7 +227,8 @@ static int s_TestMqtt5DeviceDefenderCustomMetricSuccess(Aws::Crt::Allocator *all
std::condition_variable cv;
bool taskStopped = false;

auto onCancelled = [&](void *a) -> void {
auto onCancelled = [&](void *a) -> void
{
auto *data = reinterpret_cast<bool *>(a);
*data = true;
taskStopped = true;
Expand All @@ -237,7 +245,8 @@ static int s_TestMqtt5DeviceDefenderCustomMetricSuccess(Aws::Crt::Allocator *all

// ================
// Add the custom metrics
std::function<int(double *)> local_metric_number_func = [](double *output) {
std::function<int(double *)> local_metric_number_func = [](double *output)
{
*output = 10;
return AWS_OP_SUCCESS;
};
Expand All @@ -246,32 +255,35 @@ static int s_TestMqtt5DeviceDefenderCustomMetricSuccess(Aws::Crt::Allocator *all
task->RegisterCustomMetricNumber("CustomNumberTwo", std::move(global_metric_number_func_ref));

std::function<int(Aws::Crt::Vector<double> *)> local_metric_number_list_func =
[](Aws::Crt::Vector<double> *output) {
output->push_back(101);
output->push_back(102);
output->push_back(103);
return AWS_OP_SUCCESS;
};
[](Aws::Crt::Vector<double> *output)
{
output->push_back(101);
output->push_back(102);
output->push_back(103);
return AWS_OP_SUCCESS;
};
task->RegisterCustomMetricNumberList("CustomNumberList", std::move(local_metric_number_list_func));

std::function<int(Aws::Crt::Vector<Aws::Crt::String> *)> local_metric_str_list_func =
[](Aws::Crt::Vector<Aws::Crt::String> *output) {
output->push_back("One Fish");
output->push_back("Two Fish");
output->push_back("Red Fish");
output->push_back("Blue Fish");
return AWS_OP_SUCCESS;
};
[](Aws::Crt::Vector<Aws::Crt::String> *output)
{
output->push_back("One Fish");
output->push_back("Two Fish");
output->push_back("Red Fish");
output->push_back("Blue Fish");
return AWS_OP_SUCCESS;
};
task->RegisterCustomMetricStringList("CustomStringList", std::move(local_metric_str_list_func));

std::function<int(Aws::Crt::Vector<Aws::Crt::String> *)> local_metric_ip_list_func =
[](Aws::Crt::Vector<Aws::Crt::String> *output) {
output->push_back("192.0.2.0");
output->push_back("198.51.100.0");
output->push_back("203.0.113.0");
output->push_back("233.252.0.0");
return AWS_OP_SUCCESS;
};
[](Aws::Crt::Vector<Aws::Crt::String> *output)
{
output->push_back("192.0.2.0");
output->push_back("198.51.100.0");
output->push_back("203.0.113.0");
output->push_back("233.252.0.0");
return AWS_OP_SUCCESS;
};
task->RegisterCustomMetricIpAddressList("CustomIPList", std::move(local_metric_ip_list_func));

// ================
Expand Down Expand Up @@ -333,7 +345,8 @@ static int s_TestMqtt5DeviceDefenderCustomMetricFail(Aws::Crt::Allocator *alloca
std::condition_variable cv;
bool taskStopped = false;

auto onCancelled = [&](void *a) -> void {
auto onCancelled = [&](void *a) -> void
{
auto *data = reinterpret_cast<bool *>(a);
*data = true;
taskStopped = true;
Expand All @@ -349,7 +362,8 @@ static int s_TestMqtt5DeviceDefenderCustomMetricFail(Aws::Crt::Allocator *alloca
std::shared_ptr<Aws::Iotdevicedefenderv1::ReportTask> task = taskBuilder.Build();

// Add the error custom metric
std::function<int(double *)> number_metric_func = [](double *output) {
std::function<int(double *)> number_metric_func = [](double *output)
{
*output = 10;
return AWS_OP_ERR;
};
Expand Down
6 changes: 4 additions & 2 deletions devicedefender/tests/DeviceDefenderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ static int s_TestDeviceDefenderResourceSafety(Aws::Crt::Allocator *allocator, vo
std::condition_variable cv;
bool taskStopped = false;

auto onCancelled = [&](void *a) -> void {
auto onCancelled = [&](void *a) -> void
{
auto *data = reinterpret_cast<bool *>(a);
*data = true;
taskStopped = true;
Expand Down Expand Up @@ -177,7 +178,8 @@ static int s_TestMqtt5DeviceDefenderResourceSafety(Aws::Crt::Allocator *allocato
std::condition_variable cv;
bool taskStopped = false;

auto onCancelled = [&](void *a) -> void {
auto onCancelled = [&](void *a) -> void
{
auto *data = reinterpret_cast<bool *>(a);
*data = true;
taskStopped = true;
Expand Down
5 changes: 4 additions & 1 deletion discovery/source/ConnectivityInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ namespace Aws
}
}

ConnectivityInfo::ConnectivityInfo(const Crt::JsonView &doc) { LoadFromObject(*this, doc); }
ConnectivityInfo::ConnectivityInfo(const Crt::JsonView &doc)
{
LoadFromObject(*this, doc);
}

ConnectivityInfo &ConnectivityInfo::operator=(const Crt::JsonView &doc)
{
Expand Down
5 changes: 4 additions & 1 deletion discovery/source/DiscoverResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ namespace Aws
}
}

DiscoverResponse::DiscoverResponse(const Crt::JsonView &doc) { LoadFromObject(*this, doc); }
DiscoverResponse::DiscoverResponse(const Crt::JsonView &doc)
{
LoadFromObject(*this, doc);
}

DiscoverResponse &DiscoverResponse::operator=(const Crt::JsonView &doc)
{
Expand Down
16 changes: 8 additions & 8 deletions discovery/source/DiscoveryClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ namespace Aws

bool res = m_connectionManager->AcquireConnection(
[this, callbackContext, thingName, onDiscoverResponse](
std::shared_ptr<Crt::Http::HttpClientConnection> connection, int errorCode) {
std::shared_ptr<Crt::Http::HttpClientConnection> connection, int errorCode)
{
if (errorCode)
{
onDiscoverResponse(nullptr, errorCode, 0);
Expand Down Expand Up @@ -164,15 +165,14 @@ namespace Aws
[](Crt::Http::HttpStream &, aws_http_header_block, const Crt::Http::HttpHeader *, std::size_t) {
};
requestOptions.onIncomingHeadersBlockDone =
[callbackContext](Crt::Http::HttpStream &stream, aws_http_header_block) {
callbackContext->responseCode = stream.GetResponseStatusCode();
};
[callbackContext](Crt::Http::HttpStream &stream, aws_http_header_block)
{ callbackContext->responseCode = stream.GetResponseStatusCode(); };
requestOptions.onIncomingBody =
[callbackContext](Crt::Http::HttpStream &, const Crt::ByteCursor &data) {
callbackContext->ss.write(reinterpret_cast<const char *>(data.ptr), data.len);
};
[callbackContext](Crt::Http::HttpStream &, const Crt::ByteCursor &data)
{ callbackContext->ss.write(reinterpret_cast<const char *>(data.ptr), data.len); };
requestOptions.onStreamComplete = [request, connection, callbackContext, onDiscoverResponse](
Crt::Http::HttpStream &, int errorCode) {
Crt::Http::HttpStream &, int errorCode)
{
if (!errorCode && callbackContext->responseCode == 200)
{
Crt::JsonObject jsonObject(callbackContext->ss.str());
Expand Down
5 changes: 4 additions & 1 deletion discovery/source/GGCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ namespace Aws
}
}

GGCore::GGCore(const Crt::JsonView &doc) { LoadFromObject(*this, doc); }
GGCore::GGCore(const Crt::JsonView &doc)
{
LoadFromObject(*this, doc);
}

GGCore &GGCore::operator=(const Crt::JsonView &doc)
{
Expand Down
5 changes: 4 additions & 1 deletion discovery/source/GGGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ namespace Aws
}
}

GGGroup::GGGroup(const Crt::JsonView &doc) { LoadFromObject(*this, doc); }
GGGroup::GGGroup(const Crt::JsonView &doc)
{
LoadFromObject(*this, doc);
}

GGGroup &GGGroup::operator=(const Crt::JsonView &doc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ namespace Aws
void PrependHeaders(Crt::List<EventStreamHeader> &&headers);
void SetPayload(const Crt::Optional<Crt::ByteBuf> &payload) noexcept;
void SetPayload(Crt::Optional<Crt::ByteBuf> &&payload);
const Crt::List<EventStreamHeader> &GetHeaders() const &noexcept;
const Crt::List<EventStreamHeader> &GetHeaders() const & noexcept;
Crt::List<EventStreamHeader> &&GetHeaders() &&;
const Crt::Optional<Crt::ByteBuf> &GetPayload() const &noexcept;
const Crt::Optional<Crt::ByteBuf> &GetPayload() const & noexcept;
Crt::Optional<Crt::ByteBuf> &&GetPayload() &&;

private:
Expand Down
Loading
Loading