Skip to content

Commit

Permalink
Fix Dynamic Bridge example compilation (#26129)
Browse files Browse the repository at this point in the history
* Make dynamic bridge app compile again

* Make sure dynamic bridge builds are in CI

* Update unit tests

* Add license blurb

* Restyle

* Remove extra namespace usage

* Make sure we allow ValueAssign.h to use std::string

* Fix regex syntax

* Fix naming of output app
  • Loading branch information
andy31415 authored Apr 17, 2023
1 parent 24b22a7 commit 1ec70b8
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 17 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/examples-linux-standalone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ jobs:
linux debug bridge-app \
out/linux-x64-bridge/chip-bridge-app \
/tmp/bloat_reports/
- name: Build example Dynamic Bridge
timeout-minutes: 10
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py \
--target linux-x64-dynamic-bridge-ipv6only \
build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
linux debug dynamic-bridge-app-ipv6only \
out/linux-x64-dynamic-bridge-ipv6only/dynamic-chip-bridge-app \
/tmp/bloat_reports/
- name: Build example OTA Provider
timeout-minutes: 10
run: |
Expand Down
3 changes: 2 additions & 1 deletion examples/dynamic-bridge-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ executable("dynamic-chip-bridge-app") {
"${chip_root}/examples/platform/linux:app-main",
"${chip_root}/src/app/tests/suites/credentials:dac_provider",
"${chip_root}/src/lib",
"${chip_root}/src/lib/assign",
]

include_dirs = [
Expand Down Expand Up @@ -116,7 +117,7 @@ executable("dynamic-chip-bridge-app") {

output_dir = root_out_dir

configs += ["${chip_root}/src:includes"]
configs += [ "${chip_root}/src:includes" ]
}

group("linux") {
Expand Down
12 changes: 6 additions & 6 deletions examples/dynamic-bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,6 @@ chip::Optional<chip::ClusterId> LookupClusterByName(const char * name)
return chip::Optional<chip::ClusterId>();
}

std::unique_ptr<GeneratedCluster> CreateCluster(const char * name)
{
auto id = LookupClusterByName(name);
return id.HasValue() ? CreateCluster(id.Value()) : nullptr;
}

std::unique_ptr<GeneratedCluster> CreateCluster(chip::ClusterId id)
{
for (const auto & cluster : clusters::kKnownClusters)
Expand All @@ -202,6 +196,12 @@ std::unique_ptr<GeneratedCluster> CreateCluster(chip::ClusterId id)
return nullptr;
}

std::unique_ptr<GeneratedCluster> CreateCluster(const char * name)
{
auto id = LookupClusterByName(name);
return id.HasValue() ? CreateCluster(id.Value()) : nullptr;
}

CHIP_ERROR TLVWriteValue(chip::TLV::TLVWriter & wr, const Span<const char> & v)
{
return wr.PutString(chip::TLV::AnonymousTag(), v);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <app/data-model/Nullable.h>
#include <lib/assign/ValueAssign.h>

#include <string>
#include <vector>
Expand All @@ -15,19 +16,19 @@ struct {{struct.name}}
chip::app::Clusters::detail::Structs::{{struct.name}}::DecodableType t;
CHIP_ERROR err = t.Decode(reader);
if(err == CHIP_NO_ERROR) {
{%- for field in struct.fields %}
{{field.name}} = t.{{field.name}};
{%- endfor %}
{%- for field in struct.fields %}
chip::Value::Assign({{field.name}}, t.{{field.name}});
{%- endfor %}
}
return err;
}

CHIP_ERROR Encode(chip::TLV::TLVWriter & writer, chip::TLV::Tag tag) const
{
chip::app::Clusters::detail::Structs::{{struct.name}}::Type t;
{%- for field in struct.fields %}
t.{{field.name}} = {{field.name}};
{%- endfor %}
{%- for field in struct.fields %}
chip::Value::Assign(t.{{field.name}}, {{field.name}});
{%- endfor %}
return t.Encode(writer, tag);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <app/data-model/Nullable.h>
#include <lib/assign/ValueAssign.h>

#include <string>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <app/data-model/Nullable.h>
#include <lib/assign/ValueAssign.h>

#include <string>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <app/data-model/Nullable.h>
#include <lib/assign/ValueAssign.h>

#include <string>
#include <vector>
Expand All @@ -15,17 +16,17 @@ struct LabelStruct
chip::app::Clusters::detail::Structs::LabelStruct::DecodableType t;
CHIP_ERROR err = t.Decode(reader);
if(err == CHIP_NO_ERROR) {
label = t.label;
value = t.value;
chip::Value::Assign(label, t.label);
chip::Value::Assign(value, t.value);
}
return err;
}

CHIP_ERROR Encode(chip::TLV::TLVWriter & writer, chip::TLV::Tag tag) const
{
chip::app::Clusters::detail::Structs::LabelStruct::Type t;
t.label = label;
t.value = value;
chip::Value::Assign(t.label, label);
chip::Value::Assign(t.value, value);
return t.Encode(writer, tag);
}
std::string label;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <app/data-model/Nullable.h>
#include <lib/assign/ValueAssign.h>

#include <string>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <app/data-model/Nullable.h>
#include <lib/assign/ValueAssign.h>

#include <string>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions scripts/tools/check_includes_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'/Test',
'/tests/',
'/tools/',
r'/lib/assign/ValueAssign\.h',

# Platforms can opt in or out.
'/darwin/',
Expand Down
22 changes: 22 additions & 0 deletions src/lib/assign/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2023 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

static_library("assign") {
sources = [ "ValueAssign.h" ]

public_deps = [ "${chip_root}/src/lib/support" ]
}
45 changes: 45 additions & 0 deletions src/lib/assign/ValueAssign.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <lib/support/Span.h>
#include <string>

namespace chip {
namespace Value {

template <class SRC, class DEST>
SRC & Assign(SRC & dest, const DEST & src)
{
return dest = src;
}

template <>
std::string & Assign(std::string & dest, const CharSpan & src)
{
dest = std::string(src.begin(), src.end());
return dest;
}

template <>
CharSpan & Assign(CharSpan & dest, const std::string & src)
{
dest = CharSpan(src.c_str(), src.size());
return dest;
}

} // namespace Value
} // namespace chip

0 comments on commit 1ec70b8

Please sign in to comment.