4156f7cca8055d4736b3eb6b22d521796d9ced1e
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_cont_man_slave.h
1 #ifndef SCD_CONT_MAN_SLAVE_H
2 #define SCD_CONT_MAN_SLAVE_H
3
4 #include "scd_simulator.h"
5 #include "scd_socket.h"
6 #include "scd_out_connector.h"
7 #include "scd_command_writer.h"
8 #include "scd_command_reader.h"
9 #include "scd_cont_man.h"
10 #include "scd_sock_poller.h"
11
12 #include "fsm/scd_cont_fsm.h"
13 #include "fsm/scd_sts_init.h"
14 #include "fsm/scd_sts_busy.h"
15 #include "fsm/scd_sts_idle.h"
16 #include "fsm/scd_sts_done.h"
17 #include "fsm/scd_sts_time_ack.h"
18 #include "fsm/scd_sts_time.h"
19 #include "fsm/scd_sts_term_ack.h"
20 #include "fsm/scd_sts_terminated.h"
21 #include "fsm/scd_sts_fail.h"
22 #include "fsm/scd_sts_failed.h"
23
24 /**
25  * Control manager for a slave. Connects to the master controller and
26  * synchronizes the local and global simulation state.
27  */
28 class scd_cont_man_slave : public scd_cont_man, public scd_cont_fsm,
29     public scd_sock_ev_handler_if
30 {
31     friend class scd_sts_base;
32
33 public:
34     /**
35      * Constructor.
36      * \param sim the simulation environment
37      */
38     scd_cont_man_slave(scd_simulator& sim);
39
40     virtual ~scd_cont_man_slave();
41
42     /**
43      * Sets the socket where to read from and write to after the connection
44      * has been established to the master.
45      */
46     void set_socket();
47
48     /**
49      * Sends a command to the master.
50      * \param cmd the command to send
51      */
52     void send_command(scd_command* cmd);
53
54     /**
55      * Indicates if a command is being sent to the master (and did not finish
56      * yet).
57      * \return true if a command is currently being sent
58      */
59     bool is_sending();
60
61     /**
62      * Closes the connection to the master controller.
63      */
64     void close();
65  
66     /* scd_cont_man */
67     void set_master(const std::string& host, uint16_t port);
68     void register_slave(const std::string& name);
69
70     /* scd_cont_fsm_if */
71     void set_idle(const sc_core::sc_time& t) { return _state->set_idle(t); }
72     void set_busy() { return _state->set_busy(); }
73     void set_done() { return _state->set_done(); }
74     void set_fail() { return _state->set_fail(); }
75     void process() { return _state->process(); }
76     bool active() const { return _state->active(); }
77     bool busy() const { return _state->busy(); }
78     bool failed() const { return _state->failed(); }
79     bool advance_time() const { return _state->advance_time(); }
80     const sc_core::sc_time& get_time_step() { return _state->get_time_step(); }
81
82     /* scd_sock_ev_handler_if */
83     void handle_sock_ev(sock_ev events);
84     const scd_socket& get_sock();
85
86 private:
87     scd_simulator& _sim;
88     
89     scd_socket* _socket;
90     scd_out_connector _connector;
91     scd_command_writer _writer;
92     scd_command_reader _reader;
93     bool _has_master;
94
95     /* states */
96     scd_sts_init _st_init;
97     scd_sts_busy _st_busy;
98     scd_sts_idle _st_idle;
99     scd_sts_done _st_done;
100     scd_sts_time_ack _st_time_ack;
101     scd_sts_time _st_time;
102     scd_sts_term_ack _st_term_ack;
103     scd_sts_terminated _st_terminated;
104     scd_sts_fail _st_fail;
105     scd_sts_failed _st_failed;
106
107     /* member functions */
108     void _process_cmd(scd_command& cmd);
109 };
110
111 #endif