• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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_JS_APP_HOST_H
17 #define OHOS_JS_APP_HOST_H
18 
19 #include "cmsis_os2.h"
20 #include "js_ability.h"
21 #include "js_async_work.h"
22 
23 extern "C" void LP_TaskBegin();
24 extern "C" void LP_TaskEnd();
25 
26 namespace OHOS {
27 class JsAppHost {
28 public:
29     JsAppHost();
30     ~JsAppHost();
31 
32     static void JsAppTaskHandler(uint32_t uwArg);
33 
SetMessageQueueId(const osMessageQueueId_t jsAppQueueId)34     void SetMessageQueueId(const osMessageQueueId_t jsAppQueueId)
35     {
36         jsAppQueueId_ = jsAppQueueId;
37         ACELite::JsAsyncWork::SetAppQueueHandler(reinterpret_cast<ACELite::QueueHandler>(jsAppQueueId));
38     }
39 
GetMessageQueueId()40     const osMessageQueueId_t &GetMessageQueueId() const
41     {
42         return jsAppQueueId_;
43     }
44 
45     void ForceDestroy() const;
46 
47 private:
48     void OnActive(uint16_t token, const char *bundleName, const char *path);
49     void OnBackground(uint16_t token);
50     void OnDestroy(uint16_t token);
51     void BackPressed();
52     void SendMsgToAbilityService(uint16_t token, int32_t id);
53     void HandleTickEvent();
54 
55     ACELite::JSAbility *jsAbility_ = nullptr;
56     osMessageQueueId_t jsAppQueueId_ = {nullptr};
57     bool isBackground_ = false;
58 };
59 } // namespace OHOS
60 #endif // OHOS_JS_APP_HOST_H
61