dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_chan_wrapper.h
1 #ifndef SCD_CHAN_WRAPPER_H
2 #define SCD_CHAN_WRAPPER_H
3
4 #include <string>
5
6 #include <systemc>
7 using sc_core::sc_prim_channel;
8
9 #include "scd_sock_poller.h"
10 #include "scd_socket.h"
11 #include "scd_simulator.h"
12 #include "scd_rem_chan_if.h"
13
14
15 /**
16  * Size of the input buffer. Limits the ammount of data that
17  * can be read from the socket in one system call.
18  */
19 static const size_t SCD_CHAN_BUFLEN = 512;
20
21 /* forward declaration */
22 class scd_simulator;
23
24
25 /**
26  * Wrapper for a remote channel. Writes data from the output buffer
27  * of the channel to the socket. Receives data from the socket and 
28  * writes it to the input buffer of the channel.
29  */
30 class scd_chan_wrapper : public scd_sock_ev_handler_if
31 {
32 public:
33     /**
34      * Constructor.
35      * \param sim the simulation environment
36      * \param name the name of the channel
37      * \param chan the SystemC channel implementing 
38      * remote channel interface(s)
39      */
40     scd_chan_wrapper(scd_simulator& sim, const std::string& name,
41             sc_prim_channel& chan);
42
43     virtual ~scd_chan_wrapper();
44
45     /**
46      * Indicates if a socket has been set for this channel.
47      * \return true if a socket has been set
48      */
49     bool is_initialized() const;
50
51     /**
52      * Returns the name of the channel.
53      */
54     const std::string& get_name() const;
55
56     /**
57      * Sets the socket of the channel.
58      */
59     void connect(scd_socket* sock);
60
61     /**
62      * Checks if data has to be send or can be received again and activates
63      * transmission if necessary. Call this function after every simulation
64      * step.
65      */
66     void process();
67
68     /**
69      * Closes the connection to the peer.
70      */
71     void close();
72     
73
74     /* scd_sock_ev_handler_if */
75     void handle_sock_ev(sock_ev events);
76     const scd_socket &get_sock();
77
78 private:
79     scd_simulator& _sim;
80     std::string _name;
81     bool _is_initialized;
82
83     scd_socket* _socket;
84     scd_rem_chan_in_if* _chan_in;
85     scd_rem_chan_out_if* _chan_out;
86     char _buf[SCD_CHAN_BUFLEN];
87     bool _is_writing;
88     bool _is_reading;
89
90     /* member functions */
91     void _write_event();
92     void _read_event();
93 };
94
95 #endif