Skip to content

Commit

Permalink
Removed the double instanciation of report scheduler in ESP32 to redu…
Browse files Browse the repository at this point in the history
…ce ram usage
  • Loading branch information
lpbeliveau-silabs committed Aug 3, 2023
1 parent 55bccd6 commit 2451ab0
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 36 deletions.
7 changes: 1 addition & 6 deletions examples/chef/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
#include <lib/support/CHIPMem.h>
#include <platform/CHIPDeviceLayer.h>

#include <app/TimerDelegates.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/reporting/ReportSchedulerImpl.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>

Expand Down Expand Up @@ -159,10 +157,7 @@ void InitServer(intptr_t)
{
// Start IM server
static chip::CommonCaseDeviceServerInitParams initParams;
// Report scheduler and timer delegate instance
static chip::app::DefaultTimerDelegate sTimerDelegate;
static chip::app::reporting::ReportSchedulerImpl sReportScheduler(&sTimerDelegate);
initParams.reportScheduler = &sReportScheduler;

(void) initParams.InitializeStaticResourcesBeforeServerInit();
chip::Server::GetInstance().Init(initParams);

Expand Down
7 changes: 1 addition & 6 deletions examples/platform/esp32/common/Esp32AppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

#include "Esp32AppServer.h"
#include "CHIPDeviceManager.h"
#include <app/TimerDelegates.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
#include <app/reporting/ReportSchedulerImpl.h>
#include <app/server/Dnssd.h>
#include <app/server/Server.h>
#include <platform/ESP32/NetworkCommissioningDriver.h>
Expand Down Expand Up @@ -99,10 +97,7 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
{
// Init ZCL Data Model and CHIP App Server
static chip::CommonCaseDeviceServerInitParams initParams;
// Report scheduler and timer delegate instance
static chip::app::DefaultTimerDelegate sTimerDelegate;
static chip::app::reporting::ReportSchedulerImpl sReportScheduler(&sTimerDelegate);
initParams.reportScheduler = &sReportScheduler;

#if CONFIG_TEST_EVENT_TRIGGER_ENABLED && CONFIG_ENABLE_OTA_REQUESTOR
if (hex_string_to_binary(CONFIG_TEST_EVENT_TRIGGER_ENABLE_KEY, sTestEventTriggerEnableKey,
sizeof(sTestEventTriggerEnableKey)) == 0)
Expand Down
103 changes: 79 additions & 24 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct ServerInitParams
ServerInitParams() = default;

// Not copyable
ServerInitParams(const ServerInitParams &) = delete;
ServerInitParams(const ServerInitParams &) = delete;
ServerInitParams & operator=(const ServerInitParams &) = delete;

// Application delegate to handle some commissioning lifecycle events
Expand Down Expand Up @@ -182,7 +182,7 @@ struct CommonCaseDeviceServerInitParams : public ServerInitParams
CommonCaseDeviceServerInitParams() = default;

// Not copyable
CommonCaseDeviceServerInitParams(const CommonCaseDeviceServerInitParams &) = delete;
CommonCaseDeviceServerInitParams(const CommonCaseDeviceServerInitParams &) = delete;
CommonCaseDeviceServerInitParams & operator=(const CommonCaseDeviceServerInitParams &) = delete;

/**
Expand Down Expand Up @@ -267,12 +267,10 @@ struct CommonCaseDeviceServerInitParams : public ServerInitParams
static PersistentStorageOperationalKeystore sPersistentStorageOperationalKeystore;
static Credentials::PersistentStorageOpCertStore sPersistentStorageOpCertStore;
static Credentials::GroupDataProviderImpl sGroupDataProvider;

static chip::app::DefaultTimerDelegate sTimerDelegate;
#if CHIP_CONFIG_SYNCHRONOUS_REPORTS_ENABLED
static chip::SynchronizedTimerDelegate sTimerDelegate;
static app::reporting::SynchronizedReportSchedulerImpl sReportScheduler;
#else
static chip::app::DefaultTimerDelegate sTimerDelegate;
static app::reporting::ReportSchedulerImpl sReportScheduler;
#endif
#if CHIP_CONFIG_ENABLE_SESSION_RESUMPTION
Expand Down Expand Up @@ -318,43 +316,97 @@ class Server
*/
void RejoinExistingMulticastGroups();

FabricTable & GetFabricTable() { return mFabrics; }
FabricTable & GetFabricTable()
{
return mFabrics;
}

CASESessionManager * GetCASESessionManager() { return &mCASESessionManager; }
CASESessionManager * GetCASESessionManager()
{
return &mCASESessionManager;
}

Messaging::ExchangeManager & GetExchangeManager() { return mExchangeMgr; }
Messaging::ExchangeManager & GetExchangeManager()
{
return mExchangeMgr;
}

SessionManager & GetSecureSessionManager() { return mSessions; }
SessionManager & GetSecureSessionManager()
{
return mSessions;
}

SessionResumptionStorage * GetSessionResumptionStorage() { return mSessionResumptionStorage; }
SessionResumptionStorage * GetSessionResumptionStorage()
{
return mSessionResumptionStorage;
}

app::SubscriptionResumptionStorage * GetSubscriptionResumptionStorage() { return mSubscriptionResumptionStorage; }
app::SubscriptionResumptionStorage * GetSubscriptionResumptionStorage()
{
return mSubscriptionResumptionStorage;
}

TransportMgrBase & GetTransportManager() { return mTransports; }
TransportMgrBase & GetTransportManager()
{
return mTransports;
}

Credentials::GroupDataProvider * GetGroupDataProvider() { return mGroupsProvider; }
Credentials::GroupDataProvider * GetGroupDataProvider()
{
return mGroupsProvider;
}

Crypto::SessionKeystore * GetSessionKeystore() const { return mSessionKeystore; }
Crypto::SessionKeystore * GetSessionKeystore() const
{
return mSessionKeystore;
}

#if CONFIG_NETWORK_LAYER_BLE
Ble::BleLayer * GetBleLayerObject() { return mBleLayer; }
Ble::BleLayer * GetBleLayerObject()
{
return mBleLayer;
}
#endif

CommissioningWindowManager & GetCommissioningWindowManager() { return mCommissioningWindowManager; }
CommissioningWindowManager & GetCommissioningWindowManager()
{
return mCommissioningWindowManager;
}

PersistentStorageDelegate & GetPersistentStorage() { return *mDeviceStorage; }
PersistentStorageDelegate & GetPersistentStorage()
{
return *mDeviceStorage;
}

app::FailSafeContext & GetFailSafeContext() { return mFailSafeContext; }
app::FailSafeContext & GetFailSafeContext()
{
return mFailSafeContext;
}

TestEventTriggerDelegate * GetTestEventTriggerDelegate() { return mTestEventTriggerDelegate; }
TestEventTriggerDelegate * GetTestEventTriggerDelegate()
{
return mTestEventTriggerDelegate;
}

Crypto::OperationalKeystore * GetOperationalKeystore() { return mOperationalKeystore; }
Crypto::OperationalKeystore * GetOperationalKeystore()
{
return mOperationalKeystore;
}

Credentials::OperationalCertificateStore * GetOpCertStore() { return mOpCertStore; }
Credentials::OperationalCertificateStore * GetOpCertStore()
{
return mOpCertStore;
}

app::DefaultAttributePersistenceProvider & GetDefaultAttributePersister() { return mAttributePersister; }
app::DefaultAttributePersistenceProvider & GetDefaultAttributePersister()
{
return mAttributePersister;
}

app::reporting::ReportScheduler * GetReportScheduler() { return mReportScheduler; }
app::reporting::ReportScheduler * GetReportScheduler()
{
return mReportScheduler;
}

/**
* This function causes the ShutDown event to be generated async on the
Expand All @@ -371,7 +423,10 @@ class Server
return System::SystemClock().GetMonotonicMicroseconds64() - mInitTimestamp;
}

static Server & GetInstance() { return sServer; }
static Server & GetInstance()
{
return sServer;
}

private:
Server() {}
Expand Down

0 comments on commit 2451ab0

Please sign in to comment.