| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2018 Philippe Proulx <pproulx@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #define BT_LOG_TAG "CTF-WRITER/FIELD-WRAPPER" |
| 8 | #include "logging.h" |
| 9 | |
| 10 | #include <glib.h> |
| 11 | |
| 12 | #include "fields.h" |
| 13 | #include "field-wrapper.h" |
| 14 | #include "object.h" |
| 15 | |
| 16 | struct bt_ctf_field_wrapper *bt_ctf_field_wrapper_new( |
| 17 | void *data __attribute__((unused))) |
| 18 | { |
| 19 | struct bt_ctf_field_wrapper *field_wrapper = |
| 20 | g_new0(struct bt_ctf_field_wrapper, 1); |
| 21 | |
| 22 | BT_LOGD_STR("Creating empty field wrapper object."); |
| 23 | |
| 24 | if (!field_wrapper) { |
| 25 | BT_LOGE("Failed to allocate one field wrapper."); |
| 26 | goto end; |
| 27 | } |
| 28 | |
| 29 | bt_ctf_object_init_unique(&field_wrapper->base); |
| 30 | BT_LOGD("Created empty field wrapper object: addr=%p", |
| 31 | field_wrapper); |
| 32 | |
| 33 | end: |
| 34 | return field_wrapper; |
| 35 | } |
| 36 | |
| 37 | void bt_ctf_field_wrapper_destroy(struct bt_ctf_field_wrapper *field_wrapper) |
| 38 | { |
| 39 | BT_LOGD("Destroying field wrapper: addr=%p", field_wrapper); |
| 40 | BT_ASSERT_DBG(!field_wrapper->field); |
| 41 | BT_LOGD_STR("Putting stream class."); |
| 42 | g_free(field_wrapper); |
| 43 | } |
| 44 | |
| 45 | struct bt_ctf_field_wrapper *bt_ctf_field_wrapper_create( |
| 46 | struct bt_ctf_object_pool *pool, struct bt_ctf_field_type *ft) |
| 47 | { |
| 48 | struct bt_ctf_field_wrapper *field_wrapper = NULL; |
| 49 | |
| 50 | BT_ASSERT_DBG(pool); |
| 51 | BT_ASSERT_DBG(ft); |
| 52 | field_wrapper = bt_ctf_object_pool_create_object(pool); |
| 53 | if (!field_wrapper) { |
| 54 | BT_LOGE("Cannot allocate one field wrapper"); |
| 55 | goto end; |
| 56 | } |
| 57 | |
| 58 | BT_ASSERT_DBG(field_wrapper->field); |
| 59 | |
| 60 | end: |
| 61 | return field_wrapper; |
| 62 | } |