From 2215c63d157f5c6b79933dd7a6f6557975ac9652 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Mon, 18 Jan 2021 16:29:52 +0100 Subject: [PATCH] Update EMBER_AF_PLUGIN_REPORTING to EMBER_AF_PLUGIN_REPORTING_SERVER in InitDataModelHandler #### Problem The stack status callbacks should be called for the server side, not for the client. This PR also contains some small changes to the `HandleDataModelMessage` signature as one of the argument is unused, and the other is only used to get the `NodeId`. --- src/app/server/DataModelHandler.cpp | 67 ++++++++++++----------------- src/app/server/DataModelHandler.h | 14 ++++-- src/app/server/Server.cpp | 2 +- 3 files changed, 39 insertions(+), 44 deletions(-) diff --git a/src/app/server/DataModelHandler.cpp b/src/app/server/DataModelHandler.cpp index 937d712809b708..9aa97327d58f93 100644 --- a/src/app/server/DataModelHandler.cpp +++ b/src/app/server/DataModelHandler.cpp @@ -22,15 +22,11 @@ #include -#include -#include #include #include -#include #include -#include -#ifdef EMBER_AF_PLUGIN_REPORTING +#ifdef EMBER_AF_PLUGIN_REPORTING_SERVER void emberAfPluginReportingStackStatusCallback(EmberStatus status); #endif #ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER @@ -42,24 +38,38 @@ void emberAfPluginIasZoneServerStackStatusCallback(EmberStatus status); using namespace ::chip; -/** - * Handle a message that should be processed via our data model processing - * codepath. This function will free the packet buffer. - * - * @param [in] buffer The buffer holding the message. This function guarantees - * that it will free the buffer before returning. - */ -void HandleDataModelMessage(const PacketHeader & header, System::PacketBufferHandle buffer, SecureSessionMgr * mgr) +void InitDataModelHandler() +{ + emberAfEndpointConfigure(); + emberAfInit(); + +#if defined(EMBER_AF_PLUGIN_REPORTING_SERVER) || defined(EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER) || \ + defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER) + EmberStatus status = EMBER_NETWORK_UP; +#endif + +#ifdef EMBER_AF_PLUGIN_REPORTING_SERVER + emberAfPluginReportingStackStatusCallback(status); +#endif +#ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER + emberAfPluginTemperatureMeasurementServerStackStatusCallback(status); +#endif +#ifdef EMBER_AF_PLUGIN_IAS_ZONE_SERVER + emberAfPluginIasZoneServerStackStatusCallback(status); +#endif +} + +void HandleDataModelMessage(NodeId nodeId, System::PacketBufferHandle buffer) { EmberApsFrame frame; bool ok = extractApsFrame(buffer->Start(), buffer->DataLength(), &frame) > 0; if (ok) { - ChipLogProgress(Zcl, "APS frame processing success!"); + ChipLogDetail(Zcl, "APS frame processing success!"); } else { - ChipLogProgress(Zcl, "APS frame processing failure!"); + ChipLogDetail(Zcl, "APS frame processing failure!"); return; } @@ -68,36 +78,15 @@ void HandleDataModelMessage(const PacketHeader & header, System::PacketBufferHan ok = emberAfProcessMessage(&frame, 0, // type message, messageLen, - header.GetSourceNodeId().Value(), // source identifier + nodeId, // source identifier NULL); if (ok) { - ChipLogProgress(Zcl, "Data model processing success!"); + ChipLogDetail(Zcl, "Data model processing success!"); } else { - ChipLogProgress(Zcl, "Data model processing failure!"); + ChipLogDetail(Zcl, "Data model processing failure!"); } } - -void InitDataModelHandler() -{ - emberAfEndpointConfigure(); - emberAfInit(); - -#if defined(EMBER_AF_PLUGIN_REPORTING) || defined(EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER) || \ - defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER) - EmberStatus status = EMBER_NETWORK_UP; -#endif - -#ifdef EMBER_AF_PLUGIN_REPORTING - emberAfPluginReportingStackStatusCallback(status); -#endif -#ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER - emberAfPluginTemperatureMeasurementServerStackStatusCallback(status); -#endif -#ifdef EMBER_AF_PLUGIN_IAS_ZONE_SERVER - emberAfPluginIasZoneServerStackStatusCallback(status); -#endif -} diff --git a/src/app/server/DataModelHandler.h b/src/app/server/DataModelHandler.h index 39854b8d55606f..b6085e80ab45c5 100644 --- a/src/app/server/DataModelHandler.h +++ b/src/app/server/DataModelHandler.h @@ -23,16 +23,22 @@ #pragma once #include -#include #include +/** + * Initialize the data model internal code to be ready to send and receive + * data model messages. + * + */ +void InitDataModelHandler(); + /** * Handle a message that should be processed via our data model processing * codepath. * + * @param [in] nodeId The source node id of the message * @param [in] buffer The buffer holding the message. This function guarantees * that it will free the buffer before returning. + * */ -void HandleDataModelMessage(const chip::PacketHeader & header, chip::System::PacketBufferHandle buffer, - chip::SecureSessionMgr * mgr); -void InitDataModelHandler(); +void HandleDataModelMessage(chip::NodeId nodeId, chip::System::PacketBufferHandle buffer); diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 17df8c2a66bfef..c5aa4490c18961 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -81,7 +81,7 @@ class ServerCallback : public SecureSessionMgrDelegate ChipLogProgress(AppServer, "Packet received from %s: %zu bytes", src_addr, static_cast(data_len)); - HandleDataModelMessage(header, std::move(buffer), mgr); + HandleDataModelMessage(header.GetSourceNodeId().Value(), std::move(buffer)); exit:; }