This patch marks packet structures and their payloads as const.
This indicates to packet receivers that modifications to these are
not allowed. In general all pointers should be marked const unless
modification of the referenced data is explicitly allowed.
/*--- session.c -------------------------------------------------------------*/
SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
- struct sr_datafeed_packet *packet);
+ const struct sr_datafeed_packet *packet);
/*--- hardware/common/serial.c ----------------------------------------------*/
struct sr_datafeed_packet {
uint16_t type;
- void *payload;
+ const void *payload;
};
struct sr_datafeed_header {
int (*event) (struct sr_output *o, int event_type, uint8_t **data_out,
uint64_t *length_out);
GString *(*recv) (struct sr_output *o, const struct sr_dev_inst *sdi,
- struct sr_datafeed_packet *packet);
+ const struct sr_datafeed_packet *packet);
int (*cleanup) (struct sr_output *o);
};
}
static GString *receive(struct sr_output *o, const struct sr_dev_inst *sdi,
- struct sr_datafeed_packet *packet)
+ const struct sr_datafeed_packet *packet)
{
- struct sr_datafeed_analog *analog;
+ const struct sr_datafeed_analog *analog;
struct context *ctx;
- float *fdata;
+ const float *fdata;
int i, j;
(void)sdi;
break;
case SR_DF_ANALOG:
analog = packet->payload;
- fdata = (float *)analog->data;
+ fdata = (const float *)analog->data;
for (i = 0; i < analog->num_samples; i++) {
for (j = 0; j < ctx->num_enabled_probes; j++) {
g_string_append_printf(ctx->out, "%s: ",
/*--- session.c -------------------------------------------------------------*/
typedef void (*sr_datafeed_callback_t)(const struct sr_dev_inst *sdi,
- struct sr_datafeed_packet *packet);
+ const struct sr_datafeed_packet *packet);
/* Session setup */
SR_API int sr_session_load(const char *filename);
*
* @param packet The packet to show debugging information for.
*/
-static void datafeed_dump(struct sr_datafeed_packet *packet)
+static void datafeed_dump(const struct sr_datafeed_packet *packet)
{
- struct sr_datafeed_logic *logic;
- struct sr_datafeed_analog *analog;
+ const struct sr_datafeed_logic *logic;
+ const struct sr_datafeed_analog *analog;
switch (packet->type) {
case SR_DF_HEADER:
* @private
*/
SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
- struct sr_datafeed_packet *packet)
+ const struct sr_datafeed_packet *packet)
{
GSList *l;
sr_datafeed_callback_t cb;