diff --git a/examples/all-clusters-app/all-clusters-common/BUILD.gn b/examples/all-clusters-app/all-clusters-common/BUILD.gn index d6bbe53239f2d0..ced567e5c18f81 100644 --- a/examples/all-clusters-app/all-clusters-common/BUILD.gn +++ b/examples/all-clusters-app/all-clusters-common/BUILD.gn @@ -20,4 +20,5 @@ chip_data_model("all-clusters-common") { zap_file = "all-clusters-app.zap" zap_pregenerated_dir = "gen" + is_server = true } diff --git a/examples/bridge-app/bridge-common/BUILD.gn b/examples/bridge-app/bridge-common/BUILD.gn index 46b94ab8d49c7c..38c003a2a6b8f8 100644 --- a/examples/bridge-app/bridge-common/BUILD.gn +++ b/examples/bridge-app/bridge-common/BUILD.gn @@ -20,4 +20,5 @@ chip_data_model("bridge-common") { zap_file = "bridge-app.zap" zap_pregenerated_dir = "gen" + is_server = true } diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn index 8bd2c3ec412f36..494a23fdf7497d 100644 --- a/examples/chip-tool/BUILD.gn +++ b/examples/chip-tool/BUILD.gn @@ -44,7 +44,6 @@ executable("chip-tool") { deps = [ ":data_model", - "${chip_root}/src/app/server", "${chip_root}/src/lib", "${chip_root}/src/platform", "${chip_root}/third_party/inipp", diff --git a/examples/chip-tool/commands/common/Command.h b/examples/chip-tool/commands/common/Command.h index db847b9bd7d991..953ff7205da870 100644 --- a/examples/chip-tool/commands/common/Command.h +++ b/examples/chip-tool/commands/common/Command.h @@ -18,7 +18,6 @@ #pragma once -#include #include #include #include diff --git a/examples/chip-tool/commands/reporting/ReportingCommand.cpp b/examples/chip-tool/commands/reporting/ReportingCommand.cpp index 6f79239c0b3354..b19d99cec1dc38 100644 --- a/examples/chip-tool/commands/reporting/ReportingCommand.cpp +++ b/examples/chip-tool/commands/reporting/ReportingCommand.cpp @@ -48,8 +48,6 @@ CHIP_ERROR ReportingCommand::Run(PersistentStorage & storage, NodeId localId, No err = mCommissioner.GetDevice(remoteId, &mDevice); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(chipTool, "Init failure! No pairing for device: %" PRIu64, localId)); - mDevice->SetDelegate(this); - AddReportCallbacks(mEndPointId); cluster.Associate(mDevice, mEndPointId); @@ -64,14 +62,3 @@ CHIP_ERROR ReportingCommand::Run(PersistentStorage & storage, NodeId localId, No mCommissioner.Shutdown(); return err; } - -void ReportingCommand::OnMessage(PacketBufferHandle buffer) -{ - ChipLogDetail(chipTool, "%" PRIu64 ": Received %zu bytes", mDevice->GetDeviceId(), buffer->DataLength()); - HandleDataModelMessage(mDevice->GetDeviceId(), std::move(buffer)); -} - -void ReportingCommand::OnStatusChange(void) -{ - ChipLogDetail(chipTool, "DeviceStatusDelegate::OnStatusChange"); -} diff --git a/examples/chip-tool/commands/reporting/ReportingCommand.h b/examples/chip-tool/commands/reporting/ReportingCommand.h index caaa60543cafb1..bb86cbc466c4a9 100644 --- a/examples/chip-tool/commands/reporting/ReportingCommand.h +++ b/examples/chip-tool/commands/reporting/ReportingCommand.h @@ -25,7 +25,7 @@ #define CHIP_ZCL_ENDPOINT_MIN 0x00 #define CHIP_ZCL_ENDPOINT_MAX 0xF0 -class ReportingCommand : public Command, public chip::Controller::DeviceStatusDelegate +class ReportingCommand : public Command { public: ReportingCommand(const char * commandName) : Command(commandName) @@ -36,10 +36,6 @@ class ReportingCommand : public Command, public chip::Controller::DeviceStatusDe /////////// Command Interface ///////// CHIP_ERROR Run(PersistentStorage & storage, NodeId localId, NodeId remoteId) override; - /////////// DeviceStatusDelegate Interface ///////// - void OnMessage(PacketBufferHandle buffer) override; - void OnStatusChange(void) override; - virtual void AddReportCallbacks(uint8_t endPointId) = 0; private: diff --git a/examples/chip-tool/main.cpp b/examples/chip-tool/main.cpp index 164c8c77260d50..2730abf0ac777e 100644 --- a/examples/chip-tool/main.cpp +++ b/examples/chip-tool/main.cpp @@ -31,8 +31,6 @@ // ================================================================================ int main(int argc, char * argv[]) { - InitDataModelHandler(); - Commands commands; registerCommandsDiscover(commands); registerCommandsPayload(commands); diff --git a/examples/lighting-app/lighting-common/BUILD.gn b/examples/lighting-app/lighting-common/BUILD.gn index c44f5b9875e332..4346081585b73d 100644 --- a/examples/lighting-app/lighting-common/BUILD.gn +++ b/examples/lighting-app/lighting-common/BUILD.gn @@ -31,4 +31,5 @@ chip_data_model("lighting-common") { zap_file = "lighting-app.zap" zap_pregenerated_dir = "gen" + is_server = true } diff --git a/examples/lighting-app/nrfconnect/CMakeLists.txt b/examples/lighting-app/nrfconnect/CMakeLists.txt index e959b4a2dbfcc5..3c7bd6dac3288b 100644 --- a/examples/lighting-app/nrfconnect/CMakeLists.txt +++ b/examples/lighting-app/nrfconnect/CMakeLists.txt @@ -68,6 +68,12 @@ target_sources(app PRIVATE ${CHIP_ROOT}/src/app/util/process-cluster-message.cpp ${CHIP_ROOT}/src/app/util/process-global-message.cpp ${CHIP_ROOT}/src/app/util/util.cpp + ${CHIP_ROOT}/src/app/server/EchoHandler.cpp + ${CHIP_ROOT}/src/app/server/Mdns.cpp + ${CHIP_ROOT}/src/app/server/OnboardingCodesUtil.cpp + ${CHIP_ROOT}/src/app/server/RendezvousServer.cpp + ${CHIP_ROOT}/src/app/server/Server.cpp + ${CHIP_ROOT}/src/app/server/StorablePeerConnection.cpp ${CHIP_ROOT}/src/app/clusters/basic/basic.cpp ${CHIP_ROOT}/src/app/clusters/bindings/bindings.cpp ${CHIP_ROOT}/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp diff --git a/examples/lock-app/efr32/src/AppTask.cpp b/examples/lock-app/efr32/src/AppTask.cpp index 0e350b25eb55a9..ce3230d5f76f89 100644 --- a/examples/lock-app/efr32/src/AppTask.cpp +++ b/examples/lock-app/efr32/src/AppTask.cpp @@ -28,7 +28,6 @@ #include "gen/cluster-id.h" #include "lcd.h" #include "qrcodegen.h" -#include #include #include #include diff --git a/examples/lock-app/lock-common/BUILD.gn b/examples/lock-app/lock-common/BUILD.gn index a0eb36cdd585e0..7e8a655f17aaf3 100644 --- a/examples/lock-app/lock-common/BUILD.gn +++ b/examples/lock-app/lock-common/BUILD.gn @@ -20,4 +20,5 @@ chip_data_model("lock-common") { zap_file = "lock-app.zap" zap_pregenerated_dir = "gen" + is_server = true } diff --git a/examples/lock-app/nrfconnect/CMakeLists.txt b/examples/lock-app/nrfconnect/CMakeLists.txt index cc3286bea1795c..6289bccf49d5b4 100644 --- a/examples/lock-app/nrfconnect/CMakeLists.txt +++ b/examples/lock-app/nrfconnect/CMakeLists.txt @@ -68,6 +68,12 @@ target_sources(app PRIVATE ${CHIP_ROOT}/src/app/util/process-cluster-message.cpp ${CHIP_ROOT}/src/app/util/process-global-message.cpp ${CHIP_ROOT}/src/app/util/util.cpp + ${CHIP_ROOT}/src/app/server/EchoHandler.cpp + ${CHIP_ROOT}/src/app/server/Mdns.cpp + ${CHIP_ROOT}/src/app/server/OnboardingCodesUtil.cpp + ${CHIP_ROOT}/src/app/server/RendezvousServer.cpp + ${CHIP_ROOT}/src/app/server/Server.cpp + ${CHIP_ROOT}/src/app/server/StorablePeerConnection.cpp ${CHIP_ROOT}/src/app/clusters/basic/basic.cpp ${CHIP_ROOT}/src/app/clusters/bindings/bindings.cpp ${CHIP_ROOT}/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp diff --git a/examples/platform/linux/BUILD.gn b/examples/platform/linux/BUILD.gn index ff8dd7cde5b714..a8964d31b74cbb 100644 --- a/examples/platform/linux/BUILD.gn +++ b/examples/platform/linux/BUILD.gn @@ -31,7 +31,10 @@ source_set("app-main") { defines = [ "PW_RPC_ENABLED" ] } - public_deps = [ "${chip_root}/src/lib" ] + public_deps = [ + "${chip_root}/src/app/server", + "${chip_root}/src/lib", + ] public_configs = [ ":app-main-config" ] } diff --git a/examples/window-app/common/BUILD.gn b/examples/window-app/common/BUILD.gn index 4052665e0f2b77..a481ae68d5e804 100644 --- a/examples/window-app/common/BUILD.gn +++ b/examples/window-app/common/BUILD.gn @@ -20,4 +20,5 @@ chip_data_model("window-common") { zap_file = "window-app.zap" zap_pregenerated_dir = "gen" + is_server = true } diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index a08807b2831dbd..4f92244c0e9786 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -61,6 +61,7 @@ template("chip_data_model") { "cluster_sources", "zap_file", "use_default_client_callbacks", + "is_server", ]) if (!defined(sources)) { @@ -170,6 +171,10 @@ template("chip_data_model") { "${chip_root}/src/protocols/secure_channel", ] + if (defined(invoker.is_server)) { + public_deps += [ "${chip_root}/src/app/server" ] + } + if (!defined(public_configs)) { public_configs = [] } diff --git a/src/app/server/DataModelHandler.cpp b/src/app/server/DataModelHandler.cpp deleted file mode 100644 index b3b60f87f3f358..00000000000000 --- a/src/app/server/DataModelHandler.cpp +++ /dev/null @@ -1,100 +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 - -#if __has_include("gen/endpoint_config.h") -#define USE_ZAP_CONFIG 1 -#include -#include -#endif -#include - -#ifdef EMBER_AF_PLUGIN_REPORTING_SERVER -void emberAfPluginReportingStackStatusCallback(EmberStatus status); -#endif -#ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER -void emberAfPluginTemperatureMeasurementServerStackStatusCallback(EmberStatus status); -#endif -#ifdef EMBER_AF_PLUGIN_IAS_ZONE_SERVER -void emberAfPluginIasZoneServerStackStatusCallback(EmberStatus status); -#endif - -using namespace ::chip; - -void InitDataModelHandler() -{ -#ifdef USE_ZAP_CONFIG - ChipLogProgress(Zcl, "Using ZAP configuration..."); - 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 -#endif -} - -void HandleDataModelMessage(NodeId nodeId, System::PacketBufferHandle buffer) -{ -#ifdef USE_ZAP_CONFIG - EmberApsFrame frame; - bool ok = extractApsFrame(buffer->Start(), buffer->DataLength(), &frame) > 0; - if (ok) - { - ChipLogDetail(Zcl, "APS frame processing success!"); - } - else - { - ChipLogDetail(Zcl, "APS frame processing failure!"); - return; - } - - uint8_t * message; - uint16_t messageLen = extractMessage(buffer->Start(), buffer->DataLength(), &message); - ok = emberAfProcessMessage(&frame, - 0, // type - message, messageLen, - nodeId, // source identifier - NULL); - - if (ok) - { - ChipLogDetail(Zcl, "Data model processing success!"); - } - else - { - ChipLogDetail(Zcl, "Data model processing failure!"); - } -#endif -} diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index dc4f342074e14d..c300b4df8a9d64 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -20,10 +20,10 @@ #include #include -#include #include #include #include +#include #include #include @@ -407,16 +407,6 @@ SecurePairingUsingTestSecret gTestPairing; } // namespace -SecureSessionMgr & chip::SessionManager() -{ - return gSessions; -} - -Messaging::ExchangeManager & chip::ExchangeManager() -{ - return gExchangeMgr; -} - CHIP_ERROR OpenDefaultPairingWindow(ResetAdmins resetAdmins, chip::PairingWindowAdvertisement advertisementMode) { // TODO(cecille): If this is re-called when the window is already open, what should happen? @@ -489,7 +479,7 @@ void InitServer(AppDelegate * delegate) chip::Platform::MemoryInit(); - InitDataModelHandler(); + InitDataModelHandler(&gExchangeMgr); gCallbacks.SetDelegate(delegate); #if CHIP_DEVICE_LAYER_TARGET_DARWIN diff --git a/src/app/server/Server.h b/src/app/server/Server.h index e00f6bfe7a5ab6..8fc253d02b558e 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -64,10 +64,6 @@ enum class PairingWindowAdvertisement kBle, kMdns, }; - -SecureSessionMgr & SessionManager(); -Messaging::ExchangeManager & ExchangeManager(); - } // namespace chip /** diff --git a/src/app/util/DataModelHandler.cpp b/src/app/util/DataModelHandler.cpp index b3b60f87f3f358..7ee94246b85897 100644 --- a/src/app/util/DataModelHandler.cpp +++ b/src/app/util/DataModelHandler.cpp @@ -20,7 +20,7 @@ * This file implements the handler for data model messages. */ -#include +#include #if __has_include("gen/endpoint_config.h") #define USE_ZAP_CONFIG 1 @@ -41,12 +41,12 @@ void emberAfPluginIasZoneServerStackStatusCallback(EmberStatus status); using namespace ::chip; -void InitDataModelHandler() +void InitDataModelHandler(chip::Messaging::ExchangeManager * exchangeManager) { #ifdef USE_ZAP_CONFIG ChipLogProgress(Zcl, "Using ZAP configuration..."); emberAfEndpointConfigure(); - emberAfInit(); + emberAfInit(exchangeManager); #if defined(EMBER_AF_PLUGIN_REPORTING_SERVER) || defined(EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER) || \ defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER) diff --git a/src/app/server/DataModelHandler.h b/src/app/util/DataModelHandler.h similarity index 92% rename from src/app/server/DataModelHandler.h rename to src/app/util/DataModelHandler.h index b6085e80ab45c5..e0a600111b1b83 100644 --- a/src/app/server/DataModelHandler.h +++ b/src/app/util/DataModelHandler.h @@ -22,6 +22,7 @@ #pragma once +#include #include #include @@ -30,7 +31,7 @@ * data model messages. * */ -void InitDataModelHandler(); +void InitDataModelHandler(chip::Messaging::ExchangeManager * exchangeMgr); /** * Handle a message that should be processed via our data model processing diff --git a/src/app/util/chip-message-send.cpp b/src/app/util/chip-message-send.cpp index 07f3e810fcc65e..8fd9ba88a20bd3 100644 --- a/src/app/util/chip-message-send.cpp +++ b/src/app/util/chip-message-send.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include using namespace chip; @@ -49,8 +48,7 @@ class DeviceExchangeDelegate : public Messaging::ExchangeDelegate void OnResponseTimeout(Messaging::ExchangeContext * ec) override {} }; -extern SecureSessionMgr & SessionManager(); -extern Messaging::ExchangeManager & ExchangeManager(); +extern Messaging::ExchangeManager * ExchangeManager(); } // namespace chip EmberStatus chipSendUnicast(NodeId destination, EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message) @@ -88,8 +86,14 @@ EmberStatus chipSendUnicast(NodeId destination, EmberApsFrame * apsFrame, uint16 memcpy(buffer->Start() + frameSize, message, messageLength); buffer->SetDataLength(dataLength); - // TODO: temprary create a handle from node id, will be fix in PR 3602 - Messaging::ExchangeContext * exchange = ExchangeManager().NewContext({ destination, Transport::kAnyKeyId, 0 }, nullptr); + // TODO: temporary create a handle from node id, will be fix in PR 3602 + Messaging::ExchangeManager * exchangeMgr = ExchangeManager(); + if (exchangeMgr == nullptr) + { + return EMBER_DELIVERY_FAILED; + } + + Messaging::ExchangeContext * exchange = exchangeMgr->NewContext({ destination, Transport::kAnyKeyId, 0 }, nullptr); if (exchange == nullptr) { return EMBER_DELIVERY_FAILED; diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index 1b59dc186e7858..2ba6e603fd1692 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -100,6 +100,9 @@ EmberAfClusterCommand curCmd; // to NULL when the function exits. EmberAfClusterCommand * emAfCurrentCommand; +// A pointer to the global exchange manager +chip::Messaging::ExchangeManager * emAfExchangeMgr = nullptr; + // DEPRECATED. uint8_t emberAfIncomingZclSequenceNumber = 0xFF; @@ -266,13 +269,15 @@ static void prepareForResponse(const EmberAfClusterCommand * cmd) // **************************************** // Initialize Clusters // **************************************** -void emberAfInit(void) +void emberAfInit(chip::Messaging::ExchangeManager * exchangeMgr) { uint8_t i; #ifdef EMBER_AF_ENABLE_STATISTICS afNumPktsSent = 0; #endif + emAfExchangeMgr = exchangeMgr; + for (i = 0; i < EMBER_SUPPORTED_NETWORKS; i++) { // FIXME: Do we need to support more than one network? @@ -1240,3 +1245,8 @@ uint8_t emberAfMake8bitEncodedChanPg(uint8_t page, uint8_t channel) return channel | ENCODED_8BIT_CHANPG_PAGE_MASK_PAGE_0; } } + +chip::Messaging::ExchangeManager * chip::ExchangeManager() +{ + return emAfExchangeMgr; +} diff --git a/src/app/util/util.h b/src/app/util/util.h index aa0d45139112c1..085ac22591c4d0 100644 --- a/src/app/util/util.h +++ b/src/app/util/util.h @@ -48,6 +48,7 @@ #pragma once #include +#include // User asserts can override SLAB_ASSERT and should be defined as follows: // void userAssert (int file, int line); // declaration @@ -141,7 +142,7 @@ uint16_t emberAfGetMfgCodeFromCurrentCommand(void); // EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH is defined in config.h #define EMBER_AF_RESPONSE_BUFFER_LEN EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH -void emberAfInit(void); +void emberAfInit(chip::Messaging::ExchangeManager * exchangeContext); void emberAfTick(void); uint16_t emberAfFindClusterNameIndex(chip::ClusterId cluster); uint16_t emberAfFindClusterNameIndexWithMfgCode(chip::ClusterId cluster, uint16_t mfgCode); @@ -286,3 +287,7 @@ uint8_t emberAfGetChannelFrom8bitEncodedChanPg(uint8_t chanPg); * @return 8-bit encoded channel-page, 0xFF if invalid */ uint8_t emberAfMake8bitEncodedChanPg(uint8_t page, uint8_t channel); + +namespace chip { +chip::Messaging::ExchangeManager * ExchangeManager(); +} // namespace chip diff --git a/src/controller/CHIPDevice.cpp b/src/controller/CHIPDevice.cpp index b8f2822f1f479e..60151e0d7cd62b 100644 --- a/src/controller/CHIPDevice.cpp +++ b/src/controller/CHIPDevice.cpp @@ -36,7 +36,7 @@ #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #include -#include +#include #include #include #include diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 34a9dbfa319fd0..624f3bfc46206c 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -40,7 +40,7 @@ #endif #include -#include +#include #include #include #include @@ -196,7 +196,7 @@ CHIP_ERROR DeviceController::Init(NodeId localDeviceId, ControllerInitParams par } #endif // CHIP_DEVICE_CONFIG_ENABLE_MDNS - InitDataModelHandler(); + InitDataModelHandler(mExchangeMgr); mState = State::Initialized; mLocalDeviceId = localDeviceId; diff --git a/src/controller/EmptyDataModelHandler.cpp b/src/controller/EmptyDataModelHandler.cpp index 325a36640eb1f2..6565486adf77c7 100644 --- a/src/controller/EmptyDataModelHandler.cpp +++ b/src/controller/EmptyDataModelHandler.cpp @@ -22,7 +22,7 @@ // defaults so that the controller library is self-sufficient and a controller // which has not yet implemented ZCL handlers builds without linker errors. -#include +#include -__attribute__((weak)) void InitDataModelHandler() {} +__attribute__((weak)) void InitDataModelHandler(chip::Messaging::ExchangeManager * exchangeMgr) {} __attribute__((weak)) void HandleDataModelMessage(chip::NodeId nodeId, chip::System::PacketBufferHandle buffer) {} diff --git a/src/lib/BUILD.gn b/src/lib/BUILD.gn index 19c6a1678dd88a..685704e8cc7e67 100644 --- a/src/lib/BUILD.gn +++ b/src/lib/BUILD.gn @@ -13,7 +13,6 @@ # limitations under the License. import("//build_overrides/chip.gni") -import("${chip_root}/src/platform/device.gni") declare_args() { chip_build_shell_lib = false @@ -45,10 +44,6 @@ static_library("lib") { public_deps += [ "${chip_root}/src/lib/shell" ] } - if (chip_device_platform != "none") { - public_deps += [ "${chip_root}/src/app/server" ] - } - cflags = [ "-Wconversion" ] output_name = "libCHIP"