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 19

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

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

powered by: WebSVN 2.1.0

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