Skip to content

Commit

Permalink
Ensure the stack is using a single ExchangeManager
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed Apr 30, 2021
1 parent 0de2a17 commit 6f96b3b
Show file tree
Hide file tree
Showing 23 changed files with 54 additions and 144 deletions.
1 change: 1 addition & 0 deletions examples/all-clusters-app/all-clusters-common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ chip_data_model("all-clusters-common") {
zap_file = "all-clusters-app.zap"

zap_pregenerated_dir = "gen"
is_server = true
}
1 change: 1 addition & 0 deletions examples/bridge-app/bridge-common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ chip_data_model("bridge-common") {
zap_file = "bridge-app.zap"

zap_pregenerated_dir = "gen"
is_server = true
}
1 change: 0 additions & 1 deletion examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 0 additions & 13 deletions examples/chip-tool/commands/reporting/ReportingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
}
6 changes: 1 addition & 5 deletions examples/chip-tool/commands/reporting/ReportingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions examples/chip-tool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
// ================================================================================
int main(int argc, char * argv[])
{
InitDataModelHandler();

Commands commands;
registerCommandsDiscover(commands);
registerCommandsPayload(commands);
Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/lighting-common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ chip_data_model("lighting-common") {
zap_file = "lighting-app.zap"

zap_pregenerated_dir = "gen"
is_server = true
}
1 change: 1 addition & 0 deletions examples/lock-app/lock-common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ chip_data_model("lock-common") {
zap_file = "lock-app.zap"

zap_pregenerated_dir = "gen"
is_server = true
}
6 changes: 6 additions & 0 deletions examples/lock-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/OnboardingCodeUtils.cpp
${CHIP_ROOT}/src/app/server/RendezvousServer.cpp
${CHIP_ROOT}/src/app/server/Server.cpp
${CHIP_ROOT}/src/app/server/StoragePeerConnection.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
Expand Down
5 changes: 4 additions & 1 deletion examples/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ source_set("app-main") {
defines = [ "PW_RPC_ENABLED" ]
}

public_deps = [ "${chip_root}/src/lib" ]
public_deps = [
"${chip_root}/src/lib",
"${chip_root}/src/app/server",
]

public_configs = [ ":app-main-config" ]
}
1 change: 1 addition & 0 deletions examples/window-app/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ chip_data_model("window-common") {
zap_file = "window-app.zap"

zap_pregenerated_dir = "gen"
is_server = true
}
5 changes: 5 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ template("chip_data_model") {
"cluster_sources",
"zap_file",
"use_default_client_callbacks",
"is_server",
])

if (!defined(sources)) {
Expand Down Expand Up @@ -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 = []
}
Expand Down
100 changes: 0 additions & 100 deletions src/app/server/DataModelHandler.cpp

This file was deleted.

3 changes: 2 additions & 1 deletion src/app/server/DataModelHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#pragma once

#include <messaging/ExchangeMgr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/raw/MessageHeader.h>

Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,6 @@ 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?
Expand Down Expand Up @@ -489,7 +484,7 @@ void InitServer(AppDelegate * delegate)

chip::Platform::MemoryInit();

InitDataModelHandler();
InitDataModelHandler(&gExchangeMgr);
gCallbacks.SetDelegate(delegate);

#if CHIP_DEVICE_LAYER_TARGET_DARWIN
Expand Down
1 change: 0 additions & 1 deletion src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ enum class PairingWindowAdvertisement
};

SecureSessionMgr & SessionManager();
Messaging::ExchangeManager & ExchangeManager();

} // namespace chip

Expand Down
4 changes: 2 additions & 2 deletions src/app/util/DataModelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/app/util/chip-message-send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DeviceExchangeDelegate : public Messaging::ExchangeDelegate
};

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)
Expand Down Expand Up @@ -88,8 +88,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;
Expand Down
12 changes: 11 additions & 1 deletion src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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;
}
7 changes: 6 additions & 1 deletion src/app/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#pragma once

#include <inttypes.h>
#include <messaging/ExchangeMgr.h>

// User asserts can override SLAB_ASSERT and should be defined as follows:
// void userAssert (int file, int line); // declaration
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/EmptyDataModelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@

#include <app/server/DataModelHandler.h>

__attribute__((weak)) void InitDataModelHandler() {}
__attribute__((weak)) void InitDataModelHandler(chip::Messaging::ExchangeManager * exchangeMgr) {}
__attribute__((weak)) void HandleDataModelMessage(chip::NodeId nodeId, chip::System::PacketBufferHandle buffer) {}
Loading

0 comments on commit 6f96b3b

Please sign in to comment.