OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [tools/] [src/] [librlink/] [RlinkServer.hpp] - Blame information for rev 28

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 28 wfjm
// $Id: RlinkServer.hpp 625 2014-12-30 16:17:45Z mueller $
2 19 wfjm
//
3 27 wfjm
// Copyright 2013-2014 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 19 wfjm
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16 28 wfjm
// 2014-12-30   625   2.1    adopt to Rlink V4 attn logic
17 27 wfjm
// 2014-11-30   607   2.0    re-organize for rlink v4
18 21 wfjm
// 2013-05-01   513   1.0.2  fTraceLevel now uint32_t
19 20 wfjm
// 2013-04-21   509   1.0.1  add Resume(), reorganize server start handling
20 19 wfjm
// 2013-03-06   495   1.0    Initial version
21
// 2013-01-12   474   0.5    First draft
22
// ---------------------------------------------------------------------------
23
 
24
/*!
25
  \file
26 28 wfjm
  \version $Id: RlinkServer.hpp 625 2014-12-30 16:17:45Z mueller $
27 19 wfjm
  \brief   Declaration of class \c RlinkServer.
28
*/
29
 
30
#ifndef included_Retro_RlinkServer
31
#define included_Retro_RlinkServer 1
32
 
33
#include <poll.h>
34
 
35
#include <cstdint>
36
#include <vector>
37
#include <list>
38
 
39
#include "boost/utility.hpp"
40
#include "boost/thread/thread.hpp"
41
#include "boost/shared_ptr.hpp"
42
 
43
#include "librtools/Rstats.hpp"
44
 
45
#include "ReventFd.hpp"
46
#include "RlinkConnect.hpp"
47
#include "RlinkContext.hpp"
48
#include "RlinkServerEventLoop.hpp"
49
 
50
namespace Retro {
51
 
52
  class RlinkServer : private boost::noncopyable {
53
    public:
54
 
55
      struct AttnArgs {
56 28 wfjm
        uint16_t    fAttnPatt;              //<! in: current attention pattern
57
        uint16_t    fAttnMask;              //<! in: handler attention mask
58
        uint16_t    fAttnHarvest;           //<! out: harvested attentions
59
        bool        fHarvestDone;           //<! out: set true when harvested
60 19 wfjm
                    AttnArgs();
61
                    AttnArgs(uint16_t apatt, uint16_t amask);
62
      };
63
 
64 28 wfjm
      typedef ReventLoop::pollhdl_t            pollhdl_t;
65
      typedef boost::function<int(AttnArgs&)>  attnhdl_t;
66
      typedef boost::function<int()>           actnhdl_t;
67 19 wfjm
 
68
      explicit      RlinkServer();
69
      virtual      ~RlinkServer();
70
 
71
      void          SetConnect(const boost::shared_ptr<RlinkConnect>& spconn);
72
      const boost::shared_ptr<RlinkConnect>& ConnectSPtr() const;
73
      RlinkConnect& Connect() const;
74
      RlogFile&     LogFile() const;
75
      RlinkContext& Context();
76
 
77
      bool          Exec(RlinkCommandList& clist, RerrMsg& emsg);
78
      bool          Exec(RlinkCommandList& clist);
79
 
80
      void          AddAttnHandler(const attnhdl_t& attnhdl, uint16_t mask,
81
                                   void* cdata = 0);
82
      void          RemoveAttnHandler(uint16_t mask, void* cdata = 0);
83 28 wfjm
      void          GetAttnInfo(AttnArgs& args, RlinkCommandList& clist);
84
      void          GetAttnInfo(AttnArgs& args);
85 19 wfjm
 
86
      void          QueueAction(const actnhdl_t& actnhdl);
87
 
88
      void          AddPollHandler(const pollhdl_t& pollhdl,
89
                                   int fd, short events=POLLIN);
90
      bool          TestPollHandler(int fd, short events=POLLIN);
91
      void          RemovePollHandler(int fd, short events, bool nothrow=false);
92
      void          RemovePollHandler(int fd);
93
 
94
      void          Start();
95
      void          Stop();
96 20 wfjm
      void          Resume();
97 19 wfjm
      void          Wakeup();
98 27 wfjm
      void          SignalAttnNotify(uint16_t apat);
99 19 wfjm
 
100
      bool          IsActive() const;
101
      bool          IsActiveInside() const;
102
      bool          IsActiveOutside() const;
103
 
104 21 wfjm
      void          SetTraceLevel(uint32_t level);
105
      uint32_t      TraceLevel() const;
106 19 wfjm
 
107
      const Rstats& Stats() const;
108
 
109
      void          Print(std::ostream& os) const;
110
      void          Dump(std::ostream& os, int ind=0, const char* text=0) const;
111
 
112
    // statistics counter indices
113
      enum stats {
114 27 wfjm
        kStatNEloopWait = 0,                //!< event loop turns (wait)
115
        kStatNEloopPoll,                    //!< event loop turns (poll)
116
        kStatNWakeupEvt,                    //!< Wakeup events
117
        kStatNRlinkEvt,                     //!< Rlink data events
118 28 wfjm
        kStatNAttnHdl,                      //<! Attn handler calls
119
        kStatNAttnNoti,                     //<! Attn notifies processed
120
        kStatNAttnHarv,                     //<! Attn handler restarts
121 27 wfjm
        kStatNAttn00,                       //!< Attn bit  0 set
122
        kStatNAttn01,                       //!< Attn bit  1 set
123
        kStatNAttn02,                       //!< Attn bit  2 set
124
        kStatNAttn03,                       //!< Attn bit  3 set
125
        kStatNAttn04,                       //!< Attn bit  4 set
126
        kStatNAttn05,                       //!< Attn bit  5 set
127
        kStatNAttn06,                       //!< Attn bit  6 set
128
        kStatNAttn07,                       //!< Attn bit  7 set
129
        kStatNAttn08,                       //!< Attn bit  8 set
130
        kStatNAttn09,                       //!< Attn bit  9 set
131
        kStatNAttn10,                       //!< Attn bit 10 set
132
        kStatNAttn11,                       //!< Attn bit 11 set
133
        kStatNAttn12,                       //!< Attn bit 12 set
134
        kStatNAttn13,                       //!< Attn bit 13 set
135
        kStatNAttn14,                       //!< Attn bit 14 set
136
        kStatNAttn15,                       //!< Attn bit 15 set
137 19 wfjm
        kDimStat
138
      };
139
 
140
      friend class RlinkServerEventLoop;
141
 
142
    protected:
143 20 wfjm
      void          StartOrResume(bool resume);
144 19 wfjm
      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 {
161
        attnhdl_t   fHandler;
162
        AttnId      fId;
163
                    AttnDsc();
164
                    AttnDsc(attnhdl_t hdl, const AttnId& id);
165
      };
166
 
167
      boost::shared_ptr<RlinkConnect>  fspConn;
168
      RlinkContext  fContext;               //!< default server context
169
      std::vector<AttnDsc>  fAttnDsc;
170
      std::list<actnhdl_t>  fActnList;
171
      ReventFd      fWakeupEvent;
172
      RlinkServerEventLoop fELoop;
173
      boost::thread fServerThread;
174 27 wfjm
      uint16_t      fAttnPatt;              //!< current attn pattern
175
      uint16_t      fAttnNotiPatt;          //!< attn notifier pattern
176 21 wfjm
      uint32_t      fTraceLevel;            //!< trace level
177 19 wfjm
      Rstats        fStats;                 //!< statistics
178
};
179
 
180
} // end namespace Retro
181
 
182
#include "RlinkServer.ipp"
183
 
184
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.