configure: re-enable '-Wunused-parameter'
[babeltrace.git] / src / lib / trace-ir / field-wrapper.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #define BT_LOG_TAG "LIB/FIELD-WRAPPER"
8 #include "lib/logging.h"
9
10 #include "lib/object-pool.h"
11 #include "lib/object.h"
12 #include <glib.h>
13
14 #include "field-wrapper.h"
15 #include "field.h"
16
17 struct bt_field_wrapper *bt_field_wrapper_new(void *data __attribute__((unused)))
18 {
19 struct bt_field_wrapper *field_wrapper =
20 g_new0(struct bt_field_wrapper, 1);
21
22 BT_LOGD_STR("Creating empty field wrapper object.");
23
24 if (!field_wrapper) {
25 BT_LIB_LOGE_APPEND_CAUSE(
26 "Failed to allocate one field wrapper.");
27 goto end;
28 }
29
30 bt_object_init_unique(&field_wrapper->base);
31 BT_LOGD("Created empty field wrapper object: addr=%p",
32 field_wrapper);
33
34 end:
35 return field_wrapper;
36 }
37
38 void bt_field_wrapper_destroy(struct bt_field_wrapper *field_wrapper)
39 {
40 BT_LOGD("Destroying field wrapper: addr=%p", field_wrapper);
41
42 if (field_wrapper->field) {
43 BT_LOGD_STR("Destroying field.");
44 bt_field_destroy((void *) field_wrapper->field);
45 field_wrapper->field = NULL;
46 }
47
48 BT_LOGD_STR("Putting stream class.");
49 g_free(field_wrapper);
50 }
51
52 struct bt_field_wrapper *bt_field_wrapper_create(
53 struct bt_object_pool *pool, struct bt_field_class *fc)
54 {
55 struct bt_field_wrapper *field_wrapper = NULL;
56
57 BT_ASSERT_DBG(pool);
58 BT_ASSERT_DBG(fc);
59 field_wrapper = bt_object_pool_create_object(pool);
60 if (!field_wrapper) {
61 BT_LIB_LOGE_APPEND_CAUSE(
62 "Cannot allocate one field wrapper from field wrapper pool: "
63 "%![pool-]+o", pool);
64 goto error;
65 }
66
67 if (!field_wrapper->field) {
68 field_wrapper->field = (void *) bt_field_create(fc);
69 if (!field_wrapper->field) {
70 BT_LIB_LOGE_APPEND_CAUSE(
71 "Cannot create field wrapper from field class: "
72 "%![fc-]+F", fc);
73 goto error;
74 }
75
76 BT_LIB_LOGD("Created initial field wrapper object: "
77 "wrapper-addr=%p, %![field-]+f", field_wrapper,
78 field_wrapper->field);
79 }
80
81 goto end;
82
83 error:
84 if (field_wrapper) {
85 bt_field_wrapper_destroy(field_wrapper);
86 field_wrapper = NULL;
87 }
88
89 end:
90 return field_wrapper;
91 }
This page took 0.030993 seconds and 4 git commands to generate.