bzr branch
http://suren.me/webbzr/alps/pcitool
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
1 |
#define _PCILIB_VIEW_ENUM_C
|
2 |
||
3 |
#include <stdio.h> |
|
4 |
#include <unistd.h> |
|
5 |
#include <stdlib.h> |
|
6 |
#include <string.h> |
|
311
by Suren A. Chilingaryan
Implement enum view |
7 |
#include <strings.h> |
8 |
||
9 |
#include <uthash.h> |
|
10 |
||
11 |
#include "error.h" |
|
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
12 |
#include "version.h" |
13 |
#include "model.h" |
|
14 |
#include "enum.h" |
|
311
by Suren A. Chilingaryan
Implement enum view |
15 |
#include "view.h" |
16 |
#include "value.h" |
|
17 |
||
18 |
||
19 |
static void pcilib_enum_view_free(pcilib_t *ctx, pcilib_view_description_t *view) { |
|
20 |
pcilib_enum_view_description_t *v = (pcilib_enum_view_description_t*)view; |
|
21 |
if (v->names) |
|
22 |
free(v->names); |
|
23 |
free(v); |
|
24 |
}
|
|
25 |
||
26 |
static int pcilib_enum_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t regval, pcilib_value_t *val) { |
|
27 |
int i; |
|
28 |
||
29 |
const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); |
|
30 |
pcilib_enum_view_description_t *v = (pcilib_enum_view_description_t*)(model_info->views[view_ctx->view]); |
|
31 |
||
32 |
for (i = 0; v->names[i].name; i++) { |
|
33 |
if ((regval >= v->names[i].min)&&(regval <= v->names[i].max)) |
|
34 |
return pcilib_set_value_from_static_string(ctx, val, v->names[i].name); |
|
35 |
}
|
|
36 |
||
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
37 |
return pcilib_set_value_from_register_value(ctx, val, regval); |
311
by Suren A. Chilingaryan
Implement enum view |
38 |
}
|
39 |
||
40 |
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) { |
|
41 |
int i; |
|
42 |
||
43 |
const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); |
|
44 |
pcilib_enum_view_description_t *v = (pcilib_enum_view_description_t*)(model_info->views[view_ctx->view]); |
|
45 |
||
46 |
if (val->type != PCILIB_TYPE_STRING) { |
|
47 |
pcilib_warning("Value of unsupported type (%s) is passed to enum_view", pcilib_get_type_name(val->type)); |
|
48 |
return PCILIB_ERROR_INVALID_ARGUMENT; |
|
49 |
}
|
|
50 |
||
51 |
for (i = 0; v->names[i].name; i++) { |
|
52 |
if (!strcasecmp(v->names[i].name, val->sval)) { |
|
53 |
*regval = v->names[i].value; |
|
54 |
return 0; |
|
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
55 |
}
|
56 |
}
|
|
311
by Suren A. Chilingaryan
Implement enum view |
57 |
|
58 |
pcilib_warning("Error setting register value, the value corresponding to name (%s) is not defined", val->sval); |
|
59 |
return PCILIB_ERROR_NOTFOUND; |
|
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
60 |
}
|
61 |
||
62 |
const pcilib_view_api_description_t pcilib_enum_view_static_api = |
|
310
by Suren A. Chilingaryan
Introduce hashes |
63 |
{ PCILIB_VERSION, sizeof(pcilib_enum_view_description_t), NULL, NULL, NULL, pcilib_enum_view_read, pcilib_enum_view_write }; |
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
64 |
const pcilib_view_api_description_t pcilib_enum_view_xml_api = |
310
by Suren A. Chilingaryan
Introduce hashes |
65 |
{ PCILIB_VERSION, sizeof(pcilib_enum_view_description_t), NULL, NULL, pcilib_enum_view_free, pcilib_enum_view_read, pcilib_enum_view_write }; |