Skip to content

Commit a9ab8f3

Browse files
[Silabs] BaseApplication Init refactor (#37985)
* Refactor of BaseApplication to reduce code copied accross examples * Removed unused method * Update examples/platform/silabs/BaseApplication.h Co-authored-by: Mathieu Kardous <84793247+mkardous-silabs@users.noreply.github.com> * Update examples/platform/silabs/BaseApplication.h * Update examples/platform/silabs/BaseApplication.h * Update examples/platform/silabs/BaseApplication.h --------- Co-authored-by: Mathieu Kardous <84793247+mkardous-silabs@users.noreply.github.com>
1 parent fbf4bd2 commit a9ab8f3

File tree

26 files changed

+63
-131
lines changed

26 files changed

+63
-131
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-9
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
{
@@ -110,7 +103,6 @@ CHIP_ERROR AppTask::Init()
110103
#endif // QR_CODE_ENABLED
111104
#endif
112105

113-
BaseApplication::InitCompleteCallback(err);
114106
return err;
115107
}
116108

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

+23-6
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,29 @@ 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+
SILABS_TRACE_END_ERROR(TimeTraceOperation::kAppInit, err);
321+
SILABS_TRACE_END_ERROR(TimeTraceOperation::kBootup, err);
322+
return err;
323+
}
324+
325+
CHIP_ERROR BaseApplication::BaseInit()
303326
{
304327
CHIP_ERROR err = CHIP_NO_ERROR;
305328

@@ -381,12 +404,6 @@ CHIP_ERROR BaseApplication::Init()
381404
return err;
382405
}
383406

384-
void BaseApplication::InitCompleteCallback(CHIP_ERROR err)
385-
{
386-
SILABS_TRACE_END(TimeTraceOperation::kAppInit);
387-
SILABS_TRACE_END(TimeTraceOperation::kBootup);
388-
}
389-
390407
void BaseApplication::FunctionTimerEventHandler(void * timerCbArg)
391408
{
392409
AppEvent event;

examples/platform/silabs/BaseApplication.h

+4-7
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,11 @@ class BaseApplication
178178

179179
protected:
180180
CHIP_ERROR Init();
181-
182-
/** @brief
183-
* Function to be called at the end of Init to indicate that the application has completed its initialization.
184-
* Currently only used for tracing, might want to move logging here as well in the future
185-
* @param err CHIP_NO_ERROR on success, corresponding error code on Init failure, note that Init failure leads to an app error
186-
* so this is purely to have a trace logged with the error code
181+
CHIP_ERROR BaseInit();
182+
/** @brief Template for to implement a Application specific init.
183+
* Function is called after the BaseApplication::Init function.
187184
*/
188-
void InitCompleteCallback(CHIP_ERROR err);
185+
virtual CHIP_ERROR AppInit() = 0;
189186

190187
/**
191188
* @brief Function called to start the function timer

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
{

0 commit comments

Comments
 (0)