w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
ReventLoop.hpp
Go to the documentation of this file.
1// $Id: ReventLoop.hpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-12-17 1085 1.2.6 use std::mutex instead of boost
8// 2018-12-16 1084 1.2.5 use =delete for noncopyable instead of boost
9// 2018-12-15 1083 1.2.4 AddPollHandler(): use rval ref and move
10// 2018-12-14 1081 1.2.3 use std::function instead of boost
11// 2018-12-07 1078 1.2.2 use std::shared_ptr instead of boost
12// 2017-04-07 868 1.2.1 Dump(): add detail arg
13// 2015-04-04 662 1.2 BUGFIX: fix race in Stop(), add UnStop,StopPending
14// 2013-05-01 513 1.1.1 fTraceLevel now uint32_t
15// 2013-02-22 491 1.1 use new RlogFile/RlogMsg interfaces
16// 2013-01-11 473 1.0 Initial version
17// ---------------------------------------------------------------------------
18
19
24#ifndef included_Retro_ReventLoop
25#define included_Retro_ReventLoop 1
26
27#include <poll.h>
28
29#include <cstdint>
30#include <vector>
31#include <memory>
32#include <functional>
33#include <mutex>
34
36
37namespace Retro {
38
39 class ReventLoop {
40 public:
41 typedef std::function<int(const pollfd&)> pollhdl_t;
42
43 ReventLoop();
44 virtual ~ReventLoop();
45
46 ReventLoop(const ReventLoop&) = delete; // noncopyable
47 ReventLoop& operator=(const ReventLoop&) = delete; // noncopyable
48
49 void AddPollHandler(pollhdl_t&& pollhdl,
50 int fd, short events=POLLIN);
51 bool TestPollHandler(int fd, short events=POLLIN);
52 void RemovePollHandler(int fd, short events, bool nothrow=false);
53 void RemovePollHandler(int fd);
54
55 void SetLogFile(const std::shared_ptr<RlogFile>& splog);
56 void SetTraceLevel(uint32_t level);
57 uint32_t TraceLevel() const;
58
59 void Stop();
60 void UnStop();
61 bool StopPending();
62 virtual void EventLoop();
63
64 virtual void Dump(std::ostream& os, int ind=0, const char* text=0,
65 int detail=0) const;
66
67 protected:
68
69 int DoPoll(int timeout=-1);
70 void DoCall(void);
71
72 protected:
73
74 struct PollDsc {
76 int fFd;
77 short fEvents;
78 PollDsc(pollhdl_t hdl,int fd,short evts) :
79 fHandler(hdl),fFd(fd),fEvents(evts) {}
80 };
81
84 std::mutex fPollDscMutex;
85 std::vector<PollDsc> fPollDsc;
86 std::vector<pollfd> fPollFd;
87 std::vector<pollhdl_t> fPollHdl;
88 uint32_t fTraceLevel;
89 std::shared_ptr<RlogFile> fspLog;
90};
91
92} // end namespace Retro
93
94#include "ReventLoop.ipp"
95
96#endif
FIXME_docs.
Definition: ReventLoop.hpp:39
virtual void EventLoop()
FIXME_docs.
Definition: ReventLoop.cpp:157
std::shared_ptr< RlogFile > fspLog
log file ptr
Definition: ReventLoop.hpp:89
ReventLoop(const ReventLoop &)=delete
virtual ~ReventLoop()
FIXME_docs.
Definition: ReventLoop.cpp:66
ReventLoop & operator=(const ReventLoop &)=delete
ReventLoop()
FIXME_docs.
Definition: ReventLoop.cpp:52
void SetLogFile(const std::shared_ptr< RlogFile > &splog)
FIXME_docs.
Definition: ReventLoop.ipp:50
std::mutex fPollDscMutex
Definition: ReventLoop.hpp:84
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Definition: ReventLoop.cpp:181
void DoCall(void)
FIXME_docs.
Definition: ReventLoop.cpp:259
void Stop()
FIXME_docs.
Definition: ReventLoop.ipp:24
uint32_t TraceLevel() const
FIXME_docs.
Definition: ReventLoop.ipp:68
void UnStop()
FIXME_docs.
Definition: ReventLoop.ipp:33
void SetTraceLevel(uint32_t level)
FIXME_docs.
Definition: ReventLoop.ipp:59
std::vector< pollfd > fPollFd
Definition: ReventLoop.hpp:86
int DoPoll(int timeout=-1)
FIXME_docs.
Definition: ReventLoop.cpp:210
void AddPollHandler(pollhdl_t &&pollhdl, int fd, short events=POLLIN)
FIXME_docs.
Definition: ReventLoop.cpp:75
std::vector< PollDsc > fPollDsc
Definition: ReventLoop.hpp:85
bool StopPending()
FIXME_docs.
Definition: ReventLoop.ipp:42
uint32_t fTraceLevel
trace level
Definition: ReventLoop.hpp:88
std::function< int(const pollfd &)> pollhdl_t
Definition: ReventLoop.hpp:41
bool TestPollHandler(int fd, short events=POLLIN)
FIXME_docs.
Definition: ReventLoop.cpp:124
std::vector< pollhdl_t > fPollHdl
Definition: ReventLoop.hpp:87
void RemovePollHandler(int fd, short events, bool nothrow=false)
FIXME_docs.
Definition: ReventLoop.cpp:101
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47
PollDsc(pollhdl_t hdl, int fd, short evts)
Definition: ReventLoop.hpp:78