Commit | Line | Data |
---|---|---|
16ca5ff0 PP |
1 | /* |
2 | * Copyright 2018 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | * of this software and associated documentation files (the "Software"), to deal | |
6 | * in the Software without restriction, including without limitation the rights | |
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | * copies of the Software, and to permit persons to whom the Software is | |
9 | * furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
20 | * SOFTWARE. | |
21 | */ | |
22 | ||
350ad6c1 | 23 | #define BT_LOG_TAG "CTF-WRITER/FIELD-WRAPPER" |
67d2ce02 | 24 | #include "logging.h" |
16ca5ff0 | 25 | |
16ca5ff0 PP |
26 | #include <glib.h> |
27 | ||
578e048b MJ |
28 | #include "lib/object-pool.h" |
29 | ||
30 | #include "fields.h" | |
31 | #include "field-wrapper.h" | |
32 | #include "object.h" | |
33 | ||
16ca5ff0 PP |
34 | BT_HIDDEN |
35 | struct bt_ctf_field_wrapper *bt_ctf_field_wrapper_new(void *data) | |
36 | { | |
37 | struct bt_ctf_field_wrapper *field_wrapper = | |
38 | g_new0(struct bt_ctf_field_wrapper, 1); | |
39 | ||
40 | BT_LOGD_STR("Creating empty field wrapper object."); | |
41 | ||
42 | if (!field_wrapper) { | |
43 | BT_LOGE("Failed to allocate one field wrapper."); | |
44 | goto end; | |
45 | } | |
46 | ||
e1e02a22 | 47 | bt_ctf_object_init_unique(&field_wrapper->base); |
16ca5ff0 PP |
48 | BT_LOGD("Created empty field wrapper object: addr=%p", |
49 | field_wrapper); | |
50 | ||
51 | end: | |
52 | return field_wrapper; | |
53 | } | |
54 | ||
55 | BT_HIDDEN | |
56 | void bt_ctf_field_wrapper_destroy(struct bt_ctf_field_wrapper *field_wrapper) | |
57 | { | |
58 | BT_LOGD("Destroying field wrapper: addr=%p", field_wrapper); | |
59 | BT_ASSERT(!field_wrapper->field); | |
60 | BT_LOGD_STR("Putting stream class."); | |
61 | g_free(field_wrapper); | |
62 | } | |
63 | ||
64 | BT_HIDDEN | |
65 | struct bt_ctf_field_wrapper *bt_ctf_field_wrapper_create( | |
e1e02a22 | 66 | struct bt_ctf_object_pool *pool, struct bt_ctf_field_type *ft) |
16ca5ff0 PP |
67 | { |
68 | struct bt_ctf_field_wrapper *field_wrapper = NULL; | |
69 | ||
70 | BT_ASSERT(pool); | |
71 | BT_ASSERT(ft); | |
e1e02a22 | 72 | field_wrapper = bt_ctf_object_pool_create_object(pool); |
16ca5ff0 | 73 | if (!field_wrapper) { |
67d2ce02 | 74 | BT_LOGE("Cannot allocate one field wrapper"); |
16ca5ff0 PP |
75 | goto error; |
76 | } | |
77 | ||
78 | BT_ASSERT(field_wrapper->field); | |
79 | goto end; | |
80 | ||
81 | error: | |
82 | if (field_wrapper) { | |
83 | bt_ctf_field_wrapper_destroy(field_wrapper); | |
84 | field_wrapper = NULL; | |
85 | } | |
86 | ||
87 | end: | |
88 | return field_wrapper; | |
89 | } |