1 /* 2 * Copyright (c) 2025 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 #ifndef OHOS_ABILITY_RUNTIME_CHILD_PROCESS_ARGS_MANAGER_H 17 #define OHOS_ABILITY_RUNTIME_CHILD_PROCESS_ARGS_MANAGER_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 23 #include "native_child_process.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace AbilityRuntime { 28 29 class ChildProcessArgsManager { 30 public: GetInstance()31 static ChildProcessArgsManager &GetInstance() 32 { 33 static ChildProcessArgsManager instance; 34 return instance; 35 } 36 37 virtual ~ChildProcessArgsManager() = default; 38 SetChildProcessArgs(const NativeChildProcess_Args & args)39 void SetChildProcessArgs(const NativeChildProcess_Args &args) 40 { 41 std::lock_guard<std::mutex> lock(mutex_); 42 args_ = std::make_shared<NativeChildProcess_Args>(args); 43 } 44 GetChildProcessArgs()45 NativeChildProcess_Args* GetChildProcessArgs() 46 { 47 std::lock_guard<std::mutex> lock(mutex_); 48 if (args_ == nullptr) { 49 return nullptr; 50 } 51 return args_.get(); 52 } 53 54 private: 55 ChildProcessArgsManager() = default; 56 DISALLOW_COPY_AND_MOVE(ChildProcessArgsManager); 57 58 std::mutex mutex_; 59 std::shared_ptr<NativeChildProcess_Args> args_ = nullptr; 60 }; 61 } // namespace AbilityRuntime 62 } // namespace OHOS 63 #endif // OHOS_ABILITY_RUNTIME_CHILD_PROCESS_ARGS_MANAGER_H