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 COER_EVENT_SERVER_H 17 #define COER_EVENT_SERVER_H 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include "device_node.h" 25 26 struct epoll_event; 27 namespace OHOS { 28 namespace HiviewDFX { 29 class SocketDevice : public DeviceNode { 30 public: SocketDevice()31 SocketDevice() {}; ~SocketDevice()32 virtual ~SocketDevice() {}; 33 int Close() override; 34 int Open() override; 35 uint32_t GetEvents() override; 36 std::string GetName() override; 37 int ReceiveMsg(std::vector<std::shared_ptr<EventReceiver>> &receivers) override; 38 private: 39 void InitSocket(int &socketId); 40 int socketId_ = -1; 41 }; 42 43 class BBoxDevice : public DeviceNode { 44 public: BBoxDevice()45 BBoxDevice() {}; ~BBoxDevice()46 virtual ~BBoxDevice() {}; 47 int Close() override; 48 int Open() override; 49 uint32_t GetEvents() override; 50 std::string GetName() override; 51 int ReceiveMsg(std::vector<std::shared_ptr<EventReceiver>> &receivers) override; 52 private: 53 int fd_ = -1; 54 }; 55 56 class EventServer { 57 public: EventServer()58 EventServer(): isStart_(false) {}; ~EventServer()59 ~EventServer() {} 60 void Start(); 61 void Stop(); 62 void AddReceiver(std::shared_ptr<EventReceiver> receiver); 63 private: 64 void AddDev(std::shared_ptr<DeviceNode> dev); 65 int OpenDevs(); 66 void CloseDevs(); 67 int AddToMonitor(int pollFd, struct epoll_event pollEvents[]); 68 std::map<int, std::shared_ptr<DeviceNode>> devs_; 69 std::vector<std::shared_ptr<EventReceiver>> receivers_; 70 bool isStart_; 71 }; 72 } // namespace HiviewDFX 73 } // namespace OHOS 74 #endif // COER_EVENT_SERVER_H