Pass sr_datafeed_packets and payloads with const pointers
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.
This commit is contained in:
parent
16d6e56d12
commit
bf53457d1d
|
@ -122,7 +122,7 @@ SR_PRIV int sr_source_add(int fd, int events, int timeout,
|
|||
/*--- 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 ----------------------------------------------*/
|
||||
|
||||
|
|
|
@ -268,7 +268,7 @@ struct sr_context;
|
|||
|
||||
struct sr_datafeed_packet {
|
||||
uint16_t type;
|
||||
void *payload;
|
||||
const void *payload;
|
||||
};
|
||||
|
||||
struct sr_datafeed_header {
|
||||
|
@ -336,7 +336,7 @@ struct sr_output_format {
|
|||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -189,11 +189,11 @@ static void fancyprint(int unit, int mqflags, float value, GString *out)
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -214,7 +214,7 @@ static GString *receive(struct sr_output *o, const struct sr_dev_inst *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: ",
|
||||
|
|
2
proto.h
2
proto.h
|
@ -89,7 +89,7 @@ SR_API const struct sr_hwcap_option *sr_devopt_name_get(const char *optname);
|
|||
/*--- 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);
|
||||
|
|
|
@ -370,10 +370,10 @@ SR_API int sr_session_stop(void)
|
|||
*
|
||||
* @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:
|
||||
|
@ -426,7 +426,7 @@ static void datafeed_dump(struct sr_datafeed_packet *packet)
|
|||
* @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;
|
||||
|
|
Loading…
Reference in New Issue