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 a8d396a
Show file tree
Hide file tree
Showing 23 changed files with 54 additions and 154 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/OnboardingCodesUtil.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/app/server",
"${chip_root}/src/lib",
]

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

chip::Platform::MemoryInit();

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

#if CHIP_DEVICE_LAYER_TARGET_DARWIN
Expand Down
4 changes: 0 additions & 4 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ enum class PairingWindowAdvertisement
kBle,
kMdns,
};

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
14 changes: 9 additions & 5 deletions src/app/util/chip-message-send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <messaging/ExchangeMgr.h>
#include <protocols/Protocols.h>
#include <support/logging/CHIPLogging.h>
#include <transport/SecureSessionMgr.h>
#include <transport/raw/MessageHeader.h>

using namespace chip;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
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;
}
Loading

0 comments on commit a8d396a

Please sign in to comment.