• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 FAULT_LOGGER_SERVER_H_
17 #define FAULT_LOGGER_SERVER_H_
18 
19 #include <map>
20 #include "epoll_manager.h"
21 #include "fault_logger_service.h"
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 class SocketServer {
26 public:
27     explicit SocketServer(EpollManager& epollManager);
28     bool Init();
29     void AddService(int32_t clientType, std::unique_ptr<IFaultLoggerService> service);
30 private:
31     bool AddServerListener(const char* socketName);
32     class SocketServerListener : public EpollListener {
33     public:
34         SocketServerListener(SocketServer& socketServer, SmartFd fd, std::string socketName);
35         void OnEventPoll() override;
36         SocketServer& socketServer_;
37         const std::string socketName_;
38     };
39 
40     class ClientRequestListener : public EpollListener {
41     public:
42         ClientRequestListener(SocketServerListener& socketServerListener, SmartFd fd, uid_t clientUid);
43         ~ClientRequestListener() override;
44         void OnEventPoll() override;
45     private:
46         SocketServerListener& socketServerListener_;
47         uid_t clientUid_;
48         IFaultLoggerService* GetTargetService(int32_t faultLoggerClientType) const;
49     };
50     EpollManager& epollManager_;
51     std::vector<std::pair<int32_t, std::unique_ptr<IFaultLoggerService>>> faultLoggerServices_{};
52     std::map<uid_t, uint32_t> connectionNums_{};
53 };
54 }
55 }
56 #endif // FAULT_LOGGER_SERVER_H_
57