1 /*
2 * Copyright (c) 2024 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 #include "time_hilog.h"
17 #include "cj_ffi/cj_common_ffi.h"
18 #include "system_date_time.h"
19 #include "system_date_time_ffi.h"
20
21 namespace OHOS {
22 namespace CJSystemapi {
23 namespace SystemDateTime {
24
25 extern "C" {
FfiOHOSSysDateTimeSetTime(int64_t time)26 RetCode FfiOHOSSysDateTimeSetTime(int64_t time)
27 {
28 RetCode ret = SystemDateTimeImpl::SetTime(time);
29 if (ret != SUCCESS_CODE) {
30 return ret;
31 }
32 return ret;
33 }
34
FfiOHOSSysDateTimegetCurrentTime(bool isNano)35 RetDataI64 FfiOHOSSysDateTimegetCurrentTime(bool isNano)
36 {
37 RetDataI64 ret = { .code = INVALID_DATA_ID, .data = 0 };
38 auto [state, time] = SystemDateTimeImpl::getCurrentTime(isNano);
39 if (state != SUCCESS_CODE) {
40 ret.code = state;
41 ret.data = 0;
42 return ret;
43 }
44 ret.code = state;
45 ret.data = time;
46 return ret;
47 }
48
FfiOHOSSysDateTimegetRealActiveTime(bool isNano)49 RetDataI64 FfiOHOSSysDateTimegetRealActiveTime(bool isNano)
50 {
51 RetDataI64 ret = { .code = INVALID_DATA_ID, .data = 0 };
52 auto [state, time] = SystemDateTimeImpl::getRealActiveTime(isNano);
53 if (state != SUCCESS_CODE) {
54 ret.code = state;
55 ret.data = 0;
56 return ret;
57 }
58 ret.code = state;
59 ret.data = time;
60 return ret;
61 }
62
FfiOHOSSysDateTimegetRealTime(bool isNano)63 RetDataI64 FfiOHOSSysDateTimegetRealTime(bool isNano)
64 {
65 RetDataI64 ret = { .code = INVALID_DATA_ID, .data = 0 };
66 auto [state, time] = SystemDateTimeImpl::getRealTime(isNano);
67 if (state != SUCCESS_CODE) {
68 ret.code = state;
69 ret.data = 0;
70 return ret;
71 }
72 ret.code = state;
73 ret.data = time;
74 return ret;
75 }
76
FfiOHOSSysDateTimeGetTime(bool isNano)77 RetDataI64 FfiOHOSSysDateTimeGetTime(bool isNano)
78 {
79 RetDataI64 ret = { .code = INVALID_DATA_ID, .data = 0 };
80 auto [state, time] = SystemDateTimeImpl::getTime(isNano);
81 if (state != SUCCESS_CODE) {
82 ret.code = state;
83 ret.data = 0;
84 return ret;
85 }
86 ret.code = state;
87 ret.data = time;
88 return ret;
89 }
90
FfiOHOSSysDateTimeGetUptime(int32_t timeType,bool isNano)91 RetDataI64 FfiOHOSSysDateTimeGetUptime(int32_t timeType, bool isNano)
92 {
93 RetDataI64 ret = { .code = INVALID_DATA_ID, .data = 0 };
94 auto [state, time] = SystemDateTimeImpl::getUpTime(timeType, isNano);
95 if (state != SUCCESS_CODE) {
96 ret.code = state;
97 ret.data = 0;
98 return ret;
99 }
100 ret.code = state;
101 ret.data = time;
102 return ret;
103 }
104
FfiOHOSSysSetTimezone(char * timezone)105 RetCode FfiOHOSSysSetTimezone(char* timezone)
106 {
107 RetCode ret = SystemDateTimeImpl::SetTimeZone(timezone);
108 if (ret != SUCCESS_CODE) {
109 return ret;
110 }
111 return ret;
112 }
113
FfiOHOSSysGetTimezone()114 RetDataCString FfiOHOSSysGetTimezone()
115 {
116 RetDataCString ret = { .code = INVALID_DATA_ID, .data = nullptr };
117 auto [state, time] = SystemDateTimeImpl::getTimezone();
118 if (state != SUCCESS_CODE) {
119 ret.code = state;
120 ret.data = nullptr;
121 return ret;
122 }
123 ret.code = state;
124 ret.data = time;
125 return ret;
126 }
127 }
128 } // SystemDateTime
129 } // CJSystemapi
130 } // OHOS