blob: df2a448057f85a900a75087c0361943bb24aeb61 [file] [log] [blame]
fesseha-evefa07cc92023-07-05 10:04:51 +02001/**
2 *
3 * Copyright (c) 2023 Project CHIP Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @file API declarations for time sync cluster.
20 */
21
22#pragma once
23
24#include <app-common/zap-generated/cluster-objects.h>
25#include <lib/core/CHIPPersistentStorageDelegate.h>
26#include <lib/support/Span.h>
27
28namespace chip {
29
30class TimeSyncDataProvider
31{
32 using TrustedTimeSource = chip::app::Clusters::TimeSynchronization::Structs::TrustedTimeSourceStruct::Type;
33 using TimeZoneStruct = chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type;
34 using DSTOffsets = chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::DSTOffsetStruct::Type>;
35
36public:
37 static constexpr size_t kTimeZoneNameLength = 64;
38 struct TimeZoneStore
39 {
40 TimeZoneStruct timeZone;
41 char name[kTimeZoneNameLength];
42 };
43 struct TimeZoneObj
44 {
45 Span<TimeZoneStore> timeZoneList;
46 size_t validSize;
47 };
48 struct DSTOffsetObj
49 {
50 DSTOffsets dstOffsetList;
51 size_t validSize;
52 };
53
54 ~TimeSyncDataProvider() {}
55
56 void Init(PersistentStorageDelegate & persistentStorage) { mPersistentStorage = &persistentStorage; }
57
58 CHIP_ERROR StoreTrustedTimeSource(const TrustedTimeSource & timeSource);
59 CHIP_ERROR LoadTrustedTimeSource(TrustedTimeSource & timeSource);
60 CHIP_ERROR ClearTrustedTimeSource();
61
62 CHIP_ERROR StoreDefaultNtp(const CharSpan & defaultNtp);
63 CHIP_ERROR LoadDefaultNtp(MutableCharSpan & defaultNtp);
64 CHIP_ERROR ClearDefaultNtp();
65
66 CHIP_ERROR StoreTimeZone(const chip::Span<TimeZoneStore> & timeZoneList);
67 CHIP_ERROR LoadTimeZone(TimeZoneObj & timeZoneObj);
68 CHIP_ERROR ClearTimeZone();
69
70 CHIP_ERROR StoreDSTOffset(const DSTOffsets & dstOffsetList);
71 CHIP_ERROR LoadDSTOffset(DSTOffsetObj & dstOffsetObj);
72 CHIP_ERROR ClearDSTOffset();
73
74private:
75 CHIP_ERROR Load(const char * key, MutableByteSpan & buffer);
76 PersistentStorageDelegate * mPersistentStorage = nullptr;
77 CHIP_ERROR Clear(const char * key);
78};
79
80} // namespace chip