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 "ChildProcess.h"
17 #include "AbilityKit/native_child_process.h"
18
DummyCallBack(int errCode, OHIPCRemoteProxy *remoteProxy)19 static void DummyCallBack(int errCode, OHIPCRemoteProxy *remoteProxy)
20 {
21 if (remoteProxy != nullptr) {
22 OH_IPCRemoteProxy_Destroy(remoteProxy);
23 }
24 }
25
MainProc()26 void ChildProcess::MainProc()
27 {
28 StdUniLock autoLock(processMutex_);
29 mRunning = true;
30 processCondVar_.wait(autoLock);
31 mRunning = false;
32 }
33
RequestExitChildProcess()34 bool ChildProcess::RequestExitChildProcess()
35 {
36 StdUniLock autoLock(processMutex_);
37 if (!mRunning) {
38 return false;
39 }
40
41 processCondVar_.notify_all();
42 return true;
43 }
44
Add(int32_t a, int32_t b)45 int32_t ChildProcess::Add(int32_t a, int32_t b)
46 {
47 return a + b;
48 }
49
StartNativeChildProcess()50 int32_t ChildProcess::StartNativeChildProcess()
51 {
52 return OH_Ability_CreateNativeChildProcess("libentry.so", DummyCallBack);
53 }
54