xref: /ide/tools/previewer/jsapp/lite/JsAppImpl.h (revision 7c804472)
1/*
2 * Copyright (c) 2023 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 JSAPPIMPL_H
17#define JSAPPIMPL_H
18
19#include <atomic>
20#include <thread>
21
22#include "CppTimer.h"
23#include "JsApp.h"
24#include "js_ability.h"
25
26class JsAppImpl : public JsApp {
27public:
28    JsAppImpl();
29    virtual ~JsAppImpl();
30    JsAppImpl& operator=(const JsAppImpl&) = delete;
31    JsAppImpl(const JsAppImpl&) = delete;
32
33    static JsAppImpl& GetInstance();
34    void Start() override;
35    void Restart() override;
36    void Interrupt() override;
37    void InitJsApp() override;
38    static const uint8_t FONT_SIZE_DEFAULT = 30;
39
40private:
41    std::atomic<bool> isInterrupt;
42    const long TASK_HANDLE_TIMER_INTERVAL = 15;
43    const long DEVICE_CHECK_TIMER_INTERVAL = 100;
44    const long JS_CHECK_TIMER_INTERVAL = 1000;
45    std::unique_ptr<CppTimer> taskHandleTimer;
46    std::unique_ptr<CppTimer> deviceCheckTimer;
47    std::unique_ptr<CppTimer> jsCheckTimer;
48    std::unique_ptr<OHOS::ACELite::JSAbility> jsAbility;
49    std::unique_ptr<std::thread> jsThread;
50
51    void ThreadCallBack();
52    void InitTimer();
53    void StartJsApp();
54};
55
56#endif // JSAPPIMPL_H
57