-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a BDX transfer server to handle unsolicited BDX init messages.
- Loading branch information
1 parent
6ba0d13
commit 3715977
Showing
4 changed files
with
135 additions
and
0 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
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 |
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,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 |
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,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 |