Skip to content

Commit

Permalink
Add device info provider in more NRF locations, fix null pointer cras…
Browse files Browse the repository at this point in the history
…h for storage info (#18847)

* Add device info provider in more NRF locations

* Add device info provider to light switch app as well

* Add device info provider to window cover app as well
  • Loading branch information
andy31415 authored and pull[bot] committed Jul 16, 2022
1 parent 2c446e1 commit 1396618
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
18 changes: 15 additions & 3 deletions examples/all-clusters-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "LEDUtil.h"
#include "binding-handler.h"

#include <DeviceInfoProviderImpl.h>

#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>

Expand Down Expand Up @@ -53,9 +55,15 @@ using namespace ::chip::DeviceLayer;
LOG_MODULE_DECLARE(app, CONFIG_MATTER_LOG_LEVEL);
K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(AppEvent));

static LEDWidget sStatusLED;
static UnusedLedsWrapper<3> sUnusedLeds{ { DK_LED2, DK_LED3, DK_LED4 } };
static k_timer sFunctionTimer;
namespace {

LEDWidget sStatusLED;
UnusedLedsWrapper<3> sUnusedLeds{ { DK_LED2, DK_LED3, DK_LED4 } };
k_timer sFunctionTimer;

chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;

} // namespace

constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

Expand Down Expand Up @@ -141,7 +149,11 @@ CHIP_ERROR AppTask::Init()

static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();

ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams));

gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
#if CONFIG_CHIP_OTA_REQUESTOR
InitBasicOTARequestor();
#endif
Expand Down
7 changes: 7 additions & 0 deletions examples/light-switch-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "LightSwitch.h"
#include "ThreadUtil.h"

#include <DeviceInfoProviderImpl.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
Expand Down Expand Up @@ -80,6 +81,8 @@ k_timer sFunctionTimer;
k_timer sDimmerPressKeyTimer;
k_timer sDimmerTimer;

chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;

} /* namespace */

AppTask AppTask::sAppTask;
Expand Down Expand Up @@ -164,6 +167,10 @@ CHIP_ERROR AppTask::Init()
static chip::CommonCaseDeviceServerInitParams initParams;
ReturnErrorOnFailure(initParams.InitializeStaticResourcesBeforeServerInit());
ReturnErrorOnFailure(Server::GetInstance().Init(initParams));

gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);

#if CONFIG_CHIP_OTA_REQUESTOR
InitBasicOTARequestor();
#endif
Expand Down
3 changes: 2 additions & 1 deletion examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ CHIP_ERROR AppTask::Init()

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

gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);

ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams));
#if CONFIG_CHIP_OTA_REQUESTOR
InitBasicOTARequestor();
#endif
Expand Down
6 changes: 6 additions & 0 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "LEDWidget.h"
#include "ThreadUtil.h"

#include <DeviceInfoProviderImpl.h>
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
Expand Down Expand Up @@ -72,6 +73,8 @@ bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sHaveBLEConnections = false;

chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;

} // namespace

AppTask AppTask::sAppTask;
Expand Down Expand Up @@ -157,6 +160,9 @@ CHIP_ERROR AppTask::Init()
(void) initParams.InitializeStaticResourcesBeforeServerInit();

ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams));

gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
#if CONFIG_CHIP_OTA_REQUESTOR
InitBasicOTARequestor();
#endif
Expand Down
7 changes: 7 additions & 0 deletions examples/pump-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "PumpManager.h"
#include "ThreadUtil.h"

#include <DeviceInfoProviderImpl.h>
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
Expand Down Expand Up @@ -73,6 +74,8 @@ bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sHaveBLEConnections = false;

chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;

} // namespace

AppTask AppTask::sAppTask;
Expand Down Expand Up @@ -153,6 +156,10 @@ CHIP_ERROR AppTask::Init()
(void) initParams.InitializeStaticResourcesBeforeServerInit();

ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams));

gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);

#if CONFIG_CHIP_OTA_REQUESTOR
InitBasicOTARequestor();
#endif
Expand Down
6 changes: 6 additions & 0 deletions examples/pump-controller-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "PumpManager.h"
#include "ThreadUtil.h"

#include <DeviceInfoProviderImpl.h>
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
Expand Down Expand Up @@ -70,6 +71,8 @@ bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sHaveBLEConnections = false;

chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;

} // namespace

AppTask AppTask::sAppTask;
Expand Down Expand Up @@ -150,6 +153,9 @@ CHIP_ERROR AppTask::Init()
(void) initParams.InitializeStaticResourcesBeforeServerInit();

ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams));

gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
#if CONFIG_CHIP_OTA_REQUESTOR
InitBasicOTARequestor();
#endif
Expand Down
19 changes: 16 additions & 3 deletions examples/window-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "LEDUtil.h"
#include "WindowCovering.h"

#include <DeviceInfoProviderImpl.h>

#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>

Expand Down Expand Up @@ -50,9 +52,16 @@
LOG_MODULE_DECLARE(app, CONFIG_MATTER_LOG_LEVEL);
K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(AppEvent));

static LEDWidget sStatusLED;
static UnusedLedsWrapper<1> sUnusedLeds{ { DK_LED4 } };
static k_timer sFunctionTimer;
namespace {

LEDWidget sStatusLED;
UnusedLedsWrapper<1> sUnusedLeds{ { DK_LED4 } };
k_timer sFunctionTimer;

chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;

} // namespace

namespace LedConsts {
constexpr uint32_t kBlinkRate_ms{ 500 };
namespace StatusLed {
Expand Down Expand Up @@ -138,6 +147,10 @@ CHIP_ERROR AppTask::Init()
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams));

gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);

#if CONFIG_CHIP_OTA_REQUESTOR
InitBasicOTARequestor();
#endif
Expand Down

0 comments on commit 1396618

Please sign in to comment.