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

Convert a few more items to std::optional #33073

Merged
merged 16 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void BoundDeviceChangedHandler(const EmberBindingTableEntry & binding, ch
}

if (binding.type == MATTER_UNICAST_BINDING && binding.local == 1 &&
(!binding.clusterId.HasValue() || binding.clusterId.Value() == Clusters::OnOff::Id))
binding.clusterId.value_or(Clusters::OnOff::Id) == Clusters::OnOff::Id)
{
auto onSuccess = [](const ConcreteCommandPath & commandPath, const StatusIB & status, const auto & dataResponse) {
ChipLogProgress(NotSpecified, "OnOff command succeeds");
Expand Down
4 changes: 2 additions & 2 deletions examples/all-clusters-app/ameba/main/BindingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ CHIP_ERROR BindingGroupBindCommandHandler(int argc, char ** argv)
entry->fabricIndex = atoi(argv[0]);
entry->groupId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->clusterId.SetValue(6); // Hardcoded to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcoded to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand All @@ -210,7 +210,7 @@ CHIP_ERROR BindingUnicastBindCommandHandler(int argc, char ** argv)
entry->nodeId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->remote = atoi(argv[2]);
entry->clusterId.SetValue(6); // Hardcode to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcode to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion examples/all-clusters-app/nxp/mw320/binding-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void BoundDeviceChangedHandler(const EmberBindingTableEntry & binding, ch
}

if (binding.type == MATTER_UNICAST_BINDING && binding.local == 1 &&
(!binding.clusterId.HasValue() || binding.clusterId.Value() == Clusters::OnOff::Id))
binding.clusterId.value_or(Clusters::OnOff::Id) == Clusters::OnOff::Id)
{
auto onSuccess = [](const ConcreteCommandPath & commandPath, const StatusIB & status, const auto & dataResponse) {
ChipLogProgress(NotSpecified, "OnOff command succeeds");
Expand Down
4 changes: 2 additions & 2 deletions examples/light-switch-app/ameba/main/BindingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ CHIP_ERROR BindingGroupBindCommandHandler(int argc, char ** argv)
entry->fabricIndex = atoi(argv[0]);
entry->groupId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->clusterId.SetValue(6); // Hardcoded to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcoded to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand All @@ -266,7 +266,7 @@ CHIP_ERROR BindingUnicastBindCommandHandler(int argc, char ** argv)
entry->nodeId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->remote = atoi(argv[2]);
entry->clusterId.SetValue(6); // Hardcode to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcode to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion examples/light-switch-app/asr/src/BindingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void BindingHandler::PrintBindingTable()
\t+ ClusterId %d \n \
\t+ RemoteEndpointId %d \n \
\t+ NodeId %d",
(int) entry.fabricIndex, (int) entry.local, (int) entry.clusterId.Value(), (int) entry.remote,
(int) entry.fabricIndex, (int) entry.local, (int) entry.clusterId.value_or(-1), (int) entry.remote,
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
(int) entry.nodeId);
break;
case MATTER_MULTICAST_BINDING:
Expand Down
4 changes: 2 additions & 2 deletions examples/light-switch-app/esp32/main/BindingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ CHIP_ERROR BindingGroupBindCommandHandler(int argc, char ** argv)
entry->fabricIndex = atoi(argv[0]);
entry->groupId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->clusterId.SetValue(6); // Hardcoded to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcoded to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand All @@ -264,7 +264,7 @@ CHIP_ERROR BindingUnicastBindCommandHandler(int argc, char ** argv)
entry->nodeId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->remote = atoi(argv[2]);
entry->clusterId.SetValue(6); // Hardcode to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcode to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions examples/light-switch-app/genio/src/BindingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ CHIP_ERROR BindingGroupBindCommandHandler(int argc, char ** argv)
entry->fabricIndex = atoi(argv[0]);
entry->groupId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->clusterId.SetValue(6); // Hardcoded to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcoded to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand All @@ -263,7 +263,7 @@ CHIP_ERROR BindingUnicastBindCommandHandler(int argc, char ** argv)
entry->nodeId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->remote = atoi(argv[2]);
entry->clusterId.SetValue(6); // Hardcode to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcode to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ CHIP_ERROR GroupBindCommandHandler(int argc, char ** argv)
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->fabricIndex = atoi(argv[0]);
entry->groupId = atoi(argv[1]);
entry->clusterId.SetValue(atoi(argv[3]));
entry->clusterId.emplace(atoi(argv[3]));

DeviceLayer::PlatformMgr().ScheduleWork(BindingHandler::BindingWorkerHandler, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand All @@ -384,7 +384,7 @@ CHIP_ERROR UnicastBindCommandHandler(int argc, char ** argv)
entry->fabricIndex = atoi(argv[0]);
entry->nodeId = atoi(argv[1]);
entry->remote = atoi(argv[2]);
entry->clusterId.SetValue(atoi(argv[3]));
entry->clusterId.emplace(atoi(argv[3]));

DeviceLayer::PlatformMgr().ScheduleWork(BindingHandler::BindingWorkerHandler, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void BindingHandler::PrintBindingTable()
\t+ ClusterId %d \n \
\t+ RemoteEndpointId %d \n \
\t+ NodeId %d \n",
(int) entry.fabricIndex, (int) entry.local, (int) entry.clusterId.Value(), (int) entry.remote,
(int) entry.fabricIndex, (int) entry.local, (int) entry.clusterId.value_or(-1), (int) entry.remote,
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
(int) entry.nodeId);
break;
case MATTER_MULTICAST_BINDING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void BindingHandler::PrintBindingTable()
\t+ ClusterId %d \n \
\t+ RemoteEndpointId %d \n \
\t+ NodeId %d",
(int) entry.fabricIndex, (int) entry.local, (int) entry.clusterId.Value(), (int) entry.remote,
(int) entry.fabricIndex, (int) entry.local, (int) entry.clusterId.value_or(-1), (int) entry.remote,
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
(int) entry.nodeId);
break;
case MATTER_MULTICAST_BINDING:
Expand Down
4 changes: 2 additions & 2 deletions examples/light-switch-app/silabs/src/ShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ CHIP_ERROR BindingGroupBindCommandHandler(int argc, char ** argv)
entry->fabricIndex = atoi(argv[0]);
entry->groupId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->clusterId.SetValue(6); // Hardcoded to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcoded to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand All @@ -159,7 +159,7 @@ CHIP_ERROR BindingUnicastBindCommandHandler(int argc, char ** argv)
entry->nodeId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->remote = atoi(argv[2]);
entry->clusterId.SetValue(6); // Hardcode to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcode to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions examples/light-switch-app/telink/src/binding-handler.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ CHIP_ERROR BindingGroupBindCommandHandler(int argc, char ** argv)
entry->fabricIndex = atoi(argv[0]);
entry->groupId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->clusterId.SetValue(6); // Hardcoded to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcoded to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand All @@ -259,7 +259,7 @@ CHIP_ERROR BindingUnicastBindCommandHandler(int argc, char ** argv)
entry->nodeId = atoi(argv[1]);
entry->local = 1; // Hardcoded to endpoint 1 for now
entry->remote = atoi(argv[2]);
entry->clusterId.SetValue(6); // Hardcode to OnOff cluster for now
entry->clusterId.emplace(6); // Hardcode to OnOff cluster for now

DeviceLayer::PlatformMgr().ScheduleWork(BindingWorkerFunction, reinterpret_cast<intptr_t>(entry));
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion examples/tv-casting-app/linux/CastingShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void PrintBindings()
"Binding type=%d fab=%d nodeId=0x" ChipLogFormatX64
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local,
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0)));
binding.remote, ChipLogValueMEI(binding.clusterId.value_or(0)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/tv-casting-app/linux/simple-app-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void PrintBindings()
"Binding type=%d fab=%d nodeId=0x" ChipLogFormatX64
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local,
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0)));
binding.remote, ChipLogValueMEI(binding.clusterId.value_or(0)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void CastingServer::ReadServerClustersForNode(NodeId nodeId)
"Binding type=%d fab=%d nodeId=0x" ChipLogFormatX64
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local,
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0)));
binding.remote, ChipLogValueMEI(binding.clusterId.value_or(0)));
if (binding.type == MATTER_UNICAST_BINDING && nodeId == binding.nodeId)
{
if (!mActiveTargetVideoPlayerInfo.HasEndpoint(binding.remote))
Expand Down Expand Up @@ -584,7 +584,7 @@ void CastingServer::DeviceEventCallback(const DeviceLayer::ChipDeviceEvent * eve
"CastingServer::DeviceEventCallback Read cached binding type=%d fabrixIndex=%d nodeId=0x" ChipLogFormatX64
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local,
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0)));
binding.remote, ChipLogValueMEI(binding.clusterId.value_or(0)));
if (binding.type == MATTER_UNICAST_BINDING && event->BindingsChanged.fabricIndex == binding.fabricIndex)
{
ChipLogProgress(
Expand Down Expand Up @@ -675,7 +675,7 @@ NodeId CastingServer::GetVideoPlayerNodeForFabricIndex(FabricIndex fabricIndex)
"Binding type=%d fab=%d nodeId=0x" ChipLogFormatX64
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local,
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0)));
binding.remote, ChipLogValueMEI(binding.clusterId.value_or(0)));
if (binding.type == MATTER_UNICAST_BINDING && fabricIndex == binding.fabricIndex)
{
ChipLogProgress(NotSpecified, "GetVideoPlayerNodeForFabricIndex nodeId=0x" ChipLogFormatX64,
Expand All @@ -701,7 +701,7 @@ FabricIndex CastingServer::GetVideoPlayerFabricIndexForNode(NodeId nodeId)
"Binding type=%d fab=%d nodeId=0x" ChipLogFormatX64
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local,
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0)));
binding.remote, ChipLogValueMEI(binding.clusterId.value_or(0)));
if (binding.type == MATTER_UNICAST_BINDING && nodeId == binding.nodeId)
{
ChipLogProgress(NotSpecified, "GetVideoPlayerFabricIndexForNode fabricIndex=%d nodeId=0x" ChipLogFormatX64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void ChipDeviceEventHandler::HandleBindingsChangedViaCluster(const chip::DeviceL
"nodeId=0x" ChipLogFormatX64
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local,
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0)));
binding.remote, ChipLogValueMEI(binding.clusterId.value_or(0)));
if (binding.type == MATTER_UNICAST_BINDING && event->BindingsChanged.fabricIndex == binding.fabricIndex)
{
ChipLogProgress(AppServer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ CHIP_ERROR EndpointListLoader::Load()
"Binding type=%d fab=%d nodeId=0x" ChipLogFormatX64
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local,
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0)));
binding.remote, ChipLogValueMEI(binding.clusterId.value_or(0)));
if (binding.type == MATTER_UNICAST_BINDING && CastingPlayer::GetTargetCastingPlayer()->GetNodeId() == binding.nodeId)
{
// if we discovered a new Endpoint from the bindings, read its EndpointAttributes
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/bindings/BindingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ CHIP_ERROR BindingManager::NotifyBoundClusterChanged(EndpointId endpoint, Cluste

for (auto iter = BindingTable::GetInstance().begin(); iter != BindingTable::GetInstance().end(); ++iter)
{
if (iter->local == endpoint && (!iter->clusterId.HasValue() || iter->clusterId.Value() == cluster))
if (iter->local == endpoint && (iter->clusterId.value_or(cluster) == cluster))
{
if (iter->type == MATTER_UNICAST_BINDING)
{
Expand Down
9 changes: 5 additions & 4 deletions src/app/clusters/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ CHIP_ERROR CreateBindingEntry(const TargetStructType & entry, EndpointId localEn

if (entry.group.HasValue())
{
bindingEntry = EmberBindingTableEntry::ForGroup(entry.fabricIndex, entry.group.Value(), localEndpoint, entry.cluster);
bindingEntry =
EmberBindingTableEntry::ForGroup(entry.fabricIndex, entry.group.Value(), localEndpoint, entry.cluster.std_optional());
}
else
{
bindingEntry = EmberBindingTableEntry::ForNode(entry.fabricIndex, entry.node.Value(), localEndpoint, entry.endpoint.Value(),
entry.cluster);
entry.cluster.std_optional());
}

return AddBindingEntry(bindingEntry);
Expand Down Expand Up @@ -159,7 +160,7 @@ CHIP_ERROR BindingTableAccess::ReadBindingTable(EndpointId endpoint, AttributeVa
.node = MakeOptional(entry.nodeId),
.group = NullOptional,
.endpoint = MakeOptional(entry.remote),
.cluster = entry.clusterId,
.cluster = FromStdOptional(entry.clusterId),
.fabricIndex = entry.fabricIndex,
};
ReturnErrorOnFailure(subEncoder.Encode(value));
Expand All @@ -170,7 +171,7 @@ CHIP_ERROR BindingTableAccess::ReadBindingTable(EndpointId endpoint, AttributeVa
.node = NullOptional,
.group = MakeOptional(entry.groupId),
.endpoint = NullOptional,
.cluster = entry.clusterId,
.cluster = FromStdOptional(entry.clusterId),
.fabricIndex = entry.fabricIndex,
};
ReturnErrorOnFailure(subEncoder.Encode(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct GroupTableCodec
TLV::TLVType inner;
ReturnErrorOnFailure(writer.StartContainer(TagEndpoints(), TLV::kTLVType_Array, inner));
GroupDataProvider::GroupEndpoint mapping;
auto iter = mProvider->IterateEndpoints(mFabric, MakeOptional(mInfo.group_id));
auto iter = mProvider->IterateEndpoints(mFabric, std::make_optional(mInfo.group_id));
if (nullptr != iter)
{
while (iter->Next(mapping))
Expand Down
Loading
Loading