• 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 
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     bool hasBbox_ = false;
55 };
56 
57 class EventServer {
58 public:
EventServer()59     EventServer(): isStart_(false) {};
~EventServer()60     ~EventServer() {}
61     void Start();
62     void Stop();
63     void AddReceiver(std::shared_ptr<EventReceiver> receiver);
64 private:
65     void AddDev(std::shared_ptr<DeviceNode> dev);
66     int OpenDevs();
67     void CloseDevs();
68     int AddToMonitor(int pollFd, struct epoll_event pollEvents[]);
69     std::map<int, std::shared_ptr<DeviceNode>> devs_;
70     std::vector<std::shared_ptr<EventReceiver>> receivers_;
71     bool isStart_;
72 };
73 } // namespace HiviewDFX
74 } // namespace OHOS
75 #endif // COER_EVENT_SERVER_H