Skip to content
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

feat: Add terms-and-conditions sample app for CI testing #36950

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions docs/issue_triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ types or functionality) as well as individual examples.
| `examples/rvc-app` | | UNMAINTAINED |
| `examples/smoke-co-alarm-app` | | UNMAINTAINED |
| `examples/temperature-measurement-app` | | UNMAINTAINED |
| `examples/terms-and-conditions-app` | James Swan | |
| `examples/thermostat` | | UNMAINTAINED |
| `examples/thread-br-app` | | UNMAINTAINED |
| `examples/tv-app` | Chris DeCenzo, Lazar Kovacic | |
Expand Down
25 changes: 25 additions & 0 deletions examples/terms-and-conditions-app/linux/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2024 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")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
import("//args.gni")
}
32 changes: 32 additions & 0 deletions examples/terms-and-conditions-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2024 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/chip.gni")
import("${chip_root}/build/chip/tools.gni")
import("${chip_root}/src/app/common_flags.gni")

executable("chip-terms-and-conditions-app") {
sources = [ "main.cpp" ]

deps = [
"${chip_root}/examples/platform/linux:app-main",
"${chip_root}/examples/terms-and-conditions-app/terms-and-conditions-common",
]

output_dir = root_out_dir
}

group("default") {
deps = [ ":chip-terms-and-conditions-app" ]
}
18 changes: 18 additions & 0 deletions examples/terms-and-conditions-app/linux/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2024 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/chip.gni")
import("${chip_root}/config/standalone/args.gni")

chip_terms_and_conditions_required = true
1 change: 1 addition & 0 deletions examples/terms-and-conditions-app/linux/build_overrides
86 changes: 86 additions & 0 deletions examples/terms-and-conditions-app/linux/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* 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.
*/

#include <AppMain.h>
#include <app/server/TermsAndConditionsManager.h>
#include <app/server/TermsAndConditionsProvider.h>

using namespace chip;
using namespace chip::ArgParser;

static uint16_t sTcMinRequiredVersion = 0;
static uint16_t sTcRequiredAcknowledgements = 0;

static OptionDef sTermsAndConditionsOptions[] = {
{ "tc-min-required-version", kArgumentRequired, 'm' },
{ "tc-required-acknowledgements", kArgumentRequired, 'r' },
{ nullptr },
};

static const char * const sTermsAndConditionsOptionHelp =
"-m, --tc-min-required-version <number>\n Configure the minimum required TC version.\n\n"
"-r, --tc-required-acknowledgements <number (bitfield)>\n Configure the required TC acknowledgements.\n\n";

static bool HandleOption(const char * progName, OptionSet * optSet, int id, const char * name, const char * arg)
{
switch (id)
{
case 'm':
sTcMinRequiredVersion = static_cast<uint16_t>(atoi(arg));
break;
case 'r':
sTcRequiredAcknowledgements = static_cast<uint16_t>(atoi(arg));
break;
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", progName, name);
return false;
}

return true;
}

static OptionSet sTermsAndConditionsCmdLineOptions = {
HandleOption,
sTermsAndConditionsOptions,
"TERMS AND CONDITIONS OPTIONS",
sTermsAndConditionsOptionHelp,
};

void ApplicationInit()
{
const app::TermsAndConditions termsAndConditions = app::TermsAndConditions(sTcRequiredAcknowledgements, sTcMinRequiredVersion);

const Optional<app::TermsAndConditions> requiredTermsAndConditions = Optional<app::TermsAndConditions>(termsAndConditions);
swan-amazon marked this conversation as resolved.
Show resolved Hide resolved

PersistentStorageDelegate & persistentStorageDelegate = Server::GetInstance().GetPersistentStorage();

chip::app::TermsAndConditionsManager::GetInstance()->Init(&persistentStorageDelegate, requiredTermsAndConditions);
swan-amazon marked this conversation as resolved.
Show resolved Hide resolved
}

void ApplicationShutdown() {}

int main(int argc, char * argv[])
{
if (ChipLinuxAppInit(argc, argv, &sTermsAndConditionsCmdLineOptions) != 0)
{
return -1;
}

ChipLinuxAppMainLoop();
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2024 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/chip.gni")

import("${chip_root}/src/app/chip_data_model.gni")

chip_data_model("terms-and-conditions-common") {
zap_file = "terms-and-conditions-app.zap"
is_server = true
}
Loading
Loading