mirror of
https://github.com/openharmony/miscservices_time.git
synced 2026-07-19 12:02:04 -04:00
@@ -154,15 +154,15 @@ napi_value JSSystemTimeSetTime(napi_env env, napi_callback_info info)
|
||||
TimePaddingAsyncCallbackInfo(env, asyncContext, callback, promise);
|
||||
napi_value resource = nullptr;
|
||||
napi_create_string_utf8(env, "JSSystemTimeSetTime", NAPI_AUTO_LENGTH, &resource);
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resource,
|
||||
[](napi_env env, void* data) {
|
||||
AsyncContext* asyncContext = (AsyncContext*)data;
|
||||
[](napi_env env, void *data) {
|
||||
AsyncContext *asyncContext = (AsyncContext*)data;
|
||||
asyncContext->isOK = TimeServiceClient::GetInstance()->SetTime(asyncContext->time);
|
||||
},
|
||||
[](napi_env env, napi_status status, void* data) {
|
||||
AsyncContext* asyncContext = (AsyncContext*)data;
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
AsyncContext *asyncContext = (AsyncContext*)data;
|
||||
if (!asyncContext->isOK) {
|
||||
asyncContext->errorCode = ERROR;
|
||||
}
|
||||
@@ -214,7 +214,7 @@ napi_value ParseParametersBySetTimezone(const napi_env &env, const napi_value (&
|
||||
return TimeNapiGetNull(env);
|
||||
}
|
||||
|
||||
napi_value JSSystemTimeSetTimeZone(napi_env env, napi_callback_info info)
|
||||
napi_value JSSystemTimeSetTimeZone(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = SET_TIMEZONE_MAX_PARA;
|
||||
napi_value argv[SET_TIMEZONE_MAX_PARA] = {0};
|
||||
@@ -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);
|
||||
}
|
||||
@@ -236,12 +236,12 @@ napi_value JSSystemTimeSetTimeZone(napi_env env, napi_callback_info info)
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resource,
|
||||
[](napi_env env, void* data) {
|
||||
AsyncContext* asyncContext = (AsyncContext*)data;
|
||||
[](napi_env env, void *data) {
|
||||
AsyncContext *asyncContext = (AsyncContext*)data;
|
||||
asyncContext->isOK = TimeServiceClient::GetInstance()->SetTimeZone(asyncContext->timeZone);
|
||||
},
|
||||
[](napi_env env, napi_status status, void* data) {
|
||||
AsyncContext* asyncContext = (AsyncContext*)data;
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
AsyncContext *asyncContext = (AsyncContext*)data;
|
||||
if (!asyncContext->isOK) {
|
||||
asyncContext->errorCode = ERROR;
|
||||
}
|
||||
|
||||
@@ -198,9 +198,9 @@ void ITimerInfoInstance::OnTrigger()
|
||||
return;
|
||||
}
|
||||
|
||||
SetCallback(dataWorkerData->env,
|
||||
dataWorkerData->ref,
|
||||
NO_ERROR,
|
||||
SetCallback(dataWorkerData->env,
|
||||
dataWorkerData->ref,
|
||||
NO_ERROR,
|
||||
NapiGetNull(dataWorkerData->env));
|
||||
delete dataWorkerData;
|
||||
dataWorkerData = nullptr;
|
||||
|
||||
@@ -59,7 +59,7 @@ int32_t TimeServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mes
|
||||
}
|
||||
pid_t p = IPCSkeleton::GetCallingPid();
|
||||
pid_t p1 = IPCSkeleton::GetCallingUid();
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE,
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE,
|
||||
"CallingPid = %{public}d, CallingUid = %{public}d, code = %{public}u", p, p1, code);
|
||||
auto itFunc = memberFuncMap_.find(code);
|
||||
if (itFunc != memberFuncMap_.end()) {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
namespace {
|
||||
const int WANTAGENT_CODE_ELEVEN = 11;
|
||||
const int WANTAGENT_CODE_ELEVEN = 11;
|
||||
}
|
||||
std::mutex TimerCallback::instanceLock_;
|
||||
sptr<TimerCallback> TimerCallback::instance_;
|
||||
@@ -102,5 +102,5 @@ void TimerCallback::NotifyTimer(const uint64_t timerId)
|
||||
}
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "end.");
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
@@ -46,7 +46,7 @@ std::shared_ptr<TimerInfo> Batch::Get(size_t index) const
|
||||
}
|
||||
|
||||
bool Batch::CanHold(std::chrono::steady_clock::time_point whenElapsed,
|
||||
std::chrono::steady_clock::time_point maxWhen) const
|
||||
std::chrono::steady_clock::time_point maxWhen) const
|
||||
{
|
||||
return (end_ > whenElapsed) && (start_ <= maxWhen);
|
||||
}
|
||||
@@ -54,8 +54,8 @@ bool Batch::CanHold(std::chrono::steady_clock::time_point whenElapsed,
|
||||
bool Batch::Add(const std::shared_ptr<TimerInfo> &alarm)
|
||||
{
|
||||
bool new_start = false;
|
||||
auto it = std::upper_bound(alarms_.begin(),
|
||||
alarms_.end(),
|
||||
auto it = std::upper_bound(alarms_.begin(),
|
||||
alarms_.end(),
|
||||
alarm,
|
||||
[](const std::shared_ptr<TimerInfo> &first, const std::shared_ptr<TimerInfo> &second) {
|
||||
return first->whenElapsed < second->whenElapsed;
|
||||
@@ -116,10 +116,10 @@ bool Batch::Remove(std::function<bool (const TimerInfo &)> predicate)
|
||||
|
||||
bool Batch::HasPackage(const std::string &package_name)
|
||||
{
|
||||
return std::find_if(alarms_.begin(),
|
||||
return std::find_if(alarms_.begin(),
|
||||
alarms_.end(),
|
||||
[package_name] (const std::shared_ptr<TimerInfo> &alarm) {
|
||||
return alarm->Matches(package_name);
|
||||
[package_name] (const std::shared_ptr<TimerInfo> &alarm) {
|
||||
return alarm->Matches(package_name);
|
||||
}) != alarms_.end();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@ bool TimerInfo::Matches(const std::string &packageName) const
|
||||
}
|
||||
|
||||
TimerInfo::TimerInfo(uint64_t _id, int _type,
|
||||
std::chrono::milliseconds _when,
|
||||
std::chrono::steady_clock::time_point _whenElapsed,
|
||||
std::chrono::milliseconds _windowLength,
|
||||
std::chrono::steady_clock::time_point _maxWhen,
|
||||
std::chrono::milliseconds _interval,
|
||||
std::function<void(const uint64_t)> _callback,
|
||||
uint32_t _flags,
|
||||
uint64_t _uid)
|
||||
std::chrono::milliseconds _when,
|
||||
std::chrono::steady_clock::time_point _whenElapsed,
|
||||
std::chrono::milliseconds _windowLength,
|
||||
std::chrono::steady_clock::time_point _maxWhen,
|
||||
std::chrono::milliseconds _interval,
|
||||
std::function<void(const uint64_t)> _callback,
|
||||
uint32_t _flags,
|
||||
uint64_t _uid)
|
||||
: id {_id},
|
||||
type {_type},
|
||||
origWhen {_when},
|
||||
|
||||
@@ -63,14 +63,14 @@ TimerManager::TimerManager(std::shared_ptr<TimerHandler> impl)
|
||||
alarmThread_.reset(new std::thread(&TimerManager::TimerLooper, this));
|
||||
}
|
||||
|
||||
uint64_t TimerManager::CreateTimer(int type,
|
||||
uint64_t windowLength,
|
||||
uint64_t interval,
|
||||
uint64_t TimerManager::CreateTimer(int type,
|
||||
uint64_t windowLength,
|
||||
uint64_t interval,
|
||||
int flag,
|
||||
std::function<void (const uint64_t)> callback,
|
||||
std::function<void (const uint64_t)> callback,
|
||||
uint64_t uid)
|
||||
{
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE,
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE,
|
||||
"Create timer: %{public}d windowLength:%{public}" PRId64 "interval:%{public}" PRId64 "flag:%{public}d",
|
||||
type,
|
||||
windowLength,
|
||||
@@ -81,12 +81,12 @@ uint64_t TimerManager::CreateTimer(int type,
|
||||
timerNumber = random_();
|
||||
}
|
||||
auto timerInfo = std::make_shared<TimerEntry>(TimerEntry {
|
||||
timerNumber,
|
||||
timerNumber,
|
||||
type,
|
||||
windowLength,
|
||||
interval,
|
||||
flag,
|
||||
std::move(callback),
|
||||
windowLength,
|
||||
interval,
|
||||
flag,
|
||||
std::move(callback),
|
||||
uid
|
||||
});
|
||||
std::lock_guard<std::mutex> lock(entryMapMutex_);
|
||||
@@ -151,7 +151,7 @@ void TimerManager::SetHandler(uint64_t id,
|
||||
uint64_t windowLength,
|
||||
uint64_t interval,
|
||||
int flag,
|
||||
std::function<void (const uint64_t)> callback,
|
||||
std::function<void (const uint64_t)> callback,
|
||||
uint64_t uid)
|
||||
{
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "start id: %{public}" PRId64 "", id);
|
||||
@@ -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) {
|
||||
@@ -343,8 +343,8 @@ void TimerManager::TimerLooper()
|
||||
lastTimeChangeClockTime = lastTimeChangeClockTime_;
|
||||
expectedClockTime = lastTimeChangeClockTime + (duration_cast<milliseconds>(nowElapsed.time_since_epoch()) -
|
||||
duration_cast<milliseconds>(lastTimeChangeRealtime_.time_since_epoch()));
|
||||
if (lastTimeChangeClockTime == system_clock::time_point::min()
|
||||
|| nowRtc < (expectedClockTime - milliseconds(ONE_THOUSAND))
|
||||
if (lastTimeChangeClockTime == system_clock::time_point::min()
|
||||
|| nowRtc < (expectedClockTime - milliseconds(ONE_THOUSAND))
|
||||
|| nowRtc > (expectedClockTime + milliseconds(ONE_THOUSAND))) {
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "Time changed notification from kernel; rebatching");
|
||||
ReBatchAllTimers();
|
||||
@@ -399,7 +399,7 @@ bool TimerManager::TriggerTimersLocked(std::vector<std::shared_ptr<TimerInfo>> &
|
||||
alarm->count = 1;
|
||||
triggerList.push_back(alarm);
|
||||
if (alarm->repeatInterval > milliseconds::zero()) {
|
||||
alarm->count += duration_cast<milliseconds>(nowElapsed -
|
||||
alarm->count += duration_cast<milliseconds>(nowElapsed -
|
||||
alarm->expectedWhenElapsed) / alarm->repeatInterval;
|
||||
auto delta = alarm->count * alarm->repeatInterval;
|
||||
auto nextElapsed = alarm->whenElapsed + delta;
|
||||
@@ -412,7 +412,7 @@ bool TimerManager::TriggerTimersLocked(std::vector<std::shared_ptr<TimerInfo>> &
|
||||
}
|
||||
}
|
||||
}
|
||||
std::sort(triggerList.begin(),
|
||||
std::sort(triggerList.begin(),
|
||||
triggerList.end(),
|
||||
[] (const std::shared_ptr<TimerInfo> &l, const std::shared_ptr<TimerInfo> &r) {
|
||||
return l->whenElapsed < r->whenElapsed;
|
||||
@@ -508,19 +508,19 @@ void TimerManager::DeliverTimersLocked(const std::vector<std::shared_ptr<TimerIn
|
||||
bool AddBatchLocked(std::vector<std::shared_ptr<Batch>> &list, const std::shared_ptr<Batch> &newBatch)
|
||||
{
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "start");
|
||||
auto it = std::upper_bound(list.begin(),
|
||||
list.end(),
|
||||
auto it = std::upper_bound(list.begin(),
|
||||
list.end(),
|
||||
newBatch,
|
||||
[](const std::shared_ptr<Batch> &first, const std::shared_ptr<Batch> &second) {
|
||||
return first->GetStart() < second->GetStart();
|
||||
});
|
||||
return first->GetStart() < second->GetStart();
|
||||
});
|
||||
list.insert(it, newBatch);
|
||||
TIME_HILOGI(TIME_MODULE_SERVICE, "end");
|
||||
return it == list.begin();
|
||||
}
|
||||
|
||||
steady_clock::time_point MaxTriggerTime(steady_clock::time_point now,
|
||||
steady_clock::time_point triggerAtTime,
|
||||
steady_clock::time_point MaxTriggerTime(steady_clock::time_point now,
|
||||
steady_clock::time_point triggerAtTime,
|
||||
milliseconds interval)
|
||||
{
|
||||
milliseconds futurity = (interval == milliseconds::zero()) ?
|
||||
|
||||
Reference in New Issue
Block a user