From 791d9bc66da51dbe00c1efc733a24532fac13a22 Mon Sep 17 00:00:00 2001 From: guduhanyan Date: Tue, 12 Oct 2021 17:38:31 +0800 Subject: [PATCH] 20211012master00 Signed-off-by: guduhanyan --- .../napi/system_time/include/js_systemtime.h | 5 +++-- .../js/napi/system_time/src/js_systemtime.cpp | 8 +++---- .../js/napi/system_timer/src/system_timer.cpp | 13 +++++++----- services/time_manager/src/time_service.cpp | 21 +++++++++---------- .../time_manager/src/time_service_stub.cpp | 2 +- services/timer/src/batch.cpp | 2 +- services/timer/src/timer_manager.cpp | 2 +- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/interfaces/kits/js/napi/system_time/include/js_systemtime.h b/interfaces/kits/js/napi/system_time/include/js_systemtime.h index 697ce40a..b9dbb4f7 100644 --- a/interfaces/kits/js/napi/system_time/include/js_systemtime.h +++ b/interfaces/kits/js/napi/system_time/include/js_systemtime.h @@ -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; diff --git a/interfaces/kits/js/napi/system_time/src/js_systemtime.cpp b/interfaces/kits/js/napi/system_time/src/js_systemtime.cpp index 5827d07d..2738005f 100644 --- a/interfaces/kits/js/napi/system_time/src/js_systemtime.cpp +++ b/interfaces/kits/js/napi/system_time/src/js_systemtime.cpp @@ -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); } diff --git a/interfaces/kits/js/napi/system_timer/src/system_timer.cpp b/interfaces/kits/js/napi/system_timer/src/system_timer.cpp index e79f0018..1b4748a3 100644 --- a/interfaces/kits/js/napi/system_timer/src/system_timer.cpp +++ b/interfaces/kits/js/napi/system_timer/src/system_timer.cpp @@ -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); } diff --git a/services/time_manager/src/time_service.cpp b/services/time_manager/src/time_service.cpp index abf5b731..08fd0131 100644 --- a/services/time_manager/src/time_service.cpp +++ b/services/time_manager/src/time_service.cpp @@ -328,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; @@ -403,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); @@ -459,7 +459,7 @@ int32_t TimeService::GetTimeZone(std::string &timeZoneId) } int32_t TimeService::GetWallTimeMs(int64_t ×) -{ +{ struct timespec tv {}; if (GetTimeByClockid(CLOCK_REALTIME, &tv)) { @@ -470,7 +470,7 @@ int32_t TimeService::GetWallTimeMs(int64_t ×) } int32_t TimeService::GetWallTimeNs(int64_t ×) -{ +{ struct timespec tv {}; if (GetTimeByClockid(CLOCK_REALTIME, &tv)) { @@ -481,7 +481,7 @@ int32_t TimeService::GetWallTimeNs(int64_t ×) } int32_t TimeService::GetBootTimeMs(int64_t ×) -{ +{ struct timespec tv {}; if (GetTimeByClockid(CLOCK_BOOTTIME, &tv)) { @@ -492,7 +492,7 @@ int32_t TimeService::GetBootTimeMs(int64_t ×) } int32_t TimeService::GetBootTimeNs(int64_t ×) -{ +{ struct timespec tv {}; if (GetTimeByClockid(CLOCK_BOOTTIME, &tv)) { @@ -503,7 +503,7 @@ int32_t TimeService::GetBootTimeNs(int64_t ×) } int32_t TimeService::GetMonotonicTimeMs(int64_t ×) -{ +{ struct timespec tv {}; if (GetTimeByClockid(CLOCK_MONOTONIC, &tv)) { @@ -514,7 +514,7 @@ int32_t TimeService::GetMonotonicTimeMs(int64_t ×) } int32_t TimeService::GetMonotonicTimeNs(int64_t ×) -{ +{ struct timespec tv {}; if (GetTimeByClockid(CLOCK_MONOTONIC, &tv)) { @@ -525,7 +525,7 @@ int32_t TimeService::GetMonotonicTimeNs(int64_t ×) } int32_t TimeService::GetThreadTimeMs(int64_t ×) -{ +{ struct timespec tv {}; int ret; clockid_t cid; @@ -542,7 +542,7 @@ int32_t TimeService::GetThreadTimeMs(int64_t ×) } int32_t TimeService::GetThreadTimeNs(int64_t ×) -{ +{ struct timespec tv {}; int ret; clockid_t cid; @@ -566,6 +566,5 @@ bool TimeService::GetTimeByClockid(clockid_t clk_id, struct timespec *tv) } return true; } - } // namespace MiscServices } // namespace OHOS diff --git a/services/time_manager/src/time_service_stub.cpp b/services/time_manager/src/time_service_stub.cpp index 3d744a37..3d8bde61 100644 --- a/services/time_manager/src/time_service_stub.cpp +++ b/services/time_manager/src/time_service_stub.cpp @@ -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; } diff --git a/services/timer/src/batch.cpp b/services/timer/src/batch.cpp index 049b4c99..fb387cdb 100644 --- a/services/timer/src/batch.cpp +++ b/services/timer/src/batch.cpp @@ -87,7 +87,7 @@ bool Batch::Remove(std::function 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)) { diff --git a/services/timer/src/timer_manager.cpp b/services/timer/src/timer_manager.cpp index 036cd21b..eec6f0b1 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -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) { -- Gitee