Skip to content

Commit

Permalink
Add a BDX transfer server to handle unsolicited BDX init messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
harimau-qirex committed Sep 7, 2024
1 parent 6ba0d13 commit 3715977
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/controller/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 37 additions & 0 deletions src/controller/python/chip/bdx/bdx-transfer-pool.h
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions src/controller/python/chip/bdx/bdx-transfer-server.cpp
Original file line number Diff line number Diff line change
@@ -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 <controller/python/chip/bdx/bdx-transfer-server.h>

#include <messaging/ExchangeDelegate.h>
#include <transport/raw/MessageHeader.h>

#include <controller/python/chip/bdx/bdx-transfer-pool.h>

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
42 changes: 42 additions & 0 deletions src/controller/python/chip/bdx/bdx-transfer-server.h
Original file line number Diff line number Diff line change
@@ -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 <messaging/ExchangeDelegate.h>
#include <transport/raw/MessageHeader.h>

#include <controller/python/chip/bdx/bdx-transfer-pool.h>

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

0 comments on commit 3715977

Please sign in to comment.