Skip to content

Commit

Permalink
[OIS/example] Sharing lock-app cluster service between Linux and OIS …
Browse files Browse the repository at this point in the history
…platforms (#24551)

* [Examples] Create common lock-app cluster service

Move lock endpoint, manager and ZCL callbacks from Linux to
lock-common directory.
Create source set with lock cluster service files.
Create cmake macro to add common lock-app sources to the
specific target.
Use lock-cluster-service in Linux lock-app example.
Change "setting door lock state" logs to progress level to
be informed of the lock status change directly.

Sources can now be easily shared across platform implementations.

Signed-off-by: ATmobica <artur.tynecki@arm.com>

* [OIS] Use common lock-app sources

Directly use of common lock cluster service sources in lock-app
example instead of creating the copy.
Lock-app integration test adaptation.

Signed-off-by: ATmobica <artur.tynecki@arm.com>

---------

Signed-off-by: ATmobica <artur.tynecki@arm.com>
  • Loading branch information
ATmobica authored and pull[bot] committed Sep 18, 2023
1 parent 2dad7a6 commit 63e1357
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 915 deletions.
10 changes: 6 additions & 4 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ source_set("chip-all-clusters-common") {

source_set("chip-lock-app-common") {
sources = [
"${chip_root}/examples/lock-app/linux/src/LockEndpoint.cpp",
"${chip_root}/examples/lock-app/linux/src/LockManager.cpp",
"${chip_root}/examples/lock-app/linux/src/ZCLDoorLockCallbacks.cpp",
"${chip_root}/examples/lock-app/lock-common/include/LockEndpoint.h",
"${chip_root}/examples/lock-app/lock-common/include/LockManager.h",
"${chip_root}/examples/lock-app/lock-common/src/LockEndpoint.cpp",
"${chip_root}/examples/lock-app/lock-common/src/LockManager.cpp",
"${chip_root}/examples/lock-app/lock-common/src/ZCLDoorLockCallbacks.cpp",
]

deps = [ "${chip_root}/examples/all-clusters-app/all-clusters-common" ]

include_dirs = [ "${chip_root}/examples/lock-app/linux/include" ]
include_dirs = [ "${chip_root}/examples/lock-app/lock-common/include" ]

cflags = [ "-Wconversion" ]
}
Expand Down
10 changes: 6 additions & 4 deletions examples/all-clusters-minimal-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ source_set("chip-all-clusters-common") {

source_set("chip-lock-app-common") {
sources = [
"${chip_root}/examples/lock-app/linux/src/LockEndpoint.cpp",
"${chip_root}/examples/lock-app/linux/src/LockManager.cpp",
"${chip_root}/examples/lock-app/linux/src/ZCLDoorLockCallbacks.cpp",
"${chip_root}/examples/lock-app/lock-common/include/LockEndpoint.h",
"${chip_root}/examples/lock-app/lock-common/include/LockManager.h",
"${chip_root}/examples/lock-app/lock-common/src/LockEndpoint.cpp",
"${chip_root}/examples/lock-app/lock-common/src/LockManager.cpp",
"${chip_root}/examples/lock-app/lock-common/src/ZCLDoorLockCallbacks.cpp",
]

deps =
[ "${chip_root}/examples/all-clusters-minimal-app/all-clusters-common" ]

include_dirs = [ "${chip_root}/examples/lock-app/linux/include" ]
include_dirs = [ "${chip_root}/examples/lock-app/lock-common/include" ]

cflags = [ "-Wconversion" ]
}
Expand Down
9 changes: 2 additions & 7 deletions examples/lock-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@ executable("chip-lock-app") {
sources = [
"main.cpp",
"src/LockAppCommandDelegate.cpp",
"src/LockEndpoint.cpp",
"src/LockManager.cpp",
"src/ZCLDoorLockCallbacks.cpp",
]

deps = [
"${chip_root}/examples/lock-app/lock-common",
"${chip_root}/examples/lock-app/lock-common:lock-cluster-service",
"${chip_root}/examples/platform/linux:app-main",
"${chip_root}/src/lib",
"${chip_root}/third_party/jsoncpp",
]

include_dirs = [
"${chip_root}/examples/lock-app/lock-common/include",
"include",
]
include_dirs = [ "include" ]

cflags = [ "-Wconversion" ]

Expand Down
19 changes: 19 additions & 0 deletions examples/lock-app/lock-common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,22 @@ chip_data_model("lock-common") {
zap_pregenerated_dir = "${chip_root}/zzz_generated/lock-app/zap-generated"
is_server = true
}

config("config") {
include_dirs = [ "include" ]
}

source_set("lock-cluster-service") {
deps = [
"${chip_root}/examples/lock-app/lock-common",
"${chip_root}/src/lib",
]
public_configs = [ ":config" ]
sources = [
"include/LockEndpoint.h",
"include/LockManager.h",
"src/LockEndpoint.cpp",
"src/LockManager.cpp",
"src/ZCLDoorLockCallbacks.cpp",
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2022-2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2020-2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
45 changes: 45 additions & 0 deletions examples/lock-app/lock-common/lock-app.cmake
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.
#

cmake_minimum_required(VERSION 3.21)

set(CHIP_LOCK_COMMON_BASE_DIR ${CMAKE_CURRENT_LIST_DIR})


# Add common lock sources to the specific target
# [Args]:
# target - target name
# Available options are:
# SCOPE sources scope for the target, PRIVATE as default
macro(chip_add_lock_app_common target)
set(SCOPE PRIVATE)
cmake_parse_arguments(ARG "" "SCOPE" "" ${ARGN})
if (ARG_SCOPE)
set(SCOPE ${ARG_SCOPE})
endif()

target_include_directories(${target}
${SCOPE}
${CHIP_LOCK_COMMON_BASE_DIR}/include
)

target_sources(${target}
${SCOPE}
${CHIP_LOCK_COMMON_BASE_DIR}/src/ZCLDoorLockCallbacks.cpp
${CHIP_LOCK_COMMON_BASE_DIR}/src/LockManager.cpp
${CHIP_LOCK_COMMON_BASE_DIR}/src/LockEndpoint.cpp
)
endmacro()
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2022-2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -392,8 +392,8 @@ bool LockEndpoint::setLockState(DlLockState lockState, const Optional<chip::Byte
// If a pin code is not required
if (!requirePin)
{
ChipLogDetail(Zcl, "Door Lock App: setting door lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState),
mEndpointId);
ChipLogProgress(Zcl, "Door Lock App: setting door lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState),
mEndpointId);

DoorLockServer::Instance().SetLockState(mEndpointId, lockState);

Expand Down Expand Up @@ -454,7 +454,7 @@ bool LockEndpoint::setLockState(DlLockState lockState, const Optional<chip::Byte
return false;
}
}
ChipLogDetail(
ChipLogProgress(
Zcl,
"Lock App: specified PIN code was found in the database, setting door lock state to \"%s\" [endpointId=%d,userIndex=%u]",
lockStateToString(lockState), mEndpointId, userIndex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2020-2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
*
* Copyright (c) 2020-2023 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 <app/clusters/door-lock-server/door-lock-server.h>
#include <app/util/af.h>

Expand Down
11 changes: 8 additions & 3 deletions examples/lock-app/openiotsdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ cmake_minimum_required(VERSION 3.21)
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. REALPATH)
get_filename_component(OPEN_IOT_SDK_CONFIG ${CHIP_ROOT}/config/openiotsdk REALPATH)
get_filename_component(OPEN_IOT_SDK_EXAMPLE_COMMON ${CHIP_ROOT}/examples/platform/openiotsdk REALPATH)
get_filename_component(LOCK_APP_COMMON ${CHIP_ROOT}/examples/lock-app/lock-common REALPATH)

list(APPEND CMAKE_MODULE_PATH ${OPEN_IOT_SDK_CONFIG}/cmake)
list(APPEND CMAKE_MODULE_PATH ${LOCK_APP_COMMON})

set(APP_TARGET chip-openiotsdk-lock-app-example_ns)

Expand Down Expand Up @@ -61,6 +63,12 @@ add_subdirectory(${OPEN_IOT_SDK_EXAMPLE_COMMON}/app ./app_build)

chip_add_data_model(openiotsdk-app PUBLIC lock)

# Add common lock-app sources
include(lock-app)
chip_add_lock_app_common(openiotsdk-app
SCOPE PUBLIC
)

target_include_directories(${APP_TARGET}
PRIVATE
main/include
Expand All @@ -69,9 +77,6 @@ target_include_directories(${APP_TARGET}
target_sources(${APP_TARGET}
PRIVATE
main/main_ns.cpp
main/ZclCallbacks.cpp
main/LockManager.cpp
main/LockEndpoint.cpp
)

target_link_libraries(${APP_TARGET}
Expand Down
Loading

0 comments on commit 63e1357

Please sign in to comment.