• 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 #include "want_wrap_ohos.h"
17 
18 #include "base/log/log_wrapper.h"
19 #include "base/utils/utils.h"
20 #include "napi_common_want.h"
21 
22 namespace OHOS::Ace {
CreateWantWrap(NativeEngine * engine,NativeValue * value)23 RefPtr<WantParamsWrap> WantParamsWrap::CreateWantWrap(NativeEngine* engine, NativeValue* value)
24 {
25     return AceType::MakeRefPtr<WantParamsWrapOhos>(engine, value);
26 }
WantParamsWrapOhos(NativeEngine * engine,NativeValue * value)27 WantParamsWrapOhos::WantParamsWrapOhos(NativeEngine* engine, NativeValue* value)
28 {
29     AppExecFwk::UnwrapWantParams(
30         reinterpret_cast<napi_env>(engine), reinterpret_cast<napi_value>(value), params_);
31 }
32 
ConvertToNativeValue(const OHOS::AAFwk::Want & want,NativeEngine * engine)33 NativeValue* WantWrap::ConvertToNativeValue(const OHOS::AAFwk::Want& want, NativeEngine* engine)
34 {
35     return reinterpret_cast<NativeValue*>(OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(engine), want));
36 }
37 
ConvertParamsToNativeValue(const OHOS::AAFwk::WantParams & wantParams,NativeEngine * engine)38 NativeValue* WantWrap::ConvertParamsToNativeValue(const OHOS::AAFwk::WantParams& wantParams, NativeEngine* engine)
39 {
40     return reinterpret_cast<NativeValue*>(
41         OHOS::AppExecFwk::WrapWantParams(reinterpret_cast<napi_env>(engine), wantParams));
42 }
43 
CreateWantWrap(void * nativeEngine,void * nativeValue)44 RefPtr<WantWrap> WantWrap::CreateWantWrap(void* nativeEngine, void* nativeValue)
45 {
46     NativeEngine* engine = reinterpret_cast<NativeEngine*>(nativeEngine);
47     NativeValue* value = reinterpret_cast<NativeValue*>(nativeValue);
48     if (engine == nullptr || value == nullptr) {
49         LOGW("engine or value is nullptr when CreateWantWrap.");
50         return nullptr;
51     }
52 
53     return AceType::MakeRefPtr<WantWrapOhos>(engine, value);
54 }
55 
CreateWantWrap(const std::string & bundleName,const std::string & abilityName)56 RefPtr<WantWrap> WantWrap::CreateWantWrap(const std::string& bundleName, const std::string& abilityName)
57 {
58     return AceType::MakeRefPtr<WantWrapOhos>(bundleName, abilityName);
59 }
60 
WantWrapOhos(NativeEngine * engine,NativeValue * value)61 WantWrapOhos::WantWrapOhos(NativeEngine* engine, NativeValue* value)
62 {
63     OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(engine),
64                                  reinterpret_cast<napi_value>(value),
65                                  want_);
66 }
67 
WantWrapOhos(const std::string & bundleName,const std::string & abilityName)68 WantWrapOhos::WantWrapOhos(const std::string& bundleName, const std::string& abilityName)
69 {
70     want_.SetElementName(bundleName, abilityName);
71 }
72 
SetWantParamsFromWantWrap(void * want)73 void WantWrapOhos::SetWantParamsFromWantWrap(void* want)
74 {
75     auto destWant = reinterpret_cast<AAFwk::Want*>(want);
76     CHECK_NULL_VOID_NOLOG(destWant);
77     auto params = want_.GetParams();
78     destWant->SetParams(params);
79 }
80 
SetWantParam(const std::map<std::string,std::string> & params)81 void WantWrapOhos::SetWantParam(const std::map<std::string, std::string>& params)
82 {
83     for (const auto& param : params) {
84         want_.SetParam(param.first, param.second);
85     }
86 }
87 
ToString() const88 std::string WantWrapOhos::ToString() const
89 {
90     return want_.ToString();
91 }
92 } // namespace OHOS::Ace
93