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 "epoll_manager.h" 20 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, int32_t 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, int32_t fd); 43 void OnEventPoll() override; 44 SocketServerListener& socketServerListener_; 45 46 private: 47 IFaultLoggerService* GetTargetService(int32_t faultLoggerClientType) const; 48 }; 49 EpollManager& epollManager_; 50 std::vector<std::pair<int32_t, std::unique_ptr<IFaultLoggerService>>> faultLoggerServices_{}; 51 }; 52 } 53 } 54 #endif // FAULT_LOGGER_SERVER_H_ 55