dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_cont_slave_wrapper.h
1 #ifndef SCD_CONT_SLAVE_WRAPPER_H
2 #define SCD_CONT_SLAVE_WRAPPER_H
3
4 #include "scd_simulator.h"
5 #include "scd_socket.h"
6 #include "scd_command_writer.h"
7 #include "scd_command_reader.h"
8 #include "scd_cont_man.h"
9 #include "scd_sock_poller.h"
10 #include "fsm/scd_cont_fsm.h"
11 #include "fsm/scd_cont_wrapper_if.h"
12
13 #include "fsm/scd_stsw_init.h"
14 #include "fsm/scd_stsw_busy.h"
15 #include "fsm/scd_stsw_idle.h"
16 #include "fsm/scd_stsw_done.h"
17 #include "fsm/scd_stsw_time_req.h"
18 #include "fsm/scd_stsw_time_ack.h"
19 #include "fsm/scd_stsw_term_req.h"
20 #include "fsm/scd_stsw_term_ack.h"
21 #include "fsm/scd_stsw_terminate.h"
22 #include "fsm/scd_stsw_terminated.h"
23 #include "fsm/scd_stsw_fail.h"
24 #include "fsm/scd_stsw_failed.h"
25
26 /**
27  * Control manager wrapper for a slave. Reflects the masters view of the
28  * slaves state.
29  */
30 class scd_cont_slave_wrapper : public scd_cont_fsm_if, public scd_cont_fsm,
31     public scd_cont_wrapper_if, public scd_sock_ev_handler_if
32 {
33     friend class scd_stsw_base;
34
35 public:
36     /**
37      * Constructor.
38      * \param sim the simulation environment
39      * \param name the name of the slave
40      */
41     scd_cont_slave_wrapper(scd_simulator& sim, const std::string& name);
42
43     virtual ~scd_cont_slave_wrapper();
44
45     /**
46      * Returns the name of the slave.
47      */
48     const std::string& get_name() const;
49
50     /**
51      * Sets the socket of the slave.
52      * \param sock the connection to the slave
53      */
54     void connect(scd_socket* sock);
55
56     /**
57      * Sends a command to the slave.
58      */
59     void send_command(scd_command* cmd);
60
61     /**
62      * Indicates if a command is being sent to the slave.
63      * \return true if a command is still being sent
64      */
65     bool is_sending() const;
66
67     /**
68      * Closes the connection to the slave.
69      */
70     void close();
71  
72     /* scd_cont_slave_wrapper_if */
73     void send_time_req()
74         { return static_cast<scd_stsw_base*>(_state)->send_time_req(); }
75     void send_time_nack()
76         { return static_cast<scd_stsw_base*>(_state)->send_time_nack(); }
77     void send_time(const sc_core::sc_time& time)
78         { return static_cast<scd_stsw_base*>(_state)->send_time(time); }
79     void send_term_req()
80         { return static_cast<scd_stsw_base*>(_state)->send_term_req(); }
81     void send_term_nack()
82         { return static_cast<scd_stsw_base*>(_state)->send_term_nack(); }
83     void send_term()
84         { return static_cast<scd_stsw_base*>(_state)->send_term(); }
85     bool time_req() const
86         { return static_cast<scd_stsw_base*>(_state)->time_req(); }
87     bool time_ack() const
88         { return static_cast<scd_stsw_base*>(_state)->time_ack(); }
89     bool term_req() const
90         { return static_cast<scd_stsw_base*>(_state)->term_req(); }
91     bool term_ack() const
92         { return static_cast<scd_stsw_base*>(_state)->term_ack(); }
93     bool idle() const
94         { return static_cast<scd_stsw_base*>(_state)->idle(); }
95     bool done() const
96         { return static_cast<scd_stsw_base*>(_state)->done(); }
97
98     /* scd_cont_fsm_if */
99     void set_busy() { return _state->set_busy(); }
100     void set_idle(const sc_core::sc_time& t) { return _state->set_idle(t); }
101     void set_done() { return _state->set_done(); }
102     void set_fail() { return _state->set_fail(); }
103     void process() { return _state->process(); }
104     bool active() const { return _state->active(); }
105     bool busy() const { return _state->busy(); }
106     bool failed() const { return _state->failed(); }
107     bool advance_time() const { return _state->advance_time(); }
108     const sc_core::sc_time& get_time_step() { return _state->get_time_step(); }
109
110     /* scd_sock_ev_handler_if */
111     void handle_sock_ev(sock_ev events);
112     const scd_socket& get_sock();
113
114 private:
115     scd_simulator& _sim;
116     std::string _name;
117     bool _is_connected;
118     
119     scd_socket* _socket;
120     scd_command_writer _writer;
121     scd_command_reader _reader;
122     sc_core::sc_time _time_step;
123
124     /* states */
125     scd_stsw_init _st_init;
126     scd_stsw_busy _st_busy;
127     scd_stsw_idle _st_idle;
128     scd_stsw_done _st_done;
129     scd_stsw_time_req _st_time_req;
130     scd_stsw_time_ack _st_time_ack;
131     scd_stsw_term_req _st_term_req;
132     scd_stsw_term_ack _st_term_ack;
133     scd_stsw_terminate _st_terminate;
134     scd_stsw_terminated _st_terminated;
135     scd_stsw_fail _st_fail;
136     scd_stsw_failed _st_failed;
137
138     /* member functions */
139     void _process_cmd(const scd_command& cmd);
140 };
141
142 #endif