Skip to content

Commit e2ea7d7

Browse files
authored
Remove weak-linkage usage for matter callbacks for pre/post attribute read/write and command invocation (project-chip#32673)
* Move placeholder commands to use actual callback classes * Remove the weak redirects ... they don't seem used
1 parent cbdba88 commit e2ea7d7

File tree

4 files changed

+42
-107
lines changed

4 files changed

+42
-107
lines changed

examples/placeholder/linux/include/MatterCallbacks.h

-40
This file was deleted.

examples/placeholder/linux/main.cpp

+39-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,44 @@
1818

1919
#include "AppMain.h"
2020
#include "AppOptions.h"
21-
#include "MatterCallbacks.h"
21+
#include "InteractiveServer.h"
22+
23+
#include <app/util/MatterCallbacks.h>
24+
25+
namespace {
26+
class InteractiveServerRedirectCallbacks : public chip::DataModelCallbacks
27+
{
28+
public:
29+
void AttributeOperation(OperationType operation, OperationOrder order, const chip::app::ConcreteAttributePath & path) override
30+
{
31+
if (order != OperationOrder::Post)
32+
{
33+
return;
34+
}
35+
36+
// TODO: is there any value in checking the return of read/write attributes?
37+
// they seem to only return true/false based on isRead (i.e. commissioning complete)
38+
switch (operation)
39+
{
40+
case OperationType::Read:
41+
(void) InteractiveServer::GetInstance().ReadAttribute(path);
42+
break;
43+
case OperationType::Write:
44+
(void) InteractiveServer::GetInstance().WriteAttribute(path);
45+
break;
46+
}
47+
}
48+
49+
void PostCommandReceived(const chip::app::ConcreteCommandPath & commandPath,
50+
const chip::Access::SubjectDescriptor & subjectDescriptor) override
51+
{
52+
(void) InteractiveServer::GetInstance().Command(commandPath);
53+
}
54+
};
55+
56+
InteractiveServerRedirectCallbacks gDmCallbacks;
57+
58+
} // namespace
2259

2360
void ApplicationInit() {}
2461

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

76+
chip::DataModelCallbacks::SetInstance(&gDmCallbacks);
3977
ChipLinuxAppMainLoop();
4078

4179
return 0;

src/app/CommandHandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ Status CommandHandler::ProcessGroupCommandDataIB(CommandDataIB::Parser & aComman
564564
else
565565
{
566566
ChipLogError(DataManagement,
567-
"Error when calling MatterPreCommandReceivedCallback for Endpoint=%u Cluster=" ChipLogFormatMEI
567+
"Error when calling PreCommandReceived for Endpoint=%u Cluster=" ChipLogFormatMEI
568568
" Command=" ChipLogFormatMEI " : %" CHIP_ERROR_FORMAT,
569569
mapping.endpoint_id, ChipLogValueMEI(clusterId), ChipLogValueMEI(commandId), err.Format());
570570
continue;

src/app/util/MatterCallbacks.cpp

+2-65
Original file line numberDiff line numberDiff line change
@@ -15,74 +15,11 @@
1515
*/
1616
#include "MatterCallbacks.h"
1717

18-
// The defines below are using link-time callback and should be removed
19-
//
20-
// TODO: applications should be converted to use DataModelCallbacks instead
21-
// of relying on weak linkage
22-
void __attribute__((weak)) MatterPreAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) {}
23-
void __attribute__((weak)) MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) {}
24-
void __attribute__((weak)) MatterPreAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) {}
25-
void __attribute__((weak)) MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) {}
26-
CHIP_ERROR __attribute__((weak)) MatterPreCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath,
27-
const chip::Access::SubjectDescriptor & subjectDescriptor)
28-
{
29-
return CHIP_NO_ERROR;
30-
}
31-
void __attribute__((weak)) MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath,
32-
const chip::Access::SubjectDescriptor & subjectDescriptor)
33-
{}
34-
3518
namespace chip {
3619
namespace {
3720

38-
class WeakRedirectCallbacks : public DataModelCallbacks
39-
{
40-
public:
41-
void AttributeOperation(OperationType operation, OperationOrder order, const chip::app::ConcreteAttributePath & path) override
42-
{
43-
switch (operation)
44-
{
45-
case OperationType::Read:
46-
switch (order)
47-
{
48-
case OperationOrder::Pre:
49-
MatterPreAttributeReadCallback(path);
50-
break;
51-
case OperationOrder::Post:
52-
MatterPostAttributeReadCallback(path);
53-
break;
54-
}
55-
break;
56-
case OperationType::Write:
57-
switch (order)
58-
{
59-
case OperationOrder::Pre:
60-
MatterPreAttributeWriteCallback(path);
61-
break;
62-
case OperationOrder::Post:
63-
MatterPostAttributeWriteCallback(path);
64-
break;
65-
}
66-
break;
67-
}
68-
}
69-
70-
CHIP_ERROR PreCommandReceived(const chip::app::ConcreteCommandPath & commandPath,
71-
const chip::Access::SubjectDescriptor & subjectDescriptor) override
72-
{
73-
return MatterPreCommandReceivedCallback(commandPath, subjectDescriptor);
74-
}
75-
76-
void PostCommandReceived(const chip::app::ConcreteCommandPath & commandPath,
77-
const chip::Access::SubjectDescriptor & subjectDescriptor) override
78-
{
79-
80-
MatterPostCommandReceivedCallback(commandPath, subjectDescriptor);
81-
}
82-
};
83-
84-
WeakRedirectCallbacks gWeakCallbacks;
85-
DataModelCallbacks * gInstance = &gWeakCallbacks;
21+
DataModelCallbacks gNoopCallbacks;
22+
DataModelCallbacks * gInstance = &gNoopCallbacks;
8623

8724
} // namespace
8825

0 commit comments

Comments
 (0)