fields.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #ifndef BABELTRACE_CTF_IR_FIELDS_H
  2. #define BABELTRACE_CTF_IR_FIELDS_H
  3. /*
  4. * Babeltrace - CTF IR: Event Fields
  5. *
  6. * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  7. *
  8. * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26. * SOFTWARE.
  27. *
  28. * The Common Trace Format (CTF) Specification is available at
  29. * http://www.efficios.com/ctf
  30. */
  31. #include <stdint.h>
  32. #include <stddef.h>
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. struct bt_ctf_event_class;
  37. struct bt_ctf_event;
  38. struct bt_ctf_field;
  39. struct bt_ctf_field_type;
  40. /*
  41. * bt_ctf_field_create: create an instance of a field.
  42. *
  43. * Allocate a new field of the type described by the bt_ctf_field_type
  44. * structure.The creation of a field sets its reference count to 1.
  45. *
  46. * @param type Field type to be instanciated.
  47. *
  48. * Returns an allocated field on success, NULL on error.
  49. */
  50. extern struct bt_ctf_field *bt_ctf_field_create(
  51. struct bt_ctf_field_type *type);
  52. /*
  53. * bt_ctf_field_variant_get_field: get a variant's selected field.
  54. *
  55. * Return the variant's selected field. The "tag" field is the selector enum
  56. * field. bt_ctf_field_put() must be called on the returned value.
  57. *
  58. * @param variant Variant field instance.
  59. * @param tag Selector enumeration field.
  60. *
  61. * Returns a field instance on success, NULL on error.
  62. */
  63. extern struct bt_ctf_field *bt_ctf_field_variant_get_field(
  64. struct bt_ctf_field *variant, struct bt_ctf_field *tag);
  65. /*
  66. * bt_ctf_field_structure_get_field: get a structure's field.
  67. *
  68. * Get the structure's field corresponding to the provided field name.
  69. * bt_ctf_field_put() must be called on the returned value.
  70. *
  71. * @param structure Structure field instance.
  72. * @param name Name of the field in the provided structure.
  73. *
  74. * Returns a field instance on success, NULL on error.
  75. */
  76. extern struct bt_ctf_field *bt_ctf_field_structure_get_field(
  77. struct bt_ctf_field *structure, const char *name);
  78. /*
  79. * bt_ctf_field_array_get_field: get an array's field at position "index".
  80. *
  81. * Return the array's field at position "index". bt_ctf_field_put() must be
  82. * called on the returned value.
  83. *
  84. * @param array Array field instance.
  85. * @param index Position of the array's desired element.
  86. *
  87. * Returns a field instance on success, NULL on error.
  88. */
  89. extern struct bt_ctf_field *bt_ctf_field_array_get_field(
  90. struct bt_ctf_field *array, uint64_t index);
  91. /*
  92. * bt_ctf_field_sequence_set_length: set a sequence's length.
  93. *
  94. * Set the sequence's length field.
  95. *
  96. * @param sequence Sequence field instance.
  97. * @param length_field Unsigned integer field instance indicating the
  98. * sequence's length.
  99. *
  100. * Returns 0 on success, a negative value on error.
  101. */
  102. extern int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence,
  103. struct bt_ctf_field *length_field);
  104. /*
  105. * bt_ctf_field_sequence_get_field: get a sequence's field at position "index".
  106. *
  107. * Return the sequence's field at position "index". The sequence's length must
  108. * have been set prior to calling this function using
  109. * bt_ctf_field_sequence_set_length().
  110. * bt_ctf_field_put() must be called on the returned value.
  111. *
  112. * @param array Sequence field instance.
  113. * @param index Position of the sequence's desired element.
  114. *
  115. * Returns a field instance on success, NULL on error.
  116. */
  117. extern struct bt_ctf_field *bt_ctf_field_sequence_get_field(
  118. struct bt_ctf_field *sequence, uint64_t index);
  119. /*
  120. * bt_ctf_field_enumeration_get_container: get an enumeration field's container.
  121. *
  122. * Return the enumeration's underlying container field (an integer).
  123. * bt_ctf_field_put() must be called on the returned value.
  124. *
  125. * @param enumeration Enumeration field instance.
  126. *
  127. * Returns a field instance on success, NULL on error.
  128. */
  129. extern struct bt_ctf_field *bt_ctf_field_enumeration_get_container(
  130. struct bt_ctf_field *enumeration);
  131. /*
  132. * bt_ctf_field_signed_integer_set_value: set a signed integer field's value
  133. *
  134. * Set a signed integer field's value. The value is checked to make sure it
  135. * can be stored in the underlying field.
  136. *
  137. * @param integer Signed integer field instance.
  138. * @param value Signed integer field value.
  139. *
  140. * Returns 0 on success, a negative value on error.
  141. */
  142. extern int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer,
  143. int64_t value);
  144. /*
  145. * bt_ctf_field_unsigned_integer_set_value: set unsigned integer field's value
  146. *
  147. * Set an unsigned integer field's value. The value is checked to make sure it
  148. * can be stored in the underlying field.
  149. *
  150. * @param integer Unsigned integer field instance.
  151. * @param value Unsigned integer field value.
  152. *
  153. * Returns 0 on success, a negative value on error.
  154. */
  155. extern int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer,
  156. uint64_t value);
  157. /*
  158. * bt_ctf_field_floating_point_set_value: set a floating point field's value
  159. *
  160. * Set a floating point field's value. The underlying type may not support the
  161. * double's full precision.
  162. *
  163. * @param floating_point Floating point field instance.
  164. * @param value Floating point field value.
  165. *
  166. * Returns 0 on success, a negative value on error.
  167. */
  168. extern int bt_ctf_field_floating_point_set_value(
  169. struct bt_ctf_field *floating_point,
  170. double value);
  171. /*
  172. * bt_ctf_field_string_set_value: set a string field's value
  173. *
  174. * Set a string field's value.
  175. *
  176. * @param string_field String field instance.
  177. * @param value String field value (will be copied).
  178. *
  179. * Returns 0 on success, a negative value on error.
  180. */
  181. extern int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field,
  182. const char *value);
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif /* BABELTRACE_CTF_IR_FIELDS_H */