Skip to content

Commit

Permalink
Update content app
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarkov committed Jul 11, 2024
1 parent 473c3ab commit d7747b0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
11 changes: 10 additions & 1 deletion src/app/app-platform/ContentApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ Status ContentApp::HandleWriteAttribute(ClusterId clusterId, AttributeId attribu
return Status::Failure;
}

void ContentApp::AddClientNode(NodeId subjectNodeId)
bool ContentApp::AddClientNode(NodeId subjectNodeId)
{
for (int i = 0; i < kMaxClientNodes; ++i) {
if (mClientNodes[i] == subjectNodeId) {
// avoid storing duplicate nodes
return false;
}
}

mClientNodes[mNextClientNodeIndex++] = subjectNodeId;
if (mClientNodeCount < kMaxClientNodes)
{
Expand All @@ -76,6 +83,8 @@ void ContentApp::AddClientNode(NodeId subjectNodeId)
// if we exceed the max number, then overwrite the oldest entry
mNextClientNodeIndex = 0;
}

return true;
}

void ContentApp::SendAppObserverCommand(chip::Controller::DeviceCommissioner * commissioner, NodeId clientNodeId, char * data,
Expand Down
3 changes: 2 additions & 1 deletion src/app/app-platform/ContentApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ class DLL_EXPORT ContentApp
uint16_t maxReadLength);
Protocols::InteractionModel::Status HandleWriteAttribute(ClusterId clusterId, AttributeId attributeId, uint8_t * buffer);

void AddClientNode(NodeId clientNodeId);
// returns true only if new node is added
bool AddClientNode(NodeId clientNodeId);
uint8_t GetClientNodeCount() const { return mClientNodeCount; }
NodeId GetClientNode(uint8_t index) const { return mClientNodes[index]; }

Expand Down
31 changes: 17 additions & 14 deletions src/app/app-platform/ContentAppPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,26 +800,29 @@ CHIP_ERROR ContentAppPlatform::ManageClientAccess(Messaging::ExchangeManager & e
.cluster = NullOptional,
.fabricIndex = kUndefinedFabricIndex,
});

accessAllowed = true;
}
accessAllowed = true;
}
if (accessAllowed)
{
// notify content app about this nodeId
app->AddClientNode(subjectNodeId);
bool isNodeAdded = app->AddClientNode(subjectNodeId);

// handle login
auto setupPIN = std::to_string(passcode);
auto accountLoginDelegate = app->GetAccountLoginDelegate();
if (accountLoginDelegate != nullptr)
{
auto status = accountLoginDelegate->HandleLogin(rotatingId, { setupPIN.data(), setupPIN.size() },
MakeOptional(subjectNodeId));
ChipLogProgress(Controller, "AccountLogin::Login command sent and returned with status: %d", status);
}
else
{
ChipLogError(Controller, "AccountLoginDelegate not found for app");
if (isNodeAdded) {
// handle login
auto setupPIN = std::to_string(passcode);
auto accountLoginDelegate = app->GetAccountLoginDelegate();
if (accountLoginDelegate != nullptr)
{
auto status = accountLoginDelegate->HandleLogin(rotatingId, { setupPIN.data(), setupPIN.size() },
MakeOptional(subjectNodeId));
ChipLogProgress(Controller, "AccountLogin::Login command sent and returned with status: %d", status);
}
else
{
ChipLogError(Controller, "AccountLoginDelegate not found for app");
}
}
}
}
Expand Down

0 comments on commit d7747b0

Please sign in to comment.