• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_MONITOR_OBJECT_H
17 #define OHOS_ABILITY_RUNTIME_CJ_ABILITY_MONITOR_OBJECT_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 
23 #include "cj_macro.h"
24 
25 extern "C" {
26 struct CJMonitorFuncs {
27     void (*cjOnAbilityCreate)(int64_t monitorId, int64_t abilityId);
28     void (*cjOnAbilityForeground)(int64_t monitorId, int64_t abilityId);
29     void (*cjOnAbilityBackground)(int64_t monitorId, int64_t abilityId);
30     void (*cjOnAbilityDestroy)(int64_t monitorId, int64_t abilityId);
31     void (*cjOnWindowStageCreate)(int64_t monitorId, int64_t abilityId);
32     void (*cjOnWindowStageRestore)(int64_t monitorId, int64_t abilityId);
33     void (*cjOnWindowStageDestroy)(int64_t monitorId, int64_t abilityId);
34 };
35 
36 CJ_EXPORT void RegisterCJMonitorFuncs(void (*registerFunc)(CJMonitorFuncs*));
37 }
38 namespace OHOS {
39 namespace AbilityDelegatorCJ {
40 class CJMonitorObject {
41 public:
42     /**
43      * A constructor used to create a CJMonitorObject instance with the input
44      * parameter passed.
45      */
46     explicit CJMonitorObject(const int64_t monitorId);
47     /**
48      * Default deconstructor used to deconstruct.
49      */
50     ~CJMonitorObject() = default;
51 
52     /**
53      * Called when ability is started.
54      * Then call the corresponding method on the js side through the saved js
55      * object.
56      *
57      * @param abilityId Indicates the ability object.
58      */
59     void OnAbilityCreate(const int64_t abilityId);
60 
61     /**
62      * Called when ability is in foreground.
63      * Then call the corresponding method on the js side through the saved js
64      * object.
65      *
66      * @param abilityId Indicates the ability object.
67      */
68     void OnAbilityForeground(const int64_t abilityId);
69 
70     /**
71      * Called when ability is in background.
72      * Then call the corresponding method on the js side through the saved js
73      * object.
74      *
75      * @param abilityId Indicates the ability object.
76      */
77     void OnAbilityBackground(const int64_t abilityId);
78 
79     /**
80      * Called when ability is stopped.
81      * Then call the corresponding method on the js side through the saved js
82      * object.
83      *
84      * @param abilityId Indicates the ability object.
85      */
86     void OnAbilityDestroy(const int64_t abilityId);
87 
88     /**
89      * Called when window stage is created.
90      * Then call the corresponding method on the js side through the saved js
91      * object.
92      *
93      * @param abilityId Indicates the ability object.
94      */
95     void OnWindowStageCreate(const int64_t abilityId);
96 
97     /**
98      * Called when window stage is restored.
99      * Then call the corresponding method on the js side through the saved js
100      * object.
101      *
102      * @param abilityId Indicates the ability object.
103      */
104     void OnWindowStageRestore(const int64_t abilityId);
105 
106     /**
107      * Called when window stage is destroyed.
108      * Then call the corresponding method on the js side through the saved js
109      * object.
110      *
111      * @param abilityId Indicates the ability object.
112      */
113     void OnWindowStageDestroy(const int64_t abilityId);
114 
GetId()115     int64_t GetId()
116     {
117         return monitorId_;
118     }
119 
120 private:
121     int64_t monitorId_;
122 };
123 } // namespace AbilityDelegatorCJ
124 } // namespace OHOS
125 #endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_MONITOR_H