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

[ICD] Creation of ICDManager classes #26523

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
60119a6
Creation of ICDManager
mkardous-silabs May 11, 2023
ab3ee5d
restyle
mkardous-silabs May 11, 2023
7569a7f
refactor object management
mkardous-silabs May 12, 2023
02a8539
add shutdown
mkardous-silabs May 12, 2023
d29bd69
restyle
mkardous-silabs May 12, 2023
41f986b
Add event callback
mkardous-silabs May 12, 2023
7e717fe
restyle
mkardous-silabs May 12, 2023
3c2e63e
make the changes in the wifi file
mkardous-silabs May 12, 2023
8d9a6ca
fix typos
mkardous-silabs May 12, 2023
ab28af0
address review comments
mkardous-silabs May 12, 2023
7097932
restyle
mkardous-silabs May 12, 2023
af3b403
add missing define
mkardous-silabs May 12, 2023
64faf94
move files
mkardous-silabs Jun 1, 2023
5eeddcc
Remove handler in shutdown
mkardous-silabs Jun 1, 2023
23f2e2e
refactor ICD Manager structure
mkardous-silabs Jun 1, 2023
9746c7b
restyle
mkardous-silabs Jun 1, 2023
79400b4
remove line
mkardous-silabs Jun 2, 2023
bb48d94
fix ifdef
mkardous-silabs Jun 2, 2023
47297b5
address comments on comments
mkardous-silabs Jun 2, 2023
36ec0b2
refactor gn files
mkardous-silabs Jun 2, 2023
2bb8208
restyle
mkardous-silabs Jun 2, 2023
b9c554d
address comments
mkardous-silabs Jun 2, 2023
46f740a
Apply suggestions from code review
mkardous-silabs Jun 2, 2023
45ea6a3
Address first wave of comments
mkardous-silabs Jun 2, 2023
439ad57
Address second wave of comments
mkardous-silabs Jun 2, 2023
fbeb297
fix typo
mkardous-silabs Jun 2, 2023
fc49437
clean defines
mkardous-silabs Jun 2, 2023
9e43929
rename define
mkardous-silabs Jun 2, 2023
569e560
fix gn check error
mkardous-silabs Jun 5, 2023
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
5 changes: 5 additions & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import("${chip_root}/src/platform/device.gni")

import("${chip_root}/build/chip/buildconfig_header.gni")
import("common_flags.gni")
import("icd/icd.gni")
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved

declare_args() {
# Enable strict schema checks.
Expand Down Expand Up @@ -210,6 +211,10 @@ static_library("app") {
"${nlio_root}:nlio",
]

if (chip_enable_icd_server) {
public_deps += [ "${chip_root}/src/app/icd:server-srcs" ]
}

cflags = [ "-Wconversion" ]

public_configs = [ "${chip_root}/src:includes" ]
Expand Down
53 changes: 53 additions & 0 deletions src/app/icd/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (c) 2020 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("icd.gni")

# ICD Server sources and configurations

# ICD Manager source-set is broken out of the main source-set to enable unit tests
# All sources and configurations used by the ICDManager need to go in this source-set
source_set("manager-srcs") {
sources = [
"ICDManager.cpp",
"ICDManager.h",
]

public_deps = [ "${chip_root}/src/lib/core" ]
}

# ICD Server Configuration
# All configurations necessary to the ICD Server featureset need to in this configuration
config("server-config") {
defines = [ "CHIP_CONFIG_ENABLE_ICD_SERVER" ]
}

# servers-srcs source-set contains all the sources and configurations necessary to build the ICD Server functionality
# All sources, configurations and dependencies necessary for the ICD Server featureset need to go in this source-set
#
# The ICD Server featureset is enabled with the chip_enable_icd_server in the src/app/BUILD.gn file
source_set("server-srcs") {
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
sources = [
"ICDEventManager.cpp",
"ICDEventManager.h",
]

public_deps = [
":manager-srcs",
"${chip_root}/src/platform:platform",
]

public_configs = [ ":server-config" ]
}
49 changes: 49 additions & 0 deletions src/app/icd/ICDEventManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
*
* 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.
*/

#include <app/icd/ICDEventManager.h>

using namespace chip::DeviceLayer;

namespace chip {
namespace app {

CHIP_ERROR ICDEventManager::Init(ICDManager * icdManager)
{
VerifyOrReturnError(icdManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
mICDManager = icdManager;

PlatformMgr().AddEventHandler(ICDEventHandler, reinterpret_cast<intptr_t>(nullptr));

return CHIP_NO_ERROR;
}

CHIP_ERROR ICDEventManager::Shutdown()
{
PlatformMgr().RemoveEventHandler(ICDEventHandler, reinterpret_cast<intptr_t>(nullptr));
mICDManager = nullptr;

return CHIP_NO_ERROR;
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
}

void ICDEventManager::ICDEventHandler(const ChipDeviceEvent * event, intptr_t arg)
{
// TODO
}

} // namespace app
} // namespace chip
55 changes: 55 additions & 0 deletions src/app/icd/ICDEventManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* 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 <platform/internal/CHIPDeviceLayerInternal.h>

#include <app/icd/ICDManager.h>
#include <lib/core/CHIPError.h>
#include <platform/CHIPDeviceEvent.h>

namespace chip {
namespace app {

/**
* @brief ICDEventManager class is responsible of processing Platform Events that affect an ICD's behaviour
* The class registers an Event Handler with the Platform Manager and dispatches the processing to the ICDManager class.
*/
class ICDEventManager
{

public:
ICDEventManager() = default;

/**
* @brief Initialisation function of the ICDEventManager.
* Init function MUST be called before using the object
*/
CHIP_ERROR Init(ICDManager * icdManager);
CHIP_ERROR Shutdown();

private:
/**
* @brief Event Handler callback given to the PlatformManager
* Function dispatchs the event to the ICDManager member
*/
static void ICDEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);

ICDManager * mICDManager;
};

} // namespace app
} // namespace chip
26 changes: 26 additions & 0 deletions src/app/icd/ICDManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
*
* 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.
*/

#include <app/icd/ICDManager.h>

namespace chip {
namespace app {

ICDManager::ICDManager() {}

} // namespace app
} // namespace chip
34 changes: 34 additions & 0 deletions src/app/icd/ICDManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
*
* 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

namespace chip {
namespace app {

/**
* @brief ICD Manager is responsible of processing the events and triggering the correct action for an ICD
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
*/
class ICDManager
{
public:
ICDManager();

private:
};

} // namespace app
} // namespace chip
23 changes: 23 additions & 0 deletions src/app/icd/icd.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.

declare_args() {
# Matter SDK Configuration flag to enable ICD server functionality
# TODO - Add Specifics when the design is refined
chip_enable_icd_server = false

# Matter SDK Configuration flag to enable ICD client functionality
# TODO - Add Specifics when the design is refined
chip_enable_icd_client = false
}
7 changes: 7 additions & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
}
#endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT

