cbb3bedfa24294591e97b6ce02dea986dd00c0bf
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_command.h
1 #ifndef SCD_COMMAND_H
2 #define SCD_COMMAND_H
3
4 #include <stdint.h>
5 #include <sys/types.h>
6 #include <string>
7
8 #include "systemc"
9
10
11 const size_t SCD_CM_MAXLEN = 512;
12 const size_t SCD_CM_HEADER = 3*2;
13
14 /* command types */
15 const uint16_t SCD_CM_REGISTER = 1;
16 const uint16_t SCD_CM_CONFIG = 2;
17 const uint16_t SCD_CM_CONTROL = 3;
18
19 /* command subtypes */
20 // register
21 const uint16_t SCD_CM_NETSIM = 1;
22 const uint16_t SCD_CM_CHANNEL = 2;
23 // control
24 const uint16_t SCD_CM_BUSY = 1;
25 const uint16_t SCD_CM_IDLE = 2;
26 const uint16_t SCD_CM_DONE = 3;
27 const uint16_t SCD_CM_FAILED = 4;
28 const uint16_t SCD_CM_TIME_REQ = 5;
29 const uint16_t SCD_CM_TIME_ACK = 6;
30 const uint16_t SCD_CM_TIME_NACK = 7;
31 const uint16_t SCD_CM_TIME = 8;
32 const uint16_t SCD_CM_TERM_REQ = 9;
33 const uint16_t SCD_CM_TERM_ACK = 10;
34 const uint16_t SCD_CM_TERM_NACK = 11;
35 const uint16_t SCD_CM_TERM = 12;
36
37 /* forward declarations */
38 class scd_command_reader;
39 class scd_command_writer;
40
41
42 /**
43  * Command class. Commands are control messages that are sent between
44  * the different simulators. A command has a type, a subtype and a potential
45  * message part.
46  */
47 class scd_command
48 {
49 friend class scd_command_reader;
50 friend class scd_command_writer;
51
52 public:
53     /**
54      * Default constructor. Creates an empty command.
55      */
56     scd_command();
57     
58     /*
59      * Constructor. Creates a command with no message part.
60      * \param type the type of this command
61      * \param subtype the subtype of this command
62      */
63     scd_command(uint16_t type, uint16_t subtype);
64
65     /**
66      * Constructor. Creates a new command with a string as message
67      * part.
68      */
69     scd_command(uint16_t type, uint16_t subtype, const std::string& msg);
70
71     /**
72      * Constructor. Creates a new command with a SystemC time value as
73      * message part.
74      */
75     scd_command(uint16_t type, uint16_t subtype, const sc_core::sc_time& time);
76
77     virtual ~scd_command();
78
79     /**
80      * Returns the type of the command.
81      */
82     uint16_t get_type() const;
83
84     /**
85      * Returns the subtype of the command.
86      */
87     uint16_t get_subtype() const;
88
89     /**
90      * Returns the message part interpreted as a string.
91      */
92     std::string get_string() const;
93     
94     /**
95      * Returns the message part interpreted as a SystemC time.
96      * If the message part does not have the correct size SC_ZERO_TIME
97      * is returned instead.
98      */
99     sc_core::sc_time get_time() const;
100
101 private:
102         uint16_t _type;
103         uint16_t _subtype;
104         uint16_t _msglen;
105         char* _msg;
106 };
107
108 #endif