Skip to content

Commit

Permalink
Time sync: add check for fabric removal (#28011)
Browse files Browse the repository at this point in the history
* Time sync: add check for fabric removal

* Update src/app/clusters/time-synchronization-server/time-synchronization-server.cpp
  • Loading branch information
cecille authored and pull[bot] committed Jan 19, 2024
1 parent b0b0c8a commit 9248099
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ void TimeSynchronizationServer::Init()
{
mGranularity = GranularityEnum::kNoTimeGranularity;
}
// This can error, but it's not clear what should happen in this case. For now, just ignore it because we still
// want time sync even if we can't register the deletgate here.
CHIP_ERROR err = chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(this);
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Unable to register Fabric table delegate for time sync");
}
}

CHIP_ERROR TimeSynchronizationServer::SetTrustedTimeSource(const DataModel::Nullable<Structs::TrustedTimeSourceStruct::Type> & tts)
Expand Down Expand Up @@ -663,6 +670,16 @@ void TimeSynchronizationServer::ClearEventFlag(TimeSyncEventFlag flag)
mEventFlag = static_cast<TimeSyncEventFlag>(eventFlag);
}

void TimeSynchronizationServer::OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex)
{
if (!mTrustedTimeSource.IsNull() && mTrustedTimeSource.Value().fabricIndex == fabricIndex)
{
DataModel::Nullable<Structs::TrustedTimeSourceStruct::Type> tts;
TimeSynchronizationServer::Instance().SetTrustedTimeSource(tts);
emitMissingTrustedTimeSourceEvent(0);
}
}

namespace {

class TimeSynchronizationAttrAccess : public AttributeAccessInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <app/server/Server.h>
#include <app/util/af-types.h>
#include <app/util/config.h>
#include <credentials/FabricTable.h>
#include <lib/core/TLV.h>

#include <app-common/zap-generated/cluster-objects.h>
Expand Down Expand Up @@ -60,7 +61,7 @@ enum class TimeSyncEventFlag : uint8_t
kMissingTTSource = 16,
};

class TimeSynchronizationServer
class TimeSynchronizationServer : public FabricTable::Delegate
{
public:
void Init();
Expand Down Expand Up @@ -94,6 +95,9 @@ class TimeSynchronizationServer
TimeSyncEventFlag GetEventFlag(void);
void ClearEventFlag(TimeSyncEventFlag flag);

// Fabric Table delegate functions
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex);

private:
DataModel::Nullable<Structs::TrustedTimeSourceStruct::Type> mTrustedTimeSource;
TimeSyncDataProvider::TimeZoneObj mTimeZoneObj{ Span<TimeSyncDataProvider::TimeZoneStore>(mTz), 0 };
Expand Down

0 comments on commit 9248099

Please sign in to comment.