From 7257d44b19fa1fd34f67a4271a0279393ff7d713 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Tue, 27 Oct 2020 17:47:38 +0100 Subject: [PATCH] Use DataModelHandler from examples/common/chip-app-server in ESP32 wifi-echo demo app instead of its own copy (#3468) --- .../esp32/main/DataModelHandler.cpp | 79 ------------------ .../esp32/main/component.mk | 4 +- .../esp32/main/include/DataModelHandler.h | 54 ------------- .../server/esp32/main/DataModelHandler.cpp | 80 ------------------- .../wifi-echo/server/esp32/main/component.mk | 4 +- .../esp32/main/include/DataModelHandler.h | 51 ------------ 6 files changed, 6 insertions(+), 266 deletions(-) delete mode 100644 examples/temperature-measurement-app/esp32/main/DataModelHandler.cpp delete mode 100644 examples/temperature-measurement-app/esp32/main/include/DataModelHandler.h delete mode 100644 examples/wifi-echo/server/esp32/main/DataModelHandler.cpp delete mode 100644 examples/wifi-echo/server/esp32/main/include/DataModelHandler.h diff --git a/examples/temperature-measurement-app/esp32/main/DataModelHandler.cpp b/examples/temperature-measurement-app/esp32/main/DataModelHandler.cpp deleted file mode 100644 index f41d9f24241454..00000000000000 --- a/examples/temperature-measurement-app/esp32/main/DataModelHandler.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file implements the handler for data model messages. - */ - -#include "esp_log.h" -#include -#include - -#include "DataModelHandler.h" - -#include "attribute-storage.h" -#include "gen/attribute-id.h" -#include "gen/cluster-id.h" -#include "gen/znet-bookkeeping.h" -#include "util.h" -#include - -using namespace ::chip; - -static const char * TAG = "data_model_server"; - -void InitDataModelHandler() -{ - emberAfEndpointConfigure(); - emAfInit(); -} - -void HandleDataModelMessage(const PacketHeader & header, System::PacketBuffer * buffer, SecureSessionMgrBase * mgr) -{ - EmberApsFrame frame; - bool ok = extractApsFrame(buffer->Start(), buffer->DataLength(), &frame) > 0; - if (ok) - { - ESP_LOGI(TAG, "APS frame processing success!"); - } - else - { - ESP_LOGI(TAG, "APS frame processing failure"); - System::PacketBuffer::Free(buffer); - return; - } - - uint8_t * message; - uint16_t messageLen = extractMessage(buffer->Start(), buffer->DataLength(), &message); - ok = emberAfProcessMessage(&frame, - 0, // type - message, messageLen, - header.GetSourceNodeId().Value(), // source identifier - nullptr); - - System::PacketBuffer::Free(buffer); - - if (ok) - { - ESP_LOGI(TAG, "Data model processing success!"); - } - else - { - ESP_LOGI(TAG, "Data model processing failure"); - } -} diff --git a/examples/temperature-measurement-app/esp32/main/component.mk b/examples/temperature-measurement-app/esp32/main/component.mk index c9bb5c1453910a..a1fa47a35339f0 100644 --- a/examples/temperature-measurement-app/esp32/main/component.mk +++ b/examples/temperature-measurement-app/esp32/main/component.mk @@ -24,12 +24,14 @@ COMPONENT_DEPENDS := chip QRCode tft spidriver COMPONENT_SRCDIRS := \ . \ gen \ + ../third_party/connectedhomeip/examples/common/chip-app-server \ ../third_party/connectedhomeip/src/app/util \ ../third_party/connectedhomeip/src/app/clusters/basic \ ../third_party/connectedhomeip/src/app/clusters/temperature-measurement-server \ -COMPONENT_EXTRA_INCLUDES := $(PROJECT_PATH)/third_party/connectedhomeip/src/app/util \ +COMPONENT_EXTRA_INCLUDES := $(PROJECT_PATH)/third_party/connectedhomeip/src/app/util \ + $(PROJECT_PATH)/third_party/connectedhomeip/examples/common/chip-app-server/include \ $(PROJECT_PATH)/third_party/connectedhomeip/src # So "gen/*" files are found by the src/app bits. diff --git a/examples/temperature-measurement-app/esp32/main/include/DataModelHandler.h b/examples/temperature-measurement-app/esp32/main/include/DataModelHandler.h deleted file mode 100644 index 455f1c89dd632c..00000000000000 --- a/examples/temperature-measurement-app/esp32/main/include/DataModelHandler.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file defines the API for the handler for data model messages. - */ - -#ifndef DATA_MODEL_HANDLER_H -#define DATA_MODEL_HANDLER_H - -namespace chip { -namespace System { -class PacketBuffer; -} // namespace System - -class SecureSessionMgrBase; -class MessageHeader; -} // namespace chip - -/** - * Initialize the data model handler. This must be called once, and before any - * HandleDataModelMessage calls happen. - */ -void InitDataModelHandler(); - -/** - * Handle a message that should be processed via our data model processing - * codepath. - * - * @param[in] header The message header for the incoming message. - * @param[in] buffer The buffer holding the message. This function guarantees - * that it will free the buffer before returning. - * @param[in] mgr The session manager to use for sending a response to the - * message. - */ -void HandleDataModelMessage(const chip::PacketHeader & header, chip::System::PacketBuffer * buffer, - chip::SecureSessionMgrBase * mgr); - -#endif // DATA_MODEL_HANDLER_H diff --git a/examples/wifi-echo/server/esp32/main/DataModelHandler.cpp b/examples/wifi-echo/server/esp32/main/DataModelHandler.cpp deleted file mode 100644 index fafdae23d3f78f..00000000000000 --- a/examples/wifi-echo/server/esp32/main/DataModelHandler.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file implements the handler for data model messages. - */ - -#include "esp_log.h" -#include -#include - -#include "DataModelHandler.h" -#include "LEDWidget.h" - -#include "attribute-storage.h" -#include "gen/attribute-id.h" -#include "gen/cluster-id.h" -#include "gen/znet-bookkeeping.h" -#include "util.h" -#include - -using namespace ::chip; - -static const char * TAG = "data_model_server"; - -void InitDataModelHandler() -{ - emberAfEndpointConfigure(); - emAfInit(); -} - -void HandleDataModelMessage(const PacketHeader & header, System::PacketBuffer * buffer, SecureSessionMgrBase * mgr) -{ - EmberApsFrame frame; - bool ok = extractApsFrame(buffer->Start(), buffer->DataLength(), &frame) > 0; - if (ok) - { - ESP_LOGI(TAG, "APS frame processing success!"); - } - else - { - ESP_LOGI(TAG, "APS frame processing failure"); - System::PacketBuffer::Free(buffer); - return; - } - - uint8_t * message; - uint16_t messageLen = extractMessage(buffer->Start(), buffer->DataLength(), &message); - ok = emberAfProcessMessage(&frame, - 0, // type - message, messageLen, - header.GetSourceNodeId().Value(), // source identifier - NULL); - - System::PacketBuffer::Free(buffer); - - if (ok) - { - ESP_LOGI(TAG, "Data model processing success!"); - } - else - { - ESP_LOGI(TAG, "Data model processing failure"); - } -} diff --git a/examples/wifi-echo/server/esp32/main/component.mk b/examples/wifi-echo/server/esp32/main/component.mk index 8eea98627c1229..331c2a78590d8f 100644 --- a/examples/wifi-echo/server/esp32/main/component.mk +++ b/examples/wifi-echo/server/esp32/main/component.mk @@ -24,6 +24,7 @@ COMPONENT_DEPENDS := chip QRCode tft spidriver COMPONENT_SRCDIRS := \ . \ gen \ + ../third_party/connectedhomeip/examples/common/chip-app-server \ ../third_party/connectedhomeip/src/app/util \ ../third_party/connectedhomeip/src/app/clusters/on-off-server \ ../third_party/connectedhomeip/src/app/clusters/level-control \ @@ -42,7 +43,8 @@ COMPONENT_SRCDIRS := # ../third_party/connectedhomeip/src/app/clusters/ias-zone-client \ -COMPONENT_EXTRA_INCLUDES := $(PROJECT_PATH)/third_party/connectedhomeip/src/app/util \ +COMPONENT_EXTRA_INCLUDES := $(PROJECT_PATH)/third_party/connectedhomeip/src/app/util \ + $(PROJECT_PATH)/third_party/connectedhomeip/examples/common/chip-app-server/include \ $(PROJECT_PATH)/third_party/connectedhomeip/src # So "gen/*" files are found by the src/app bits. diff --git a/examples/wifi-echo/server/esp32/main/include/DataModelHandler.h b/examples/wifi-echo/server/esp32/main/include/DataModelHandler.h deleted file mode 100644 index 07a6a107b7ce81..00000000000000 --- a/examples/wifi-echo/server/esp32/main/include/DataModelHandler.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file defines the API for the handler for data model messages. - */ - -#pragma once - -namespace chip { -namespace System { -class PacketBuffer; -} // namespace System - -class SecureSessionMgrBase; -class MessageHeader; -} // namespace chip - -/** - * Initialize the data model handler. This must be called once, and before any - * HandleDataModelMessage calls happen. - */ -void InitDataModelHandler(); - -/** - * Handle a message that should be processed via our data model processing - * codepath. - * - * @param[in] header The message header for the incoming message. - * @param[in] buffer The buffer holding the message. This function guarantees - * that it will free the buffer before returning. - * @param[in] mgr The session manager to use for sending a response to the - * message. - */ -void HandleDataModelMessage(const chip::PacketHeader & header, chip::System::PacketBuffer * buffer, - chip::SecureSessionMgrBase * mgr);