Skip to content

Commit

Permalink
Remove weak-linkage usage for matter callbacks for pre/post attribute…
Browse files Browse the repository at this point in the history
… read/write and command invocation (#32673)

* Move placeholder commands to use actual callback classes

* Remove the weak redirects ... they don't seem used
  • Loading branch information
andy31415 authored and pull[bot] committed Apr 8, 2024
1 parent f1d1270 commit 403f837
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 107 deletions.
40 changes: 0 additions & 40 deletions examples/placeholder/linux/include/MatterCallbacks.h

This file was deleted.

40 changes: 39 additions & 1 deletion examples/placeholder/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,44 @@

#include "AppMain.h"
#include "AppOptions.h"
#include "MatterCallbacks.h"
#include "InteractiveServer.h"

#include <app/util/MatterCallbacks.h>

namespace {
class InteractiveServerRedirectCallbacks : public chip::DataModelCallbacks
{
public:
void AttributeOperation(OperationType operation, OperationOrder order, const chip::app::ConcreteAttributePath & path) override
{
if (order != OperationOrder::Post)
{
return;
}

// TODO: is there any value in checking the return of read/write attributes?
// they seem to only return true/false based on isRead (i.e. commissioning complete)
switch (operation)
{
case OperationType::Read:
(void) InteractiveServer::GetInstance().ReadAttribute(path);
break;
case OperationType::Write:
(void) InteractiveServer::GetInstance().WriteAttribute(path);
break;
}
}

void PostCommandReceived(const chip::app::ConcreteCommandPath & commandPath,
const chip::Access::SubjectDescriptor & subjectDescriptor) override
{
(void) InteractiveServer::GetInstance().Command(commandPath);
}
};

InteractiveServerRedirectCallbacks gDmCallbacks;

} // namespace

void ApplicationInit() {}

Expand All @@ -36,6 +73,7 @@ int main(int argc, char * argv[])
server.Run(AppOptions::GetInteractiveModePort());
}

chip::DataModelCallbacks::SetInstance(&gDmCallbacks);
ChipLinuxAppMainLoop();

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ Status CommandHandler::ProcessGroupCommandDataIB(CommandDataIB::Parser & aComman
else
{
ChipLogError(DataManagement,
"Error when calling MatterPreCommandReceivedCallback for Endpoint=%u Cluster=" ChipLogFormatMEI
"Error when calling PreCommandReceived for Endpoint=%u Cluster=" ChipLogFormatMEI
" Command=" ChipLogFormatMEI " : %" CHIP_ERROR_FORMAT,
mapping.endpoint_id, ChipLogValueMEI(clusterId), ChipLogValueMEI(commandId), err.Format());
continue;
Expand Down
67 changes: 2 additions & 65 deletions src/app/util/MatterCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,74 +15,11 @@
*/
#include "MatterCallbacks.h"

// The defines below are using link-time callback and should be removed
//
// TODO: applications should be converted to use DataModelCallbacks instead
// of relying on weak linkage
void __attribute__((weak)) MatterPreAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) {}
void __attribute__((weak)) MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) {}
void __attribute__((weak)) MatterPreAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) {}
void __attribute__((weak)) MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) {}
CHIP_ERROR __attribute__((weak)) MatterPreCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath,
const chip::Access::SubjectDescriptor & subjectDescriptor)
{
return CHIP_NO_ERROR;
}
void __attribute__((weak)) MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath,
const chip::Access::SubjectDescriptor & subjectDescriptor)
{}

namespace chip {
namespace {

class WeakRedirectCallbacks : public DataModelCallbacks
{
public:
void AttributeOperation(OperationType operation, OperationOrder order, const chip::app::ConcreteAttributePath & path) override
{
switch (operation)
{
case OperationType::Read:
switch (order)
{
case OperationOrder::Pre:
MatterPreAttributeReadCallback(path);
break;
case OperationOrder::Post:
MatterPostAttributeReadCallback(path);
break;
}
break;
case OperationType::Write:
switch (order)
{
case OperationOrder::Pre:
MatterPreAttributeWriteCallback(path);
break;
case OperationOrder::Post:
MatterPostAttributeWriteCallback(path);
break;
}
break;
}
}

CHIP_ERROR PreCommandReceived(const chip::app::ConcreteCommandPath & commandPath,
const chip::Access::SubjectDescriptor & subjectDescriptor) override
{
return MatterPreCommandReceivedCallback(commandPath, subjectDescriptor);
}

void PostCommandReceived(const chip::app::ConcreteCommandPath & commandPath,
const chip::Access::SubjectDescriptor & subjectDescriptor) override
{

MatterPostCommandReceivedCallback(commandPath, subjectDescriptor);
}
};

WeakRedirectCallbacks gWeakCallbacks;
DataModelCallbacks * gInstance = &gWeakCallbacks;
DataModelCallbacks gNoopCallbacks;
DataModelCallbacks * gInstance = &gNoopCallbacks;

} // namespace

Expand Down

0 comments on commit 403f837

Please sign in to comment.