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

Subversion Repositories w11

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

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

Line No. Rev Author Line
1 21 wfjm
// $Id: RlinkServer.hpp 513 2013-05-01 14:02:06Z 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 21 wfjm
// 2013-05-01   513   1.0.2  fTraceLevel now uint32_t
17 20 wfjm
// 2013-04-21   509   1.0.1  add Resume(), reorganize server start handling
18 19 wfjm
// 2013-03-06   495   1.0    Initial version
19
// 2013-01-12   474   0.5    First draft
20
// ---------------------------------------------------------------------------
21
 
22
/*!
23
  \file
24 21 wfjm
  \version $Id: RlinkServer.hpp 513 2013-05-01 14:02:06Z mueller $
25 19 wfjm
  \brief   Declaration of class \c RlinkServer.
26
*/
27
 
28
#ifndef included_Retro_RlinkServer
29
#define included_Retro_RlinkServer 1
30
 
31
#include <poll.h>
32
 
33
#include <cstdint>
34
#include <vector>
35
#include <list>
36
 
37
#include "boost/utility.hpp"
38
#include "boost/thread/thread.hpp"
39
#include "boost/shared_ptr.hpp"
40
 
41
#include "librtools/Rstats.hpp"
42
 
43
#include "ReventFd.hpp"
44
#include "RlinkConnect.hpp"
45
#include "RlinkContext.hpp"
46
#include "RlinkServerEventLoop.hpp"
47
 
48
namespace Retro {
49
 
50
  class RlinkServer : private boost::noncopyable {
51
    public:
52
 
53
      struct AttnArgs {
54
        uint16_t    fAttnPatt;
55
        uint16_t    fAttnMask;
56
        RlinkCommandList* fpClist;
57
        size_t      fOffset;
58
                    AttnArgs();
59
                    AttnArgs(uint16_t apatt, uint16_t amask);
60
                    AttnArgs(uint16_t apatt, uint16_t amask,
61
                             RlinkCommandList* pclist, size_t off);
62
      };
63
 
64
      typedef ReventLoop::pollhdl_t                  pollhdl_t;
65
      typedef boost::function<int(const AttnArgs&)>  attnhdl_t;
66
      typedef boost::function<int()>                 actnhdl_t;
67
 
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
 
84
      void          QueueAction(const actnhdl_t& actnhdl);
85
 
86
 
87
      void          AddPollHandler(const 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 20 wfjm
      void          Resume();
96 19 wfjm
      void          Wakeup();
97
      void          SignalAttn();
98
 
99
      bool          IsActive() const;
100
      bool          IsActiveInside() const;
101
      bool          IsActiveOutside() const;
102
 
103 21 wfjm
      void          SetTraceLevel(uint32_t level);
104
      uint32_t      TraceLevel() const;
105 19 wfjm
 
106
      const Rstats& Stats() const;
107
 
108
      void          Print(std::ostream& os) const;
109
      void          Dump(std::ostream& os, int ind=0, const char* text=0) const;
110
 
111
    // statistics counter indices
112
      enum stats {
113
        kStatNEloopWait = 0,
114
        kStatNEloopPoll,
115
        kStatNWakeupEvt,
116
        kStatNRlinkEvt,
117
        kStatNAttnRead,
118
        kStatNAttn00,
119
        kStatNAttn01,
120
        kStatNAttn02,
121
        kStatNAttn03,
122
        kStatNAttn04,
123
        kStatNAttn05,
124
        kStatNAttn06,
125
        kStatNAttn07,
126
        kStatNAttn08,
127
        kStatNAttn09,
128
        kStatNAttn10,
129
        kStatNAttn11,
130
        kStatNAttn12,
131
        kStatNAttn13,
132
        kStatNAttn14,
133
        kStatNAttn15,
134
        kDimStat
135
      };
136
 
137
      friend class RlinkServerEventLoop;
138
 
139
    protected:
140 20 wfjm
      void          StartOrResume(bool resume);
141 19 wfjm
      bool          AttnPending() const;
142
      bool          ActnPending() const;
143
      void          CallAttnHandler();
144
      void          CallActnHandler();
145
      int           WakeupHandler(const pollfd& pfd);
146
      int           RlinkHandler(const pollfd& pfd);
147
 
148
    protected:
149
      struct AttnId {
150
        uint16_t    fMask;
151
        void*       fCdata;
152
                    AttnId();
153
                    AttnId(uint16_t mask, void* cdata);
154
        bool        operator==(const AttnId& rhs) const;
155
      };
156
 
157
      struct AttnDsc {
158
        attnhdl_t   fHandler;
159
        AttnId      fId;
160
                    AttnDsc();
161
                    AttnDsc(attnhdl_t hdl, const AttnId& id);
162
      };
163
 
164
      boost::shared_ptr<RlinkConnect>  fspConn;
165
      RlinkContext  fContext;               //!< default server context
166
      std::vector<AttnDsc>  fAttnDsc;
167
      std::list<actnhdl_t>  fActnList;
168
      ReventFd      fWakeupEvent;
169
      RlinkServerEventLoop fELoop;
170
      boost::thread fServerThread;
171
      bool          fAttnSeen;
172
      uint16_t      fAttnPatt;
173 21 wfjm
      uint32_t      fTraceLevel;            //!< trace level
174 19 wfjm
      Rstats        fStats;                 //!< statistics
175
};
176
 
177
} // end namespace Retro
178
 
179
#include "RlinkServer.ipp"
180
 
181
#endif

powered by: WebSVN 2.1.0

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