Skip to content

Commit

Permalink
[ICD] Creation of ICDManager classes (#26523)
Browse files Browse the repository at this point in the history
* Creation of ICDManager

* restyle

* refactor object management

* add shutdown

* restyle

* Add event callback

* restyle

* make the changes in the wifi file

* fix typos
add missing define

* address review comments

* restyle

* add missing define

* move files

* Remove handler in shutdown

* refactor ICD Manager structure

* restyle

* remove line

* fix ifdef

* address comments on comments

* refactor gn files

* restyle

* address comments
  • Loading branch information
mkardous-silabs authored and pull[bot] committed Sep 5, 2023
1 parent d1c0451 commit 3492860
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 0 deletions.
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")

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") {
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;
}

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
*/
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)

0 comments on commit 3492860

Please sign in to comment.