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 OHOS_ABILITY_SLITE_ABILITY_THREAD_H
17 #define OHOS_ABILITY_SLITE_ABILITY_THREAD_H
18 
19 #include <cstdint>
20 #include "cmsis_os2.h"
21 #include "los_task.h"
22 #include "slite_ability.h"
23 
24 extern "C" void LP_TaskBegin();
25 extern "C" void LP_TaskEnd();
26 
27 namespace OHOS {
28 namespace AbilitySlite {
29 constexpr char LAUNCHER_BUNDLE_NAME[] = "com.ohos.launcher";
30 class AbilityRecord;
31 
32 enum class AbilityThreadState : int8_t {
33     ABILITY_THREAD_UNINITIALIZED,
34     ABILITY_THREAD_INITIALIZED,
35     ABILITY_THREAD_RELEASED,
36 };
37 
38 class AbilityThread {
39 public:
40     AbilityThread();
41 
42     virtual ~AbilityThread();
43 
44     virtual int32_t InitAbilityThread(const AbilityRecord *abilityRecord) = 0;
45 
46     virtual int32_t ReleaseAbilityThread() = 0;
47 
48     virtual osMessageQueueId_t GetMessageQueueId() const = 0;
49 
50     virtual UINT32 GetAppTaskId() const = 0;
51 
52     virtual int32_t SendScheduleMsgToAbilityThread(SliteAbilityInnerMsg &innerMsg);
53 
54     int32_t HandleCreate(const Want *want);
55 
56     int32_t HandleRestore(AbilitySavedData *data);
57 
58     int32_t HandleForeground(const Want *want);
59 
60     int32_t HandleBackground();
61 
62     int32_t HandleSave(AbilitySavedData *data);
63 
64     int32_t HandleDestroy();
65 
66     SliteAbility *ability_ = nullptr;
67 protected:
68     AbilityThreadState state_ = AbilityThreadState::ABILITY_THREAD_UNINITIALIZED;
69 };
70 } // namespace AbilitySlite
71 } // namespace OHOS
72 
73 #endif //OHOS_ABILITY_SLITE_ABILITY_THREAD_H
74