Skip to content

Commit 3943632

Browse files
Refactor of BaseApplication to reduce code copied accross examples
1 parent f82ef16 commit 3943632

File tree

27 files changed

+60
-119
lines changed

27 files changed

+60
-119
lines changed

examples/air-quality-sensor-app/silabs/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ class AppTask : public BaseApplication
8989
static AppTask sAppTask;
9090

9191
/**
92-
* @brief AppTask initialisation function
92+
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
9393
*
9494
* @return CHIP_ERROR
9595
*/
96-
CHIP_ERROR Init();
96+
CHIP_ERROR AppInit() override;
9797

9898
/**
9999
* @brief PB0 Button event processing function

examples/air-quality-sensor-app/silabs/src/AppTask.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ using namespace chip::app::Clusters;
6868

6969
AppTask AppTask::sAppTask;
7070

71-
CHIP_ERROR AppTask::Init()
71+
CHIP_ERROR AppTask::AppInit()
7272
{
7373
CHIP_ERROR err = CHIP_NO_ERROR;
7474
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
@@ -77,12 +77,6 @@ CHIP_ERROR AppTask::Init()
7777
GetLCD().SetCustomUI(AirQualitySensorUI::DrawUI);
7878
#endif
7979

80-
err = BaseApplication::Init();
81-
if (err != CHIP_NO_ERROR)
82-
{
83-
ChipLogDetail(AppServer, "BaseApplication::Init() failed");
84-
appError(err);
85-
}
8680
err = SensorManager::SensorMgr().Init();
8781
if (err != CHIP_NO_ERROR)
8882
{

examples/chef/silabs/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ class AppTask : public BaseApplication
8080
static AppTask sAppTask;
8181

8282
/**
83-
* @brief AppTask initialisation function
83+
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
8484
*
8585
* @return CHIP_ERROR
8686
*/
87-
CHIP_ERROR Init();
87+
CHIP_ERROR AppInit() override;
8888

8989
/**
9090
* @brief PB0 Button event processing function

examples/chef/silabs/src/AppTask.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,11 @@ using namespace ::chip::DeviceLayer;
5858

5959
AppTask AppTask::sAppTask;
6060

61-
CHIP_ERROR AppTask::Init()
61+
CHIP_ERROR AppTask::AppInit()
6262
{
6363
CHIP_ERROR err = CHIP_NO_ERROR;
6464
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
6565

66-
err = BaseApplication::Init();
67-
if (err != CHIP_NO_ERROR)
68-
{
69-
SILABS_LOG("BaseApplication::Init() failed");
70-
appError(err);
71-
}
72-
7366
return err;
7467
}
7568

examples/energy-management-app/silabs/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ class AppTask : public BaseApplication
8585
static void UpdateClusterState(intptr_t context);
8686

8787
/**
88-
* @brief AppTask initialisation function
88+
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
8989
*
9090
* @return CHIP_ERROR
9191
*/
92-
CHIP_ERROR Init();
92+
CHIP_ERROR AppInit() override;
9393

9494
/**
9595
* @brief PB0 Button event processing function

examples/energy-management-app/silabs/src/AppTask.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void ApplicationShutdown()
163163
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
164164
}
165165

166-
CHIP_ERROR AppTask::Init()
166+
CHIP_ERROR AppTask::AppInit()
167167
{
168168
CHIP_ERROR err = CHIP_NO_ERROR;
169169
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
@@ -176,13 +176,6 @@ CHIP_ERROR AppTask::Init()
176176
#endif
177177
#endif
178178

179-
err = BaseApplication::Init();
180-
if (err != CHIP_NO_ERROR)
181-
{
182-
SILABS_LOG("BaseApplication::Init() failed");
183-
appError(err);
184-
}
185-
186179
ApplicationInit();
187180

188181
#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED

examples/light-switch-app/silabs/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class AppTask : public BaseApplication
7070
static AppTask sAppTask;
7171

7272
/**
73-
* @brief AppTask initialisation function
73+
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
7474
*
7575
* @return CHIP_ERROR
7676
*/
77-
CHIP_ERROR Init();
77+
CHIP_ERROR AppInit() override;
7878
};

examples/light-switch-app/silabs/src/AppTask.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ using namespace ::chip::DeviceLayer;
6868

6969
AppTask AppTask::sAppTask;
7070

