• 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_JS_FEATURE_ABILITY_H
17 #define OHOS_ABILITY_RUNTIME_JS_FEATURE_ABILITY_H
18 
19 #include "ability.h"
20 #include "distribute_req_param.h"
21 #include "native_engine/native_engine.h"
22 #include "want.h"
23 #include "uri.h"
24 
25 class NativeEngine;
26 class NativeValue;
27 
28 namespace OHOS {
29 namespace AbilityRuntime {
30 using namespace OHOS::AppExecFwk;
31 
32 class JsFeatureAbility final {
33 public:
34     JsFeatureAbility() = default;
35     ~JsFeatureAbility() = default;
36 
37     static void Finalizer(NativeEngine* engine, void* data, void* hint);
38     static NativeValue* CreateJsFeatureAbility(NativeEngine &engine);
39     static NativeValue* StartAbility(NativeEngine* engine, NativeCallbackInfo* info);
40     static NativeValue* StartAbilityForResult(NativeEngine* engine, NativeCallbackInfo* info);
41     static NativeValue* FinishWithResult(NativeEngine* engine, NativeCallbackInfo* info);
42     static NativeValue* GetDeviceList(NativeEngine* engine, NativeCallbackInfo* info);
43     static NativeValue* CallAbility(NativeEngine* engine, NativeCallbackInfo* info);
44     static NativeValue* ContinueAbility(NativeEngine* engine, NativeCallbackInfo* info);
45     static NativeValue* SubscribeAbilityEvent(NativeEngine* engine, NativeCallbackInfo* info);
46     static NativeValue* UnsubscribeAbilityEvent(NativeEngine* engine, NativeCallbackInfo* info);
47     static NativeValue* SendMsg(NativeEngine* engine, NativeCallbackInfo* info);
48     static NativeValue* SubscribeMsg(NativeEngine* engine, NativeCallbackInfo* info);
49     static NativeValue* UnsubscribeMsg(NativeEngine* engine, NativeCallbackInfo* info);
50 private:
51     Ability* GetAbility(napi_env env);
52     Want GetWant(DistributeReqParam &requestParam);
53     bool CheckThenGetDeepLinkUri(const DistributeReqParam &requestParam, Uri &uri);
54     bool UnWrapRequestParams(napi_env env, napi_value param, DistributeReqParam &requestParam);
55     static NativeValue* CreateJsResult(NativeEngine &engine, int32_t errCode, const std::string &message);
56     void GetExtraParams(DistributeReqParam &requestParam, Want &want);
57     NativeValue* OnStartAbility(NativeEngine &engine, NativeCallbackInfo &info);
58     NativeValue* OnStartAbilityForResult(NativeEngine &engine, NativeCallbackInfo &info);
59     NativeValue* OnFinishWithResult(NativeEngine &engine, NativeCallbackInfo &info);
60     NativeValue* OnGetDeviceList(NativeEngine &engine, NativeCallbackInfo &info);
61     NativeValue* OnCallAbility(NativeEngine &engine, NativeCallbackInfo &info);
62     NativeValue* OnContinueAbility(NativeEngine &engine, NativeCallbackInfo &info);
63     NativeValue* OnSubscribeAbilityEvent(NativeEngine &engine, NativeCallbackInfo &info);
64     NativeValue* OnUnsubscribeAbilityEvent(NativeEngine &engine, NativeCallbackInfo &info);
65     NativeValue* OnSendMsg(NativeEngine &engine, NativeCallbackInfo &info);
66     NativeValue* OnSubscribeMsg(NativeEngine &engine, NativeCallbackInfo &info);
67     NativeValue* OnUnsubscribeMsg(NativeEngine &engine, NativeCallbackInfo &info);
68 
69     int requestCode_ = 0;
70 };
71 
72 NativeValue* JsFeatureAbilityInit(NativeEngine* engine, NativeValue* exports);
73 }  // namespace AbilityRuntime
74 }  // namespace OHOS
75 #endif  // OHOS_ABILITY_RUNTIME_JS_FEATURE_ABILITY_H
76