diff --git a/src/controller/python/BUILD.gn b/src/controller/python/BUILD.gn index 5fa37bbe8a0d36..328e5e68b7dd66 100644 --- a/src/controller/python/BUILD.gn +++ b/src/controller/python/BUILD.gn @@ -64,6 +64,9 @@ shared_library("ChipDeviceCtrl") { "ChipDeviceController-StorageDelegate.h", "OpCredsBinding.cpp", "chip/bdx/bdx.cpp", + "chip/bdx/bdx-transfer-pool.h", + "chip/bdx/bdx-transfer-server.cpp", + "chip/bdx/bdx-transfer-server.h", "chip/clusters/attribute.cpp", "chip/clusters/command.cpp", "chip/commissioning/PlaceholderOperationalCredentialsIssuer.h", diff --git a/src/controller/python/chip/bdx/bdx-transfer-pool.h b/src/controller/python/chip/bdx/bdx-transfer-pool.h new file mode 100644 index 00000000000000..82ad573572557e --- /dev/null +++ b/src/controller/python/chip/bdx/bdx-transfer-pool.h @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2024 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 bdx { + +// An interface to handle allocating and releasing BdxTransfer objects. +class BdxTransferPool +{ +public: + virtual ~BdxTransferPool() = default; + + // TODO: Change return type to BdxTransfer. + virtual void * Allocate(/* Details necessary to create a BdxTransfer */) = 0; + + // TODO: Change argument type to BdxTransfer. + virtual void Release(void * bdxTransfer) = 0; +}; + +} // namespace bdx +} // namespace chip diff --git a/src/controller/python/chip/bdx/bdx-transfer-server.cpp b/src/controller/python/chip/bdx/bdx-transfer-server.cpp new file mode 100644 index 00000000000000..d0152fb045093d --- /dev/null +++ b/src/controller/python/chip/bdx/bdx-transfer-server.cpp @@ -0,0 +1,53 @@ +/* + * + * Copyright (c) 2024 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 + +#include +#include + +#include + +namespace chip { +namespace bdx { + +BdxTransferServer::BdxTransferServer(BdxTransferPool * bdxTransferPool) : mBdxTransferPool(bdxTransferPool) +{ + // TODO: Verify that bdxTransferPool is non-null? +} + +CHIP_ERROR BdxTransferServer::OnUnsolicitedMessageReceived(const PayloadHeader& payloadHeader, + Messaging::ExchangeDelegate *& delegate) +{ + // TODO: Verify details from the payload header. + void * transfer = mBdxTransferPool->Allocate(); + if (!transfer) + { + return CHIP_ERROR_NO_MEMORY; + } + + delegate = transfer; + return CHIP_NO_ERROR; +} + +void BdxTransferServer::OnExchangeCreationFailed(Messaging::ExchangeDelegate * delegate) +{ + mBdxTransferPool->Release(delegate); +} + +} // namespace bdx +} // namespace chip diff --git a/src/controller/python/chip/bdx/bdx-transfer-server.h b/src/controller/python/chip/bdx/bdx-transfer-server.h new file mode 100644 index 00000000000000..4aca6ffa34621f --- /dev/null +++ b/src/controller/python/chip/bdx/bdx-transfer-server.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2024 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 +#include + +#include + +namespace chip { +namespace bdx { + +// This class handles incoming BDX init messages to start BDX transfers. It allocates BdxTransfer objects from a pool. +class BdxTransferServer : public Messaging::UnsolicitedMessageHandler +{ +public: + BdxTransferServer(BdxTransferPool * bdxTransferPool); + + CHIP_ERROR OnUnsolicitedMessageReceived(const PayloadHeader& payloadHeader, Messaging::ExchangeDelegate *& delegate) override; + void OnExchangeCreationFailed(Messaging::ExchangeDelegate * delegate) override; + +private: + BdxTransferPool * mBdxTransferPool; +}; + +} // namespace bdx +} // namespace chip \ No newline at end of file