#include <babeltrace/ctf/metadata.h>
#include <glib.h>
+#include "events-private.h"
+
/*
* thread local storage to store the last error that occured
* while reading a field, this variable must be accessed by
const char *field)
{
struct definition *def;
+ char *field_underscore;
if (scope) {
def = lookup_definition(scope, field);
+ /*
+ * optionally a field can have an underscore prefix, try
+ * to lookup the field with this prefix if it failed
+ */
+ if (!def) {
+ field_underscore = g_new(char, strlen(field) + 2);
+ field_underscore[0] = '_';
+ strcpy(&field_underscore[1], field);
+ def = lookup_definition(scope, field_underscore);
+ g_free(field_underscore);
+ }
if (bt_ctf_field_type(def) == CTF_TYPE_VARIANT) {
struct definition_variant *variant_definition;
variant_definition = container_of(def,
const char *bt_ctf_field_name(const struct definition *def)
{
if (def)
- return g_quark_to_string(def->name);
+ return rem_(g_quark_to_string(def->name));
return NULL;
}
return -1;
}
+uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event)
+{
+ if (event && event->stream->has_timestamp)
+ return ctf_get_timestamp_raw(event->stream,
+ event->stream->timestamp);
+ else
+ return -1ULL;
+}
+
uint64_t bt_ctf_get_timestamp(struct bt_ctf_event *event)
{
if (event && event->stream->has_timestamp)
- return event->stream->timestamp;
+ return ctf_get_timestamp(event->stream,
+ event->stream->timestamp);
else
- return 0;
+ return -1ULL;
}
static void bt_ctf_field_set_error(int error)
return ret;
}
+int bt_ctf_get_int_signedness(const struct definition *field)
+{
+ int ret;
+
+ if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
+ ret = get_int_signedness(field);
+ } else {
+ ret = -1;
+ bt_ctf_field_set_error(-EINVAL);
+ }
+
+ return ret;
+}
+
+int bt_ctf_get_int_base(const struct definition *field)
+{
+ int ret;
+
+ if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
+ ret = get_int_base(field);
+ } else {
+ ret = -1;
+ bt_ctf_field_set_error(-EINVAL);
+ }
+
+ return ret;
+}
+
+int bt_ctf_get_int_byte_order(const struct definition *field)
+{
+ int ret;
+
+ if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
+ ret = get_int_byte_order(field);
+ } else {
+ ret = -1;
+ bt_ctf_field_set_error(-EINVAL);
+ }
+
+ return ret;
+}
+
+enum ctf_string_encoding bt_ctf_get_encoding(const struct definition *field)
+{
+ enum ctf_string_encoding ret = 0;
+
+ if (!field)
+ goto end;
+
+ if (bt_ctf_field_type(field) == CTF_TYPE_INTEGER)
+ ret = get_int_encoding(field);
+ else if (bt_ctf_field_type(field) == CTF_TYPE_STRING)
+ ret = get_string_encoding(field);
+ else
+ goto error;
+
+end:
+ return ret;
+
+error:
+ bt_ctf_field_set_error(-EINVAL);
+ return -1;
+}
+
+int bt_ctf_get_array_len(const struct definition *field)
+{
+ int ret;
+
+ if (field && bt_ctf_field_type(field) == CTF_TYPE_ARRAY) {
+ ret = get_array_len(field);
+ } else {
+ ret = -1;
+ bt_ctf_field_set_error(-EINVAL);
+ }
+
+ return ret;
+}
+
uint64_t bt_ctf_get_uint64(const struct definition *field)
{
unsigned int ret = 0;