• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef BASE_EVENTHANDLER_FRAMEWORKS_EVENTHANDLER_INCLUDE_EVENT_INNER_RUNNER_H
17 #define BASE_EVENTHANDLER_FRAMEWORKS_EVENTHANDLER_INCLUDE_EVENT_INNER_RUNNER_H
18 
19 #include "event_handler_utils.h"
20 #include "event_queue.h"
21 #include "event_runner.h"
22 #include "nocopyable.h"
23 #include "thread_local_data.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class EventInnerRunner {
28 public:
29     explicit EventInnerRunner(const std::shared_ptr<EventRunner> &runner);
30     virtual ~EventInnerRunner() = default;
31     DISALLOW_COPY_AND_MOVE(EventInnerRunner);
32 
33     static std::shared_ptr<EventRunner> GetCurrentEventRunner();
34 
35     virtual void Run() = 0;
36     virtual void Stop() = 0;
37 
GetEventQueue()38     const std::shared_ptr<EventQueue> &GetEventQueue() const
39     {
40         return queue_;
41     }
42 
SetLogger(const std::shared_ptr<Logger> & logger)43     void SetLogger(const std::shared_ptr<Logger> &logger)
44     {
45         logger_ = logger;
46     }
47 
GetThreadName()48     const std::string &GetThreadName()
49     {
50         return threadName_;
51     }
52 
GetThreadId()53     const std::thread::id &GetThreadId()
54     {
55         return threadId_;
56     }
57 
GetKernelThreadId()58     uint64_t GetKernelThreadId()
59     {
60         return kernelThreadId_;
61     }
62 
63 protected:
64     std::shared_ptr<EventQueue> queue_;
65     std::weak_ptr<EventRunner> owner_;
66     std::shared_ptr<Logger> logger_;
67     static ThreadLocalData<std::weak_ptr<EventRunner>> currentEventRunner;
68     std::string threadName_;
69     std::thread::id threadId_;
70     int64_t kernelThreadId_{0};
71 };
72 }  // namespace AppExecFwk
73 }  // namespace OHOS
74 
75 #endif  // #ifndef BASE_EVENTHANDLER_FRAMEWORKS_EVENTHANDLER_INCLUDE_EVENT_INNER_RUNNER_H
76