Skip to content

Commit

Permalink
Refactor Clusters::Switch::Server to Clusters::SwitchServer (#19326)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Nov 29, 2023
1 parent 82f8c8c commit a62ba14
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
50 changes: 24 additions & 26 deletions src/app/clusters/switch-server/switch-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,118 +39,116 @@ using chip::DeviceLayer::DeviceControlServer;
namespace chip {
namespace app {
namespace Clusters {
namespace Switch {

Server Server::instance;
SwitchServer SwitchServer::instance;

/**********************************************************
* Server Implementation
* SwitchServer Implementation
*********************************************************/

Server & Server::Instance()
SwitchServer & SwitchServer::Instance()
{
return instance;
}

void Server::OnSwitchLatch(EndpointId endpoint, uint8_t newPosition)
void SwitchServer::OnSwitchLatch(EndpointId endpoint, uint8_t newPosition)
{
ChipLogProgress(Zcl, "Server: OnSwitchLatch");
ChipLogProgress(Zcl, "SwitchServer: OnSwitchLatch");

// Record SwitchLatched event
EventNumber eventNumber;
Events::SwitchLatched::Type event{ newPosition };

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "Server: Failed to record SwitchLatched event");
ChipLogError(Zcl, "SwitchServer: Failed to record SwitchLatched event");
}
}

void Server::OnInitialPress(EndpointId endpoint, uint8_t newPosition)
void SwitchServer::OnInitialPress(EndpointId endpoint, uint8_t newPosition)
{
ChipLogProgress(Zcl, "Server: OnInitialPress");
ChipLogProgress(Zcl, "SwitchServer: OnInitialPress");

// Record InitialPress event
EventNumber eventNumber;
Events::InitialPress::Type event{ newPosition };

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "Server: Failed to record InitialPress event");
ChipLogError(Zcl, "SwitchServer: Failed to record InitialPress event");
}
}

void Server::OnLongPress(EndpointId endpoint, uint8_t newPosition)
void SwitchServer::OnLongPress(EndpointId endpoint, uint8_t newPosition)
{
ChipLogProgress(Zcl, "Server: OnLongPress");
ChipLogProgress(Zcl, "SwitchServer: OnLongPress");

// Record LongPress event
EventNumber eventNumber;
Events::LongPress::Type event{ newPosition };

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "Server: Failed to record LongPress event");
ChipLogError(Zcl, "SwitchServer: Failed to record LongPress event");
}
}

void Server::OnShortRelease(EndpointId endpoint, uint8_t previousPosition)
void SwitchServer::OnShortRelease(EndpointId endpoint, uint8_t previousPosition)
{
ChipLogProgress(Zcl, "Server: OnShortRelease");
ChipLogProgress(Zcl, "SwitchServer: OnShortRelease");

// Record ShortRelease event
EventNumber eventNumber;
Events::ShortRelease::Type event{ previousPosition };

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "Server: Failed to record ShortRelease event");
ChipLogError(Zcl, "SwitchServer: Failed to record ShortRelease event");
}
}

void Server::OnLongRelease(EndpointId endpoint, uint8_t previousPosition)
void SwitchServer::OnLongRelease(EndpointId endpoint, uint8_t previousPosition)
{
ChipLogProgress(Zcl, "Server: OnLongRelease");
ChipLogProgress(Zcl, "SwitchServer: OnLongRelease");

// Record LongRelease event
EventNumber eventNumber;
Events::LongRelease::Type event{ previousPosition };

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "Server: Failed to record LongRelease event");
ChipLogError(Zcl, "SwitchServer: Failed to record LongRelease event");
}
}

void Server::OnMultiPressOngoing(EndpointId endpoint, uint8_t newPosition, uint8_t count)
void SwitchServer::OnMultiPressOngoing(EndpointId endpoint, uint8_t newPosition, uint8_t count)
{
ChipLogProgress(Zcl, "Server: OnMultiPressOngoing");
ChipLogProgress(Zcl, "SwitchServer: OnMultiPressOngoing");

// Record MultiPressOngoing event
EventNumber eventNumber;
Events::MultiPressOngoing::Type event{ newPosition, count };

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "Server: Failed to record MultiPressOngoing event");
ChipLogError(Zcl, "SwitchServer: Failed to record MultiPressOngoing event");
}
}

void Server::OnMultiPressComplete(EndpointId endpoint, uint8_t newPosition, uint8_t count)
void SwitchServer::OnMultiPressComplete(EndpointId endpoint, uint8_t newPosition, uint8_t count)
{
ChipLogProgress(Zcl, "Server: OnMultiPressComplete");
ChipLogProgress(Zcl, "SwitchServer: OnMultiPressComplete");

// Record MultiPressComplete event
EventNumber eventNumber;
Events::MultiPressComplete::Type event{ newPosition, count };

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "Server: Failed to record MultiPressComplete event");
ChipLogError(Zcl, "SwitchServer: Failed to record MultiPressComplete event");
}
}

} // namespace Switch
} // namespace Clusters
} // namespace app
} // namespace chip
Expand Down
8 changes: 3 additions & 5 deletions src/app/clusters/switch-server/switch-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
namespace chip {
namespace app {
namespace Clusters {
namespace Switch {

/**
* @brief switch-server class
*/
class Server
class SwitchServer
{
public:
static Server & Instance();
static SwitchServer & Instance();

/**
* @brief
Expand Down Expand Up @@ -82,10 +81,9 @@ class Server
void OnMultiPressComplete(EndpointId endpoint, uint8_t newPosition, uint8_t count);

private:
static Server instance;
static SwitchServer instance;
};

} // namespace Switch
} // namespace Clusters
} // namespace app
} // namespace chip

0 comments on commit a62ba14

Please sign in to comment.