• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 OHOS_ACELITE_MOCK_TIMER_THREAD_H
17 #define OHOS_ACELITE_MOCK_TIMER_THREAD_H
18 
19 #include <QList>
20 #include <QMutex>
21 #include <QThread>
22 #include <QWaitCondition>
23 
24 #include "nativeapi_timer_task.h"
25 
26 namespace OHOS {
27 namespace ACELite {
28 struct TimerInfo {
29     bool isPeriodic = false;
30     int32_t delay = 0;
31     void *userCallback = nullptr;
32     void *userData = nullptr;
33     timerHandle_t *timerHandle = nullptr;
34     int32_t remain = 0;
35 };
36 
37 class TimerThread : public QThread {
38 public:
TimerThread()39     TimerThread() {}
~TimerThread()40     virtual ~TimerThread() {}
41     void run() override;
42     void Quit();
43     int StartTimerTaskInner(bool isPeriodic,
44                             const unsigned int delay,
45                             void *userCallback,
46                             void *userData,
47                             timerHandle_t *timerHandle);
48     int StopTimerTaskInner(const timerHandle_t timerHandle);
49 
50 private:
51     void Traverse();
52     QList<const TimerInfo *> timerList_;
53     QWaitCondition queueCondition_;
54     QMutex mutexlock_;
55     volatile bool taskQuitFlag = false;
56 };
57 } // namespace ACELite
58 } // namespace OHOS
59 #endif // OHOS_ACELITE_MOCK_TIMER_THREAD_H
60