#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER
mICDEventManager.Init(&mICDManager);
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

// This initializes clusters, so should come after lower level initialization.
InitDataModelHandler();

Expand Down Expand Up @@ -484,6 +488,9 @@ void Server::Shutdown()
mAccessControl.Finish();
Access::ResetAccessControlToDefault();
Credentials::SetGroupDataProvider(nullptr);
#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER
mICDEventManager.Shutdown();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
mAttributePersister.Shutdown();
// TODO(16969): Remove chip::Platform::MemoryInit() call from Server class, it belongs to outer code
chip::Platform::MemoryShutdown();
Expand Down
9 changes: 9 additions & 0 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
#endif
#include <transport/raw/UDP.h>

#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER
#include <app/icd/ICDEventManager.h> // nogncheck
#include <app/icd/ICDManager.h> // nogncheck
#endif

namespace chip {

constexpr size_t kMaxBlePendingPackets = 1;
Expand Down Expand Up @@ -595,6 +600,10 @@ class Server
Inet::InterfaceId mInterfaceId;

System::Clock::Microseconds64 mInitTimestamp;
#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER
app::ICDEventManager mICDEventManager;
app::ICDManager mICDManager;
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
};

} // namespace chip
2 changes: 2 additions & 0 deletions src/app/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ chip_test_suite("tests") {
"TestEventPathParams.cpp",
"TestExtensionFieldSets.cpp",
"TestFabricScopedEventLogging.cpp",
"TestICDManager.cpp",
"TestInteractionModelEngine.cpp",
"TestMessageDef.cpp",
"TestNumericAttributeTraits.cpp",
Expand Down Expand Up @@ -170,6 +171,7 @@ chip_test_suite("tests") {
":scenes-table-test-srcs",
"${chip_root}/src/app",
"${chip_root}/src/app/common:cluster-objects",
"${chip_root}/src/app/icd:manager-srcs",
"${chip_root}/src/app/tests:helpers",
"${chip_root}/src/app/util/mock:mock_ember",
"${chip_root}/src/lib/core",
Expand Down
31 changes: 31 additions & 0 deletions src/app/tests/TestICDManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* Copyright (c) 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 <lib/support/UnitTestRegistration.h>
#include <nlunit-test.h>

int TestICDManager()
{
static nlTest sTests[] = { NL_TEST_SENTINEL() };

nlTestSuite cmSuite = { "TestICDManager", &sTests[0], nullptr, nullptr };

nlTestRunner(&cmSuite, nullptr);
return (nlTestRunnerStats(&cmSuite));
}

CHIP_REGISTER_TEST_SUITE(TestICDManager)