• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (C) 2022 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SNTP_CLIENT_NTP_TRUSTED_TIME_H
18 #define SNTP_CLIENT_NTP_TRUSTED_TIME_H
19 
20 #include <singleton.h>
21 #include <string>
22 #include <fstream>
23 #include <mutex>
24 #include <sys/time.h>
25 #include "refbase.h"
26 #include "time.h"
27 #include "time_common.h"
28 #include "json/json.h"
29 
30 namespace OHOS {
31 namespace MiscServices {
32 class NtpTrustedTime : public DelayedSingleton<NtpTrustedTime> {
33     DECLARE_DELAYED_SINGLETON(NtpTrustedTime)
34 public:
35     bool ForceRefresh(std::string ntpServer);
36     bool HasCache();
37     int64_t GetCacheAge();
38     int64_t CurrentTimeMillis();
39     int64_t GetCachedNtpTime();
40     int64_t GetCachedNtpTimeReference();
41     class TimeResult : std::enable_shared_from_this<TimeResult> {
42     public:
43         TimeResult();
44         TimeResult(int64_t mTimeMillis, int64_t mElapsedRealtimeMills, int64_t mCertaintyMillis);
45         ~TimeResult();
46         int64_t GetTimeMillis();
47         int64_t GetElapsedRealtimeMillis();
48         int64_t GetCertaintyMillis();
49         int64_t CurrentTimeMillis();
50         int64_t GetAgeMillis();
51         void Clear();
52     private:
53         int64_t mTimeMillis;
54         int64_t mElapsedRealtimeMillis;
55         int64_t mCertaintyMillis;
56     };
57 
58 private:
59     std::shared_ptr<TimeResult> mTimeResult;
60 };
61 } // MiscServices
62 } // OHOS
63 
64 #endif // SNTP_CLIENT_NTP_TRUSTED_TIME_H
65