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