• 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 #ifndef CMD_EXECUTOR_H
16 #define CMD_EXECUTOR_H
17 
18 #include <list>
19 #include <memory>
20 #include <atomic>
21 #include <thread>
22 
23 #include <socket.h>
24 #include "log_buffer.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 struct ClientThread {
29     std::thread m_clientThread;
30     std::atomic<bool> m_stopThread;
31 };
32 
33 class CmdExecutor {
34 public:
CmdExecutor(HilogBuffer & buffer)35     CmdExecutor(HilogBuffer& buffer) : m_hilogBuffer(buffer) {}
36     ~CmdExecutor();
37     void MainLoop();
38 private:
39     void OnAcceptedConnection(std::unique_ptr<Socket> handler);
40     void ClientEventLoop(std::unique_ptr<Socket> handler);
41     void CleanFinishedClients();
42 
43     HilogBuffer& m_hilogBuffer;
44     std::list<std::unique_ptr<ClientThread>> m_clients;
45     std::mutex m_clientAccess;
46     std::vector<std::thread::id> m_finishedClients;
47     std::mutex m_finishedClientAccess;
48 };
49 } // namespace HiviewDFX
50 } // namespace OHOS
51 #endif
52