mirror of
https://github.com/openharmony/miscservices_time.git
synced 2026-07-19 12:02:04 -04:00
@@ -30,6 +30,7 @@ const int THREE_PARAMETERS = 3;
|
||||
const int SET_TIME_MAX_PARA = 2;
|
||||
const int SET_TIMEZONE_MAX_PARA = 2;
|
||||
const int MAX_TIME_ZONE_ID = 1024;
|
||||
const int INVALID_TIME = -1;
|
||||
const int NO_ERROR = 0;
|
||||
const int ERROR = -1;
|
||||
const int PARAM0 = 0;
|
||||
@@ -40,8 +41,8 @@ const int ARGS_TWO = 2;
|
||||
typedef struct AsyncContext {
|
||||
napi_env env = nullptr;
|
||||
napi_async_work work = nullptr;
|
||||
int64_t time;
|
||||
std::string timeZone;
|
||||
int64_t time = INVALID_TIME;
|
||||
std::string timeZone = "";
|
||||
napi_deferred deferred = nullptr;
|
||||
napi_ref callbackRef = nullptr;
|
||||
bool isCallback = false;
|
||||
|
||||
@@ -141,12 +141,12 @@ napi_value JSSystemTimeSetTime(napi_env env, napi_callback_info info)
|
||||
napi_value argv[SET_TIME_MAX_PARA] = {0};
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
int64_t times;
|
||||
int64_t times = INVALID_TIME;
|
||||
napi_ref callback = nullptr;
|
||||
if (ParseParametersBySetTime(env, argv, argc, times, callback) == nullptr) {
|
||||
return TimeJSParaError(env, callback);
|
||||
}
|
||||
AsyncContext* asyncContext = new (std::nothrow)AsyncContext{.env = env, .time = times};
|
||||
AsyncContext *asyncContext = new (std::nothrow)AsyncContext {.env = env, .time = times};
|
||||
if (!asyncContext) {
|
||||
return TimeJSParaError(env, callback);
|
||||
}
|
||||
@@ -180,7 +180,7 @@ napi_value JSSystemTimeSetTime(napi_env env, napi_callback_info info)
|
||||
asyncContext = nullptr;
|
||||
}
|
||||
},
|
||||
(void*)asyncContext,
|
||||
(void*)asyncContext,
|
||||
&asyncContext->work);
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asyncContext->work));
|
||||
if (asyncContext->isCallback) {
|
||||
@@ -225,7 +225,7 @@ napi_value JSSystemTimeSetTimeZone(napi_env env, napi_callback_info info)
|
||||
if (ParseParametersBySetTimezone(env, argv, argc, timezoneId, callback) == nullptr) {
|
||||
return TimeJSParaError(env, callback);
|
||||
}
|
||||
AsyncContext *asyncContext = new (std::nothrow)AsyncContext{.env = env, .timeZone = timezoneId};
|
||||
AsyncContext *asyncContext = new (std::nothrow)AsyncContext {.env = env, .timeZone = timezoneId};
|
||||
if (!asyncContext) {
|
||||
return TimeJSParaError(env, callback);
|
||||
}
|
||||
|
||||
@@ -456,7 +456,8 @@ napi_value StartTimer(napi_env env, napi_callback_info info)
|
||||
return JSParaError(env, callback);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoStart *asynccallbackinfo = new (std::nothrow)AsyncCallbackInfoStart{.env = env,
|
||||
AsyncCallbackInfoStart *asynccallbackinfo = new (std::nothrow)AsyncCallbackInfoStart{
|
||||
.env = env,
|
||||
.asyncWork = nullptr,
|
||||
.timerId = timerId,
|
||||
.triggerTime = triggerTime
|
||||
@@ -568,9 +569,11 @@ napi_value StopTimer(napi_env env, napi_callback_info info)
|
||||
return JSParaError(env, callback);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoStop *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoStop{.env = env,
|
||||
.asyncWork = nullptr,
|
||||
.timerId = timerId};
|
||||
AsyncCallbackInfoStop *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoStop {
|
||||
.env = env,
|
||||
.asyncWork = nullptr,
|
||||
.timerId = timerId
|
||||
};
|
||||
if (!asynccallbackinfo) {
|
||||
return JSParaError(env, callback);
|
||||
}
|
||||
@@ -675,7 +678,7 @@ napi_value DestroyTimer(napi_env env, napi_callback_info info)
|
||||
}
|
||||
|
||||
AsyncCallbackInfoDestroy *asynccallbackinfo =
|
||||
new (std::nothrow) AsyncCallbackInfoDestroy{.env = env, .asyncWork = nullptr, .timerId = timerId};
|
||||
new (std::nothrow) AsyncCallbackInfoDestroy {.env = env, .asyncWork = nullptr, .timerId = timerId};
|
||||
if (!asynccallbackinfo) {
|
||||
return JSParaError(env, callback);
|
||||
}
|
||||
|
||||
@@ -242,8 +242,7 @@ uint64_t TimeService::CreateTimer(int32_t type, bool repeat, uint64_t interval,
|
||||
|
||||
bool TimeService::StartTimer(uint64_t timerId, uint64_t triggerTimes)
|
||||
{
|
||||
uint64_t triggerTimesIn;
|
||||
triggerTimesIn = (triggerTimes < MIN_TRIGGER_TIMES) ? MIN_TRIGGER_TIMES : triggerTimes;
|
||||
uint64_t triggerTimesIn = (triggerTimes < MIN_TRIGGER_TIMES) ? MIN_TRIGGER_TIMES : triggerTimes;
|
||||
if (timerManagerHandler_ == nullptr) {
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "Timer manager nullptr.");
|
||||
timerManagerHandler_ = TimerManager::Create();
|
||||
@@ -329,7 +328,8 @@ int32_t TimeService::SetTime(const int64_t time)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int TimeService::set_rtc_time(time_t sec) {
|
||||
int TimeService::set_rtc_time(time_t sec)
|
||||
{
|
||||
struct rtc_time rtc {};
|
||||
struct tm tm {};
|
||||
struct tm *gmtime_res = nullptr;
|
||||
@@ -404,7 +404,6 @@ int TimeService::get_wall_clock_rtc_id()
|
||||
std::string s = "rtc";
|
||||
while (errno = 0,
|
||||
dirent = readdir(dir.get())) {
|
||||
|
||||
std::string name(dirent->d_name);
|
||||
unsigned long rtc_id_t = 0;
|
||||
auto index = name.find(s);
|
||||
@@ -460,7 +459,7 @@ int32_t TimeService::GetTimeZone(std::string &timeZoneId)
|
||||
}
|
||||
|
||||
int32_t TimeService::GetWallTimeMs(int64_t ×)
|
||||
{
|
||||
{
|
||||
struct timespec tv {};
|
||||
|
||||
if (GetTimeByClockid(CLOCK_REALTIME, &tv)) {
|
||||
@@ -471,7 +470,7 @@ int32_t TimeService::GetWallTimeMs(int64_t ×)
|
||||
}
|
||||
|
||||
int32_t TimeService::GetWallTimeNs(int64_t ×)
|
||||
{
|
||||
{
|
||||
struct timespec tv {};
|
||||
|
||||
if (GetTimeByClockid(CLOCK_REALTIME, &tv)) {
|
||||
@@ -482,7 +481,7 @@ int32_t TimeService::GetWallTimeNs(int64_t ×)
|
||||
}
|
||||
|
||||
int32_t TimeService::GetBootTimeMs(int64_t ×)
|
||||
{
|
||||
{
|
||||
struct timespec tv {};
|
||||
|
||||
if (GetTimeByClockid(CLOCK_BOOTTIME, &tv)) {
|
||||
@@ -493,7 +492,7 @@ int32_t TimeService::GetBootTimeMs(int64_t ×)
|
||||
}
|
||||
|
||||
int32_t TimeService::GetBootTimeNs(int64_t ×)
|
||||
{
|
||||
{
|
||||
struct timespec tv {};
|
||||
|
||||
if (GetTimeByClockid(CLOCK_BOOTTIME, &tv)) {
|
||||
@@ -504,7 +503,7 @@ int32_t TimeService::GetBootTimeNs(int64_t ×)
|
||||
}
|
||||
|
||||
int32_t TimeService::GetMonotonicTimeMs(int64_t ×)
|
||||
{
|
||||
{
|
||||
struct timespec tv {};
|
||||
|
||||
if (GetTimeByClockid(CLOCK_MONOTONIC, &tv)) {
|
||||
@@ -515,7 +514,7 @@ int32_t TimeService::GetMonotonicTimeMs(int64_t ×)
|
||||
}
|
||||
|
||||
int32_t TimeService::GetMonotonicTimeNs(int64_t ×)
|
||||
{
|
||||
{
|
||||
struct timespec tv {};
|
||||
|
||||
if (GetTimeByClockid(CLOCK_MONOTONIC, &tv)) {
|
||||
@@ -526,7 +525,7 @@ int32_t TimeService::GetMonotonicTimeNs(int64_t ×)
|
||||
}
|
||||
|
||||
int32_t TimeService::GetThreadTimeMs(int64_t ×)
|
||||
{
|
||||
{
|
||||
struct timespec tv {};
|
||||
int ret;
|
||||
clockid_t cid;
|
||||
@@ -543,7 +542,7 @@ int32_t TimeService::GetThreadTimeMs(int64_t ×)
|
||||
}
|
||||
|
||||
int32_t TimeService::GetThreadTimeNs(int64_t ×)
|
||||
{
|
||||
{
|
||||
struct timespec tv {};
|
||||
int ret;
|
||||
clockid_t cid;
|
||||
@@ -567,6 +566,5 @@ bool TimeService::GetTimeByClockid(clockid_t clk_id, struct timespec *tv)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -241,7 +241,7 @@ int32_t TimeServiceStub::OnCreateTimer(MessageParcel &data, MessageParcel &reply
|
||||
return E_TIME_PARAMETERS_INVALID;
|
||||
}
|
||||
auto timerId = CreateTimer(type, repeat, interval, obj);
|
||||
if (timerId == 0 ) {
|
||||
if (timerId == 0) {
|
||||
TIME_HILOGE(TIME_MODULE_SERVICE, "Create timer failed");
|
||||
return E_TIME_DEAL_FAILED;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ bool Batch::Remove(std::function<bool (const TimerInfo &)> predicate)
|
||||
auto newStart = std::chrono::steady_clock::time_point::min();
|
||||
auto newEnd = std::chrono::steady_clock::time_point::max();
|
||||
uint32_t newFlags = 0;
|
||||
for (auto it = alarms_.begin(); it != alarms_.end();) {
|
||||
for (auto it = alarms_.begin(); it != alarms_.end(); ) {
|
||||
auto alarm = *it;
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "looper");
|
||||
if (predicate(*alarm)) {
|
||||
|
||||
@@ -236,7 +236,7 @@ void TimerManager::RemoveLocked(uint64_t id)
|
||||
};
|
||||
|
||||
bool didRemove = false;
|
||||
for (auto it = alarmBatches_.begin(); it != alarmBatches_.end();) {
|
||||
for (auto it = alarmBatches_.begin(); it != alarmBatches_.end(); ) {
|
||||
auto batch = *it;
|
||||
didRemove = batch->Remove(whichAlarms);
|
||||
if (batch->Size() == 0) {
|
||||
@@ -271,7 +271,7 @@ void TimerManager::ReBatchAllTimers()
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void TimerManager::ReBatchAllTimersLocked(bool doValidate)
|
||||
void TimerManager::ReBatchAllTimersLocked(bool doValidate)
|
||||
{
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "start");
|
||||
auto oldSet = alarmBatches_;
|
||||
@@ -493,7 +493,7 @@ int64_t TimerManager::AttemptCoalesceLocked(std::chrono::steady_clock::time_poin
|
||||
}
|
||||
|
||||
void TimerManager::DeliverTimersLocked(const std::vector<std::shared_ptr<TimerInfo>> &triggerList,
|
||||
std::chrono::steady_clock::time_point nowElapsed)
|
||||
std::chrono::steady_clock::time_point nowElapsed)
|
||||
{
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "start");
|
||||
for (const auto &alarm : triggerList) {
|
||||
|
||||
Reference in New Issue
Block a user