Add generic dc_field_get() helper
This generic helper just gets everything from the field cache. Dive computers can do their own things for any field they handle differently, and then at the end fall back to this for all of the common cases that are purely described by the field cache structure. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
48e46cf777
commit
e9129ff45a
@ -62,3 +62,41 @@ dc_status_t dc_field_get_string(dc_field_cache_t *cache, unsigned idx, dc_field_
|
||||
}
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Use this generic "pick fields from the field cache" helper
|
||||
* after you've handled all the ones you do differently
|
||||
*/
|
||||
dc_status_t
|
||||
dc_field_get(dc_field_cache_t *cache, dc_field_type_t type, unsigned int flags, void* value)
|
||||
{
|
||||
if (!(cache->initialized & (1 << type)))
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
switch (type) {
|
||||
case DC_FIELD_DIVETIME:
|
||||
return DC_FIELD_VALUE(*cache, value, DIVETIME);
|
||||
case DC_FIELD_MAXDEPTH:
|
||||
return DC_FIELD_VALUE(*cache, value, MAXDEPTH);
|
||||
case DC_FIELD_AVGDEPTH:
|
||||
return DC_FIELD_VALUE(*cache, value, AVGDEPTH);
|
||||
case DC_FIELD_GASMIX_COUNT:
|
||||
case DC_FIELD_TANK_COUNT:
|
||||
return DC_FIELD_VALUE(*cache, value, GASMIX_COUNT);
|
||||
case DC_FIELD_GASMIX:
|
||||
if (flags >= MAXGASES)
|
||||
break;
|
||||
return DC_FIELD_INDEX(*cache, value, GASMIX, flags);
|
||||
case DC_FIELD_SALINITY:
|
||||
return DC_FIELD_VALUE(*cache, value, SALINITY);
|
||||
case DC_FIELD_DIVEMODE:
|
||||
return DC_FIELD_VALUE(*cache, value, DIVEMODE);
|
||||
case DC_FIELD_STRING:
|
||||
return dc_field_get_string(cache, flags, (dc_field_string_t *)value);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@ -36,6 +36,7 @@ typedef struct dc_field_cache {
|
||||
dc_status_t dc_field_add_string(dc_field_cache_t *, const char *desc, const char *data);
|
||||
dc_status_t dc_field_add_string_fmt(dc_field_cache_t *, const char *desc, const char *fmt, ...);
|
||||
dc_status_t dc_field_get_string(dc_field_cache_t *, unsigned idx, dc_field_string_t *value);
|
||||
dc_status_t dc_field_get(dc_field_cache_t *, dc_field_type_t, unsigned int, void *);
|
||||
|
||||
/*
|
||||
* Macro to make it easy to set DC_FIELD_xyz values.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user