From c74050b028d91c9bb8995dafba440babc7b621ff Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Mon, 14 Nov 2011 19:28:47 +0100 Subject: Created abstraction of shm buffer management. --- include/dlt/dlt_common.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/dlt/dlt_shm.h | 6 +++--- 2 files changed, 47 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index be315a0..cb317c6 100755 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -417,6 +417,7 @@ typedef struct */ typedef struct { + uint32_t service_id; /**< service ID */ char apid[DLT_ID_SIZE]; /**< application id */ char ctid[DLT_ID_SIZE]; /**< context id */ @@ -557,6 +558,26 @@ typedef struct uint32_t count; /**< nr. of entries */ } DltRingBuffer; +typedef struct +{ + char* shm; /* pointer to beginning of shared memory */ + int size; /* size of data area in shared memory */ + char* mem; /* pointer to data area in shared memory */ + + uint32_t min_size; /**< Minimum size of buffer */ + uint32_t max_size; /**< Maximum size of buffer */ + uint32_t step_size; /**< Step size of buffer */ +} DltBuffer; + +#define DLT_BUFFER_HEAD "SHM" + +typedef struct +{ + char head[4]; + unsigned char status; + int size; +} DltBufferBlockHead; + #ifdef __cplusplus extern "C" { @@ -942,6 +963,29 @@ extern "C" */ int dlt_check_storageheader(DltStorageHeader *storageheader); + + int dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size); + int dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size); + int dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size,uint32_t step_size); + int dlt_buffer_free_static(DltBuffer *buf); + int dlt_buffer_free_dynamic(DltBuffer *buf); + int dlt_buffer_push(DltBuffer *buf,const unsigned char *data,unsigned int size); + int dlt_buffer_push3(DltBuffer *buf,const unsigned char *data1,unsigned int size1,const unsigned char *data2,unsigned int size2,const unsigned char *data3,unsigned int size3); + int dlt_buffer_pull(DltBuffer *buf,unsigned char *data, int max_size); + int dlt_buffer_copy(DltBuffer *buf,unsigned char *data, int max_size); + int dlt_buffer_remove(DltBuffer *buf); + void dlt_buffer_info(DltBuffer *buf); + void dlt_buffer_status(DltBuffer *buf); + int dlt_buffer_get_total_size(DltBuffer *buf); + int dlt_buffer_get_used_size(DltBuffer *buf); + int dlt_buffer_get_message_count(DltBuffer *buf); + + int dlt_buffer_get(DltBuffer *buf,unsigned char *data, int max_size,int delete); + int dlt_buffer_reset(DltBuffer *buf); + void dlt_buffer_write_block(DltBuffer *buf,int *write, const unsigned char *data,unsigned int size); + void dlt_buffer_read_block(DltBuffer *buf,int *read,unsigned char *data,unsigned int size); + + /** * Initialize ringbuffer of with a maximum size of size * @param dltbuf Pointer to ringbuffer structure diff --git a/include/dlt/dlt_shm.h b/include/dlt/dlt_shm.h index 3744ec7..b623981 100644 --- a/include/dlt/dlt_shm.h +++ b/include/dlt/dlt_shm.h @@ -68,6 +68,8 @@ #ifndef DLT_SHM_H #define DLT_SHM_H +#include + /* shared memory key */ /* must be the same for server and cleint */ #define DLT_SHM_KEY 11771 @@ -88,9 +90,7 @@ typedef struct { int shmid; /* Id of shared memory */ int semid; /* Id of semaphore */ - char* shm; /* pointer to beginning of shared memory */ - int size; /* size of data area in shared memory */ - char* mem; /* pointer to data area in shared memory */ + DltBuffer buffer; } DltShm; typedef struct -- cgit v1.2.1