From 10f2b72421cdb8844440ddc49a836fb73ce1b495 Mon Sep 17 00:00:00 2001 From: Nils Carlson Date: Thu, 4 Nov 2010 17:44:12 +0100 Subject: [PATCH] Add ustcomm_trace_info struct and support functions to ustcomm Signed-off-by: Nils Carlson Acked-by: David Goulet --- libustcomm/ustcomm.c | 32 ++++++++++++++++++++++++++++++++ libustcomm/ustcomm.h | 11 +++++++++++ 2 files changed, 43 insertions(+) diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c index fe8fea2..7d0fe00 100644 --- a/libustcomm/ustcomm.c +++ b/libustcomm/ustcomm.c @@ -621,6 +621,38 @@ char * ustcomm_restore_ptr(char *ptr, char *data_field, int data_field_size) return data_field + (long)ptr; } +int ustcomm_pack_trace_info(struct ustcomm_header *header, + struct ustcomm_trace_info *trace_inf, + const char *trace) +{ + int offset = 0; + + trace_inf->trace = ustcomm_print_data(trace_inf->data, + sizeof(trace_inf->data), + &offset, + trace); + + if (trace_inf->trace == USTCOMM_POISON_PTR) { + return -ENOMEM; + } + + header->size = COMPUTE_MSG_SIZE(trace_inf, offset); + + return 0; +} + + +int ustcomm_unpack_trace_info(struct ustcomm_trace_info *trace_inf) +{ + trace_inf->trace = ustcomm_restore_ptr(trace_inf->trace, + trace_inf->data, + sizeof(trace_inf->data)); + if (!trace_inf->trace) { + return -EINVAL; + } + + return 0; +} int ustcomm_pack_channel_info(struct ustcomm_header *header, struct ustcomm_channel_info *ch_inf, diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h index 4c2e7cd..ed8470f 100644 --- a/libustcomm/ustcomm.h +++ b/libustcomm/ustcomm.h @@ -78,6 +78,11 @@ enum tracectl_commands { STOP_TRACE, }; +struct ustcomm_trace_info { + char *trace; + char data[USTCOMM_DATA_SIZE]; +}; + struct ustcomm_channel_info { char *channel; unsigned int subbuf_size; @@ -172,6 +177,12 @@ extern char * ustcomm_restore_ptr(char *ptr, char *data_field, (size_t) (long)(struct_ptr)->data - (long)(struct_ptr) + (offset) /* Packing and unpacking functions, making life easier */ +extern int ustcomm_pack_trace_info(struct ustcomm_header *header, + struct ustcomm_trace_info *trace_inf, + const char *trace); + +extern int ustcomm_unpack_trace_info(struct ustcomm_trace_info *trace_inf); + extern int ustcomm_pack_channel_info(struct ustcomm_header *header, struct ustcomm_channel_info *ch_inf, const char *channel); -- 2.34.1