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, "Convert inner ipc object to OHIPCRemoteProxy point failed");
46 callback_(NCP_ERR_INTERNAL, nullptr);
47 return;
48 }
49
50 callback_(static_cast<int32_t>(ChildProcessManagerErrorCode::ERR_OK), ipcProxy);
51 }
52
OnError(int32_t errCode)53 void NativeChildCallback::OnError(int32_t errCode)
54 {
55 if (callback_ == nullptr) {
56 TAG_LOGE(AAFwkTag::PROCESSMGR, "null callback_");
57 return;
58 }
59
60 TAG_LOGI(AAFwkTag::PROCESSMGR, "Native child process start err %{public}d", errCode);
61 callback_(errCode, nullptr);
62 }
63
64 } // namespace AbilityRuntime
65 } // namespace OHOS
66