Skip to content

Commit

Permalink
see if tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
nivi-apple committed Oct 1, 2023
1 parent 0dddcdb commit 840223d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/darwin/Framework/CHIP/MTROTAImageTransferHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@
CHIP_ERROR error = CHIP_NO_ERROR;
if (event.EventType == TransferSession::OutputEventType::kTransferTimeout) {
error = CHIP_ERROR_TIMEOUT;
} else if (event.EventType != TransferSession::OutputEventType::kAckEOFReceived
|| event.EventType != TransferSession::OutputEventType::kAckEOFReceived) {
} else if (event.EventType != TransferSession::OutputEventType::kAckEOFReceived) {
error = CHIP_ERROR_INTERNAL;
}

Expand Down
8 changes: 8 additions & 0 deletions src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class MTROTAProviderDelegateBridge : public chip::app::Clusters::OTAProviderDele

CHIP_ERROR Init(chip::Messaging::ExchangeManager * exchangeMgr);

// Shutdown must be called after the event loop has been stopped, since it
// touches Matter objects.
void Shutdown();

// ControllerShuttingDown must be called on the Matter work queue, since it
// touches Matter objects.
void ControllerShuttingDown(MTRDeviceController * controller);

void HandleQueryImage(
chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImage::DecodableType & commandData) override;
Expand Down
39 changes: 31 additions & 8 deletions src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@
MTROTAProviderDelegateBridge::MTROTAProviderDelegateBridge()
{
Clusters::OTAProvider::SetDelegate(kOtaProviderEndpoint, this);

// The singleton unsolicited BDX message handler which will create
// the MTROTAImageTransferHandler object for handling each BDX session.
sOtaUnsolicitedBDXMsgHandler = new MTROTAUnsolicitedBDXMessageHandler();
}

MTROTAProviderDelegateBridge::~MTROTAProviderDelegateBridge()
{
Clusters::OTAProvider::SetDelegate(kOtaProviderEndpoint, nullptr);

delete sOtaUnsolicitedBDXMsgHandler;
sOtaUnsolicitedBDXMsgHandler = nullptr;
if (sOtaUnsolicitedBDXMsgHandler != nil)
{
delete sOtaUnsolicitedBDXMsgHandler;
sOtaUnsolicitedBDXMsgHandler = nil;
}
}

CHIP_ERROR MTROTAProviderDelegateBridge::Init(Messaging::ExchangeManager * exchangeMgr)
Expand All @@ -70,16 +69,40 @@

VerifyOrReturnError(exchangeMgr != nullptr, CHIP_ERROR_INCORRECT_STATE);

// Initialize the singleton MTROTAUnsolicitedBDXMessageHandler
VerifyOrReturnValue(sOtaUnsolicitedBDXMsgHandler != nil, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnValue(sOtaUnsolicitedBDXMsgHandler == nil, CHIP_ERROR_INCORRECT_STATE);

// The singleton unsolicited BDX message handler which will create
// the MTROTAImageTransferHandler object for handling each BDX session.
sOtaUnsolicitedBDXMsgHandler = new MTROTAUnsolicitedBDXMessageHandler();

// Initialize the singleton MTROTAUnsolicitedBDXMessageHandler
CHIP_ERROR err = sOtaUnsolicitedBDXMsgHandler->Init(exchangeMgr);
if (err != CHIP_NO_ERROR) {
ChipLogError(Controller, "Failed to initialize the unsolicited BDX Message handler with err %s", err.AsString());
}
return err;
}

void MTROTAProviderDelegateBridge::Shutdown()
{
assertChipStackLockedByCurrentThread();

if (sOtaUnsolicitedBDXMsgHandler != nullptr)
{
sOtaUnsolicitedBDXMsgHandler->Shutdown();
}
}

void MTROTAProviderDelegateBridge::ControllerShuttingDown(MTRDeviceController * controller)
{
assertChipStackLockedByCurrentThread();

if (sOtaUnsolicitedBDXMsgHandler != nullptr)
{
sOtaUnsolicitedBDXMsgHandler->ControllerShuttingDown(controller);
}
}

namespace {
// Return false if we could not get peer node info (a running controller for
// the fabric and a node id). In that case we will have already added an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class MTROTAUnsolicitedBDXMessageHandler : public chip::Messaging::UnsolicitedMe

CHIP_ERROR Init(chip::Messaging::ExchangeManager * exchangeManager);

// Shutdown must be called after the event loop has been stopped, since it
// touches Matter objects.
void Shutdown();

// ControllerShuttingDown must be called on the Matter work queue, since it
// touches Matter objects.
void ControllerShuttingDown(MTRDeviceController * controller);

// Returns the number of delegates that are currently handling BDX transfers
static uint8_t GetNumberOfDelegates();

Expand Down
35 changes: 29 additions & 6 deletions src/darwin/Framework/CHIP/MTROTAUnsolicitedBDXMessageHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@
MTROTAUnsolicitedBDXMessageHandler::~MTROTAUnsolicitedBDXMessageHandler()
{
assertChipStackLockedByCurrentThread();
mExchangeMgr = nullptr;

if (mExchangeMgr) {
mExchangeMgr->UnregisterUnsolicitedMessageHandlerForProtocol(Protocols::BDX::Id);
mExchangeMgr = nullptr;
}
MTROTAUnsolicitedBDXMessageHandler::mNumberOfDelegates = 0;
}

Expand All @@ -47,6 +44,26 @@
return mExchangeMgr->RegisterUnsolicitedMessageHandlerForProtocol(Protocols::BDX::Id, this);
}

void MTROTAUnsolicitedBDXMessageHandler::Shutdown()
{
assertChipStackLockedByCurrentThread();

if (mExchangeMgr) {
mExchangeMgr->UnregisterUnsolicitedMessageHandlerForProtocol(Protocols::BDX::Id);
}
MTROTAUnsolicitedBDXMessageHandler::mNumberOfDelegates = 0;
}

void MTROTAUnsolicitedBDXMessageHandler::ControllerShuttingDown(MTRDeviceController * controller)
{
assertChipStackLockedByCurrentThread();

if (mExchangeMgr) {
mExchangeMgr->UnregisterUnsolicitedMessageHandlerForProtocol(Protocols::BDX::Id);
}
MTROTAUnsolicitedBDXMessageHandler::mNumberOfDelegates = 0;
}

CHIP_ERROR MTROTAUnsolicitedBDXMessageHandler::OnUnsolicitedMessageReceived(
const PayloadHeader & payloadHeader, ExchangeDelegate * _Nonnull & newDelegate)
{
Expand All @@ -71,6 +88,12 @@
return MTROTAUnsolicitedBDXMessageHandler::mNumberOfDelegates;
}

void MTROTAUnsolicitedBDXMessageHandler::IncrementNumberOfDelegates() { MTROTAUnsolicitedBDXMessageHandler::mNumberOfDelegates++; }
void MTROTAUnsolicitedBDXMessageHandler::IncrementNumberOfDelegates()
{
MTROTAUnsolicitedBDXMessageHandler::mNumberOfDelegates++;
}

void MTROTAUnsolicitedBDXMessageHandler::DecrementNumberOfDelegates() { MTROTAUnsolicitedBDXMessageHandler::mNumberOfDelegates--; }
void MTROTAUnsolicitedBDXMessageHandler::DecrementNumberOfDelegates()
{
MTROTAUnsolicitedBDXMessageHandler::mNumberOfDelegates--;
}

0 comments on commit 840223d

Please sign in to comment.