Refactoring: hide internal fields of ring buffer context
[lttng-ust.git] / liblttng-ust / lttng-context-ip.c
index 20c6fef34b8efbf5aa56dea460a4e8e72d6ed4f7..4f4ef632508542911ebbbf0b3aa7271b6ee50159 100644 (file)
@@ -7,12 +7,13 @@
  */
 
 #define _LGPL_SOURCE
+#include <limits.h>
 #include <stddef.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 
@@ -21,7 +22,7 @@ size_t ip_get_size(struct lttng_ust_ctx_field *field, size_t offset)
 {
        size_t size = 0;
 
-       size += lib_ring_buffer_align(offset, lttng_alignof(void *));
+       size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(void *));
        size += sizeof(void *);
        return size;
 }
@@ -29,36 +30,50 @@ size_t ip_get_size(struct lttng_ust_ctx_field *field, size_t offset)
 static
 void ip_record(struct lttng_ust_ctx_field *field,
                 struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                struct lttng_channel *chan)
+                struct lttng_ust_channel_buffer *chan)
 {
        void *ip;
 
        ip = ctx->ip;
-       lib_ring_buffer_align_ctx(ctx, lttng_alignof(ip));
-       chan->ops->event_write(ctx, &ip, sizeof(ip));
+       chan->ops->event_write(ctx, &ip, sizeof(ip), lttng_ust_rb_alignof(ip));
 }
 
 int lttng_add_ip_to_ctx(struct lttng_ust_ctx **ctx)
 {
        struct lttng_ust_ctx_field *field;
+       struct lttng_ust_type_common *type;
+       int ret;
 
-       field = lttng_append_context(ctx);
-       if (!field)
+       type = lttng_ust_create_type_integer(sizeof(void *) * CHAR_BIT,
+                       lttng_ust_rb_alignof(void *) * CHAR_BIT,
+                       lttng_ust_is_signed_type(void *),
+                       BYTE_ORDER, 16);
+       if (!type)
                return -ENOMEM;
+       field = lttng_append_context(ctx);
+       if (!field) {
+               ret = -ENOMEM;
+               goto error_context;
+       }
        if (lttng_find_context(*ctx, "ip")) {
-               lttng_remove_context_field(ctx, field);
-               return -EEXIST;
+               ret = -EEXIST;
+               goto error_find_context;
        }
-       field->event_field->name = "ip";
-       field->event_field->type.atype = atype_integer;
-       field->event_field->type.u.integer.size = sizeof(void *) * CHAR_BIT;
-       field->event_field->type.u.integer.alignment = lttng_alignof(void *) * CHAR_BIT;
-       field->event_field->type.u.integer.signedness = lttng_is_signed_type(void *);
-       field->event_field->type.u.integer.reverse_byte_order = 0;
-       field->event_field->type.u.integer.base = 16;
-       field->event_field->type.u.integer.encoding = lttng_encode_none;
+       field->event_field->name = strdup("ip");
+       if (!field->event_field->name) {
+               ret = -ENOMEM;
+               goto error_name;
+       }
+       field->event_field->type = type;
        field->get_size = ip_get_size;
        field->record = ip_record;
        lttng_context_update(*ctx);
        return 0;
+
+error_name:
+error_find_context:
+       lttng_remove_context_field(ctx, field);
+error_context:
+       lttng_ust_destroy_type(type);
+       return ret;
 }
This page took 0.02587 seconds and 4 git commands to generate.