Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency of InteractionModelEngine in CommandHandler #31830

Merged
merged 20 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/lighting-app/tizen/src/DBusInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <app/clusters/color-control-server/color-control-server.h>
#include <app/clusters/level-control/level-control.h>
#include <app/clusters/on-off-server/on-off-server.h>
#include <app/InteractionModelEngine.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/CHIPDeviceLayer.h>

Expand All @@ -44,6 +45,7 @@ class CommandHandlerCallback : public CommandHandler::Callback
void OnDone(CommandHandler & apCommandObj) {}
void DispatchCommand(CommandHandler & apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & apPayload) {}
Status CommandExists(const ConcreteCommandPath & aCommandPath) { return Status::Success; }
uint32_t GetInteractionModelEngineMagicNumber() const { return InteractionModelEngine::GetInstance()->GetInteractionModelEngineMagicNumber(); }
};

DBusInterface::DBusInterface(chip::EndpointId endpointId) : mEndpointId(endpointId)
Expand Down
6 changes: 3 additions & 3 deletions src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,14 +810,14 @@ CommandHandler * CommandHandler::Handle::Get()
// Not safe to work with CommandHandler in parallel with other Matter work.
assertChipStackLockedByCurrentThread();

return (mMagic == InteractionModelEngine::GetInstance()->GetMagicNumber()) ? mpHandler : nullptr;
return (mMagic == mpHandler->mpCallback->GetInteractionModelEngineMagicNumber()) ? mpHandler : nullptr;
}

void CommandHandler::Handle::Release()
{
if (mpHandler != nullptr)
{
if (mMagic == InteractionModelEngine::GetInstance()->GetMagicNumber())
if (mMagic == mpHandler->mpCallback->GetInteractionModelEngineMagicNumber())
{
mpHandler->DecrementHoldOff();
}
Expand All @@ -832,7 +832,7 @@ CommandHandler::Handle::Handle(CommandHandler * handle)
{
handle->IncrementHoldOff();
mpHandler = handle;
mMagic = InteractionModelEngine::GetInstance()->GetMagicNumber();
mMagic = mpHandler->mpCallback->GetInteractionModelEngineMagicNumber();
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/app/CommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class CommandHandler
* fails to exist.
*/
virtual Protocols::InteractionModel::Status CommandExists(const ConcreteCommandPath & aCommandPath) = 0;

/*
* Get the magic number of the InteractionModelEngine. A CommandHandler::Handle is valid iff
* its magic number is equals to the InteractionModelEngine's one.
*/
virtual uint32_t GetInteractionModelEngineMagicNumber() const = 0;
yyzhong-g marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down Expand Up @@ -143,7 +149,7 @@ class CommandHandler
}

/**
* Get the CommandHandler object it holds. Get() may return a nullptr if the CommandHandler object is holds is no longer
* Get the CommandHandler object it holds. Get() may return a nullptr if the CommandHandler object it holds is no longer
* valid.
*/
CommandHandler * Get();
Expand Down
5 changes: 3 additions & 2 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
WriteHandler * ActiveWriteHandlerAt(unsigned int aIndex);

/**
* The Magic number of this InteractionModelEngine, the magic number is set during Init()
* The Magic number of this InteractionModelEngine, the magic number is set during Init() and Shundown().
yyzhong-g marked this conversation as resolved.
Show resolved Hide resolved
* An CommandHandler::Handle is valid iff. its magic equals to this one.
*/
uint32_t GetMagicNumber() const { return mMagic; }
uint32_t GetInteractionModelEngineMagicNumber() const override { return mMagic; }

reporting::Engine & GetReportingEngine() { return mReportingEngine; }

Expand Down
2 changes: 2 additions & 0 deletions src/app/tests/TestCommandInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ class MockCommandHandlerCallback : public CommandHandler::Callback

void ResetCounter() { onFinalCalledTimes = 0; }

uint32_t GetInteractionModelEngineMagicNumber() const { return chip::app::InteractionModelEngine::GetInstance()->GetInteractionModelEngineMagicNumber(); }

int onFinalCalledTimes = 0;
} mockCommandHandlerDelegate;

Expand Down
Loading