1 /* 2 * Copyright (C) 2021 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_IPC_IPC_WORK_THREAD_H 17 #define OHOS_IPC_IPC_WORK_THREAD_H 18 19 #include <string> 20 #include <thread> 21 22 #include "hilog/log.h" 23 #include "iremote_invoker.h" 24 #include "log_tags.h" 25 #include "refbase.h" 26 27 namespace OHOS { 28 #ifdef CONFIG_IPC_SINGLE 29 namespace IPC_SINGLE { 30 #endif 31 32 class IPCWorkThread : public virtual RefBase { 33 public: 34 enum { 35 SPAWN_PASSIVE, 36 SPAWN_ACTIVE, 37 PROCESS_PASSIVE, 38 PROCESS_ACTIVE, 39 }; 40 41 static std::string MakeBasicThreadName(int proto, int threadIndex); 42 explicit IPCWorkThread(std::string threadName); 43 44 ~IPCWorkThread(); 45 46 void Start(int policy, int proto, int threadIndex); 47 48 void StopWorkThread(); 49 int proto_ = IRemoteObject::IF_PROT_DEFAULT; 50 51 private: 52 int policy_ = SPAWN_PASSIVE; 53 std::thread thread_; 54 std::string threadName_; 55 static void *ThreadHandler(void *args); 56 static void JoinThread(int proto, int policy); 57 static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC_COMMON, "IPCWorkThread" }; 58 }; 59 #ifdef CONFIG_IPC_SINGLE 60 } // namespace IPC_SINGLE 61 #endif 62 } // namespace OHOS 63 #endif // OHOS_IPC_IPC_WORK_THREAD_H 64