1100ae2f9Sopenharmony_ci/* 2100ae2f9Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3100ae2f9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4100ae2f9Sopenharmony_ci * you may not use this file except in compliance with the License. 5100ae2f9Sopenharmony_ci * You may obtain a copy of the License at 6100ae2f9Sopenharmony_ci * 7100ae2f9Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8100ae2f9Sopenharmony_ci * 9100ae2f9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10100ae2f9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11100ae2f9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12100ae2f9Sopenharmony_ci * See the License for the specific language governing permissions and 13100ae2f9Sopenharmony_ci * limitations under the License. 14100ae2f9Sopenharmony_ci */ 15100ae2f9Sopenharmony_ci 16100ae2f9Sopenharmony_ci#ifndef BASE_EVENTHANDLER_INTERFACES_INNER_API_EVENT_HANDLER_H 17100ae2f9Sopenharmony_ci#define BASE_EVENTHANDLER_INTERFACES_INNER_API_EVENT_HANDLER_H 18100ae2f9Sopenharmony_ci 19100ae2f9Sopenharmony_ci#include "event_runner.h" 20100ae2f9Sopenharmony_ci#include "dumper.h" 21100ae2f9Sopenharmony_ci#include "inner_event.h" 22100ae2f9Sopenharmony_ci 23100ae2f9Sopenharmony_ci#ifndef __has_builtin 24100ae2f9Sopenharmony_ci#define __has_builtin(x) 0 25100ae2f9Sopenharmony_ci#endif 26100ae2f9Sopenharmony_ci 27100ae2f9Sopenharmony_cinamespace OHOS { 28100ae2f9Sopenharmony_cinamespace AppExecFwk { 29100ae2f9Sopenharmony_cienum class EventType { 30100ae2f9Sopenharmony_ci SYNC_EVENT = 0, 31100ae2f9Sopenharmony_ci DELAY_EVENT = 1, 32100ae2f9Sopenharmony_ci TIMING_EVENT = 2, 33100ae2f9Sopenharmony_ci}; 34100ae2f9Sopenharmony_ci 35100ae2f9Sopenharmony_citemplate<typename T> 36100ae2f9Sopenharmony_ciclass ThreadLocalData; 37100ae2f9Sopenharmony_ci 38100ae2f9Sopenharmony_cistruct TaskOptions { 39100ae2f9Sopenharmony_ci std::string dfxName_; 40100ae2f9Sopenharmony_ci int64_t delayTime_; 41100ae2f9Sopenharmony_ci EventQueue::Priority priority_; 42100ae2f9Sopenharmony_ci uintptr_t taskId_; 43100ae2f9Sopenharmony_ci TaskOptions(std::string dfxName, int64_t delayTime, EventQueue::Priority priority, uintptr_t taskId) 44100ae2f9Sopenharmony_ci : dfxName_(dfxName), delayTime_(delayTime), priority_(priority), taskId_(taskId) {} 45100ae2f9Sopenharmony_ci}; 46100ae2f9Sopenharmony_ci 47100ae2f9Sopenharmony_cistruct PendingTaskInfo { 48100ae2f9Sopenharmony_ci int32_t MaxPendingTime = 0; 49100ae2f9Sopenharmony_ci int32_t taskCount = 0; 50100ae2f9Sopenharmony_ci}; 51100ae2f9Sopenharmony_ciclass EventHandler : public std::enable_shared_from_this<EventHandler> { 52100ae2f9Sopenharmony_cipublic: 53100ae2f9Sopenharmony_ci using CallbackTimeout = std::function<void()>; 54100ae2f9Sopenharmony_ci using Callback = InnerEvent::Callback; 55100ae2f9Sopenharmony_ci using Priority = EventQueue::Priority; 56100ae2f9Sopenharmony_ci 57100ae2f9Sopenharmony_ci /** 58100ae2f9Sopenharmony_ci * Constructor, set 'EventRunner' automatically. 59100ae2f9Sopenharmony_ci * 60100ae2f9Sopenharmony_ci * @param runner The 'EventRunner'. 61100ae2f9Sopenharmony_ci */ 62100ae2f9Sopenharmony_ci explicit EventHandler(const std::shared_ptr<EventRunner> &runner = nullptr); 63100ae2f9Sopenharmony_ci virtual ~EventHandler(); 64100ae2f9Sopenharmony_ci DISALLOW_COPY_AND_MOVE(EventHandler); 65100ae2f9Sopenharmony_ci 66100ae2f9Sopenharmony_ci /** 67100ae2f9Sopenharmony_ci * Get event handler that running on current thread. 68100ae2f9Sopenharmony_ci * 69100ae2f9Sopenharmony_ci * @return Returns shared pointer of the current 'EventHandler'. 70100ae2f9Sopenharmony_ci */ 71100ae2f9Sopenharmony_ci static std::shared_ptr<EventHandler> Current(); 72100ae2f9Sopenharmony_ci 73100ae2f9Sopenharmony_ci /** 74100ae2f9Sopenharmony_ci * Send an event. 75100ae2f9Sopenharmony_ci * 76100ae2f9Sopenharmony_ci * @param event Event which should be handled. 77100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 78100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 79100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. If returns false, event should be released manually. 80100ae2f9Sopenharmony_ci */ 81100ae2f9Sopenharmony_ci bool SendEvent(InnerEvent::Pointer &event, int64_t delayTime = 0, Priority priority = Priority::LOW); 82100ae2f9Sopenharmony_ci 83100ae2f9Sopenharmony_ci /** 84100ae2f9Sopenharmony_ci * Send an event. 85100ae2f9Sopenharmony_ci * 86100ae2f9Sopenharmony_ci * @param event Event which should be handled. 87100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 88100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 89100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. If returns false, event should be released manually. 90100ae2f9Sopenharmony_ci */ 91100ae2f9Sopenharmony_ci bool SendTimingEvent(InnerEvent::Pointer &event, int64_t taskTime, Priority priority = Priority::LOW); 92100ae2f9Sopenharmony_ci 93100ae2f9Sopenharmony_ci /** 94100ae2f9Sopenharmony_ci * Send an event. 95100ae2f9Sopenharmony_ci * 96100ae2f9Sopenharmony_ci * @param event Event which should be handled. 97100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 98100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. If returns false, event should be released manually. 99100ae2f9Sopenharmony_ci */ 100100ae2f9Sopenharmony_ci inline bool SendEvent(InnerEvent::Pointer &event, Priority priority) 101100ae2f9Sopenharmony_ci { 102100ae2f9Sopenharmony_ci return SendEvent(event, 0, priority); 103100ae2f9Sopenharmony_ci } 104100ae2f9Sopenharmony_ci 105100ae2f9Sopenharmony_ci /** 106100ae2f9Sopenharmony_ci * Send an event. 107100ae2f9Sopenharmony_ci * 108100ae2f9Sopenharmony_ci * @param event Event which should be handled. 109100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 110100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 111100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 112100ae2f9Sopenharmony_ci */ 113100ae2f9Sopenharmony_ci inline bool SendEvent(InnerEvent::Pointer &&event, int64_t delayTime = 0, Priority priority = Priority::LOW) 114100ae2f9Sopenharmony_ci { 115100ae2f9Sopenharmony_ci return SendEvent(event, delayTime, priority); 116100ae2f9Sopenharmony_ci } 117100ae2f9Sopenharmony_ci 118100ae2f9Sopenharmony_ci /** 119100ae2f9Sopenharmony_ci * Send an event. 120100ae2f9Sopenharmony_ci * 121100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 122100ae2f9Sopenharmony_ci * @param param Basic parameter of the event, default is 0. 123100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 124100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 125100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 126100ae2f9Sopenharmony_ci */ 127100ae2f9Sopenharmony_ci inline bool SendEvent(uint32_t innerEventId, int64_t param, int64_t delayTime, const Caller &caller = {}) 128100ae2f9Sopenharmony_ci { 129100ae2f9Sopenharmony_ci return SendEvent(InnerEvent::Get(innerEventId, param, caller), delayTime); 130100ae2f9Sopenharmony_ci } 131100ae2f9Sopenharmony_ci 132100ae2f9Sopenharmony_ci /** 133100ae2f9Sopenharmony_ci * Send an event. 134100ae2f9Sopenharmony_ci * 135100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 136100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 137100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 138100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 139100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 140100ae2f9Sopenharmony_ci */ 141100ae2f9Sopenharmony_ci inline bool SendEvent(uint32_t innerEventId, int64_t delayTime = 0, 142100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 143100ae2f9Sopenharmony_ci { 144100ae2f9Sopenharmony_ci return SendEvent(InnerEvent::Get(innerEventId, 0, caller), delayTime, priority); 145100ae2f9Sopenharmony_ci } 146100ae2f9Sopenharmony_ci 147100ae2f9Sopenharmony_ci /** 148100ae2f9Sopenharmony_ci * Send an event. 149100ae2f9Sopenharmony_ci * 150100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 151100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 152100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 153100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 154100ae2f9Sopenharmony_ci */ 155100ae2f9Sopenharmony_ci inline bool SendEvent(uint32_t innerEventId, Priority priority, const Caller &caller = {}) 156100ae2f9Sopenharmony_ci { 157100ae2f9Sopenharmony_ci return SendEvent(InnerEvent::Get(innerEventId, 0, caller), 0, priority); 158100ae2f9Sopenharmony_ci } 159100ae2f9Sopenharmony_ci 160100ae2f9Sopenharmony_ci /** 161100ae2f9Sopenharmony_ci * Send an event. 162100ae2f9Sopenharmony_ci * 163100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 164100ae2f9Sopenharmony_ci * @param object Shared pointer of object. 165100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 166100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 167100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 168100ae2f9Sopenharmony_ci */ 169100ae2f9Sopenharmony_ci template<typename T> 170100ae2f9Sopenharmony_ci inline bool SendEvent(uint32_t innerEventId, const std::shared_ptr<T> &object, 171100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 172100ae2f9Sopenharmony_ci { 173100ae2f9Sopenharmony_ci return SendEvent(InnerEvent::Get(innerEventId, object, 0, caller), delayTime); 174100ae2f9Sopenharmony_ci } 175100ae2f9Sopenharmony_ci 176100ae2f9Sopenharmony_ci /** 177100ae2f9Sopenharmony_ci * Send an event. 178100ae2f9Sopenharmony_ci * 179100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 180100ae2f9Sopenharmony_ci * @param object Weak pointer of object. 181100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 182100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 183100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 184100ae2f9Sopenharmony_ci */ 185100ae2f9Sopenharmony_ci template<typename T> 186100ae2f9Sopenharmony_ci inline bool SendEvent(uint32_t innerEventId, const std::weak_ptr<T> &object, 187100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 188100ae2f9Sopenharmony_ci { 189100ae2f9Sopenharmony_ci return SendEvent(InnerEvent::Get(innerEventId, object, 0, caller), delayTime); 190100ae2f9Sopenharmony_ci } 191100ae2f9Sopenharmony_ci 192100ae2f9Sopenharmony_ci /** 193100ae2f9Sopenharmony_ci * Send an event. 194100ae2f9Sopenharmony_ci * 195100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 196100ae2f9Sopenharmony_ci * @param object Unique pointer of object. 197100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 198100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 199100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 200100ae2f9Sopenharmony_ci */ 201100ae2f9Sopenharmony_ci template<typename T, typename D> 202100ae2f9Sopenharmony_ci inline bool SendEvent(uint32_t innerEventId, std::unique_ptr<T, D> &object, 203100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 204100ae2f9Sopenharmony_ci { 205100ae2f9Sopenharmony_ci return SendEvent(InnerEvent::Get(innerEventId, object, 0, caller), delayTime); 206100ae2f9Sopenharmony_ci } 207100ae2f9Sopenharmony_ci 208100ae2f9Sopenharmony_ci /** 209100ae2f9Sopenharmony_ci * Send an event. 210100ae2f9Sopenharmony_ci * 211100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 212100ae2f9Sopenharmony_ci * @param object Unique pointer of object. 213100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 214100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 215100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 216100ae2f9Sopenharmony_ci */ 217100ae2f9Sopenharmony_ci template<typename T, typename D> 218100ae2f9Sopenharmony_ci inline bool SendEvent(uint32_t innerEventId, std::unique_ptr<T, D> &&object, 219100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 220100ae2f9Sopenharmony_ci { 221100ae2f9Sopenharmony_ci return SendEvent(InnerEvent::Get(innerEventId, object, 0, caller), delayTime); 222100ae2f9Sopenharmony_ci } 223100ae2f9Sopenharmony_ci 224100ae2f9Sopenharmony_ci /** 225100ae2f9Sopenharmony_ci * Send an immediate event. 226100ae2f9Sopenharmony_ci * 227100ae2f9Sopenharmony_ci * @param event Event which should be handled. 228100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 229100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 230100ae2f9Sopenharmony_ci */ 231100ae2f9Sopenharmony_ci inline bool SendImmediateEvent(InnerEvent::Pointer &event) 232100ae2f9Sopenharmony_ci { 233100ae2f9Sopenharmony_ci return SendEvent(event, 0, Priority::IMMEDIATE); 234100ae2f9Sopenharmony_ci } 235100ae2f9Sopenharmony_ci 236100ae2f9Sopenharmony_ci /** 237100ae2f9Sopenharmony_ci * Send an immediate event. 238100ae2f9Sopenharmony_ci * 239100ae2f9Sopenharmony_ci * @param event Event which should be handled. 240100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 241100ae2f9Sopenharmony_ci */ 242100ae2f9Sopenharmony_ci inline bool SendImmediateEvent(InnerEvent::Pointer &&event) 243100ae2f9Sopenharmony_ci { 244100ae2f9Sopenharmony_ci return SendImmediateEvent(event); 245100ae2f9Sopenharmony_ci } 246100ae2f9Sopenharmony_ci 247100ae2f9Sopenharmony_ci /** 248100ae2f9Sopenharmony_ci * Send an immediate event. 249100ae2f9Sopenharmony_ci * 250100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 251100ae2f9Sopenharmony_ci * @param param Basic parameter of the event, default is 0. 252100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 253100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 254100ae2f9Sopenharmony_ci */ 255100ae2f9Sopenharmony_ci inline bool SendImmediateEvent(uint32_t innerEventId, int64_t param = 0, const Caller &caller = {}) 256100ae2f9Sopenharmony_ci { 257100ae2f9Sopenharmony_ci return SendImmediateEvent(InnerEvent::Get(innerEventId, param, caller)); 258100ae2f9Sopenharmony_ci } 259100ae2f9Sopenharmony_ci 260100ae2f9Sopenharmony_ci /** 261100ae2f9Sopenharmony_ci * Send an immediate event. 262100ae2f9Sopenharmony_ci * 263100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 264100ae2f9Sopenharmony_ci * @param object Shared pointer of object. 265100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 266100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 267100ae2f9Sopenharmony_ci */ 268100ae2f9Sopenharmony_ci template<typename T> 269100ae2f9Sopenharmony_ci inline bool SendImmediateEvent(uint32_t innerEventId, const std::shared_ptr<T> &object, 270100ae2f9Sopenharmony_ci const Caller &caller = {}) 271100ae2f9Sopenharmony_ci { 272100ae2f9Sopenharmony_ci return SendImmediateEvent(InnerEvent::Get(innerEventId, object, 0, caller)); 273100ae2f9Sopenharmony_ci } 274100ae2f9Sopenharmony_ci 275100ae2f9Sopenharmony_ci /** 276100ae2f9Sopenharmony_ci * Send an immediate event. 277100ae2f9Sopenharmony_ci * 278100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 279100ae2f9Sopenharmony_ci * @param object Weak pointer of object. 280100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 281100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 282100ae2f9Sopenharmony_ci */ 283100ae2f9Sopenharmony_ci template<typename T> 284100ae2f9Sopenharmony_ci inline bool SendImmediateEvent(uint32_t innerEventId, const std::weak_ptr<T> &object, 285100ae2f9Sopenharmony_ci const Caller &caller = {}) 286100ae2f9Sopenharmony_ci { 287100ae2f9Sopenharmony_ci return SendImmediateEvent(InnerEvent::Get(innerEventId, object, 0, caller)); 288100ae2f9Sopenharmony_ci } 289100ae2f9Sopenharmony_ci 290100ae2f9Sopenharmony_ci /** 291100ae2f9Sopenharmony_ci * Send an immediate event. 292100ae2f9Sopenharmony_ci * 293100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 294100ae2f9Sopenharmony_ci * @param object Unique pointer of object. 295100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 296100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 297100ae2f9Sopenharmony_ci */ 298100ae2f9Sopenharmony_ci template<typename T, typename D> 299100ae2f9Sopenharmony_ci inline bool SendImmediateEvent(uint32_t innerEventId, std::unique_ptr<T, D> &object, 300100ae2f9Sopenharmony_ci const Caller &caller = {}) 301100ae2f9Sopenharmony_ci { 302100ae2f9Sopenharmony_ci return SendImmediateEvent(InnerEvent::Get(innerEventId, object, 0, caller)); 303100ae2f9Sopenharmony_ci } 304100ae2f9Sopenharmony_ci 305100ae2f9Sopenharmony_ci /** 306100ae2f9Sopenharmony_ci * Send an immediate event. 307100ae2f9Sopenharmony_ci * 308100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 309100ae2f9Sopenharmony_ci * @param object Unique pointer of object. 310100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 311100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 312100ae2f9Sopenharmony_ci */ 313100ae2f9Sopenharmony_ci template<typename T, typename D> 314100ae2f9Sopenharmony_ci inline bool SendImmediateEvent(uint32_t innerEventId, std::unique_ptr<T, D> &&object, 315100ae2f9Sopenharmony_ci const Caller &caller = {}) 316100ae2f9Sopenharmony_ci { 317100ae2f9Sopenharmony_ci return SendImmediateEvent(InnerEvent::Get(innerEventId, object, 0, caller)); 318100ae2f9Sopenharmony_ci } 319100ae2f9Sopenharmony_ci 320100ae2f9Sopenharmony_ci /** 321100ae2f9Sopenharmony_ci * Send an high priority event. 322100ae2f9Sopenharmony_ci * 323100ae2f9Sopenharmony_ci * @param event Event which should be handled. 324100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 325100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 326100ae2f9Sopenharmony_ci */ 327100ae2f9Sopenharmony_ci inline bool SendHighPriorityEvent(InnerEvent::Pointer &event, int64_t delayTime = 0) 328100ae2f9Sopenharmony_ci { 329100ae2f9Sopenharmony_ci return SendEvent(event, delayTime, Priority::HIGH); 330100ae2f9Sopenharmony_ci } 331100ae2f9Sopenharmony_ci 332100ae2f9Sopenharmony_ci /** 333100ae2f9Sopenharmony_ci * Send an high priority event. 334100ae2f9Sopenharmony_ci * 335100ae2f9Sopenharmony_ci * @param event Event which should be handled. 336100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 337100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 338100ae2f9Sopenharmony_ci */ 339100ae2f9Sopenharmony_ci inline bool SendHighPriorityEvent(InnerEvent::Pointer &&event, int64_t delayTime = 0) 340100ae2f9Sopenharmony_ci { 341100ae2f9Sopenharmony_ci return SendHighPriorityEvent(event, delayTime); 342100ae2f9Sopenharmony_ci } 343100ae2f9Sopenharmony_ci 344100ae2f9Sopenharmony_ci /** 345100ae2f9Sopenharmony_ci * Send an high priority event. 346100ae2f9Sopenharmony_ci * 347100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 348100ae2f9Sopenharmony_ci * @param param Basic parameter of the event, default is 0. 349100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 350100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 351100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 352100ae2f9Sopenharmony_ci */ 353100ae2f9Sopenharmony_ci inline bool SendHighPriorityEvent(uint32_t innerEventId, int64_t param = 0, 354100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 355100ae2f9Sopenharmony_ci { 356100ae2f9Sopenharmony_ci return SendHighPriorityEvent(InnerEvent::Get(innerEventId, param, caller), delayTime); 357100ae2f9Sopenharmony_ci } 358100ae2f9Sopenharmony_ci 359100ae2f9Sopenharmony_ci /** 360100ae2f9Sopenharmony_ci * Send an high priority event. 361100ae2f9Sopenharmony_ci * 362100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 363100ae2f9Sopenharmony_ci * @param object Shared pointer of object. 364100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 365100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 366100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 367100ae2f9Sopenharmony_ci */ 368100ae2f9Sopenharmony_ci template<typename T> 369100ae2f9Sopenharmony_ci inline bool SendHighPriorityEvent(uint32_t innerEventId, const std::shared_ptr<T> &object, 370100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 371100ae2f9Sopenharmony_ci { 372100ae2f9Sopenharmony_ci return SendHighPriorityEvent(InnerEvent::Get(innerEventId, object, 0, caller), delayTime); 373100ae2f9Sopenharmony_ci } 374100ae2f9Sopenharmony_ci 375100ae2f9Sopenharmony_ci /** 376100ae2f9Sopenharmony_ci * Send an high priority event. 377100ae2f9Sopenharmony_ci * 378100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 379100ae2f9Sopenharmony_ci * @param object Weak pointer of object. 380100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 381100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 382100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 383100ae2f9Sopenharmony_ci */ 384100ae2f9Sopenharmony_ci template<typename T> 385100ae2f9Sopenharmony_ci inline bool SendHighPriorityEvent(uint32_t innerEventId, const std::weak_ptr<T> &object, 386100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 387100ae2f9Sopenharmony_ci { 388100ae2f9Sopenharmony_ci return SendHighPriorityEvent(InnerEvent::Get(innerEventId, object, 0, caller), delayTime); 389100ae2f9Sopenharmony_ci } 390100ae2f9Sopenharmony_ci 391100ae2f9Sopenharmony_ci /** 392100ae2f9Sopenharmony_ci * Send an high priority event. 393100ae2f9Sopenharmony_ci * 394100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 395100ae2f9Sopenharmony_ci * @param object Unique pointer of object. 396100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 397100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 398100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 399100ae2f9Sopenharmony_ci */ 400100ae2f9Sopenharmony_ci template<typename T, typename D> 401100ae2f9Sopenharmony_ci inline bool SendHighPriorityEvent(uint32_t innerEventId, std::unique_ptr<T, D> &object, 402100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 403100ae2f9Sopenharmony_ci { 404100ae2f9Sopenharmony_ci return SendHighPriorityEvent(InnerEvent::Get(innerEventId, object, 0, caller), delayTime); 405100ae2f9Sopenharmony_ci } 406100ae2f9Sopenharmony_ci 407100ae2f9Sopenharmony_ci /** 408100ae2f9Sopenharmony_ci * Send an high priority event. 409100ae2f9Sopenharmony_ci * 410100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 411100ae2f9Sopenharmony_ci * @param object Unique pointer of object. 412100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 413100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 414100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 415100ae2f9Sopenharmony_ci */ 416100ae2f9Sopenharmony_ci template<typename T, typename D> 417100ae2f9Sopenharmony_ci inline bool SendHighPriorityEvent(uint32_t innerEventId, std::unique_ptr<T, D> &&object, 418100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 419100ae2f9Sopenharmony_ci { 420100ae2f9Sopenharmony_ci return SendHighPriorityEvent(InnerEvent::Get(innerEventId, object, 0, caller), delayTime); 421100ae2f9Sopenharmony_ci } 422100ae2f9Sopenharmony_ci 423100ae2f9Sopenharmony_ci /** 424100ae2f9Sopenharmony_ci * Post a task. 425100ae2f9Sopenharmony_ci * 426100ae2f9Sopenharmony_ci * @param callback Task callback. 427100ae2f9Sopenharmony_ci * @param name Name of the task. 428100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 429100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 430100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 431100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 432100ae2f9Sopenharmony_ci */ 433100ae2f9Sopenharmony_ci inline bool PostTask(const Callback &callback, const std::string &name = std::string(), 434100ae2f9Sopenharmony_ci int64_t delayTime = 0, Priority priority = Priority::LOW, const Caller &caller = {}) 435100ae2f9Sopenharmony_ci { 436100ae2f9Sopenharmony_ci return SendEvent(InnerEvent::Get(callback, name, caller), delayTime, priority); 437100ae2f9Sopenharmony_ci } 438100ae2f9Sopenharmony_ci 439100ae2f9Sopenharmony_ci /** 440100ae2f9Sopenharmony_ci * Post a task at front of queue. 441100ae2f9Sopenharmony_ci * 442100ae2f9Sopenharmony_ci * @param callback Task callback. 443100ae2f9Sopenharmony_ci * @param name Name of the task. 444100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 445100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 446100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 447100ae2f9Sopenharmony_ci */ 448100ae2f9Sopenharmony_ci bool PostTaskAtFront(const Callback &callback, const std::string &name = std::string(), 449100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}); 450100ae2f9Sopenharmony_ci 451100ae2f9Sopenharmony_ci /** 452100ae2f9Sopenharmony_ci * Set delivery time out callback. 453100ae2f9Sopenharmony_ci * 454100ae2f9Sopenharmony_ci * @param callback Delivery Time out callback. 455100ae2f9Sopenharmony_ci */ 456100ae2f9Sopenharmony_ci void SetDeliveryTimeoutCallback(const Callback &callback) 457100ae2f9Sopenharmony_ci { 458100ae2f9Sopenharmony_ci deliveryTimeoutCallback_ = callback; 459100ae2f9Sopenharmony_ci } 460100ae2f9Sopenharmony_ci 461100ae2f9Sopenharmony_ci /** 462100ae2f9Sopenharmony_ci * Set distribute time out callback. 463100ae2f9Sopenharmony_ci * 464100ae2f9Sopenharmony_ci * @param callback Distribute Time out callback. 465100ae2f9Sopenharmony_ci */ 466100ae2f9Sopenharmony_ci void SetDistributeTimeoutCallback(const Callback &callback) 467100ae2f9Sopenharmony_ci { 468100ae2f9Sopenharmony_ci distributeTimeoutCallback_ = callback; 469100ae2f9Sopenharmony_ci } 470100ae2f9Sopenharmony_ci 471100ae2f9Sopenharmony_ci /** 472100ae2f9Sopenharmony_ci * Post a task. 473100ae2f9Sopenharmony_ci * 474100ae2f9Sopenharmony_ci * @param callback Task callback. 475100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 476100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 477100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 478100ae2f9Sopenharmony_ci */ 479100ae2f9Sopenharmony_ci inline bool PostTask(const Callback &callback, Priority priority, const Caller &caller = {}) 480100ae2f9Sopenharmony_ci { 481100ae2f9Sopenharmony_ci return PostTask(callback, std::string(), 0, priority, caller); 482100ae2f9Sopenharmony_ci } 483100ae2f9Sopenharmony_ci 484100ae2f9Sopenharmony_ci /** 485100ae2f9Sopenharmony_ci * Post a task. 486100ae2f9Sopenharmony_ci * 487100ae2f9Sopenharmony_ci * @param callback Task callback. 488100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 489100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 490100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 491100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 492100ae2f9Sopenharmony_ci */ 493100ae2f9Sopenharmony_ci inline bool PostTask(const Callback &callback, int64_t delayTime, Priority priority = Priority::LOW, 494100ae2f9Sopenharmony_ci const Caller &caller = {}) 495100ae2f9Sopenharmony_ci { 496100ae2f9Sopenharmony_ci return PostTask(callback, std::string(), delayTime, priority, caller); 497100ae2f9Sopenharmony_ci } 498100ae2f9Sopenharmony_ci 499100ae2f9Sopenharmony_ci /** 500100ae2f9Sopenharmony_ci * Post an immediate task. 501100ae2f9Sopenharmony_ci * 502100ae2f9Sopenharmony_ci * @param callback Task callback. 503100ae2f9Sopenharmony_ci * @param name Remove events by name of the task. 504100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 505100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 506100ae2f9Sopenharmony_ci */ 507100ae2f9Sopenharmony_ci inline bool PostImmediateTask(const Callback &callback, const std::string &name = std::string(), 508100ae2f9Sopenharmony_ci const Caller &caller = {}) 509100ae2f9Sopenharmony_ci { 510100ae2f9Sopenharmony_ci return SendEvent(InnerEvent::Get(callback, name, caller), 0, Priority::IMMEDIATE); 511100ae2f9Sopenharmony_ci } 512100ae2f9Sopenharmony_ci 513100ae2f9Sopenharmony_ci /** 514100ae2f9Sopenharmony_ci * Post a high priority task. 515100ae2f9Sopenharmony_ci * 516100ae2f9Sopenharmony_ci * @param callback Task callback. 517100ae2f9Sopenharmony_ci * @param name Name of the task. 518100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 519100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 520100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 521100ae2f9Sopenharmony_ci */ 522100ae2f9Sopenharmony_ci inline bool PostHighPriorityTask(const Callback &callback, const std::string &name = std::string(), 523100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 524100ae2f9Sopenharmony_ci { 525100ae2f9Sopenharmony_ci return PostTask(callback, name, delayTime, Priority::HIGH, caller); 526100ae2f9Sopenharmony_ci } 527100ae2f9Sopenharmony_ci 528100ae2f9Sopenharmony_ci /** 529100ae2f9Sopenharmony_ci * Post a high priority task. 530100ae2f9Sopenharmony_ci * 531100ae2f9Sopenharmony_ci * @param callback Task callback. 532100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 533100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 534100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 535100ae2f9Sopenharmony_ci */ 536100ae2f9Sopenharmony_ci inline bool PostHighPriorityTask(const Callback &callback, int64_t delayTime, const Caller &caller = {}) 537100ae2f9Sopenharmony_ci { 538100ae2f9Sopenharmony_ci return PostHighPriorityTask(callback, std::string(), delayTime, caller); 539100ae2f9Sopenharmony_ci } 540100ae2f9Sopenharmony_ci 541100ae2f9Sopenharmony_ci /** 542100ae2f9Sopenharmony_ci * Post a idle task. 543100ae2f9Sopenharmony_ci * 544100ae2f9Sopenharmony_ci * @param callback task callback. 545100ae2f9Sopenharmony_ci * @param name Name of the task. 546100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 547100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 548100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 549100ae2f9Sopenharmony_ci */ 550100ae2f9Sopenharmony_ci inline bool PostIdleTask(const Callback &callback, const std::string &name = std::string(), 551100ae2f9Sopenharmony_ci int64_t delayTime = 0, const Caller &caller = {}) 552100ae2f9Sopenharmony_ci { 553100ae2f9Sopenharmony_ci return PostTask(callback, name, delayTime, Priority::IDLE, caller); 554100ae2f9Sopenharmony_ci } 555100ae2f9Sopenharmony_ci 556100ae2f9Sopenharmony_ci /** 557100ae2f9Sopenharmony_ci * Post a idle task. 558100ae2f9Sopenharmony_ci * 559100ae2f9Sopenharmony_ci * @param callback Task callback. 560100ae2f9Sopenharmony_ci * @param delayTime Process the event after 'delayTime' milliseconds. 561100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 562100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 563100ae2f9Sopenharmony_ci */ 564100ae2f9Sopenharmony_ci inline bool PostIdleTask(const Callback &callback, int64_t delayTime, const Caller &caller = {}) 565100ae2f9Sopenharmony_ci { 566100ae2f9Sopenharmony_ci return PostIdleTask(callback, std::string(), delayTime, caller); 567100ae2f9Sopenharmony_ci } 568100ae2f9Sopenharmony_ci 569100ae2f9Sopenharmony_ci /** 570100ae2f9Sopenharmony_ci * Send an event, and wait until this event has been handled. 571100ae2f9Sopenharmony_ci * 572100ae2f9Sopenharmony_ci * @param event Event which should be handled. 573100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. 574100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. If returns false, event should be released manually. 575100ae2f9Sopenharmony_ci */ 576100ae2f9Sopenharmony_ci bool SendSyncEvent(InnerEvent::Pointer &event, Priority priority = Priority::LOW); 577100ae2f9Sopenharmony_ci 578100ae2f9Sopenharmony_ci /** 579100ae2f9Sopenharmony_ci * Send an event. 580100ae2f9Sopenharmony_ci * 581100ae2f9Sopenharmony_ci * @param event Event which should be handled. 582100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 583100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. 584100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 585100ae2f9Sopenharmony_ci */ 586100ae2f9Sopenharmony_ci inline bool SendSyncEvent(InnerEvent::Pointer &&event, Priority priority = Priority::LOW) 587100ae2f9Sopenharmony_ci { 588100ae2f9Sopenharmony_ci return SendSyncEvent(event, priority); 589100ae2f9Sopenharmony_ci } 590100ae2f9Sopenharmony_ci 591100ae2f9Sopenharmony_ci /** 592100ae2f9Sopenharmony_ci * Send an event, and wait until this event has been handled. 593100ae2f9Sopenharmony_ci * 594100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 595100ae2f9Sopenharmony_ci * @param param Basic parameter of the event, default is 0. 596100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. 597100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 598100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 599100ae2f9Sopenharmony_ci */ 600100ae2f9Sopenharmony_ci inline bool SendSyncEvent(uint32_t innerEventId, int64_t param = 0, 601100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 602100ae2f9Sopenharmony_ci { 603100ae2f9Sopenharmony_ci return SendSyncEvent(InnerEvent::Get(innerEventId, param, caller), priority); 604100ae2f9Sopenharmony_ci } 605100ae2f9Sopenharmony_ci 606100ae2f9Sopenharmony_ci /** 607100ae2f9Sopenharmony_ci * Send an event, and wait until this event has been handled. 608100ae2f9Sopenharmony_ci * 609100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 610100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. 611100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 612100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 613100ae2f9Sopenharmony_ci */ 614100ae2f9Sopenharmony_ci inline bool SendSyncEvent(uint32_t innerEventId, Priority priority, const Caller &caller = {}) 615100ae2f9Sopenharmony_ci { 616100ae2f9Sopenharmony_ci return SendSyncEvent(InnerEvent::Get(innerEventId, 0, caller), priority); 617100ae2f9Sopenharmony_ci } 618100ae2f9Sopenharmony_ci 619100ae2f9Sopenharmony_ci /** 620100ae2f9Sopenharmony_ci * Send an event, and wait until this event has been handled. 621100ae2f9Sopenharmony_ci * 622100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 623100ae2f9Sopenharmony_ci * @param object Shared pointer of object. 624100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. 625100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 626100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 627100ae2f9Sopenharmony_ci */ 628100ae2f9Sopenharmony_ci template<typename T> 629100ae2f9Sopenharmony_ci inline bool SendSyncEvent(uint32_t innerEventId, const std::shared_ptr<T> &object, 630100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 631100ae2f9Sopenharmony_ci { 632100ae2f9Sopenharmony_ci return SendSyncEvent(InnerEvent::Get(innerEventId, object, 0, caller), priority); 633100ae2f9Sopenharmony_ci } 634100ae2f9Sopenharmony_ci 635100ae2f9Sopenharmony_ci /** 636100ae2f9Sopenharmony_ci * Send an event, and wait until this event has been handled. 637100ae2f9Sopenharmony_ci * 638100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 639100ae2f9Sopenharmony_ci * @param object Weak pointer of object. 640100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. 641100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 642100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 643100ae2f9Sopenharmony_ci */ 644100ae2f9Sopenharmony_ci template<typename T> 645100ae2f9Sopenharmony_ci inline bool SendSyncEvent(uint32_t innerEventId, const std::weak_ptr<T> &object, 646100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 647100ae2f9Sopenharmony_ci { 648100ae2f9Sopenharmony_ci return SendSyncEvent(InnerEvent::Get(innerEventId, object, 0, caller), priority); 649100ae2f9Sopenharmony_ci } 650100ae2f9Sopenharmony_ci 651100ae2f9Sopenharmony_ci /** 652100ae2f9Sopenharmony_ci * Send an event, and wait until this event has been handled. 653100ae2f9Sopenharmony_ci * 654100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 655100ae2f9Sopenharmony_ci * @param object Unique pointer of object. 656100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. 657100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 658100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 659100ae2f9Sopenharmony_ci */ 660100ae2f9Sopenharmony_ci template<typename T, typename D> 661100ae2f9Sopenharmony_ci inline bool SendSyncEvent(uint32_t innerEventId, std::unique_ptr<T, D> &object, 662100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 663100ae2f9Sopenharmony_ci { 664100ae2f9Sopenharmony_ci return SendSyncEvent(InnerEvent::Get(innerEventId, object, 0, caller), priority); 665100ae2f9Sopenharmony_ci } 666100ae2f9Sopenharmony_ci 667100ae2f9Sopenharmony_ci /** 668100ae2f9Sopenharmony_ci * Send an event, and wait until this event has been handled. 669100ae2f9Sopenharmony_ci * 670100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 671100ae2f9Sopenharmony_ci * @param object Unique pointer of object. 672100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. 673100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 674100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 675100ae2f9Sopenharmony_ci */ 676100ae2f9Sopenharmony_ci template<typename T, typename D> 677100ae2f9Sopenharmony_ci inline bool SendSyncEvent(uint32_t innerEventId, std::unique_ptr<T, D> &&object, 678100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 679100ae2f9Sopenharmony_ci { 680100ae2f9Sopenharmony_ci return SendSyncEvent(InnerEvent::Get(innerEventId, object, 0, caller), priority); 681100ae2f9Sopenharmony_ci } 682100ae2f9Sopenharmony_ci 683100ae2f9Sopenharmony_ci /** 684100ae2f9Sopenharmony_ci * Post a task, and wait until this task has been handled. 685100ae2f9Sopenharmony_ci * 686100ae2f9Sopenharmony_ci * @param callback Task callback. 687100ae2f9Sopenharmony_ci * @param name Name of the task. 688100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. 689100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 690100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 691100ae2f9Sopenharmony_ci */ 692100ae2f9Sopenharmony_ci inline bool PostSyncTask(const Callback &callback, const std::string &name, 693100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 694100ae2f9Sopenharmony_ci { 695100ae2f9Sopenharmony_ci return SendSyncEvent(InnerEvent::Get(callback, name, caller), priority); 696100ae2f9Sopenharmony_ci } 697100ae2f9Sopenharmony_ci 698100ae2f9Sopenharmony_ci /** 699100ae2f9Sopenharmony_ci * Post a task, and wait until this task has been handled. 700100ae2f9Sopenharmony_ci * 701100ae2f9Sopenharmony_ci * @param callback Task callback. 702100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event, IDLE is not permitted for sync event. 703100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 704100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 705100ae2f9Sopenharmony_ci */ 706100ae2f9Sopenharmony_ci inline bool PostSyncTask(const Callback &callback, Priority priority = Priority::LOW, 707100ae2f9Sopenharmony_ci const Caller &caller = {}) 708100ae2f9Sopenharmony_ci { 709100ae2f9Sopenharmony_ci return PostSyncTask(callback, std::string(), priority, caller); 710100ae2f9Sopenharmony_ci } 711100ae2f9Sopenharmony_ci 712100ae2f9Sopenharmony_ci /** 713100ae2f9Sopenharmony_ci * Send a timing event. 714100ae2f9Sopenharmony_ci * 715100ae2f9Sopenharmony_ci * @param event Event which should be handled. 716100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 717100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 718100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 719100ae2f9Sopenharmony_ci */ 720100ae2f9Sopenharmony_ci inline bool SendTimingEvent(InnerEvent::Pointer &&event, int64_t taskTime, Priority priority) 721100ae2f9Sopenharmony_ci { 722100ae2f9Sopenharmony_ci return SendTimingEvent(event, taskTime, priority); 723100ae2f9Sopenharmony_ci } 724100ae2f9Sopenharmony_ci 725100ae2f9Sopenharmony_ci /** 726100ae2f9Sopenharmony_ci * Send a timing event. 727100ae2f9Sopenharmony_ci * 728100ae2f9Sopenharmony_ci * @param event Event which should be handled. 729100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 730100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 731100ae2f9Sopenharmony_ci */ 732100ae2f9Sopenharmony_ci inline bool SendTimingEvent(InnerEvent::Pointer &&event, int64_t taskTime) 733100ae2f9Sopenharmony_ci { 734100ae2f9Sopenharmony_ci return SendTimingEvent(event, taskTime, Priority::LOW); 735100ae2f9Sopenharmony_ci } 736100ae2f9Sopenharmony_ci 737100ae2f9Sopenharmony_ci /** 738100ae2f9Sopenharmony_ci * Send a timing event. 739100ae2f9Sopenharmony_ci * 740100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 741100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 742100ae2f9Sopenharmony_ci * @param param Basic parameter of the event. 743100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 744100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 745100ae2f9Sopenharmony_ci */ 746100ae2f9Sopenharmony_ci inline bool SendTimingEvent(uint32_t innerEventId, int64_t taskTime, int64_t param, 747100ae2f9Sopenharmony_ci const Caller &caller = {}) 748100ae2f9Sopenharmony_ci { 749100ae2f9Sopenharmony_ci return SendTimingEvent(InnerEvent::Get(innerEventId, param, caller), taskTime); 750100ae2f9Sopenharmony_ci } 751100ae2f9Sopenharmony_ci 752100ae2f9Sopenharmony_ci /** 753100ae2f9Sopenharmony_ci * Send a timing event. 754100ae2f9Sopenharmony_ci * 755100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 756100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 757100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 758100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 759100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 760100ae2f9Sopenharmony_ci */ 761100ae2f9Sopenharmony_ci inline bool SendTimingEvent(uint32_t innerEventId, int64_t taskTime, Priority priority, 762100ae2f9Sopenharmony_ci const Caller &caller = {}) 763100ae2f9Sopenharmony_ci { 764100ae2f9Sopenharmony_ci return SendTimingEvent(InnerEvent::Get(innerEventId, 0, caller), taskTime, priority); 765100ae2f9Sopenharmony_ci } 766100ae2f9Sopenharmony_ci 767100ae2f9Sopenharmony_ci /** 768100ae2f9Sopenharmony_ci * Send a timing event. 769100ae2f9Sopenharmony_ci * 770100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 771100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 772100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 773100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 774100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 775100ae2f9Sopenharmony_ci */ 776100ae2f9Sopenharmony_ci inline bool SendTimingEvent(uint32_t innerEventId, int64_t taskTime, const Caller &caller = {}) 777100ae2f9Sopenharmony_ci { 778100ae2f9Sopenharmony_ci return SendTimingEvent(InnerEvent::Get(innerEventId, 0, caller), taskTime, Priority::LOW); 779100ae2f9Sopenharmony_ci } 780100ae2f9Sopenharmony_ci 781100ae2f9Sopenharmony_ci /** 782100ae2f9Sopenharmony_ci * Send a timing event. 783100ae2f9Sopenharmony_ci * 784100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 785100ae2f9Sopenharmony_ci * @param object Shared pointer of object. 786100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 787100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event 788100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 789100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 790100ae2f9Sopenharmony_ci */ 791100ae2f9Sopenharmony_ci template<typename T> 792100ae2f9Sopenharmony_ci inline bool SendTimingEvent(uint32_t innerEventId, const std::shared_ptr<T> &object, int64_t taskTime, 793100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 794100ae2f9Sopenharmony_ci { 795100ae2f9Sopenharmony_ci return SendTimingEvent(InnerEvent::Get(innerEventId, object, 0, caller), taskTime, priority); 796100ae2f9Sopenharmony_ci } 797100ae2f9Sopenharmony_ci 798100ae2f9Sopenharmony_ci /** 799100ae2f9Sopenharmony_ci * Send a timing event. 800100ae2f9Sopenharmony_ci * 801100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 802100ae2f9Sopenharmony_ci * @param object Weak pointer of object. 803100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 804100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event 805100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 806100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 807100ae2f9Sopenharmony_ci */ 808100ae2f9Sopenharmony_ci template<typename T> 809100ae2f9Sopenharmony_ci inline bool SendTimingEvent(uint32_t innerEventId, const std::weak_ptr<T> &object, int64_t taskTime, 810100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 811100ae2f9Sopenharmony_ci { 812100ae2f9Sopenharmony_ci return SendTimingEvent(InnerEvent::Get(innerEventId, object, 0, caller), taskTime, priority); 813100ae2f9Sopenharmony_ci } 814100ae2f9Sopenharmony_ci 815100ae2f9Sopenharmony_ci /** 816100ae2f9Sopenharmony_ci * Send a timing event. 817100ae2f9Sopenharmony_ci * 818100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 819100ae2f9Sopenharmony_ci * @param object Unique pointer of object. 820100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 821100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event 822100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 823100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 824100ae2f9Sopenharmony_ci */ 825100ae2f9Sopenharmony_ci template<typename T, typename D> 826100ae2f9Sopenharmony_ci inline bool SendTimingEvent(uint32_t innerEventId, std::unique_ptr<T, D> &object, int64_t taskTime, 827100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 828100ae2f9Sopenharmony_ci { 829100ae2f9Sopenharmony_ci return SendTimingEvent(InnerEvent::Get(innerEventId, object, 0, caller), taskTime, priority); 830100ae2f9Sopenharmony_ci } 831100ae2f9Sopenharmony_ci 832100ae2f9Sopenharmony_ci /** 833100ae2f9Sopenharmony_ci * Send a timing event. 834100ae2f9Sopenharmony_ci * 835100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 836100ae2f9Sopenharmony_ci * @param object Unique pointer of object. 837100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 838100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event 839100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 840100ae2f9Sopenharmony_ci * @return Returns true if event has been sent successfully. 841100ae2f9Sopenharmony_ci */ 842100ae2f9Sopenharmony_ci template<typename T, typename D> 843100ae2f9Sopenharmony_ci inline bool SendTimingEvent(uint32_t innerEventId, std::unique_ptr<T, D> &&object, int64_t taskTime, 844100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 845100ae2f9Sopenharmony_ci { 846100ae2f9Sopenharmony_ci return SendTimingEvent(InnerEvent::Get(innerEventId, object, 0, caller), taskTime, priority); 847100ae2f9Sopenharmony_ci } 848100ae2f9Sopenharmony_ci 849100ae2f9Sopenharmony_ci /** 850100ae2f9Sopenharmony_ci * Post a timing task. 851100ae2f9Sopenharmony_ci * 852100ae2f9Sopenharmony_ci * @param callback Task callback. 853100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 854100ae2f9Sopenharmony_ci * @param name Name of the task. 855100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 856100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 857100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 858100ae2f9Sopenharmony_ci */ 859100ae2f9Sopenharmony_ci inline bool PostTimingTask(const Callback &callback, int64_t taskTime, const std::string &name = std::string(), 860100ae2f9Sopenharmony_ci Priority priority = Priority::LOW, const Caller &caller = {}) 861100ae2f9Sopenharmony_ci { 862100ae2f9Sopenharmony_ci return SendTimingEvent(InnerEvent::Get(callback, name, caller), taskTime, priority); 863100ae2f9Sopenharmony_ci } 864100ae2f9Sopenharmony_ci 865100ae2f9Sopenharmony_ci /** 866100ae2f9Sopenharmony_ci * Post a timing task. 867100ae2f9Sopenharmony_ci * 868100ae2f9Sopenharmony_ci * @param callback Task callback. 869100ae2f9Sopenharmony_ci * @param taskTime Process the event at taskTime. 870100ae2f9Sopenharmony_ci * @param priority Priority of the event queue for this event. 871100ae2f9Sopenharmony_ci * @param caller Caller info of the event, default is caller's file, func and line. 872100ae2f9Sopenharmony_ci * @return Returns true if task has been sent successfully. 873100ae2f9Sopenharmony_ci */ 874100ae2f9Sopenharmony_ci inline bool PostTimingTask(const Callback &callback, int64_t taskTime, Priority priority = Priority::LOW, 875100ae2f9Sopenharmony_ci const Caller &caller = {}) 876100ae2f9Sopenharmony_ci { 877100ae2f9Sopenharmony_ci return PostTimingTask(callback, taskTime, std::string(), priority, caller); 878100ae2f9Sopenharmony_ci } 879100ae2f9Sopenharmony_ci 880100ae2f9Sopenharmony_ci /** 881100ae2f9Sopenharmony_ci * Remove all sent events. 882100ae2f9Sopenharmony_ci */ 883100ae2f9Sopenharmony_ci void RemoveAllEvents(); 884100ae2f9Sopenharmony_ci 885100ae2f9Sopenharmony_ci /** 886100ae2f9Sopenharmony_ci * Remove sent events. 887100ae2f9Sopenharmony_ci * 888100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 889100ae2f9Sopenharmony_ci */ 890100ae2f9Sopenharmony_ci void RemoveEvent(uint32_t innerEventId); 891100ae2f9Sopenharmony_ci 892100ae2f9Sopenharmony_ci /** 893100ae2f9Sopenharmony_ci * Remove sent events. 894100ae2f9Sopenharmony_ci * 895100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 896100ae2f9Sopenharmony_ci * @param param Basic parameter of the event. 897100ae2f9Sopenharmony_ci */ 898100ae2f9Sopenharmony_ci void RemoveEvent(uint32_t innerEventId, int64_t param); 899100ae2f9Sopenharmony_ci 900100ae2f9Sopenharmony_ci /** 901100ae2f9Sopenharmony_ci * Remove a task. 902100ae2f9Sopenharmony_ci * 903100ae2f9Sopenharmony_ci * @param name Name of the task. 904100ae2f9Sopenharmony_ci */ 905100ae2f9Sopenharmony_ci void RemoveTask(const std::string &name); 906100ae2f9Sopenharmony_ci 907100ae2f9Sopenharmony_ci /** 908100ae2f9Sopenharmony_ci * Remove a task. 909100ae2f9Sopenharmony_ci * 910100ae2f9Sopenharmony_ci * @param name Name of the task. 911100ae2f9Sopenharmony_ci */ 912100ae2f9Sopenharmony_ci int RemoveTaskWithRet(const std::string &name); 913100ae2f9Sopenharmony_ci 914100ae2f9Sopenharmony_ci /** 915100ae2f9Sopenharmony_ci * Add file descriptor listener for a file descriptor. 916100ae2f9Sopenharmony_ci * 917100ae2f9Sopenharmony_ci * @param fileDescriptor File descriptor. 918100ae2f9Sopenharmony_ci * @param events Events from file descriptor, such as input, output, error 919100ae2f9Sopenharmony_ci * @param listener Listener callback. 920100ae2f9Sopenharmony_ci * @return Return 'ERR_OK' on success. 921100ae2f9Sopenharmony_ci */ 922100ae2f9Sopenharmony_ci ErrCode AddFileDescriptorListener(int32_t fileDescriptor, uint32_t events, 923100ae2f9Sopenharmony_ci const std::shared_ptr<FileDescriptorListener> &listener, const std::string &taskName); 924100ae2f9Sopenharmony_ci 925100ae2f9Sopenharmony_ci /** 926100ae2f9Sopenharmony_ci * Add file descriptor listener for a file descriptor. 927100ae2f9Sopenharmony_ci * 928100ae2f9Sopenharmony_ci * @param fileDescriptor File descriptor. 929100ae2f9Sopenharmony_ci * @param events Events from file descriptor, such as input, output, error 930100ae2f9Sopenharmony_ci * @param listener Listener callback. 931100ae2f9Sopenharmony_ci * @param priority Priority of the for file descriptor. 932100ae2f9Sopenharmony_ci * @return Return 'ERR_OK' on success. 933100ae2f9Sopenharmony_ci */ 934100ae2f9Sopenharmony_ci ErrCode AddFileDescriptorListener(int32_t fileDescriptor, uint32_t events, 935100ae2f9Sopenharmony_ci const std::shared_ptr<FileDescriptorListener> &listener, const std::string &taskName, 936100ae2f9Sopenharmony_ci EventQueue::Priority priority); 937100ae2f9Sopenharmony_ci 938100ae2f9Sopenharmony_ci /** 939100ae2f9Sopenharmony_ci * Remove all file descriptor listeners. 940100ae2f9Sopenharmony_ci */ 941100ae2f9Sopenharmony_ci void RemoveAllFileDescriptorListeners(); 942100ae2f9Sopenharmony_ci 943100ae2f9Sopenharmony_ci /** 944100ae2f9Sopenharmony_ci * Remove file descriptor listener for a file descriptor. 945100ae2f9Sopenharmony_ci * 946100ae2f9Sopenharmony_ci * @param fileDescriptor File descriptor. 947100ae2f9Sopenharmony_ci */ 948100ae2f9Sopenharmony_ci void RemoveFileDescriptorListener(int32_t fileDescriptor); 949100ae2f9Sopenharmony_ci 950100ae2f9Sopenharmony_ci /** 951100ae2f9Sopenharmony_ci * Set the 'EventRunner' to the 'EventHandler'. 952100ae2f9Sopenharmony_ci * 953100ae2f9Sopenharmony_ci * @param runner The 'EventRunner'. 954100ae2f9Sopenharmony_ci */ 955100ae2f9Sopenharmony_ci void SetEventRunner(const std::shared_ptr<EventRunner> &runner); 956100ae2f9Sopenharmony_ci 957100ae2f9Sopenharmony_ci /** 958100ae2f9Sopenharmony_ci * Get the 'EventRunner' of the 'EventHandler'. 959100ae2f9Sopenharmony_ci * 960100ae2f9Sopenharmony_ci * @return Return the 'EventRunner'. 961100ae2f9Sopenharmony_ci */ 962100ae2f9Sopenharmony_ci inline const std::shared_ptr<EventRunner> &GetEventRunner() const 963100ae2f9Sopenharmony_ci { 964100ae2f9Sopenharmony_ci return eventRunner_; 965100ae2f9Sopenharmony_ci } 966100ae2f9Sopenharmony_ci 967100ae2f9Sopenharmony_ci /** 968100ae2f9Sopenharmony_ci * Distribute time out handler. 969100ae2f9Sopenharmony_ci * 970100ae2f9Sopenharmony_ci * @param beginTime Dotting before distribution. 971100ae2f9Sopenharmony_ci */ 972100ae2f9Sopenharmony_ci void DistributeTimeoutHandler(const InnerEvent::TimePoint& beginTime); 973100ae2f9Sopenharmony_ci 974100ae2f9Sopenharmony_ci /** 975100ae2f9Sopenharmony_ci * Distribute the event. 976100ae2f9Sopenharmony_ci * 977100ae2f9Sopenharmony_ci * @param event The event should be distributed. 978100ae2f9Sopenharmony_ci */ 979100ae2f9Sopenharmony_ci void DistributeEvent(const InnerEvent::Pointer &event); 980100ae2f9Sopenharmony_ci 981100ae2f9Sopenharmony_ci /** 982100ae2f9Sopenharmony_ci * Distribute time out action. 983100ae2f9Sopenharmony_ci * 984100ae2f9Sopenharmony_ci * @param event The event should be distribute. 985100ae2f9Sopenharmony_ci * @param nowStart Dotting before distribution. 986100ae2f9Sopenharmony_ci */ 987100ae2f9Sopenharmony_ci void DistributeTimeAction(const InnerEvent::Pointer &event, InnerEvent::TimePoint nowStart); 988100ae2f9Sopenharmony_ci 989100ae2f9Sopenharmony_ci /** 990100ae2f9Sopenharmony_ci * Delivery time out action. 991100ae2f9Sopenharmony_ci * 992100ae2f9Sopenharmony_ci * @param event The event should be distribute. 993100ae2f9Sopenharmony_ci * @param nowStart Dotting before distribution. 994100ae2f9Sopenharmony_ci */ 995100ae2f9Sopenharmony_ci void DeliveryTimeAction(const InnerEvent::Pointer &event, InnerEvent::TimePoint nowStart); 996100ae2f9Sopenharmony_ci 997100ae2f9Sopenharmony_ci /** 998100ae2f9Sopenharmony_ci * Print out the internal information about an object in the specified format, 999100ae2f9Sopenharmony_ci * helping you diagnose internal errors of the object. 1000100ae2f9Sopenharmony_ci * 1001100ae2f9Sopenharmony_ci * @param dumpr The Dumper object you have implemented to process the output internal information. 1002100ae2f9Sopenharmony_ci */ 1003100ae2f9Sopenharmony_ci void Dump(Dumper &dumper); 1004100ae2f9Sopenharmony_ci 1005100ae2f9Sopenharmony_ci /** 1006100ae2f9Sopenharmony_ci * Check whether an event with the given ID can be found among the events that have been sent but not processed. 1007100ae2f9Sopenharmony_ci * 1008100ae2f9Sopenharmony_ci * @param innerEventId The id of the event. 1009100ae2f9Sopenharmony_ci */ 1010100ae2f9Sopenharmony_ci bool HasInnerEvent(uint32_t innerEventId); 1011100ae2f9Sopenharmony_ci 1012100ae2f9Sopenharmony_ci /** 1013100ae2f9Sopenharmony_ci * Check whether an event carrying the given param can be found among the events that have been sent but not 1014100ae2f9Sopenharmony_ci * processed. 1015100ae2f9Sopenharmony_ci * 1016100ae2f9Sopenharmony_ci * @param param Basic parameter of the event. 1017100ae2f9Sopenharmony_ci */ 1018100ae2f9Sopenharmony_ci bool HasInnerEvent(int64_t param); 1019100ae2f9Sopenharmony_ci 1020100ae2f9Sopenharmony_ci /** 1021100ae2f9Sopenharmony_ci * Check whether an event carrying the given param can be found among the events that have been sent but not 1022100ae2f9Sopenharmony_ci * processed. 1023100ae2f9Sopenharmony_ci * 1024100ae2f9Sopenharmony_ci * @param event InnerEvent whose name is to be obtained. 1025100ae2f9Sopenharmony_ci * @return Returns the task name if the given event contains a specific task; returns the event ID otherwise. 1026100ae2f9Sopenharmony_ci */ 1027100ae2f9Sopenharmony_ci std::string GetEventName(const InnerEvent::Pointer &event); 1028100ae2f9Sopenharmony_ci 1029100ae2f9Sopenharmony_ci /** 1030100ae2f9Sopenharmony_ci * Check whether there are events which priority higher than basePrio in subevent queue. 1031100ae2f9Sopenharmony_ci * 1032100ae2f9Sopenharmony_ci * @param basePrio base priority 1033100ae2f9Sopenharmony_ci * @return Return true if there are higher priority events, ohtherwise return false. 1034100ae2f9Sopenharmony_ci */ 1035100ae2f9Sopenharmony_ci bool HasPreferEvent(int basePrio); 1036100ae2f9Sopenharmony_ci 1037100ae2f9Sopenharmony_ci /** 1038100ae2f9Sopenharmony_ci * Checks whether the current event handler is idle 1039100ae2f9Sopenharmony_ci * @return Returns true if current event handler is idle otherwise return false. 1040100ae2f9Sopenharmony_ci */ 1041100ae2f9Sopenharmony_ci bool IsIdle(); 1042100ae2f9Sopenharmony_ci 1043100ae2f9Sopenharmony_ci /** 1044100ae2f9Sopenharmony_ci * @param enableEventLog dump event log handle time. 1045100ae2f9Sopenharmony_ci */ 1046100ae2f9Sopenharmony_ci void EnableEventLog(bool enableEventLog = false); 1047100ae2f9Sopenharmony_ci 1048100ae2f9Sopenharmony_ci /** 1049100ae2f9Sopenharmony_ci * Get handler id, only for inner use 1050100ae2f9Sopenharmony_ci */ 1051100ae2f9Sopenharmony_ci inline std::string GetHandlerId() 1052100ae2f9Sopenharmony_ci { 1053100ae2f9Sopenharmony_ci return handlerId_; 1054100ae2f9Sopenharmony_ci } 1055100ae2f9Sopenharmony_ci 1056100ae2f9Sopenharmony_ci /** 1057100ae2f9Sopenharmony_ci * Get pending task info 1058100ae2f9Sopenharmony_ci */ 1059100ae2f9Sopenharmony_ci PendingTaskInfo QueryPendingTaskInfo(int32_t fileDescriptor); 1060100ae2f9Sopenharmony_ci 1061100ae2f9Sopenharmony_ci /** 1062100ae2f9Sopenharmony_ci * queue_cancel_and_wait 1063100ae2f9Sopenharmony_ci */ 1064100ae2f9Sopenharmony_ci void TaskCancelAndWait(); 1065100ae2f9Sopenharmony_ci 1066100ae2f9Sopenharmony_ciprotected: 1067100ae2f9Sopenharmony_ci /** 1068100ae2f9Sopenharmony_ci * Process the event. Developers should override this method. 1069100ae2f9Sopenharmony_ci * 1070100ae2f9Sopenharmony_ci * @param event The event should be processed. 1071100ae2f9Sopenharmony_ci */ 1072100ae2f9Sopenharmony_ci virtual void ProcessEvent(const InnerEvent::Pointer &event); 1073100ae2f9Sopenharmony_ci 1074100ae2f9Sopenharmony_ciprivate: 1075100ae2f9Sopenharmony_ci std::string handlerId_; 1076100ae2f9Sopenharmony_ci bool enableEventLog_ {false}; 1077100ae2f9Sopenharmony_ci std::shared_ptr<EventRunner> eventRunner_; 1078100ae2f9Sopenharmony_ci CallbackTimeout deliveryTimeoutCallback_; 1079100ae2f9Sopenharmony_ci CallbackTimeout distributeTimeoutCallback_; 1080100ae2f9Sopenharmony_ci static thread_local std::weak_ptr<EventHandler> currentEventHandler; 1081100ae2f9Sopenharmony_ci}; 1082100ae2f9Sopenharmony_ci} // namespace AppExecFwk 1083100ae2f9Sopenharmony_cinamespace EventHandling = AppExecFwk; 1084100ae2f9Sopenharmony_ci} // namespace OHOS 1085100ae2f9Sopenharmony_ci 1086100ae2f9Sopenharmony_ci#endif // #ifndef BASE_EVENTHANDLER_INTERFACES_INNER_API_EVENT_HANDLER_H 1087