Skip to content

Commit

Permalink
More build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjerryjohns committed Jul 26, 2022
1 parent 56414ef commit ee1775a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
23 changes: 4 additions & 19 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,11 @@ void InteractionModelEngine::Shutdown()
mReadHandlers.ReleaseAll();

//
// We hold weak references to ReadClient objects. The application ultimately
// actually owns them, so it's on them to eventually shut them down and free them
// up.
// Applications should be terminating their ReadClient instances first BEFORE shutting
// down the IM engine. Otherwise, the ReadClient is going to call into the engine for
// services and crash in other wierd ways.
//
// However, we should null out their pointers back to us at the very least so that
// at destruction time, they won't attempt to reach back here to remove themselves
// from this list.
//
for (auto * readClient = mpActiveReadClientList; readClient != nullptr;)
{
readClient->mpImEngine = nullptr;
auto * tmpClient = readClient->GetNextClient();
readClient->SetNextClient(nullptr);
readClient = tmpClient;
}

//
// After that, we just null out our tracker.
//
mpActiveReadClientList = nullptr;
VerifyOrDie(mpActiveReadClientList == nullptr);

for (auto & writeHandler : mWriteHandlers)
{
Expand Down
19 changes: 8 additions & 11 deletions src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,10 @@ void TestReadInteraction::TestReadShutdown(nlTestSuite * apSuite, void * apConte
app::ReadClient * pClients[4];
TestContext & ctx = *static_cast<TestContext *>(apContext);
MockInteractionModelApp delegate;
CHIP_ERROR err = CHIP_NO_ERROR;

err = engine->Init(&ctx.GetExchangeManager(), &ctx.GetFabricTable());
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

//
// Allocate a number of clients
Expand All @@ -2129,26 +2133,19 @@ void TestReadInteraction::TestReadShutdown(nlTestSuite * apSuite, void * apConte
chip::app::ReadClient::InteractionType::Subscribe);
}

//
// Delete every other client to ensure we test out
// deleting clients from the list of clients tracked by the IM
//
Platform::Delete(pClients[1]);
Platform::Delete(pClients[3]);
Platform::Delete(pClients[2]);
Platform::Delete(pClients[0]);

//
// Shutdown the engine first so that we can
// de-activate the internal list.
//
engine->Shutdown();

//
// Shutdown the read clients. These should
// safely destruct without causing any egregious
// harm
//
Platform::Delete(pClients[0]);
Platform::Delete(pClients[2]);
err = engine->Init(&ctx.GetExchangeManager(), &ctx.GetFabricTable());
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
}

void TestReadInteraction::TestSubscribeInvalidInterval(nlTestSuite * apSuite, void * apContext)
Expand Down
11 changes: 9 additions & 2 deletions src/controller/java/AndroidCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,22 +547,29 @@ void ReportEventCallback::OnSubscriptionEstablished(SubscriptionId aSubscription
JniReferences::GetInstance().CallSubscriptionEstablished(mSubscriptionEstablishedCallbackRef);
}

void ReportEventCallback::OnResubscriptionAttempt(CHIP_ERROR aTerminationCause, uint32_t aNextResubscribeIntervalMsec)
void ReportEventCallback::OnResubscriptionAttempt(ReadClient * apReadClient, CHIP_ERROR aTerminationCause)
{
VerifyOrReturn(mResubscriptionAttemptCallbackRef != nullptr,
ChipLogError(Controller, "mResubscriptionAttemptCallbackRef is null"));

CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();

err = app::ReadClient::Callback::OnResubscriptionNeeded(apReadClient, aTerminationCause);
if (err != CHIP_NO_ERROR)
{
ReportError(nullptr, ErrorStr(err), err.AsInteger());
return;
}

jmethodID onResubscriptionAttemptMethod;
err = JniReferences::GetInstance().FindMethod(env, mResubscriptionAttemptCallbackRef, "onResubscriptionAttempt", "(II)V",
&onResubscriptionAttemptMethod);
VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onResubscriptionAttempt method"));

DeviceLayer::StackUnlock unlock;
env->CallVoidMethod(mResubscriptionAttemptCallbackRef, onResubscriptionAttemptMethod, aTerminationCause.AsInteger(),
aNextResubscribeIntervalMsec);
apReadClient->ComputeTimeTillNextSubscription());
}

void ReportEventCallback::ReportError(jobject attributePath, CHIP_ERROR err)
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/AndroidCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct ReportEventCallback : public app::ReadClient::Callback

void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override;

void OnResubscriptionAttempt(CHIP_ERROR aTerminationCause, uint32_t aNextResubscribeIntervalMsec) override;
void OnResubscriptionAttempt(ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override;

/** Report errors back to Java layer. attributePath may be nullptr for general errors. */
void ReportError(jobject eventPath, CHIP_ERROR err);
Expand Down

0 comments on commit ee1775a

Please sign in to comment.