Fawkes API
Fawkes Development Version
|
25 #include <core/exceptions/software.h>
26 #include <core/exceptions/system.h>
27 #include <interface/field_iterator.h>
28 #include <interface/interface.h>
62 interface_ = interface;
72 interface_ = fit.interface_;
74 if (fit.value_string_) {
75 value_string_ = strdup(fit.value_string_);
95 infol_ = infol_->
next;
108 InterfaceFieldIterator
123 for (
unsigned int j = 0; j < i; ++j) {
136 for (
unsigned int j = 0; j < i; ++j) {
149 return (infol_ == fi.infol_);
159 return !(*
this == fi);
167 if (infol_ == NULL) {
178 InterfaceFieldIterator &
181 interface_ = fi.interface_;
193 if (infol_ == NULL) {
206 if (infol_ == NULL) {
207 throw NullPointerException(
"Cannot get type of end element");
224 default:
return "unknown";
235 if (infol_ == NULL) {
236 throw NullPointerException(
"Cannot get type of end element");
245 std::list<const char *>
248 std::list<const char *> enums;
249 interface_enum_map_t::const_iterator enum_it;
250 for (enum_it = infol_->
enum_map->begin(); enum_it != infol_->
enum_map->end(); ++enum_it) {
251 enums.push_back(enum_it->second.c_str());
262 if (infol_ == NULL) {
263 throw NullPointerException(
"Cannot get name of end element");
275 if (infol_ == NULL) {
276 throw NullPointerException(
"Cannot get value of end element");
288 if (infol_ == NULL) {
289 throw NullPointerException(
"Cannot get length of end element");
303 if (infol_ == NULL) {
304 throw NullPointerException(
"Cannot get value of end element");
306 if (value_string_ == NULL) {
311 (
unsigned int)0xFFFFFFFF);
313 char *tmp1 = strdup(
"");
317 for (
size_t i = 0; i < infol_->
length; ++i) {
319 switch (infol_->
type) {
321 rv = asprintf(&tmp2,
"%s%s", tmp1, (((
bool *)infol_->
value)[i]) ?
"true" :
"false");
323 case IFT_INT8: rv = asprintf(&tmp2,
"%s%i", tmp1, ((int8_t *)infol_->
value)[i]);
break;
324 case IFT_INT16: rv = asprintf(&tmp2,
"%s%i", tmp1, ((int16_t *)infol_->
value)[i]);
break;
325 case IFT_INT32: rv = asprintf(&tmp2,
"%s%i", tmp1, ((int32_t *)infol_->
value)[i]);
break;
327 #if (defined(__WORDSIZE) && __WORDSIZE == 64) || (defined(LONG_BIT) && LONG_BIT == 64) \
328 || defined(__x86_64__)
329 rv = asprintf(&tmp2,
"%s%li", tmp1, ((int64_t *)infol_->
value)[i]);
331 rv = asprintf(&tmp2,
"%s%lli", tmp1, ((int64_t *)infol_->
value)[i]);
334 case IFT_UINT8: rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint8_t *)infol_->
value)[i]);
break;
336 rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint16_t *)infol_->
value)[i]);
339 rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint32_t *)infol_->
value)[i]);
342 #if (defined(__WORDSIZE) && __WORDSIZE == 64) || (defined(LONG_BIT) && LONG_BIT == 64) \
343 || defined(__x86_64__)
344 rv = asprintf(&tmp2,
"%s%lu", tmp1, ((uint64_t *)infol_->
value)[i]);
346 rv = asprintf(&tmp2,
"%s%llu", tmp1, ((uint64_t *)infol_->
value)[i]);
349 case IFT_FLOAT: rv = asprintf(&tmp2,
"%s%f", tmp1, ((
float *)infol_->
value)[i]);
break;
350 case IFT_DOUBLE: rv = asprintf(&tmp2,
"%s%f", tmp1, ((
double *)infol_->
value)[i]);
break;
351 case IFT_BYTE: rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint8_t *)infol_->
value)[i]);
break;
365 "InterfaceFieldIterator::get_value_string(): asprintf() failed (1)");
370 if ((infol_->
length > 1) && (i < infol_->length - 1)) {
371 if (asprintf(&tmp2,
"%s%s", tmp1, array_sep) == -1) {
373 "InterfaceFieldIterator::get_value_string(): asprintf() failed (2)");
380 value_string_ = tmp1;
384 if (asprintf(&value_string_,
"%s", (
const char *)infol_->
value) == -1) {
386 "InterfaceFieldIterator::get_value_string(): asprintf() failed (3)");
389 if (asprintf(&value_string_,
"%c", *((
const char *)infol_->
value)) == -1) {
391 "InterfaceFieldIterator::get_value_string(): asprintf() failed (4)");
396 return value_string_;
410 if (infol_ == NULL) {
411 throw NullPointerException(
"Cannot get value of end element");
414 }
else if (index >= infol_->
length) {
417 return ((
bool *)infol_->
value)[index];
431 if (infol_ == NULL) {
432 throw NullPointerException(
"Cannot get value of end element");
435 }
else if (index >= infol_->
length) {
438 return ((int8_t *)infol_->
value)[index];
452 if (infol_ == NULL) {
453 throw NullPointerException(
"Cannot get value of end element");
456 }
else if (index >= infol_->
length) {
459 return ((uint8_t *)infol_->
value)[index];
473 if (infol_ == NULL) {
474 throw NullPointerException(
"Cannot get value of end element");
477 }
else if (index >= infol_->
length) {
480 return ((int16_t *)infol_->
value)[index];
494 if (infol_ == NULL) {
495 throw NullPointerException(
"Cannot get value of end element");
498 }
else if (index >= infol_->
length) {
501 return ((uint16_t *)infol_->
value)[index];
515 if (infol_ == NULL) {
516 throw NullPointerException(
"Cannot get value of end element");
519 }
else if (index >= infol_->
length) {
522 return ((int32_t *)infol_->
value)[index];
536 if (infol_ == NULL) {
537 throw NullPointerException(
"Cannot get value of end element");
540 }
else if (index >= infol_->
length) {
543 return ((uint32_t *)infol_->
value)[index];
557 if (infol_ == NULL) {
558 throw NullPointerException(
"Cannot get value of end element");
561 }
else if (index >= infol_->
length) {
564 return ((int64_t *)infol_->
value)[index];
578 if (infol_ == NULL) {
579 throw NullPointerException(
"Cannot get value of end element");
582 }
else if (index >= infol_->
length) {
585 return ((uint64_t *)infol_->
value)[index];
599 if (infol_ == NULL) {
600 throw NullPointerException(
"Cannot get value of end element");
603 }
else if (index >= infol_->
length) {
606 return ((
float *)infol_->
value)[index];
620 if (infol_ == NULL) {
621 throw NullPointerException(
"Cannot get value of end element");
624 }
else if (index >= infol_->
length) {
627 return ((
double *)infol_->
value)[index];
641 if (infol_ == NULL) {
642 throw NullPointerException(
"Cannot get value of end element");
645 }
else if (index >= infol_->
length) {
648 return ((uint8_t *)infol_->
value)[index];
662 if (infol_ == NULL) {
663 throw NullPointerException(
"Cannot get value of end element");
666 }
else if (index >= infol_->
length) {
669 return ((int32_t *)infol_->
value)[index];
685 if (infol_ == NULL) {
686 throw NullPointerException(
"Cannot get value of end element");
689 }
else if (index >= infol_->
length) {
692 int32_t int_val = ((int32_t *)infol_->
value)[index];
693 interface_enum_map_t::const_iterator ev = infol_->
enum_map->find(int_val);
694 if (ev == infol_->
enum_map->end()) {
695 throw IllegalArgumentException(
"Integer value is not a canonical enum value");
697 return ev->second.c_str();
710 if (infol_ == NULL) {
711 throw NullPointerException(
"Cannot get value of end element");
714 }
else if (infol_->
length == 1) {
717 return (
bool *)infol_->
value;
730 if (infol_ == NULL) {
731 throw NullPointerException(
"Cannot get value of end element");
735 return (int8_t *)infol_->
value;
748 if (infol_ == NULL) {
749 throw NullPointerException(
"Cannot get value of end element");
753 return (uint8_t *)infol_->
value;
766 if (infol_ == NULL) {
767 throw NullPointerException(
"Cannot get value of end element");
771 return (int16_t *)infol_->
value;
784 if (infol_ == NULL) {
785 throw NullPointerException(
"Cannot get value of end element");
789 return (uint16_t *)infol_->
value;
802 if (infol_ == NULL) {
803 throw NullPointerException(
"Cannot get value of end element");
807 return (int32_t *)infol_->
value;
820 if (infol_ == NULL) {
821 throw NullPointerException(
"Cannot get value of end element");
825 return (uint32_t *)infol_->
value;
838 if (infol_ == NULL) {
839 throw NullPointerException(
"Cannot get value of end element");
843 return (int64_t *)infol_->
value;
856 if (infol_ == NULL) {
857 throw NullPointerException(
"Cannot get value of end element");
861 return (uint64_t *)infol_->
value;
874 if (infol_ == NULL) {
875 throw NullPointerException(
"Cannot get value of end element");
879 return (
float *)infol_->
value;
892 if (infol_ == NULL) {
893 throw NullPointerException(
"Cannot get value of end element");
897 return (
double *)infol_->
value;
910 if (infol_ == NULL) {
911 throw NullPointerException(
"Cannot get value of end element");
915 return (uint8_t *)infol_->
value;
928 if (infol_ == NULL) {
929 throw NullPointerException(
"Cannot get value of end element");
933 return (int32_t *)infol_->
value;
945 if (infol_ == NULL) {
946 throw NullPointerException(
"Cannot get value of end element");
950 return (
const char *)infol_->
value;
964 if (infol_ == NULL) {
965 throw NullPointerException(
"Cannot set value of end element");
968 }
else if (index >= infol_->
length) {
971 char *dst = (
char *)infol_->
value + index *
sizeof(
bool);
972 memcpy((
void *)dst, &v,
sizeof(
bool));
988 if (infol_ == NULL) {
989 throw NullPointerException(
"Cannot set value of end element");
992 }
else if (index >= infol_->
length) {
995 char *dst = (
char *)infol_->
value + index *
sizeof(int8_t);
996 memcpy((
void *)dst, &v,
sizeof(int8_t));
1012 if (infol_ == NULL) {
1013 throw NullPointerException(
"Cannot set value of end element");
1016 }
else if (index >= infol_->
length) {
1019 char *dst = (
char *)infol_->
value + index *
sizeof(uint8_t);
1020 memcpy((
void *)dst, &v,
sizeof(uint8_t));
1036 if (infol_ == NULL) {
1037 throw NullPointerException(
"Cannot set value of end element");
1040 }
else if (index >= infol_->
length) {
1043 char *dst = (
char *)infol_->
value + index *
sizeof(int16_t);
1044 memcpy((
void *)dst, &v,
sizeof(int16_t));
1060 if (infol_ == NULL) {
1061 throw NullPointerException(
"Cannot set value of end element");
1064 }
else if (index >= infol_->
length) {
1067 char *dst = (
char *)infol_->
value + index *
sizeof(uint16_t);
1068 memcpy((
void *)dst, &v,
sizeof(uint16_t));
1084 if (infol_ == NULL) {
1085 throw NullPointerException(
"Cannot set value of end element");
1088 }
else if (index >= infol_->
length) {
1091 char *dst = (
char *)infol_->
value + index *
sizeof(int32_t);
1092 memcpy((
void *)dst, &v,
sizeof(int32_t));
1108 if (infol_ == NULL) {
1109 throw NullPointerException(
"Cannot set value of end element");
1112 }
else if (index >= infol_->
length) {
1115 char *dst = (
char *)infol_->
value + index *
sizeof(uint32_t);
1116 memcpy((
void *)dst, &v,
sizeof(uint32_t));
1132 if (infol_ == NULL) {
1133 throw NullPointerException(
"Cannot set value of end element");
1136 }
else if (index >= infol_->
length) {
1139 char *dst = (
char *)infol_->
value + index *
sizeof(int64_t);
1140 memcpy((
void *)dst, &v,
sizeof(int64_t));
1156 if (infol_ == NULL) {
1157 throw NullPointerException(
"Cannot set value of end element");
1160 }
else if (index >= infol_->
length) {
1163 char *dst = (
char *)infol_->
value + index *
sizeof(uint64_t);
1164 memcpy((
void *)dst, &v,
sizeof(uint64_t));
1180 if (infol_ == NULL) {
1181 throw NullPointerException(
"Cannot set value of end element");
1184 }
else if (index >= infol_->
length) {
1187 char *dst = (
char *)infol_->
value + index *
sizeof(
float);
1188 memcpy((
void *)dst, &v,
sizeof(
float));
1204 if (infol_ == NULL) {
1205 throw NullPointerException(
"Cannot set value of end element");
1208 }
else if (index >= infol_->
length) {
1211 char *dst = (
char *)infol_->
value + index *
sizeof(
double);
1212 memcpy((
void *)dst, &v,
sizeof(
double));
1228 if (infol_ == NULL) {
1229 throw NullPointerException(
"Cannot set value of end element");
1232 }
else if (index >= infol_->
length) {
1235 char *dst = (
char *)infol_->
value + index *
sizeof(uint8_t);
1236 memcpy((
void *)dst, &v,
sizeof(uint8_t));
1252 if (infol_ == NULL) {
1253 throw NullPointerException(
"Cannot set value of end element");
1256 }
else if (index >= infol_->
length) {
1259 interface_enum_map_t::const_iterator ev = infol_->
enum_map->find(e);
1260 if (ev == infol_->
enum_map->end()) {
1261 throw IllegalArgumentException(
"Integer value is not a canonical enum value");
1263 char *dst = (
char *)infol_->
value + index *
sizeof(int32_t);
1264 memcpy((
void *)dst, &e,
sizeof(int32_t));
1280 if (infol_ == NULL) {
1281 throw NullPointerException(
"Cannot set value of end element");
1284 }
else if (index >= infol_->
length) {
1287 interface_enum_map_t::const_iterator ev;
1288 for (ev = infol_->
enum_map->begin(); ev != infol_->
enum_map->end(); ++ev) {
1289 if (ev->second == e) {
1290 char *dst = (
char *)infol_->
value + index *
sizeof(int32_t);
1291 memcpy((
void *)dst, &ev->first,
sizeof(int32_t));
1298 throw IllegalArgumentException(
"Integer value is not a canonical enum value");
1311 if (infol_ == NULL) {
1312 throw NullPointerException(
"Cannot set value of end element");
1315 }
else if (infol_->
length == 1) {
1318 memcpy(infol_->
value, v, infol_->
length *
sizeof(
bool));
1333 if (infol_ == NULL) {
1334 throw NullPointerException(
"Cannot set value of end element");
1337 }
else if (infol_->
length == 1) {
1340 memcpy(infol_->
value, v, infol_->
length *
sizeof(int8_t));
1355 if (infol_ == NULL) {
1356 throw NullPointerException(
"Cannot set value of end element");
1359 }
else if (infol_->
length == 1) {
1362 memcpy(infol_->
value, v, infol_->
length *
sizeof(uint8_t));
1377 if (infol_ == NULL) {
1378 throw NullPointerException(
"Cannot set value of end element");
1381 }
else if (infol_->
length == 1) {
1384 memcpy(infol_->
value, v, infol_->
length *
sizeof(int16_t));
1399 if (infol_ == NULL) {
1400 throw NullPointerException(
"Cannot set value of end element");
1403 }
else if (infol_->
length == 1) {
1406 memcpy(infol_->
value, v, infol_->
length *
sizeof(uint16_t));
1421 if (infol_ == NULL) {
1422 throw NullPointerException(
"Cannot set value of end element");
1425 }
else if (infol_->
length == 1) {
1428 memcpy(infol_->
value, v, infol_->
length *
sizeof(int32_t));
1443 if (infol_ == NULL) {
1444 throw NullPointerException(
"Cannot set value of end element");
1447 }
else if (infol_->
length == 1) {
1450 memcpy(infol_->
value, v, infol_->
length *
sizeof(uint32_t));
1465 if (infol_ == NULL) {
1466 throw NullPointerException(
"Cannot set value of end element");
1469 }
else if (infol_->
length == 1) {
1472 memcpy(infol_->
value, v, infol_->
length *
sizeof(int64_t));
1487 if (infol_ == NULL) {
1488 throw NullPointerException(
"Cannot set value of end element");
1491 }
else if (infol_->
length == 1) {
1494 memcpy(infol_->
value, v, infol_->
length *
sizeof(uint64_t));
1509 if (infol_ == NULL) {
1510 throw NullPointerException(
"Cannot set value of end element");
1513 }
else if (infol_->
length == 1) {
1516 memcpy(infol_->
value, v, infol_->
length *
sizeof(
float));
1531 if (infol_ == NULL) {
1532 throw NullPointerException(
"Cannot set value of end element");
1535 }
else if (infol_->
length == 1) {
1538 memcpy(infol_->
value, v, infol_->
length *
sizeof(
double));
1553 if (infol_ == NULL) {
1554 throw NullPointerException(
"Cannot set value of end element");
1557 }
else if (infol_->
length == 1) {
1560 memcpy(infol_->
value, v, infol_->
length *
sizeof(uint8_t));
1574 if (infol_ == NULL) {
1575 throw NullPointerException(
"Cannot set value of end element");
1579 strncpy((
char *)infol_->
value, v, infol_->
length);
int32_t * get_enums() const
Get value of current enum field as integer array.
void set_enum_string(const char *e, unsigned int index=0)
Set value of current field as enum (from an integer).
void set_uint64s(uint64_t *i)
Set value of current field as unsigned integer array.
8 bit unsigned integer field
uint8_t * get_bytes() const
Get value of current field as byte array.
const void * get_value() const
Get value of current field.
interface_fieldinfo_t * next
next field, NULL if last
void set_uint16(uint16_t i, unsigned int index=0)
Set value of current field as unsigned integer.
void set_int8(int8_t i, unsigned int index=0)
Set value of current field as integer.
float * get_floats() const
Get value of current field as float array.
void set_bool(bool b, unsigned int index=0)
Set value of current field as bool.
void set_int64s(int64_t *i)
Set value of current field as integer array.
interface_fieldtype_t
Interface field type.
64 bit unsigned integer field
const char * get_value_string(const char *array_sep=", ")
Get value of current field as string.
InterfaceFieldIterator()
Constructor.
void set_bytes(uint8_t *b)
Set value of current field as byte array.
void set_bools(bool *b)
Set value of current field as bool array.
~InterfaceFieldIterator()
Destructor.
uint16_t * get_uint16s() const
Get value of current field as unsigned integer array.
field with interface specific enum type
16 bit unsigned integer field
32 bit unsigned integer field
void set_int16(int16_t i, unsigned int index=0)
Set value of current field as integer.
std::list< const char * > get_enum_valuenames() const
Return the list of possible enum value names.
void set_int32(int32_t i, unsigned int index=0)
Set value of current field as integer.
InterfaceFieldIterator & operator+(unsigned int i)
Advance by i steps.
uint8_t get_byte(unsigned int index=0) const
Get value of current field as byte.
void set_float(float f, unsigned int index=0)
Set value of current field as float.
int64_t * get_int64s() const
Get value of current field as integer array.
void set_uint8(uint8_t i, unsigned int index=0)
Set value of current field as unsigned integer.
bool get_bool(unsigned int index=0) const
Get value of current field as bool.
void mark_data_changed()
Mark data as changed.
void set_double(double f, unsigned int index=0)
Set value of current field as double.
void set_byte(uint8_t b, unsigned int index=0)
Set value of current field as byte.
void set_doubles(double *f)
Set value of current field as double array.
uint8_t * get_uint8s() const
Get value of current field as unsigned integer array.
interface_fieldtype_t get_type() const
Get type of current field.
InterfaceFieldIterator & operator++()
Prefix increment.
float get_float(unsigned int index=0) const
Get value of current field as float.
void set_int32s(int32_t *i)
Set value of current field as integer array.
uint8_t get_uint8(unsigned int index=0) const
Get value of current field as unsigned integer.
const char * enumtype
text representation of enum type
uint32_t get_uint32(unsigned int index=0) const
Get value of current field as unsigned integer.
Interface field info list.
uint64_t get_uint64(unsigned int index=0) const
Get value of current field as unsigned integer.
double * get_doubles() const
Get value of current field as double array.
const char * get_enum_string(unsigned int index=0) const
Get value of current enum field as string.
int32_t * get_int32s() const
Get value of current field as integer array.
int8_t get_int8(unsigned int index=0) const
Get value of current field as integer.
void set_uint8s(uint8_t *i)
Set value of current field as unsigned integer array.
const char * get_name() const
Get name of current field.
InterfaceFieldIterator & operator+=(unsigned int i)
Advance by i steps.
int16_t get_int16(unsigned int index=0) const
Get value of current field as integer.
void set_uint16s(uint16_t *i)
Set value of current field as unsigned integer array.
bool operator==(const InterfaceFieldIterator &fit) const
Check iterators for equality.
const interface_enum_map_t * enum_map
Map of possible enum values.
int8_t * get_int8s() const
Get value of current field as integer array.
bool * get_bools() const
Get value of current field as bool array.
void set_int8s(int8_t *i)
Set value of current field as integer array.
const char * get_string() const
Get value of current field as string.
void set_uint32s(uint32_t *i)
Set value of current field as unsigned integer array.
bool is_enum() const
Check if field is an enum.
int16_t * get_int16s() const
Get value of current field as integer array.
uint64_t * get_uint64s() const
Get value of current field as unsigned integer array.
void set_uint32(uint32_t i, unsigned int index=0)
Set value of current field as unsigned integer.
const char * name
Name of this field.
size_t get_length() const
Get length of current field.
void set_string(const char *s)
Set value of current field as string.
void set_floats(float *f)
Set value of current field as float array.
uint32_t * get_uint32s() const
Get value of current field as unsigned integer array.
const void * operator*() const
Get FieldHeader.
size_t length
Length of field (array, string)
void set_int64(int64_t i, unsigned int index=0)
Set value of current field as integer.
void set_enum(int32_t e, unsigned int index=0)
Set value of current field as enum (from an integer).
virtual const char * enum_tostring(const char *enumtype, int val) const =0
byte field, alias for uint8
void set_uint64(uint64_t i, unsigned int index=0)
Set value of current field as unsigned integer.
int32_t get_int32(unsigned int index=0) const
Get value of current field as integer.
int32_t get_enum(unsigned int index=0) const
Get value of current enum field as integer.
double get_double(unsigned int index=0) const
Get value of current field as double.
interface_fieldtype_t type
type of this field
void set_int16s(int16_t *i)
Set value of current field as integer array.
int64_t get_int64(unsigned int index=0) const
Get value of current field as integer.
bool operator!=(const InterfaceFieldIterator &fit) const
Check iterators for inequality.
InterfaceFieldIterator & operator=(const InterfaceFieldIterator &fit)
Make this instance point to the same segment as fi.
uint16_t get_uint16(unsigned int index=0) const
Get value of current field as unsigned integer.
const char * get_typename() const
Get type of current field as string.
void * value
Current value of this field.