• 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 namespace OHOS {
24 class JsAppHost {
25 public:
26     JsAppHost();
27     ~JsAppHost();
28 
29     static void JsAppTaskHandler(uint32_t uwArg);
30 
SetMessageQueueId(const osMessageQueueId_t jsAppQueueId)31     void SetMessageQueueId(const osMessageQueueId_t jsAppQueueId)
32     {
33         jsAppQueueId_ = jsAppQueueId;
34         ACELite::JsAsyncWork::SetAppQueueHandler(reinterpret_cast<ACELite::QueueHandler>(jsAppQueueId));
35     }
36 
GetMessageQueueId()37     const osMessageQueueId_t &GetMessageQueueId() const
38     {
39         return jsAppQueueId_;
40     }
41 
42     void ForceDestroy() const;
43 
44 private:
45     void OnActive(uint16_t token, const char *bundleName, const char *path);
46     void OnBackground(uint16_t token);
47     void OnDestroy(uint16_t token);
48     void BackPressed();
49     void SendMsgToAbilityService(uint16_t token, int32_t id);
50     void HandleTickEvent();
51 
52     ACELite::JSAbility *jsAbility_ = nullptr;
53     osMessageQueueId_t jsAppQueueId_ = {nullptr};
54     bool isBackground_ = false;
55 };
56 } // namespace OHOS
57 #endif // OHOS_JS_APP_HOST_H
58