summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/enum.c66
-rw-r--r--views/transform.c6
2 files changed, 46 insertions, 26 deletions
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 <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
+#include <uthash.h>
+
+#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_size<strlen(((pcilib_enum_t*)(params))[j].name)) {
- pcilib_error("the string to contain the enum command is too tight");
- return PCILIB_ERROR_MEMORY;
- }
- strncpy((char*)viewval,((pcilib_enum_t*)(params))[j].name, strlen(((pcilib_enum_t*)(params))[j].name));
- k=strlen(((pcilib_enum_t*)(params))[j].name);
- ((char*)viewval)[k]='\0';
- return 0;
- }
- }
+static int pcilib_enum_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t regval, 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]);
+
+ 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));