• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 class JsAppImpl : public JsApp {
27 public:
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     static const uint8_t FONT_SIZE_DEFAULT = 30;
38 
39 private:
40     std::atomic<bool> isInterrupt;
41     const long TASK_HANDLE_TIMER_INTERVAL = 15;
42     const long DEVICE_CHECK_TIMER_INTERVAL = 100;
43     const long JS_CHECK_TIMER_INTERVAL = 1000;
44     std::unique_ptr<CppTimer> taskHandleTimer;
45     std::unique_ptr<CppTimer> deviceCheckTimer;
46     std::unique_ptr<CppTimer> jsCheckTimer;
47     std::unique_ptr<OHOS::ACELite::JSAbility> jsAbility;
48     std::unique_ptr<std::thread> jsThread;
49 
50     void ThreadCallBack();
51     void InitTimer();
52     void StartJsApp();
53 };
54 
55 #endif // JSAPPIMPL_H
56