• 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 <fstream>
21 #include <mutex>
22 #include <string>
23 #include <sys/time.h>
24 
25 #include "refbase.h"
26 #include "time.h"
27 #include "time_common.h"
28 
29 namespace OHOS {
30 namespace MiscServices {
31 class NtpTrustedTime {
32 public:
33     static NtpTrustedTime &GetInstance();
34     bool ForceRefresh(const std::string &ntpServer);
35     int64_t GetCacheAge();
36     int64_t CurrentTimeMillis();
37     int64_t ElapsedRealtimeMillis();
38     class TimeResult : std::enable_shared_from_this<TimeResult> {
39     public:
40         TimeResult();
41         TimeResult(int64_t mTimeMillis, int64_t mElapsedRealtimeMills, int64_t mCertaintyMillis);
42         ~TimeResult();
43         int64_t GetTimeMillis();
44         int64_t GetElapsedRealtimeMillis();
45         int64_t CurrentTimeMillis();
46         int64_t GetAgeMillis();
47         void Clear();
48 
49     private:
50         int64_t mTimeMillis;
51         int64_t mElapsedRealtimeMillis;
52         int64_t mCertaintyMillis;
53     };
54 
55 private:
56     std::shared_ptr<TimeResult> mTimeResult {};
57 };
58 } // namespace MiscServices
59 } // namespace OHOS
60 
61 #endif // SNTP_CLIENT_NTP_TRUSTED_TIME_H