From f13867f64fcba24ef2cb9d726b5ee1082ac1a8b9 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Fri, 9 Oct 2015 04:42:53 +0200 Subject: Implement enum view --- views/enum.c | 66 +++++++++++++++++++++++++++++++++++-------------------- views/transform.c | 6 +++-- 2 files changed, 46 insertions(+), 26 deletions(-) (limited to 'views') diff --git a/views/enum.c b/views/enum.c index 5d3a726..d712c71 100644 --- a/views/enum.c +++ b/views/enum.c @@ -4,41 +4,59 @@ #include #include #include +#include +#include + +#include "error.h" #include "version.h" #include "model.h" #include "enum.h" +#include "view.h" +#include "value.h" + -static void pcilib_enum_view_free(pcilib_t *ctx, pcilib_view_context_t *view) { +static void pcilib_enum_view_free(pcilib_t *ctx, pcilib_view_description_t *view) { + pcilib_enum_view_description_t *v = (pcilib_enum_view_description_t*)view; + if (v->names) + free(v->names); + free(v); } -static int pcilib_enum_view_read(pcilib_t *ctx, pcilib_view_context_t *view, const pcilib_register_value_t *regval, pcilib_value_t *val) { -/* for(j=0; ((pcilib_enum_t*)(params))[j].name; j++) { - if (*regval<=((pcilib_enum_t*)(params))[j].max && *regval>=((pcilib_enum_t*)(params))[j].min) { - if(viewval_sizeviews[view_ctx->view]); + + for (i = 0; v->names[i].name; i++) { + if ((regval >= v->names[i].min)&&(regval <= v->names[i].max)) + return pcilib_set_value_from_static_string(ctx, val, v->names[i].name); } - return PCILIB_ERROR_INVALID_REQUEST;*/ + + return pcilib_set_value_from_int(ctx, val, regval); } -static int pcilib_enum_view_write(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t *regval, pcilib_value_t *val) { -/* int j,k; +static int pcilib_enum_view_write(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t *regval, const pcilib_value_t *val) { + int i; + + const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); + pcilib_enum_view_description_t *v = (pcilib_enum_view_description_t*)(model_info->views[view_ctx->view]); + + if (val->type != PCILIB_TYPE_STRING) { + pcilib_warning("Value of unsupported type (%s) is passed to enum_view", pcilib_get_type_name(val->type)); + return PCILIB_ERROR_INVALID_ARGUMENT; + } + + for (i = 0; v->names[i].name; i++) { + if (!strcasecmp(v->names[i].name, val->sval)) { + *regval = v->names[i].value; + return 0; + } + } - if(view2reg==1) { - for(j=0; ((pcilib_enum_t*)(params))[j].name; j++) { - if(!(strcasecmp(((pcilib_enum_t*)(params))[j].name,(char*)viewval))) { - *regval=((pcilib_enum_t*)(params))[j].value; - return 0; - } - }*/ + pcilib_warning("Error setting register value, the value corresponding to name (%s) is not defined", val->sval); + return PCILIB_ERROR_NOTFOUND; } const pcilib_view_api_description_t pcilib_enum_view_static_api = diff --git a/views/transform.c b/views/transform.c index 8885e17..818c1d6 100644 --- a/views/transform.c +++ b/views/transform.c @@ -10,7 +10,9 @@ #include "transform.h" -static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view, const pcilib_register_value_t *regval, pcilib_value_t *val) { +static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t regval, pcilib_value_t *val) { + pcilib_set_value_from_int(ctx, val, 0); + return 0; /* int j=0; pcilib_register_value_t value=0; char* formula=NULL; @@ -43,7 +45,7 @@ static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view }*/ } -static int pcilib_transform_view_write(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t *regval, pcilib_value_t *val) { +static int pcilib_transform_view_write(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t *regval, const pcilib_value_t *val) { /* if(!(strcasecmp(unit, ((pcilib_view_t*)viewval)->base_unit.name))) { formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->write_formula)); strncpy(formula,((pcilib_formula_t*)params)->write_formula,strlen(((pcilib_formula_t*)params)->write_formula)); -- cgit v1.2.3