• 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 {
23 
CreateWantWrap(void * nativeEngine,void * nativeValue)24 RefPtr<WantWrap> WantWrap::CreateWantWrap(void* nativeEngine, void* nativeValue)
25 {
26     NativeEngine* engine = reinterpret_cast<NativeEngine*>(nativeEngine);
27     NativeValue* value = reinterpret_cast<NativeValue*>(nativeValue);
28     if (engine == nullptr || value == nullptr) {
29         LOGW("engine or value is nullptr when CreateWantWrap.");
30         return nullptr;
31     }
32 
33     return AceType::MakeRefPtr<WantWrapOhos>(engine, value);
34 }
35 
WantWrapOhos(NativeEngine * engine,NativeValue * value)36 WantWrapOhos::WantWrapOhos(NativeEngine* engine, NativeValue* value)
37 {
38     OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(engine),
39                                  reinterpret_cast<napi_value>(value),
40                                  want_);
41 }
42 
SetWantParamsFromWantWrap(void * want)43 void WantWrapOhos::SetWantParamsFromWantWrap(void* want)
44 {
45     auto destWant = reinterpret_cast<AAFwk::Want*>(want);
46     CHECK_NULL_VOID_NOLOG(destWant);
47     auto params = want_.GetParams();
48     destWant->SetParams(params);
49 }
50 
ToString() const51 std::string WantWrapOhos::ToString() const
52 {
53     return want_.ToString();
54 }
55 
56 } // namespace OHOS::Ace