1 /*
2  * Copyright (c) 2024 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_RUNTIME_CJ_ABILITY_STAGE_OBJECT_H
17 #define OHOS_ABILITY_RUNTIME_CJ_ABILITY_STAGE_OBJECT_H
18 
19 #include <memory>
20 
21 #include "configuration.h"
22 #include "want.h"
23 
24 #ifdef WINDOWS_PLATFORM
25 #define CJ_EXPORT __declspec(dllexport)
26 #else
27 #define CJ_EXPORT __attribute__((visibility("default")))
28 #endif
29 
30 using AbilityStageHandle = void*;
31 
32 extern "C" {
33 struct CJConfiguration {
34     int32_t colorMode;
35     int32_t direction;
36     int32_t displayId;
37     int32_t screenDensity;
38     bool isValid;
39     const char* language;
40 };
41 
42 struct CJAbilityStageFuncs {
43     int64_t (*LoadAbilityStage)(const char* moduleName);
44     void (*ReleaseAbilityStage)(int64_t handle);
45     void (*AbilityStageOnCreate)(int64_t handle);
46     char* (*AbilityStageOnAcceptWant)(int64_t handle, OHOS::AAFwk::Want* want);
47     void (*AbilityStageOnConfigurationUpdated)(int64_t id, CJConfiguration configuration);
48     void (*AbilityStageOnMemoryLevel)(int64_t id, int32_t level);
49     void (*AbilityStageInit)(int64_t id, void* abilityStage);
50 };
51 
52 CJ_EXPORT void RegisterCJAbilityStageFuncs(void (*registerFunc)(CJAbilityStageFuncs* result));
53 }
54 
55 namespace OHOS {
56 namespace AbilityRuntime {
57 class CJAbilityStageObject {
58 public:
59     static std::shared_ptr<CJAbilityStageObject> LoadModule(const std::string& moduleName);
60 
CJAbilityStageObject(int64_t id)61     explicit CJAbilityStageObject(int64_t id) : id_(id) {}
62     ~CJAbilityStageObject();
63 
64     void Init(AbilityStageHandle abilityStage) const;
65     void OnCreate() const;
66     std::string OnAcceptWant(const AAFwk::Want& want) const;
67     void OnConfigurationUpdated(const std::shared_ptr<AppExecFwk::Configuration>& configuration) const;
68     void OnMemoryLevel(int32_t level) const;
69 
70 private:
71     int64_t id_;
72 };
73 } // namespace AbilityRuntime
74 } // namespace OHOS
75 
76 #endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_STAGE_OBJECT_H
77