• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "refbase.h"
22 #include "hilog/log.h"
23 #include "iremote_invoker.h"
24 #include "log_tags.h"
25 
26 namespace OHOS {
27 #ifdef CONFIG_IPC_SINGLE
28 namespace IPC_SINGLE {
29 #endif
30 
31 class IPCWorkThread : public virtual RefBase {
32 public:
33     enum {
34         SPAWN_PASSIVE,
35         SPAWN_ACTIVE,
36         PROCESS_PASSIVE,
37         PROCESS_ACTIVE
38     };
39     explicit IPCWorkThread(std::string threadName);
40 
41     ~IPCWorkThread();
42 
43     void Start(int policy, int proto, std::string threadName);
44 
45     void StopWorkThread();
46     int proto_ = IRemoteObject::IF_PROT_DEFAULT;
47 
48 private:
49     int policy_ = SPAWN_PASSIVE;
50     std::thread thread_;
51     std::string threadName_;
52     static void *ThreadHandler(void *args);
53     static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCWorkThread" };
54 };
55 #ifdef CONFIG_IPC_SINGLE
56 } // namespace IPC_SINGLE
57 #endif
58 } // namespace OHOS
59 #endif // OHOS_IPC_IPC_WORK_THREAD_H
60