diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2015-10-13 00:40:04 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2015-10-13 00:40:04 +0200 |
commit | 981a4dafac2d2e7ed237cb31af68c7bf2cee8665 (patch) | |
tree | 4491e77b8a441565a084f4b169aa334977f8b0c7 /pcilib/value.c | |
parent | f13867f64fcba24ef2cb9d726b5ee1082ac1a8b9 (diff) | |
download | pcitool-981a4dafac2d2e7ed237cb31af68c7bf2cee8665.tar.gz pcitool-981a4dafac2d2e7ed237cb31af68c7bf2cee8665.tar.bz2 pcitool-981a4dafac2d2e7ed237cb31af68c7bf2cee8665.tar.xz pcitool-981a4dafac2d2e7ed237cb31af68c7bf2cee8665.zip |
Support transform views
Diffstat (limited to 'pcilib/value.c')
-rw-r--r-- | pcilib/value.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/pcilib/value.c b/pcilib/value.c index b039e5f..1a8cc45 100644 --- a/pcilib/value.c +++ b/pcilib/value.c @@ -57,6 +57,10 @@ int pcilib_set_value_from_int(pcilib_t *ctx, pcilib_value_t *value, long ival) { return 0; } +int pcilib_set_value_from_register_value(pcilib_t *ctx, pcilib_value_t *value, pcilib_register_value_t regval) { + return pcilib_set_value_from_int(ctx, value, regval); +} + int pcilib_set_value_from_static_string(pcilib_t *ctx, pcilib_value_t *value, const char *str) { pcilib_clean_value(ctx, value); @@ -66,6 +70,83 @@ int pcilib_set_value_from_static_string(pcilib_t *ctx, pcilib_value_t *value, co return 0; } +double pcilib_get_value_as_float(pcilib_t *ctx, const pcilib_value_t *val, int *ret) { + int err; + double res; + pcilib_value_t copy = {0}; + + err = pcilib_copy_value(ctx, ©, val); + if (err) { + if (ret) *ret = err; + return 0.; + } + + err = pcilib_convert_value_type(ctx, ©, PCILIB_TYPE_DOUBLE); + if (err) { + if (ret) *ret = err; + return 0.; + } + + if (ret) *ret = 0; + res = copy.fval; + + pcilib_clean_value(ctx, ©); + + return res; +} + +long pcilib_get_value_as_int(pcilib_t *ctx, const pcilib_value_t *val, int *ret) { + int err; + long res; + pcilib_value_t copy = {0}; + + err = pcilib_copy_value(ctx, ©, val); + if (err) { + if (ret) *ret = err; + return 0; + } + + err = pcilib_convert_value_type(ctx, ©, PCILIB_TYPE_LONG); + if (err) { + if (ret) *ret = err; + return 0; + } + + if (ret) *ret = 0; + res = copy.ival; + + pcilib_clean_value(ctx, ©); + + return res; +} + +pcilib_register_value_t pcilib_get_value_as_register_value(pcilib_t *ctx, const pcilib_value_t *val, int *ret) { + int err; + pcilib_register_value_t res; + pcilib_value_t copy = {0}; + + err = pcilib_copy_value(ctx, ©, val); + if (err) { + if (ret) *ret = err; + return 0.; + } + + err = pcilib_convert_value_type(ctx, ©, PCILIB_TYPE_LONG); + if (err) { + if (ret) *ret = err; + return 0.; + } + + if (ret) *ret = 0; + res = copy.ival; + + pcilib_clean_value(ctx, ©); + + return res; +} + + + /* double pcilib_value_get_float(pcilib_value_t *val) { |