SpiecsEngine
 
Loading...
Searching...
No Matches
Poller.h
Go to the documentation of this file.
1/**
2* @file Poller.h.
3* @brief The Poller Class Definitions.
4* @author Spices & Muduo.
5*/
6
7#pragma once
8#include "Core/Core.h"
9#include "../InetAddress.h"
10
11namespace Spices {
12
13namespace Net {
14
15 /**
16 * @brief Forward Declare.
17 */
18 class Channel;
19 class EventLoop;
20
21 /**
22 * @brief Inherit from this and Implement Specific Poller
23 */
24 class Poller
25 {
26 public:
27
30
31 public:
32
33 /**
34 * @brief Constructor Function.
35 * @param[in] loop EventLoop.
36 */
37 Poller(EventLoop* loop) : m_Loop(loop) {}
38
39 /**
40 * @brief Destructor Function.
41 */
42 virtual ~Poller() = default;
43
44 /**
45 * @brief Copy Constructor Function.
46 * @note This Class not allowed copy behaves.
47 */
48 Poller(const Poller&) = delete;
49
50 /**
51 * @brief Copy Assignment Operation.
52 * @note This Class not allowed copy behaves.
53 */
54 Poller& operator=(const Poller&) = delete;
55
56 /**
57 * @brief Poll events on EventList.
58 * @param[in] timeoutMs .
59 * @param[in,out] activeChannels Channels that events happened.
60 */
61 virtual void Poll(int timeoutMs, ChannelList* activeChannels) = 0;
62
63 /**
64 * @brief Update Channel and Update Poll.
65 * @param[in] channel Channel.
66 */
67 virtual void UpdateChannel(Channel* channel) = 0;
68
69 /**
70 * @brief Remove Channel and Update Poll.
71 * @param[in] channel Channel.
72 */
73 virtual void RemoveChannel(Channel* channel) = 0;
74
75 /**
76 * @brief Determine if channel is in ChannelMap.
77 * @param[in] channel Channel.
78 * @return Returns true if channel is in ChannelMap.
79 */
80 bool HasChannel(Channel* channel) const;
81
82 /**
83 * @brief Create Default Poller.
84 * @param[in] loop EventLoop.
85 * @return Returns Default Poller.
86 */
87 static std::shared_ptr<Poller> DefaultPoller(EventLoop* loop);
88
89 protected:
90
91 /**
92 * @brief This Poller interested Channels.
93 */
95
96 private:
97
98 /**
99 * @brief This Poller interested EventLoop.
100 */
102
103 };
104
105}
106
107}
#define SPICES_PROFILE_ZONE
Wrapper of SOCKET'S Event.
Definition Channel.h:27
virtual ~EventLoopThreadWrapper()
Destructor Function.
static EventLoop *& GetInst(InetAddress *address=nullptr)
Get EventLoop Instance. @reutrn Returns EventLoop Instance.
EventLoop * instance
This thread EventLoop instance.
Definition EventLoop.h:204
Wrapper of Instance/Delete ThreadCache in thread.
Definition EventLoop.h:180
void HandleWakeUp()
Handle WakeUp notify by read one byte data.
void DoPendingFunctors()
Execute all pending functors.
bool HasChannel(Channel *channel) const
Determine if channel is inside poller.
EventLoop(InetAddress *address=nullptr)
Constructor Function.
Definition EventLoop.cpp:22
void WakeUp()
WakeUp a thread, which wait on recv, by sending one byte data.
void Loop()
Start Event Loop.
Definition EventLoop.cpp:48
bool IsInLoopThread() const
Determine if current thread is in eventloop thread.
Definition EventLoop.h:109
void RunInLoop(Functor cb)
Push functor to pending functors.
Definition EventLoop.cpp:79
~EventLoop()
Destructor Function.
Definition EventLoop.cpp:42
void QueueInLoop(Functor cb)
Execute functor in EventLoop thread.
Definition EventLoop.cpp:91
void UpdateChannel(Channel *channel) const
Update channel state with poller.
void Quit()
Quit from Event Loop.
Definition EventLoop.cpp:69
void RemoveChannel(Channel *channel) const
Remove channel from poller.
Wrapper of Poller and wakeup socket to acceptor(SubLoop).
Definition EventLoop.h:28
This class is Wrapper of current socket address.
Definition InetAddress.h:22
virtual void RemoveChannel(Channel *channel)=0
Remove Channel and Update Poll.
virtual void Poll(int timeoutMs, ChannelList *activeChannels)=0
Poll events on EventList.
virtual ~Poller()=default
Destructor Function.
ChannelMap m_Channels
This Poller interested Channels.
Definition Poller.h:94
static std::shared_ptr< Poller > DefaultPoller(EventLoop *loop)
Create Default Poller.
Definition Poller.cpp:25
EventLoop * m_Loop
This Poller interested EventLoop.
Definition Poller.h:101
bool HasChannel(Channel *channel) const
Determine if channel is in ChannelMap.
Definition Poller.cpp:16
virtual void UpdateChannel(Channel *channel)=0
Update Channel and Update Poll.
Poller(EventLoop *loop)
Constructor Function.
Definition Poller.h:37
Poller & operator=(const Poller &)=delete
Copy Assignment Operation.
Poller(const Poller &)=delete
Copy Constructor Function.
Inherit from this and Implement Specific Poller.
Definition Poller.h:25
constexpr uint32_t pollTimeoutMs
Poller timeout. Default is 10s.
Definition EventLoop.cpp:20