71-
CHIP_ERROR AppTask::Init()
71+
CHIP_ERROR AppTask::AppInit()
7272
{
7373
CHIP_ERROR err = CHIP_NO_ERROR;
7474
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(LightSwitchMgr::ButtonEventHandler);
@@ -77,13 +77,6 @@ CHIP_ERROR AppTask::Init()
7777
GetLCD().Init((uint8_t *) "Light Switch");
7878
#endif
7979

80-
err = BaseApplication::Init();
81-
if (err != CHIP_NO_ERROR)
82-
{
83-
SILABS_LOG("BaseApplication::Init() failed");
84-
appError(err);
85-
}
86-
8780
err = LightSwitchMgr::GetInstance().Init(kLightSwitchEndpoint, kGenericSwitchEndpoint);
8881
if (err != CHIP_NO_ERROR)
8982
{

examples/lighting-app/silabs/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ class AppTask : public BaseApplication
8888
static void UpdateClusterState(intptr_t context);
8989

9090
/**
91-
* @brief AppTask initialisation function
91+
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
9292
*
9393
* @return CHIP_ERROR
9494
*/
95-
CHIP_ERROR Init();
95+
CHIP_ERROR AppInit() override;
9696

9797
/**
9898
* @brief PB0 Button event processing function

examples/lighting-app/silabs/src/AppTask.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ using namespace ::chip::DeviceLayer;
6464

6565
AppTask AppTask::sAppTask;
6666

67-
CHIP_ERROR AppTask::Init()
67+
CHIP_ERROR AppTask::AppInit()
6868
{
6969
CHIP_ERROR err = CHIP_NO_ERROR;
7070
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
@@ -75,13 +75,6 @@ CHIP_ERROR AppTask::Init()
7575
GetLCD().Init((uint8_t *) "Lighting-App");
7676
#endif
7777

78-
err = BaseApplication::Init();
79-
if (err != CHIP_NO_ERROR)
80-
{
81-
SILABS_LOG("BaseApplication::Init() failed");
82-
appError(err);
83-
}
84-
8578
err = LightMgr().Init();
8679
if (err != CHIP_NO_ERROR)
8780
{

examples/lit-icd-app/silabs/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ class AppTask : public BaseApplication, public chip::app::ICDStateObserver
104104
static AppTask sAppTask;
105105

106106
/**
107-
* @brief AppTask initialisation function
107+
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
108108
*
109109
* @return CHIP_ERROR
110110
*/
111-
CHIP_ERROR Init();
111+
CHIP_ERROR AppInit() override;
112112

113113
/**
114114
* @brief PB0 Button event processing function

examples/lit-icd-app/silabs/src/AppTask.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ using namespace ::chip::DeviceLayer;
6868

6969
AppTask AppTask::sAppTask;
7070

71-
CHIP_ERROR AppTask::Init()
71+
CHIP_ERROR AppTask::AppInit()
7272
{
7373
CHIP_ERROR err = CHIP_NO_ERROR;
7474
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
@@ -77,13 +77,6 @@ CHIP_ERROR AppTask::Init()
7777
GetLCD().Init((uint8_t *) "LIT ICD");
7878
#endif
7979

80-
err = BaseApplication::Init();
81-
if (err != CHIP_NO_ERROR)
82-
{
83-
SILABS_LOG("BaseApplication::Init() failed");
84-
appError(err);
85-
}
86-
8780
return err;
8881
}
8982

examples/lock-app/silabs/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ class AppTask : public BaseApplication
8989
static AppTask sAppTask;
9090

9191
/**
92-
* @brief AppTask initialisation function
92+
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
9393
*
9494
* @return CHIP_ERROR
9595
*/
96-
CHIP_ERROR Init();
96+
CHIP_ERROR AppInit() override;
9797

9898
/**
9999
* @brief PB0 Button event processing function

examples/lock-app/silabs/src/AppTask.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ using namespace ::chip::DeviceLayer;
116116

117117
AppTask AppTask::sAppTask;
118118

119-
CHIP_ERROR AppTask::Init()
119+
CHIP_ERROR AppTask::AppInit()
120120
{
121121
CHIP_ERROR err = CHIP_NO_ERROR;
122122

@@ -126,13 +126,6 @@ CHIP_ERROR AppTask::Init()
126126
GetLCD().Init((uint8_t *) "Lock-App", true);
127127
#endif
128128

129-
err = BaseApplication::Init();
130-
if (err != CHIP_NO_ERROR)
131-
{
132-
SILABS_LOG("BaseApplication::Init() failed");
133-
appError(err);
134-
}
135-
136129
#if defined(ENABLE_CHIP_SHELL)
137130
err = RegisterLockEvents();
138131
if (err != CHIP_NO_ERROR)

examples/platform/silabs/BaseApplication.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,28 @@ CHIP_ERROR BaseApplication::StartAppTask(osThreadFunc_t taskFunction)
300300
}
301301

302302
CHIP_ERROR BaseApplication::Init()
303+
{
304+
CHIP_ERROR err = BaseInit();
305+
if (err != CHIP_NO_ERROR)
306+
{
307+
SILABS_LOG("BaseInit() failed");
308+
appError(err);
309+
return err;
310+
}
311+
312+
err = AppInit();
313+
if (err != CHIP_NO_ERROR)
314+
{
315+
SILABS_LOG("AppInit() failed");
316+
appError(err);
317+
return err;
318+
}
319+
320+
InitCompleteCallback(err);
321+
return err;
322+
}
323+
324+
CHIP_ERROR BaseApplication::BaseInit()
303325
{
304326
CHIP_ERROR err = CHIP_NO_ERROR;
305327

examples/platform/silabs/BaseApplication.h

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ class BaseApplication
178178

179179
protected:
180180
CHIP_ERROR Init();
181+
CHIP_ERROR BaseInit();
182+
virtual CHIP_ERROR AppInit() { return CHIP_NO_ERROR; }
181183

182184
/** @brief
183185
* Function to be called at the end of Init to indicate that the application has completed its initialization.

examples/pump-app/silabs/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ class AppTask : public BaseApplication
7575
static void UpdateClusterState(intptr_t context);
7676

7777
/**
78-
* @brief AppTask initialisation function
78+
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
7979
*
8080
* @return CHIP_ERROR
8181
*/
82-
CHIP_ERROR Init();
82+
CHIP_ERROR AppInit() override;
8383

8484
/**
8585
* @brief PB0 Button event processing function

examples/pump-app/silabs/src/AppTask.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ using namespace ::chip::DeviceLayer;
7171

7272
AppTask AppTask::sAppTask;
7373

74-
CHIP_ERROR AppTask::Init()
74+
CHIP_ERROR AppTask::AppInit()
7575
{
7676
CHIP_ERROR err = CHIP_NO_ERROR;
7777
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
@@ -80,13 +80,6 @@ CHIP_ERROR AppTask::Init()
8080
GetLCD().Init((uint8_t *) "Pump-App");
8181
#endif
8282

83-
err = BaseApplication::Init();
84-
if (err != CHIP_NO_ERROR)
85-
{
86-
SILABS_LOG("BaseApplication::Init() failed");
87-
appError(err);
88-
}
89-
9083
err = PumpMgr().Init();
9184
if (err != CHIP_NO_ERROR)
9285
{

examples/refrigerator-app/silabs/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ class AppTask : public BaseApplication
8484
static AppTask sAppTask;
8585

8686
/**
87-
* @brief AppTask initialisation function
87+
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
8888
*
8989
* @return CHIP_ERROR
9090
*/
91-
CHIP_ERROR Init();
91+
CHIP_ERROR AppInit() override;
9292

9393
/**
9494
* @brief PB0 Button event processing function

examples/refrigerator-app/silabs/src/AppTask.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ using namespace ::chip::DeviceLayer;
7575

7676
AppTask AppTask::sAppTask;
7777

78-
CHIP_ERROR AppTask::Init()
78+
CHIP_ERROR AppTask::AppInit()
7979
{
8080
CHIP_ERROR err = CHIP_NO_ERROR;
8181
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler);
@@ -84,12 +84,6 @@ CHIP_ERROR AppTask::Init()
8484
GetLCD().Init((uint8_t *) "Refrigrator-App");
8585
#endif
8686

87-
err = BaseApplication::Init();
88-
if (err != CHIP_NO_ERROR)
89-
{
90-
ChipLogError(AppServer, "BaseApplication::Init() failed");
91-
appError(err);
92-
}
9387
err = RefrigeratorMgr().Init();
9488
if (err != CHIP_NO_ERROR)
9589
{

examples/smoke-co-alarm-app/silabs/include/AppTask.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ class AppTask : public BaseApplication
7979
static AppTask sAppTask;
8080

8181
/**
82-
* @brief AppTask initialisation function
82+
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
8383
*
8484
* @return CHIP_ERROR
8585
*/
86-
CHIP_ERROR Init();
86+
CHIP_ERROR AppInit() override;
8787

8888
/**
8989
* @brief PB0 Button event processing function

0 commit comments

Comments
 (0)