• 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 LOG_QUERIER_H
16 #define LOG_QUERIER_H
17 
18 #include <array>
19 #include <atomic>
20 #include <condition_variable>
21 #include <future>
22 #include <memory>
23 #include <mutex>
24 
25 #include <hilog_common.h>
26 #include <socket.h>
27 
28 #include "log_buffer.h"
29 
30 namespace OHOS {
31 namespace HiviewDFX {
32 class ServiceController  {
33 public:
34     static constexpr int MAX_DATA_LEN = 2048;
35     using PacketBuf = std::array<char, MAX_DATA_LEN>;
36 
37     ServiceController(std::unique_ptr<Socket> communicationSocket, HilogBuffer& buffer);
38     ~ServiceController();
39 
40     void CommunicationLoop(const std::atomic<bool>& stopLoop);
41 private:
42     void SetFilters(const PacketBuf& rawData);
43 
44     void HandleLogQueryRequest();
45     void HandleNextRequest(const PacketBuf& rawData, const std::atomic<bool>& stopLoop);
46 
47     // persist storage
48     void HandlePersistStartRequest(const PacketBuf& rawData);
49     void HandlePersistStopRequest(const PacketBuf& rawData);
50     void HandlePersistQueryRequest(const PacketBuf& rawData);
51 
52     // buffer size
53     void HandleBufferResizeRequest(const PacketBuf& rawData);
54     void HandleBufferSizeRequest(const PacketBuf& rawData);
55 
56     // statistics
57     void HandleInfoQueryRequest(const PacketBuf& rawData);
58     void HandleInfoClearRequest(const PacketBuf& rawData);
59     void HandleBufferClearRequest(const PacketBuf& rawData);
60 
61     int WriteData(LogQueryResponse& rsp, OptCRef<HilogData> pData);
62     int WriteV(const iovec* vec, size_t len);
63     int WriteLogQueryRespond(unsigned int sendId, uint32_t respondCmd, OptCRef<HilogData> pData);
64     void NotifyForNewData();
65 
66     std::unique_ptr<Socket> m_communicationSocket;
67     HilogBuffer& m_hilogBuffer;
68     HilogBuffer::ReaderId m_bufReader;
69 
70     std::condition_variable m_notifyNewDataCv;
71     std::mutex m_notifyNewDataMtx;
72 
73     LogFilterExt m_filters;
74 };
75 
76 int RestorePersistJobs(HilogBuffer& _buffer);
77 } // namespace HiviewDFX
78 } // namespace OHOS
79 #endif
80