Make API CTF-agnostic
[babeltrace.git] / lib / ctf-writer / serialize.c
index f20ad405cb99cdcebbb76ac1a4f9ae0c53d9e6a7..46ec8afbe121d8beb559c24858428c85347a455a 100644 (file)
  * SOFTWARE.
  */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <babeltrace/ctf-ir/field-types.h>
-#include <babeltrace/ctf-ir/field-types-internal.h>
-#include <babeltrace/ctf-ir/fields.h>
-#include <babeltrace/ctf-ir/fields-internal.h>
-#include <babeltrace/ctf-writer/serialize-internal.h>
+#define BT_LOG_TAG "CTF-WRITER-SERIALIZE"
+#include <babeltrace/lib-logging-internal.h>
+
 #include <babeltrace/align-internal.h>
-#include <babeltrace/mmap-align-internal.h>
-#include <babeltrace/endian-internal.h>
 #include <babeltrace/bitfield-internal.h>
+#include <babeltrace/common-internal.h>
 #include <babeltrace/compat/fcntl-internal.h>
+#include <babeltrace/ctf-writer/field-types-internal.h>
+#include <babeltrace/ctf-writer/field-types.h>
+#include <babeltrace/ctf-writer/fields-internal.h>
+#include <babeltrace/ctf-writer/fields.h>
+#include <babeltrace/ctf-writer/serialize-internal.h>
+#include <babeltrace/ctf-writer/utils-internal.h>
+#include <babeltrace/endian-internal.h>
+#include <babeltrace/mmap-align-internal.h>
 #include <babeltrace/types.h>
 #include <glib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
 
 #if (FLT_RADIX != 2)
 # error "Unsupported floating point radix"
@@ -59,11 +64,12 @@ union intval {
  * optimisation.
  */
 static
-int aligned_integer_write(struct bt_ctf_stream_pos *pos,
-               union intval value, unsigned int alignment, unsigned int size,
-               bt_bool is_signed, enum bt_ctf_byte_order byte_order)
+int aligned_integer_write(struct bt_ctf_stream_pos *pos, union intval value,
+               unsigned int alignment, unsigned int size, bt_bool is_signed,
+               enum bt_ctf_byte_order byte_order)
 {
-       bt_bool rbo = (byte_order != BT_CTF_MY_BYTE_ORDER); /* reverse byte order */
+       /* reverse byte order */
+       bt_bool rbo = (byte_order != BT_CTF_MY_BYTE_ORDER);
 
        if (!bt_ctf_stream_pos_align(pos, alignment))
                return -EFAULT;
@@ -71,7 +77,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
        if (!bt_ctf_stream_pos_access_ok(pos, size))
                return -EFAULT;
 
-       assert(!(pos->offset % CHAR_BIT));
+       BT_ASSERT(!(pos->offset % CHAR_BIT));
        if (!is_signed) {
                switch (size) {
                case 8:
@@ -200,41 +206,43 @@ int integer_write(struct bt_ctf_stream_pos *pos, union intval value,
 }
 
 BT_HIDDEN
-int bt_ctf_field_integer_write(struct bt_ctf_field_integer *int_field,
+int bt_ctf_field_integer_write(struct bt_ctf_field_common *field,
                struct bt_ctf_stream_pos *pos,
                enum bt_ctf_byte_order native_byte_order)
 {
-       struct bt_ctf_field_type *type = int_field->parent.type;
-       struct bt_ctf_field_type_integer *int_type = (void *) type;
+       struct bt_ctf_field_type_common_integer *int_type =
+               BT_CTF_FROM_COMMON(field->type);
+       struct bt_ctf_field_common_integer *int_field = BT_CTF_FROM_COMMON(field);
        enum bt_ctf_byte_order byte_order;
        union intval value;
 
-       byte_order = int_type->user_byte_order;
-       if (byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
+       byte_order = (int) int_type->user_byte_order;
+       if ((int) byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
                byte_order = native_byte_order;
        }
 
        value.signd = int_field->payload.signd;
        value.unsignd = int_field->payload.unsignd;
-       return integer_write(pos, value, type->alignment,
+       return integer_write(pos, value, int_type->common.alignment,
                int_type->size, int_type->is_signed,
                byte_order);
 }
 
 BT_HIDDEN
 int bt_ctf_field_floating_point_write(
-               struct bt_ctf_field_floating_point *flt_field,
+               struct bt_ctf_field_common *field,
                struct bt_ctf_stream_pos *pos,
                enum bt_ctf_byte_order native_byte_order)
 {
-       struct bt_ctf_field_type *type = flt_field->parent.type;
-       struct bt_ctf_field_type_floating_point *flt_type = (void *) type;
+       struct bt_ctf_field_type_common_floating_point *flt_type =
+               BT_CTF_FROM_COMMON(field->type);
+       struct bt_ctf_field_common_floating_point *flt_field = BT_CTF_FROM_COMMON(field);
        enum bt_ctf_byte_order byte_order;
        union intval value;
        unsigned int size;
 
-       byte_order = flt_type->user_byte_order;
-       if (byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
+       byte_order = (int) flt_type->user_byte_order;
+       if ((int) byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
                byte_order = native_byte_order;
        }
 
@@ -260,8 +268,8 @@ int bt_ctf_field_floating_point_write(
                return -EINVAL;
        }
 
-       return integer_write(pos, value, type->alignment, size, BT_FALSE,
-               byte_order);
+       return integer_write(pos, value, flt_type->common.alignment,
+               size, BT_FALSE, byte_order);
 }
 
 BT_HIDDEN
@@ -270,7 +278,7 @@ void bt_ctf_stream_pos_packet_seek(struct bt_ctf_stream_pos *pos, size_t index,
 {
        int ret;
 
-       assert(whence == SEEK_CUR && index == 0);
+       BT_ASSERT(whence == SEEK_CUR && index == 0);
 
        if (pos->base_mma) {
                /* unmap old base */
@@ -284,12 +292,12 @@ void bt_ctf_stream_pos_packet_seek(struct bt_ctf_stream_pos *pos, size_t index,
 
        /* The writer will add padding */
        pos->mmap_offset += pos->packet_size / CHAR_BIT;
-       pos->packet_size = getpagesize() * 8 * CHAR_BIT;
+       pos->packet_size = PACKET_LEN_INCREMENT;
        do {
                ret = bt_posix_fallocate(pos->fd, pos->mmap_offset,
                        pos->packet_size / CHAR_BIT);
        } while (ret == EINTR);
-       assert(ret == 0);
+       BT_ASSERT(ret == 0);
        pos->offset = 0;
 
        /* map new base. Need mapping length from header. */
This page took 0.028976 seconds and 4 git commands to generate.