w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RlinkServer.hpp
Go to the documentation of this file.
1// $Id: RlinkServer.hpp 1185 2019-07-12 17:29:12Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2013-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2019-06-07 1160 2.2.7 Stats() not longer const
8// 2018-12-17 1088 2.2.6 use std::thread instead of boost
9// 2018-12-16 1084 2.2.5 use =delete for noncopyable instead of boost
10// 2018-12-15 1083 2.2.4 for std::function setups: use rval ref and move
11// 2018-12-14 1081 2.2.3 use std::function instead of boost
12// 2018-12-07 1078 2.2.2 use std::shared_ptr instead of boost
13// 2017-04-07 868 2.2.1 Dump(): add detail arg
14// 2015-01-10 632 2.2 Exec() without emsg now void, will throw
15// 2014-12-30 625 2.1 adopt to Rlink V4 attn logic
16// 2014-11-30 607 2.0 re-organize for rlink v4
17// 2013-05-01 513 1.0.2 fTraceLevel now uint32_t
18// 2013-04-21 509 1.0.1 add Resume(), reorganize server start handling
19// 2013-03-06 495 1.0 Initial version
20// 2013-01-12 474 0.5 First draft
21// ---------------------------------------------------------------------------
22
27#ifndef included_Retro_RlinkServer
28#define included_Retro_RlinkServer 1
29
30#include <poll.h>
31
32#include <cstdint>
33#include <vector>
34#include <list>
35#include <memory>
36#include <functional>
37#include <thread>
38
39#include "librtools/Rstats.hpp"
41
42#include "RlinkConnect.hpp"
43#include "RlinkContext.hpp"
45
46namespace Retro {
47
49 public:
50
51 struct AttnArgs {
52 uint16_t fAttnPatt;
53 uint16_t fAttnMask;
54 uint16_t fAttnHarvest;
56 AttnArgs();
57 AttnArgs(uint16_t apatt, uint16_t amask);
58 };
59
61 typedef std::function<int(AttnArgs&)> attnhdl_t;
62 typedef std::function<int()> actnhdl_t;
63
64 explicit RlinkServer();
65 virtual ~RlinkServer();
66
67 RlinkServer(const RlinkServer&) = delete; // noncopyable
68 RlinkServer& operator=(const RlinkServer&) = delete; // noncopyable
69
70 void SetConnect(const std::shared_ptr<RlinkConnect>& spconn);
71 const std::shared_ptr<RlinkConnect>& ConnectSPtr() const;
72 RlinkConnect& Connect() const;
73 RlogFile& LogFile() const;
75
76 bool Exec(RlinkCommandList& clist, RerrMsg& emsg);
77 void Exec(RlinkCommandList& clist);
78
79 void AddAttnHandler(attnhdl_t&& attnhdl, uint16_t mask,
80 void* cdata = nullptr);
81 void RemoveAttnHandler(uint16_t mask, void* cdata = nullptr);
82 void GetAttnInfo(AttnArgs& args, RlinkCommandList& clist);
83 void GetAttnInfo(AttnArgs& args);
84
85 void QueueAction(actnhdl_t&& actnhdl);
86
87 void AddPollHandler(pollhdl_t&& pollhdl,
88 int fd, short events=POLLIN);
89 bool TestPollHandler(int fd, short events=POLLIN);
90 void RemovePollHandler(int fd, short events, bool nothrow=false);
91 void RemovePollHandler(int fd);
92
93 void Start();
94 void Stop();
95 void Resume();
96 void Wakeup();
97 void SignalAttnNotify(uint16_t apat);
98
99 bool IsActive() const;
100 bool IsActiveInside() const;
101 bool IsActiveOutside() const;
102
103 void SetTraceLevel(uint32_t level);
104 uint32_t TraceLevel() const;
105
106 Rstats& Stats();
107
108 void Print(std::ostream& os) const;
109 void Dump(std::ostream& os, int ind=0, const char* text=0,
110 int detail=0) const;
111
112 // statistics counter indices
113 enum stats {
138 };
139
141
142 protected:
143 void StartOrResume(bool resume);
144 bool AttnPending() const;
145 bool ActnPending() const;
146 void CallAttnHandler();
147 void CallActnHandler();
148 int WakeupHandler(const pollfd& pfd);
149 int RlinkHandler(const pollfd& pfd);
150
151 protected:
152 struct AttnId {
153 uint16_t fMask;
154 void* fCdata;
155 AttnId();
156 AttnId(uint16_t mask, void* cdata);
157 bool operator==(const AttnId& rhs) const;
158 };
159
160 struct AttnDsc {
163 AttnDsc();
164 AttnDsc(attnhdl_t&& hdl, const AttnId& id);
165 };
166
167 std::shared_ptr<RlinkConnect> fspConn;
169 std::vector<AttnDsc> fAttnDsc;
170 std::list<actnhdl_t> fActnList;
173 std::thread fServerThread;
174 uint16_t fAttnPatt;
175 uint16_t fAttnNotiPatt;
176 uint32_t fTraceLevel;
178};
179
180} // end namespace Retro
181
182#include "RlinkServer.ipp"
183
184#endif
FIXME_docs.
Definition: RerrMsg.hpp:25
FIXME_docs.
Definition: ReventFd.hpp:25
std::function< int(const pollfd &)> pollhdl_t
Definition: ReventLoop.hpp:41
RlinkServer & operator=(const RlinkServer &)=delete
bool TestPollHandler(int fd, short events=POLLIN)
FIXME_docs.
uint16_t fAttnNotiPatt
attn notifier pattern
uint32_t TraceLevel() const
FIXME_docs.
Definition: RlinkServer.ipp:77
std::function< int(AttnArgs &)> attnhdl_t
Definition: RlinkServer.hpp:61
bool AttnPending() const
FIXME_docs.
Definition: RlinkServer.ipp:93
bool IsActiveInside() const
Indicates whether server is active and caller is inside server thread.
std::vector< AttnDsc > fAttnDsc
RlinkServer()
Default constructor.
Definition: RlinkServer.cpp:60
void AddAttnHandler(attnhdl_t &&attnhdl, uint16_t mask, void *cdata=nullptr)
FIXME_docs.
RlinkConnect & Connect() const
FIXME_docs.
Definition: RlinkServer.ipp:36
void Wakeup()
FIXME_docs.
RlogFile & LogFile() const
FIXME_docs.
Definition: RlinkServer.ipp:44
void CallActnHandler()
FIXME_docs.
std::shared_ptr< RlinkConnect > fspConn
ReventLoop::pollhdl_t pollhdl_t
Definition: RlinkServer.hpp:60
void StartOrResume(bool resume)
FIXME_docs.
virtual ~RlinkServer()
Destructor.
int RlinkHandler(const pollfd &pfd)
FIXME_docs.
void QueueAction(actnhdl_t &&actnhdl)
FIXME_docs.
int WakeupHandler(const pollfd &pfd)
FIXME_docs.
Rstats fStats
statistics
RlinkServer(const RlinkServer &)=delete
RlinkContext fContext
default server context
std::list< actnhdl_t > fActnList
void RemovePollHandler(int fd, short events, bool nothrow=false)
FIXME_docs.
void GetAttnInfo(AttnArgs &args, RlinkCommandList &clist)
FIXME_docs.
const std::shared_ptr< RlinkConnect > & ConnectSPtr() const
FIXME_docs.
Definition: RlinkServer.ipp:28
bool IsActive() const
Indicates whether server is active.
uint16_t fAttnPatt
current attn pattern
void SetConnect(const std::shared_ptr< RlinkConnect > &spconn)
FIXME_docs.
Rstats & Stats()
FIXME_docs.
Definition: RlinkServer.ipp:85
void CallAttnHandler()
FIXME_docs.
void Stop()
FIXME_docs.
void Print(std::ostream &os) const
FIXME_docs.
bool Exec(RlinkCommandList &clist, RerrMsg &emsg)
FIXME_docs.
Definition: RlinkServer.ipp:60
RlinkServerEventLoop fELoop
void RemoveAttnHandler(uint16_t mask, void *cdata=nullptr)
FIXME_docs.
uint32_t fTraceLevel
trace level
void SetTraceLevel(uint32_t level)
FIXME_docs.
std::thread fServerThread
bool IsActiveOutside() const
Indicates whether server is active and caller is outside server thread.
@ kStatNAttn13
Attn bit 13 set.
@ kStatNAttn06
Attn bit 6 set.
@ kStatNAttn00
Attn bit 0 set.
@ kStatNAttnHarv
Attn handler restarts.
@ kStatNAttn05
Attn bit 5 set.
@ kStatNAttn12
Attn bit 12 set.
@ kStatNAttn11
Attn bit 11 set.
@ kStatNAttnHdl
Attn handler calls.
@ kStatNAttn09
Attn bit 9 set.
@ kStatNAttn08
Attn bit 8 set.
@ kStatNWakeupEvt
Wakeup events.
@ kStatNAttn04
Attn bit 4 set.
@ kStatNAttn15
Attn bit 15 set.
@ kStatNAttn14
Attn bit 14 set.
@ kStatNAttn02
Attn bit 2 set.
@ kStatNAttnNoti
Attn notifies processed.
@ kStatNEloopPoll
event loop turns (poll)
@ kStatNAttn07
Attn bit 7 set.
@ kStatNAttn01
Attn bit 1 set.
@ kStatNAttn03
Attn bit 3 set.
@ kStatNAttn10
Attn bit 10 set.
@ kStatNEloopWait
event loop turns (wait)
@ kStatNRlinkEvt
Rlink data events.
void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
void Resume()
FIXME_docs.
bool ActnPending() const
FIXME_docs.
void SignalAttnNotify(uint16_t apat)
FIXME_docs.
void Start()
FIXME_docs.
RlinkContext & Context()
FIXME_docs.
Definition: RlinkServer.ipp:52
void AddPollHandler(pollhdl_t &&pollhdl, int fd, short events=POLLIN)
FIXME_docs.
std::function< int()> actnhdl_t
Definition: RlinkServer.hpp:62
FIXME_docs.
Definition: RlogFile.hpp:34
FIXME_docs.
Definition: Rstats.hpp:28
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47
uint16_t fAttnHarvest
out: harvested attentions
Definition: RlinkServer.hpp:54
bool fHarvestDone
out: set true when harvested
Definition: RlinkServer.hpp:55
uint16_t fAttnPatt
in: current attention pattern
Definition: RlinkServer.hpp:52
uint16_t fAttnMask
in: handler attention mask
Definition: RlinkServer.hpp:53
AttnArgs()
Default constructor.
AttnDsc()
Default constructor.
bool operator==(const AttnId &rhs) const
FIXME_docs.
AttnId()
Default constructor.