dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_simulator.h
1 #ifndef SCD_SIMULATOR_H
2 #define SCD_SIMULATOR_H
3
4 #include <sys/types.h>
5 #include <string>
6
7 #include "scd_sock_poller.h"
8 #include "scd_chan_man.h"
9 #include "scd_cont_man.h"
10
11
12 /* forward declaration */
13 class scd_chan_man;
14 class scd_cont_man_if;
15
16
17 /**
18  * Simulator to run a distributed SystemC simulation. First the 
19  * channel with remote endpoints, the slave controllers and the
20  * master controller have to be registered with the channel manager
21  * and the control manager. Second the simulation has to be 
22  * initialized and third the simulation can be started.
23  */
24 class scd_simulator
25 {
26 public:
27
28     /**
29      * Constructor. Binds the simulator to the specified TCP port
30      * only on the specified network interface.
31      * \param name the name of this simulator
32      * \param loc_host IP or domain name of the interface to bind to
33      * \param loc_port TCP port to bind to
34      * \bool master SCD_MASTER if this simulator is the master, else
35      * SCD_SLAVE
36      */
37     scd_simulator(const std::string& name, const std::string &loc_host,
38             uint16_t loc_port, bool master);
39
40     /**
41      * Constructor. Binds the simulator to the specified TCP port on all
42      * available network interfaces.
43      * \param name the name of this simulator
44      * \param loc_port TCP port to bind to
45      * \bool master SCD_MASTER if this simulator is the master, else
46      * SCD_SLAVE
47      */
48     scd_simulator(const std::string& name, uint16_t loc_port, bool master);
49
50     virtual ~scd_simulator();
51
52
53     /**
54      * Returns the name of this simulator.
55      */
56     const std::string& get_name() const;
57
58     /**
59      * Returns the socket poller of this simulation.
60      */
61     scd_sock_poller& get_poller();
62
63     /**
64      * Returns the channel manager of this simulation.
65      */
66     scd_chan_man& get_chan_man();
67
68     /**
69      * Returns the control manager of this simulation.
70      */
71     scd_cont_man& get_cont_man();
72
73     /**
74      * Initializes the distributed simulation. Connects all remote channels
75      * and the control infrastructure. The channels, the slaves and the master
76      * have to be registered before initializating. A simulation can only
77      * be initialized once.
78      */
79     bool init();
80
81     /**
82      * Runs the simulation until an error occures or no more events
83      * exist globally. A simulation can only be started once.
84      */
85     bool start();
86
87
88 private:
89     scd_sock_poller* _poller;
90     scd_chan_man* _chan_man;
91     scd_cont_man* _cont_man;
92
93     std::string _name;
94     std::string _loc_host;
95     uint16_t _loc_port;
96     
97     /* member functions */
98
99     /**
100      * Indicates if events exist for the current simulation time.
101      * \return true if events exist for the current time
102      */
103     bool _pending_now();
104
105     /**
106      * Indicates if events exist in the event queues.
107      * \return true if events exist
108      */
109     bool _pending();
110
111     /**
112      * Returns the absolute time of the next event in the queues.
113      * \retunrs the absoulte time of the next event or 0 if no such event exists
114      */
115     const sc_core::sc_time _next_time();
116 };
117
118 #endif