-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
applications: Matter Bridge: architectural refactoring
- allow to inject Matter and non-Matter devices to be bridged into the BridgeManager object - added devices factory to support bridged devices creation - implemented a dedicated map facilitating device object life time management - added necessary BridgeManager modifications Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>
- Loading branch information
1 parent
969bad4
commit 34eb1ad
Showing
8 changed files
with
333 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2023 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "bridge_util.h" | ||
#include "bridged_device.h" | ||
#include "bridged_device_data_provider.h" | ||
#include <lib/support/CHIPMem.h> | ||
|
||
#ifdef CONFIG_BRIDGE_HUMIDITY_SENSOR_BRIDGED_DEVICE | ||
#include "humidity_sensor.h" | ||
#include "humidity_sensor_data_provider.h" | ||
#endif | ||
|
||
#ifdef CONFIG_BRIDGE_ONOFF_LIGHT_BRIDGED_DEVICE | ||
#include "onoff_light.h" | ||
#include "onoff_light_data_provider.h" | ||
#endif | ||
|
||
#ifdef CONFIG_BRIDGE_TEMPERATURE_SENSOR_BRIDGED_DEVICE | ||
#include "temperature_sensor.h" | ||
#include "temperature_sensor_data_provider.h" | ||
#endif | ||
|
||
namespace BridgeFactory | ||
{ | ||
|
||
using UpdateAttributeCallback = BridgedDeviceDataProvider::UpdateAttributeCallback; | ||
using DeviceType = BridgedDevice::DeviceType; | ||
using BridgedDeviceFactory = DeviceFactory<BridgedDevice, const char *>; | ||
using DataProviderFactory = DeviceFactory<BridgedDeviceDataProvider, UpdateAttributeCallback>; | ||
|
||
auto checkLabel = [](const char *nodeLabel) { | ||
/* If node label is provided it must fit the maximum defined length */ | ||
if (!nodeLabel || (nodeLabel && (strlen(nodeLabel) < BridgedDevice::kNodeLabelSize))) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
inline BridgedDeviceFactory &GetBridgedDeviceFactory() | ||
{ | ||
static BridgedDeviceFactory sBridgedDeviceFactory{ | ||
#ifdef CONFIG_BRIDGE_HUMIDITY_SENSOR_BRIDGED_DEVICE | ||
{ DeviceType::HumiditySensor, | ||
[](const char *nodeLabel) -> BridgedDevice * { | ||
if (!checkLabel(nodeLabel)) { | ||
return nullptr; | ||
} | ||
return chip::Platform::New<HumiditySensorDevice>(nodeLabel); | ||
} }, | ||
#endif | ||
#ifdef CONFIG_BRIDGE_ONOFF_LIGHT_BRIDGED_DEVICE | ||
{ DeviceType::OnOffLight, | ||
[](const char *nodeLabel) -> BridgedDevice * { | ||
if (!checkLabel(nodeLabel)) { | ||
return nullptr; | ||
} | ||
return chip::Platform::New<OnOffLightDevice>(nodeLabel); | ||
} }, | ||
#endif | ||
#ifdef CONFIG_BRIDGE_TEMPERATURE_SENSOR_BRIDGED_DEVICE | ||
{ BridgedDevice::DeviceType::TemperatureSensor, | ||
[](const char *nodeLabel) -> BridgedDevice * { | ||
if (!checkLabel(nodeLabel)) { | ||
return nullptr; | ||
} | ||
return chip::Platform::New<TemperatureSensorDevice>(nodeLabel); | ||
} }, | ||
#endif | ||
}; | ||
return sBridgedDeviceFactory; | ||
} | ||
|
||
inline DataProviderFactory &GetDataProviderFactory() | ||
{ | ||
static DataProviderFactory sDeviceDataProvider{ | ||
#ifdef CONFIG_BRIDGE_HUMIDITY_SENSOR_BRIDGED_DEVICE | ||
{ DeviceType::HumiditySensor, | ||
[](UpdateAttributeCallback clb) { return chip::Platform::New<HumiditySensorDataProvider>(clb); } }, | ||
#endif | ||
#ifdef CONFIG_BRIDGE_ONOFF_LIGHT_BRIDGED_DEVICE | ||
{ DeviceType::OnOffLight, | ||
[](UpdateAttributeCallback clb) { return chip::Platform::New<OnOffLightDataProvider>(clb); } }, | ||
#endif | ||
#ifdef CONFIG_BRIDGE_TEMPERATURE_SENSOR_BRIDGED_DEVICE | ||
{ DeviceType::TemperatureSensor, | ||
[](UpdateAttributeCallback clb) { return chip::Platform::New<TemperatureSensorDataProvider>(clb); } }, | ||
#endif | ||
}; | ||
return sDeviceDataProvider; | ||
} | ||
|
||
} // namespace BridgeFactory |
Oops, something went wrong.