47using namespace std::placeholders;
65 fWakeupEvent(
"RlinkServer::fWakeupEvent."),
120 if (!
fspConn && !spconn)
return;
123 "Bad state: fspConn already set");
125 throw Rexception(
"RlinkServer::SetConnect()",
"Bad args: spconn==0");
140 throw Rexception(
"RlinkServer::AddAttnHandler()",
"Bad args: mask == 0");
142 lock_guard<RlinkConnect> lock(*
fspConn);
145 for (
size_t i=0; i<
fAttnDsc.size(); i++) {
147 throw Rexception(
"RlinkServer::AddAttnHandler()",
148 "Bad args: duplicate handler");
151 fAttnDsc.emplace_back(move(attnhdl),
id);
163 throw Rexception(
"RlinkServer::GetAttnInfo",
"clist did't start with attn");
189 lock_guard<RlinkConnect> lock(*
fspConn);
192 for (
size_t i=0; i<
fAttnDsc.size(); i++) {
199 throw Rexception(
"RlinkServer::RemoveAttnHandler()",
200 "Bad args: unknown handler");
208 lock_guard<RlinkConnect> lock(*
fspConn);
219 lock_guard<RlinkConnect> lock(*
fspConn);
230 lock_guard<RlinkConnect> lock(*
fspConn);
239 lock_guard<RlinkConnect> lock(*
fspConn);
250 lock_guard<RlinkConnect> lock(*
fspConn);
303 lmsg <<
"SignalAttnNotify: redundant notify:"
361 os <<
"RlinkServer::Print(std::ostream& os)" << endl;
373 os << bl << (text?text:
"--") <<
"RlinkServer @ " <<
this << endl;
374 os << bl <<
" fspConn: " <<
fspConn << endl;
376 os << bl <<
" fAttnDsc: " << endl;
377 for (
size_t i=0; i<
fAttnDsc.size(); i++)
378 os << bl <<
" [" <<
RosPrintf(i,
"d",3) <<
"]: "
380 <<
", " <<
fAttnDsc[i].fId.fCdata << endl;
381 os << bl <<
" fActnList.size: " <<
fActnList.size() << endl;
384 os << bl <<
" fServerThread: " <<
fServerThread.get_id() << endl;
397 throw Rexception(
"RlinkServer::StartOrResume()",
398 "Bad state: server thread already running");
400 throw Rexception(
"RlinkServer::StartOrResume()",
401 "Bad state: RlinkConnect not open");
403 lock_guard<RlinkConnect> lock(
Connect());
411 int rlinkfd =
fspConn->Port().FdRead();
422 if (!
Connect().SndAttn(emsg)) {
424 lmsg <<
"attn send for server resume failed:" << emsg;
444 lock_guard<RlinkConnect> lock(*
fspConn);
456 for (
size_t i=0; i<16; i++) {
463 for (
size_t i=0; i<
fAttnDsc.size(); i++) {
467 lock_guard<RlinkConnect> lock(*
fspConn);
479 "Handler didn't set fHarvestDone");
481 uint16_t hnew = args.
fAttnHarvest & ~fAttnDsc[i].fId.fMask;
507 lmsg <<
"eloop: unhandled attn, mask="
528 lock_guard<RlinkConnect> lock(*
fspConn);
550 if (pfd.revents & (~pfd.events))
return -1;
564 if (pfd.revents & (~pfd.events))
return -1;
566 fspConn->HandleUnsolicitedData();
uint64_t Wait()
FIXME_docs.
void Signal(uint64_t val=1)
FIXME_docs.
void SetLogFile(const std::shared_ptr< RlogFile > &splog)
FIXME_docs.
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
void SetTraceLevel(uint32_t level)
FIXME_docs.
void AddPollHandler(pollhdl_t &&pollhdl, int fd, short events=POLLIN)
FIXME_docs.
bool TestPollHandler(int fd, short events=POLLIN)
FIXME_docs.
void RemovePollHandler(int fd, short events, bool nothrow=false)
FIXME_docs.
int Fd() const
FIXME_docs.
size_t AddWreg(uint16_t addr, uint16_t data)
FIXME_docs.
size_t AddAttn()
FIXME_docs.
uint16_t Data() const
FIXME_docs.
static const uint8_t kStat_M_RbErr
stat: rberr flag set
static const uint8_t kStat_M_RbNak
stat: rbnak flag set
static const uint8_t kStat_M_RbTout
stat: rbtout flag set
uint8_t Command() const
FIXME_docs.
static const uint8_t kCmdAttn
command code get attention
static const uint16_t kRLCNTL_M_AnEna
RLCNTL: an enable.
static const uint16_t kRbaddr_RLCNTL
rlink core reg RLCNTL
void SetStatus(uint8_t stat, uint8_t statmsk=0x00)
FIXME_docs.
virtual void EventLoop()
FIXME_docs.
bool TestPollHandler(int fd, short events=POLLIN)
FIXME_docs.
uint16_t fAttnNotiPatt
attn notifier pattern
std::function< int(AttnArgs &)> attnhdl_t
bool IsActiveInside() const
Indicates whether server is active and caller is inside server thread.
std::vector< AttnDsc > fAttnDsc
RlinkServer()
Default constructor.
void AddAttnHandler(attnhdl_t &&attnhdl, uint16_t mask, void *cdata=nullptr)
FIXME_docs.
RlinkConnect & Connect() const
FIXME_docs.
RlogFile & LogFile() const
FIXME_docs.
void CallActnHandler()
FIXME_docs.
std::shared_ptr< RlinkConnect > fspConn
ReventLoop::pollhdl_t pollhdl_t
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.
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.
bool IsActive() const
Indicates whether server is active.
uint16_t fAttnPatt
current attn pattern
void SetConnect(const std::shared_ptr< RlinkConnect > &spconn)
FIXME_docs.
void CallAttnHandler()
FIXME_docs.
void Print(std::ostream &os) const
FIXME_docs.
bool Exec(RlinkCommandList &clist, RerrMsg &emsg)
FIXME_docs.
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.
bool ActnPending() const
FIXME_docs.
void SignalAttnNotify(uint16_t apat)
FIXME_docs.
void AddPollHandler(pollhdl_t &&pollhdl, int fd, short events=POLLIN)
FIXME_docs.
std::function< int()> actnhdl_t
I/O appicator to generate fill characters.
void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
void Inc(size_t ind, double val=1.)
FIXME_docs.
void Define(size_t ind, const std::string &name, const std::string &text)
FIXME_docs.
RosPrintfS< bool > RosPrintf(bool value, const char *form=0, int width=0, int prec=0)
Creates a print object for the formatted output of a bool value.
Declaration of class ReventLoop.
uint16_t fAttnHarvest
out: harvested attentions
bool fHarvestDone
out: set true when harvested