From b2bf9e15ebcdbb3cfb7c38f43446bec48b446793 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 23 Sep 2016 09:09:40 -1000 Subject: [PATCH] Use union of datatypes supported by dataman to reduce wasted space --- src/modules/dataman/dataman.c | 9 +++++---- src/modules/dataman/dataman.h | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/modules/dataman/dataman.c b/src/modules/dataman/dataman.c index 62978e0f7c..6af444d880 100644 --- a/src/modules/dataman/dataman.c +++ b/src/modules/dataman/dataman.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -388,7 +389,7 @@ static ssize_t _ram_write(dm_item_t item, unsigned char index, dm_persitence_t p /* Make sure caller has not given us more data than we can handle */ if (count > DM_MAX_DATA_SIZE) { - return -1; + return -E2BIG; } uint8_t *buffer = &g_task_data[offset]; @@ -429,7 +430,7 @@ _file_write(dm_item_t item, unsigned char index, dm_persitence_t persistence, co /* Make sure caller has not given us more data than we can handle */ if (count > DM_MAX_DATA_SIZE) { - return -1; + return -E2BIG; } /* Write out the data, prefixed with length and persistence level */ @@ -474,7 +475,7 @@ static ssize_t _ram_read(dm_item_t item, unsigned char index, void *buf, size_t /* Make sure the caller hasn't asked for more data than we can handle */ if (count > DM_MAX_DATA_SIZE) { - return -1; + return -E2BIG; } /* Read the prefix and data */ @@ -517,7 +518,7 @@ _file_read(dm_item_t item, unsigned char index, void *buf, size_t count) /* Make sure the caller hasn't asked for more data than we can handle */ if (count > DM_MAX_DATA_SIZE) { - return -1; + return -E2BIG; } /* Read the prefix and data */ diff --git a/src/modules/dataman/dataman.h b/src/modules/dataman/dataman.h index 34d48f8979..337cdddef1 100644 --- a/src/modules/dataman/dataman.h +++ b/src/modules/dataman/dataman.h @@ -42,6 +42,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -102,8 +103,18 @@ typedef enum { DM_INIT_REASON_VOLATILE /* Data does not survive reset */ } dm_reset_reason; -/** Maximum size in bytes of a single item instance */ -#define DM_MAX_DATA_SIZE 126 +/** Maximum size in bytes of a single item instance is + * defined by adding the structure type to the union below + */ + +typedef union dataman_max_size_t { + struct mission_item_s mission_item; + struct mission_s mission; + struct fence_vertex_s vertex; +} dataman_max_size_t; + + +#define DM_MAX_DATA_SIZE sizeof(dataman_max_size_t) /** Retrieve from the data manager store */ __EXPORT ssize_t