• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SERVICES_INCLUDE_TIME_COMMON_H
17 #define SERVICES_INCLUDE_TIME_COMMON_H
18 
19 #include <string>
20 
21 #include "errors.h"
22 #include "time_hilog.h"
23 
24 namespace OHOS {
25 namespace MiscServices {
26 #define TIME_SERVICE_NAME "TimeService"
27 
28 struct TimerPara {
29     std::string name;
30     int timerType;
31     int64_t windowLength;
32     uint64_t interval;
33     bool disposable;
34     bool autoRestore;
35     uint32_t flag;
36 };
37 
38 enum TimeModule : uint8_t {
39     TIME_MODULE_SERVICE_ID = 0x04,
40 };
41 // time error offset, used only in this file.
42 constexpr ErrCode TIME_ERR_OFFSET = ErrCodeOffset(SUBSYS_SMALLSERVICES, TIME_MODULE_SERVICE_ID);
43 
44 enum TimeError : int32_t {
45     E_TIME_OK = 0,
46     // 77856768
47     E_TIME_SA_DIED = TIME_ERR_OFFSET,
48     E_TIME_READ_PARCEL_ERROR,
49     E_TIME_WRITE_PARCEL_ERROR,
50     E_TIME_PUBLISH_FAIL,
51     E_TIME_TRANSACT_ERROR,
52     E_TIME_DEAL_FAILED,
53     E_TIME_PARAMETERS_INVALID,
54     E_TIME_SET_RTC_FAILED,
55     E_TIME_NOT_FOUND,
56     E_TIME_NULLPTR,
57     E_TIME_NO_PERMISSION,
58     E_TIME_NOT_SYSTEM_APP,
59     E_TIME_NO_TIMER_ADJUST,
60     E_TIME_NTP_UPDATE_FAILED,
61     E_TIME_NTP_NOT_UPDATE,
62     #ifdef MULTI_ACCOUNT_ENABLE
63     E_TIME_ACCOUNT_NOT_MATCH,
64     E_TIME_ACCOUNT_ERROR,
65     #endif
66     E_TIME_AUTO_RESTORE_ERROR,
67 };
68 
69 enum DatabaseType : int8_t {
70     NOT_STORE = 0,
71     STORE,
72 };
73 
74 enum APIVersion : int8_t {
75     API_VERSION_7 = 0,
76     API_VERSION_9 = 1,
77 };
78 
79 class TimeUtils {
80 public:
81     static int32_t GetWallTimeMs(int64_t &time);
82     static int32_t GetBootTimeMs(int64_t &time);
83     static int32_t GetBootTimeNs(int64_t &time);
84     static bool GetTimeByClockId(clockid_t clockId, struct timespec &tv);
85 };
86 } // namespace MiscServices
87 } // namespace OHOS
88 #endif // SERVICES_INCLUDE_TIME_COMMON_H