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 20

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

Line No. Rev Author Line
1 20 wfjm
// $Id: RlinkServer.hpp 509 2013-04-21 20:46:20Z mueller $
2 19 wfjm
//
3
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
//
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 20 wfjm
// 2013-04-21   509   1.0.1  add Resume(), reorganize server start handling
17 19 wfjm
// 2013-03-06   495   1.0    Initial version
18
// 2013-01-12   474   0.5    First draft
19
// ---------------------------------------------------------------------------
20
 
21
/*!
22
  \file
23 20 wfjm
  \version $Id: RlinkServer.hpp 509 2013-04-21 20:46:20Z mueller $
24 19 wfjm
  \brief   Declaration of class \c RlinkServer.
25
*/
26
 
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
 
36
#include "boost/utility.hpp"
37
#include "boost/thread/thread.hpp"
38
#include "boost/shared_ptr.hpp"
39
 
40
#include "librtools/Rstats.hpp"
41
 
42
#include "ReventFd.hpp"
43
#include "RlinkConnect.hpp"
44
#include "RlinkContext.hpp"
45
#include "RlinkServerEventLoop.hpp"
46
 
47
namespace Retro {
48
 
49
  class RlinkServer : private boost::noncopyable {
50
    public:
51
 
52
      struct AttnArgs {
53
        uint16_t    fAttnPatt;
54
        uint16_t    fAttnMask;
55
        RlinkCommandList* fpClist;
56
        size_t      fOffset;
57
                    AttnArgs();
58
                    AttnArgs(uint16_t apatt, uint16_t amask);
59
                    AttnArgs(uint16_t apatt, uint16_t amask,
60
                             RlinkCommandList* pclist, size_t off);
61
      };
62
 
63
      typedef ReventLoop::pollhdl_t                  pollhdl_t;
64
      typedef boost::function<int(const AttnArgs&)>  attnhdl_t;
65
      typedef boost::function<int()>                 actnhdl_t;
66
 
67
      explicit      RlinkServer();
68
      virtual      ~RlinkServer();
69
 
70
      void          SetConnect(const boost::shared_ptr<RlinkConnect>& spconn);
71
      const boost::shared_ptr<RlinkConnect>& ConnectSPtr() const;
72
      RlinkConnect& Connect() const;
73
      RlogFile&     LogFile() const;
74
      RlinkContext& Context();
75
 
76
      bool          Exec(RlinkCommandList& clist, RerrMsg& emsg);
77
      bool          Exec(RlinkCommandList& clist);
78
 
79
      void          AddAttnHandler(const attnhdl_t& attnhdl, uint16_t mask,
80
                                   void* cdata = 0);
81
      void          RemoveAttnHandler(uint16_t mask, void* cdata = 0);
82
 
83
      void          QueueAction(const actnhdl_t& actnhdl);
84
 
85
 
86
      void          AddPollHandler(const pollhdl_t& pollhdl,
87
                                   int fd, short events=POLLIN);
88
      bool          TestPollHandler(int fd, short events=POLLIN);
89
      void          RemovePollHandler(int fd, short events, bool nothrow=false);
90
      void          RemovePollHandler(int fd);
91
 
92
      void          Start();
93
      void          Stop();
94 20 wfjm
      void          Resume();
95 19 wfjm
      void          Wakeup();
96
      void          SignalAttn();
97
 
98
      bool          IsActive() const;
99
      bool          IsActiveInside() const;
100
      bool          IsActiveOutside() const;
101
 
102
      void          SetTraceLevel(size_t level);
103
      size_t        TraceLevel() const;
104
 
105
      const Rstats& Stats() const;
106
 
107
      void          Print(std::ostream& os) const;
108
      void          Dump(std::ostream& os, int ind=0, const char* text=0) const;
109
 
110
    // statistics counter indices
111
      enum stats {
112
        kStatNEloopWait = 0,
113
        kStatNEloopPoll,
114
        kStatNWakeupEvt,
115
        kStatNRlinkEvt,
116
        kStatNAttnRead,
117
        kStatNAttn00,
118
        kStatNAttn01,
119
        kStatNAttn02,
120
        kStatNAttn03,
121
        kStatNAttn04,
122
        kStatNAttn05,
123
        kStatNAttn06,
124
        kStatNAttn07,
125
        kStatNAttn08,
126
        kStatNAttn09,
127
        kStatNAttn10,
128
        kStatNAttn11,
129
        kStatNAttn12,
130
        kStatNAttn13,
131
        kStatNAttn14,
132
        kStatNAttn15,
133
        kDimStat
134
      };
135
 
136
      friend class RlinkServerEventLoop;
137
 
138
    protected:
139 20 wfjm
      void          StartOrResume(bool resume);
140 19 wfjm
      bool          AttnPending() const;
141
      bool          ActnPending() const;
142
      void          CallAttnHandler();
143
      void          CallActnHandler();
144
      int           WakeupHandler(const pollfd& pfd);
145
      int           RlinkHandler(const pollfd& pfd);
146
 
147
    protected:
148
      struct AttnId {
149
        uint16_t    fMask;
150
        void*       fCdata;
151
                    AttnId();
152
                    AttnId(uint16_t mask, void* cdata);
153
        bool        operator==(const AttnId& rhs) const;
154
      };
155
 
156
      struct AttnDsc {
157
        attnhdl_t   fHandler;
158
        AttnId      fId;
159
                    AttnDsc();
160
                    AttnDsc(attnhdl_t hdl, const AttnId& id);
161
      };
162
 
163
      boost::shared_ptr<RlinkConnect>  fspConn;
164
      RlinkContext  fContext;               //!< default server context
165
      std::vector<AttnDsc>  fAttnDsc;
166
      std::list<actnhdl_t>  fActnList;
167
      ReventFd      fWakeupEvent;
168
      RlinkServerEventLoop fELoop;
169
      boost::thread fServerThread;
170
      bool          fAttnSeen;
171
      uint16_t      fAttnPatt;
172
      size_t        fTraceLevel;            //!< trace level
173
      Rstats        fStats;                 //!< statistics
174
};
175
 
176
} // end namespace Retro
177
 
178
#include "RlinkServer.ipp"
179
 
180
#endif

powered by: WebSVN 2.1.0

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