Skip to content

Commit

Permalink
[shell] Clean up shutdown handling.
Browse files Browse the repository at this point in the history
- Revert erroneous shutdown protection in Server.cpp
- Add app-level shutdown protection in cmd_server.cpp
  • Loading branch information
turon committed Jan 7, 2022
1 parent 1c9fc33 commit ef0f83a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 6 additions & 0 deletions examples/shell/shell_common/cmd_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bool lowPowerClusterSleep()
static chip::Shell::Engine sShellServerSubcommands;
static uint16_t sServerPortOperational = CHIP_PORT;
static uint16_t sServerPortCommissioning = CHIP_UDC_PORT;
static bool sServerEnabled = false;

static CHIP_ERROR CmdAppServerHelp(int argc, char ** argv)
{
Expand All @@ -57,12 +58,17 @@ static CHIP_ERROR CmdAppServerStart(int argc, char ** argv)
// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

sServerEnabled = true;

return CHIP_NO_ERROR;
}

static CHIP_ERROR CmdAppServerStop(int argc, char ** argv)
{
if (sServerEnabled == false)
return CHIP_NO_ERROR;
chip::Server::GetInstance().Shutdown();
sServerEnabled = false;
return CHIP_NO_ERROR;
}

Expand Down
8 changes: 1 addition & 7 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint
&mSessions, &mFabrics, &mSessionIDAllocator);
SuccessOrExit(err);

err = mCASESessionManager.Init();
mState = ServerState::Enabled;
err = mCASESessionManager.Init();

exit:
if (err != CHIP_NO_ERROR)
Expand All @@ -250,18 +249,13 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint

void Server::Shutdown()
{
if (mState == ServerState::Disabled)
return;

chip::Dnssd::ServiceAdvertiser::Instance().Shutdown();
chip::app::InteractionModelEngine::GetInstance()->Shutdown();
mExchangeMgr.Shutdown();
mSessions.Shutdown();
mTransports.Close();
mCommissioningWindowManager.Shutdown();
chip::Platform::MemoryShutdown();

mState = ServerState::Disabled;
}

#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
Expand Down

0 comments on commit ef0f83a

Please sign in to comment.