Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time sync: add check for fabric removal #28011

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Time sync: add check for fabric removal
cecille committed Jul 17, 2023
commit edc8120a8adf1879ef55bdbef3006cb55275caca
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not RemoveFabricdDelegate on shutdown, or at worst in the destructor?

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)
@@ -663,6 +670,17 @@ 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;
tts.SetNull();
TimeSynchronizationServer::Instance().SetTrustedTimeSource(tts);
emitMissingTrustedTimeSourceEvent(0);
}
}

namespace {

class TimeSynchronizationAttrAccess : public AttributeAccessInterface
Original file line number Diff line number Diff line change
@@ -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>
@@ -60,7 +61,7 @@ enum class TimeSyncEventFlag : uint8_t
kMissingTTSource = 16,
};

class TimeSynchronizationServer
class TimeSynchronizationServer : public FabricTable::Delegate
{
public:
void Init();
@@ -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 };