My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
regset.h
1 #ifndef regset_h
2 #define regset_h
3 
4 #include "regmap.h"
5 #include "regdata.h"
6 #include "netbuf.h"
7 
8 #include "gcp/util/common/DataFrameManager.h"
9 #include "gcp/util/common/RegDescription.h"
10 
11 /*
12  * RegSet objects contain a list of contiguous ranges of archive
13  * register elements. They are designed for use by users of
14  * MonitorStream objects to tell the stream which registers the user
15  * is interested in receiving the values of.
16  */
17 typedef struct RegSet RegSet;
18 
19 /*
20  * Create an empty register-selection set for a given register map.
21  */
22 RegSet *new_RegSet(ArrayMap *arraymap);
23 
24 /*
25  * Discard a redundant register-selection object.
26  */
27 RegSet *del_RegSet(RegSet *regset);
28 
29 /*
30  * A contiguous range of selected register elements is described by a
31  * container of the following form. A range is represented by the
32  * indexes of the first and last register elements of the range. These
33  * indexes refer to elements of the array of all archived registers
34  * in the associated register map. They can be used to index
35  * RegCalData::slots[] and RegRawData::slots[] arrays (see regdata.h).
36  * Disconnected ranges are represented by linking individual ranges
37  * into a list of ranges, via the 'next' field.
38  */
39 typedef struct RegSetRange RegSetRange;
40 struct RegSetRange {
41  unsigned int ia; /* The index of the first register in the range */
42  unsigned int ib; /* The index of the last register in the range */
43  RegSetRange *next; /* The next range in the list (NULL marks the end) */
44 };
45 
46 /*
47  * Return the head of the list of contiguous element ranges that are
48  * currently selected. Each successive range in the list covers higher
49  * index values. There are no overlapping or abutting ranges. Note
50  * that this list should be treated as readonly and ephemeral. It will
51  * only remain valid until the next application of a RegSet function
52  * to the same RegSet.
53  */
54 RegSetRange *regset_range_list(RegSet *regset);
55 
56 /*
57  * Return non-zero if two RegSet objects have identical contents.
58  */
59 int equiv_RegSet(RegSet *regset1, RegSet *regset2);
60 
61 /*
62  * Return the register map size that a RegSet object was allocated
63  * for.
64  */
65 unsigned size_RegSet(RegSet *regset, bool archivedOnly);
66 
67 /*
68  * Copy the selections of one register set into a compatible register
69  * set (two RegSet's are compatible if they were both created for
70  * the same register map). Note that this results in the previous
71  * selections of the destination register set being discarded.
72  */
73 int dup_RegSet(RegSet *into, RegSet *from);
74 
75 /*
76  * Empty a register-selection set so that no registers remain selected.
77  */
78 int clr_RegSet(RegSet *regset);
79 
80 /*
81  * Return a register set to the state of a newly allocated register set.
82  * This allows it to be reused with a new client.
83  */
84 int renew_RegSet(RegSet *regset);
85 
86 /*
87  * Add a given subset of the elements of a given register to a
88  * register selection set. This function is idempotent.
89  *
90  * NB. Functions for setting up RegMapReg objects are provided in regmap.h.
91  */
92 int add_RegSetRange(RegSet *regset, ArrRegMapReg *arreg);
93 
97 int addRegSetRange(RegSet* regset, gcp::util::RegDescription& parser);
98 
114 int addRegSetRange(RegSet *regset, int ia, int ib);
115 
116 /*
117  * Remove a given subset of the elements of a given register from a
118  * register selection set. The specified subset need not have been
119  * previously selected, either in whole or in part.
120  *
121  * NB. Functions for setting up RegMapReg objects are provided in regmap.h.
122  */
123 int rem_RegSetRange(RegSet *regset, RegMapReg *reg);
124 
125 /*
126  * Check whether the register set includes a given register specification.
127  */
128 int in_RegSet(RegSet *regset, RegMapReg *reg);
129 
130 /*-----------------------------------------------------------------------
131  * Facilities for network transmission and receipt of register sets
132  * and the register values.
133  *.......................................................................
134  *
135  * The following functions are designed for the situation where a
136  * server of register values is told what to send by a client who
137  * wants to receive register values. Before data communications can
138  * procede the client and the server must create new register
139  * selection objects, which then each have revision counts of 0.
140  * Before the client can receive any data, it has to compose a
141  * selection of registers in its RegSet object, and send that to the
142  * server. In the process of preparing the object for transmission,
143  * the net_put_RegSet() function increments its revision count. When
144  * the server receives the register set and its revision count, the server
145  * records the new register selection and revision count in it's
146  * RegSet object. It then procedes to transmit the values of the selected
147  * registers, whenever a new record of registers is received. Along
148  * with these messages it includes its RegSet revision count. The
149  * client quietly discards any register values that it receives where
150  * this revision count is less than that in the client's own RegSet
151  * object. This ensures that after the client has updated its RegSet
152  * object, no further data will be accepted from the server until the
153  * server has been sent a copy of that RegSet object and begins to
154  * transmit data with its revision count.
155  *
156  * Note that a communications channel need not be a network connection.
157  * Messages in NetBuf buffers can also be written to and read from
158  * files etc.. [See netbuf.h].
159  *---------------------------------------------------------------------*/
160 
161 /*
162  * Return the number of bytes required to pack a specified register
163  * selection into a NetBuf network buffer. Note that this depends on what
164  * registers are currently selected, as well as on the fixed dimensions
165  * of the object.
166  */
167 int net_RegSet_size(RegSet *regset);
168 
169 /*
170  * Pack a specified set of register selections into a network buffer.
171  * You should bracket this call with calls to net_start_put()
172  * and net_end_put() [see netbuf.h].
173  */
174 int net_put_RegSet(RegSet *regset, gcp::control::NetBuf *net);
175 int netPutRegSet(RegSet *regset, gcp::control::NetBuf *net);
176 
177 /*
178  * Unpack a set of register selections from a network buffer into
179  * a compatible register selection set object.
180  * You should bracket this call with calls to net_start_get()
181  * and net_end_get() [see netbuf.h].
182  */
183 int net_get_RegSet(RegSet* registerSet, gcp::control::NetBuf *net);
184 int netGetRegSet(RegSet* registerSet, gcp::control::NetBuf *net);
185 
186 /*
187  * Return the number of bytes needed to pack a selected set of
188  * register values into a NetBuf network buffer.
189  */
190 int net_regs_size(RegSet* registerSet);
191 
192 /*
193  * Pack a selected set of raw register values into a network
194  * buffer. You should bracket this call with calls to net_start_put()
195  * and net_end_put() [see netbuf.h]. Note that the revision count
196  * of the specified register selection set is also packed, so for
197  * a given connection you should always use the same RegSet object.
198  */
199 int net_put_regs(RegSet* registerSet,
200  RegRawData *raw, gcp::control::NetBuf *net);
201 
202 int netPutRegs(RegSet* registerSet,
203  RegRawData *raw, gcp::control::NetBuf *net);
204 
205 /*
206  * The return value of net_get_regs().
207  */
208 typedef enum {
209  NETREG_OK, /* Registers read OK */
210  NETREG_SKIP, /* Registers of legacy regset ignored */
211  NETREG_ERROR /* Error reading registers */
212 } NetRegState;
213 
214 /*
215  * Unpack a selected set of registers from a network buffer.
216  * If the specified RegSet has a higher revision count than the
217  * revision count that is packed with the message, NETREG_SKIP
218  * will be returned. If it has a revision count that is lower than
219  * the sender then NETREG_ERROR will be returned. Otherwise
220  * NETREG_OK will be returned to signify that 'raw' now contains
221  * a valid set of values.
222  */
223 NetRegState net_get_regs(RegSet *regset, RegRawData *raw,
224  gcp::control::NetBuf *net);
225 NetRegState netGetRegs(RegSet *regset, RegRawData *raw,
226  gcp::control::NetBuf *net);
227 
228 #endif
Definition: netbuf.h:42
Definition: arraymap.h:36
Definition: regset.h:40
Definition: RegDescription.h:26
Definition: regset.c:17
Definition: regdata.h:16
Definition: arraymap.h:177