• 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 "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(int32_t exitCode)34 bool ChildProcess::RequestExitChildProcess(int32_t exitCode)
35 {
36     StdUniLock autoLock(processMutex_);
37     if (!mRunning) {
38         return false;
39     }
40 
41     // mock child proces crash generate signal
42     if (exitCode > 0) {
43         int *ptr = nullptr;
44         *ptr = 3;
45         return true;
46     }
47     processCondVar_.notify_all();
48     return true;
49 }
50 
Add(int32_t a,int32_t b)51 int32_t ChildProcess::Add(int32_t a, int32_t b)
52 {
53     return a + b;
54 }
55 
StartNativeChildProcess()56 int32_t ChildProcess::StartNativeChildProcess()
57 {
58     return OH_Ability_CreateNativeChildProcess("libentry.so", DummyCallBack);
59 }
60