• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "native_child_callback.h"
17 #include "hilog_tag_wrapper.h"
18 #include "ipc_inner_object.h"
19 #include "child_process_manager_error_utils.h"
20 
21 namespace OHOS {
22 namespace AbilityRuntime {
23 
NativeChildCallback(OH_Ability_OnNativeChildProcessStarted cb)24 NativeChildCallback::NativeChildCallback(OH_Ability_OnNativeChildProcessStarted cb)
25     : NativeChildNotifyStub(), callback_(cb)
26 {
27 }
28 
OnNativeChildStarted(const sptr<IRemoteObject> & nativeChild)29 void NativeChildCallback::OnNativeChildStarted(const sptr<IRemoteObject> &nativeChild)
30 {
31     if (callback_ == nullptr) {
32         TAG_LOGE(AAFwkTag::PROCESSMGR, "null callback_");
33         return;
34     }
35 
36     if (!nativeChild) {
37         TAG_LOGE(AAFwkTag::PROCESSMGR, "null nativeChild");
38         return;
39     }
40 
41     TAG_LOGI(AAFwkTag::PROCESSMGR, "Native child process started");
42     sptr<IRemoteObject> ipcRemote = nativeChild;
43     OHIPCRemoteProxy *ipcProxy = CreateIPCRemoteProxy(ipcRemote);
44     if (ipcProxy == nullptr) {
45         TAG_LOGE(AAFwkTag::PROCESSMGR, "null ipcProxy");
46         callback_(NCP_ERR_INTERNAL, nullptr);
47         return;
48     }
49 
50     callback_(static_cast<int32_t>(ChildProcessManagerErrorCode::ERR_OK), ipcProxy);
51     callback_ = nullptr;
52 
53     ChildCallbackManager::GetInstance().RemoveRemoteObject(this);
54 }
55 
OnError(int32_t errCode)56 void NativeChildCallback::OnError(int32_t errCode)
57 {
58     if (callback_ == nullptr) {
59         TAG_LOGE(AAFwkTag::PROCESSMGR, "null callback_");
60         return;
61     }
62 
63     TAG_LOGI(AAFwkTag::PROCESSMGR, "Native child process start err %{public}d", errCode);
64     callback_(errCode, nullptr);
65 
66     callback_ = nullptr;
67     ChildCallbackManager::GetInstance().RemoveRemoteObject(this);
68 }
69 
70 } // namespace AbilityRuntime
71 } // namespace OHOS
72