Commit | Line | Data |
---|---|---|
a3f0c7db | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
a3f0c7db | 3 | * |
0235b0db | 4 | * Copyright 2019 EfficiOS, Inc. |
a3f0c7db SM |
5 | */ |
6 | ||
7 | #define BT_LOG_TAG "LIB/MESSAGE-ITERATOR-CLASS" | |
8 | #include "lib/logging.h" | |
9 | ||
10 | #include "message-iterator-class.h" | |
11 | ||
12 | #include "compat/compiler.h" | |
d98421f2 | 13 | #include "lib/assert-cond.h" |
a3f0c7db SM |
14 | #include "lib/func-status.h" |
15 | ||
1778c2a4 PP |
16 | #define BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(_msg_iter_cls) \ |
17 | BT_ASSERT_PRE_DEV_HOT("message-iterator-class", \ | |
18 | (_msg_iter_cls), "Message iterator class", \ | |
19 | ": %!+I", (_msg_iter_cls)) | |
a3f0c7db | 20 | |
a3f0c7db SM |
21 | void _bt_message_iterator_class_freeze( |
22 | const struct bt_message_iterator_class *msg_iter_cls) | |
23 | { | |
24 | BT_ASSERT(msg_iter_cls); | |
25 | BT_LIB_LOGD("Freezing message iterator class: %!+I", msg_iter_cls); | |
26 | ((struct bt_message_iterator_class *) msg_iter_cls)->frozen = true; | |
27 | } | |
28 | ||
1353b066 | 29 | BT_EXPORT |
a3f0c7db SM |
30 | void bt_message_iterator_class_get_ref( |
31 | const bt_message_iterator_class *message_iterator_class) | |
32 | { | |
33 | bt_object_get_ref(message_iterator_class); | |
34 | } | |
35 | ||
1353b066 | 36 | BT_EXPORT |
a3f0c7db SM |
37 | void bt_message_iterator_class_put_ref( |
38 | const bt_message_iterator_class *message_iterator_class) | |
39 | { | |
40 | bt_object_put_ref(message_iterator_class); | |
41 | } | |
42 | ||
43 | static | |
44 | void destroy_iterator_class(struct bt_object *obj) | |
45 | { | |
46 | struct bt_message_iterator_class *class; | |
47 | ||
48 | BT_ASSERT(obj); | |
49 | class = container_of(obj, struct bt_message_iterator_class, base); | |
50 | ||
51 | BT_LIB_LOGI("Destroying message iterator class: %!+I", class); | |
52 | ||
53 | g_free(class); | |
54 | } | |
55 | ||
1353b066 | 56 | BT_EXPORT |
a3f0c7db SM |
57 | struct bt_message_iterator_class *bt_message_iterator_class_create( |
58 | bt_message_iterator_class_next_method next_method) | |
59 | { | |
60 | struct bt_message_iterator_class *message_iterator_class; | |
61 | ||
62 | BT_ASSERT_PRE_NO_ERROR(); | |
1778c2a4 | 63 | BT_ASSERT_PRE_NON_NULL("next-method", next_method, "Next method"); |
a3f0c7db SM |
64 | BT_LOGI("Creating message iterator class: next-method-addr=%p", |
65 | next_method); | |
66 | ||
67 | message_iterator_class = g_new0(struct bt_message_iterator_class, 1); | |
68 | if (!message_iterator_class) { | |
69 | BT_LIB_LOGE_APPEND_CAUSE( | |
70 | "Failed to allocate one message iterator class."); | |
71 | goto end; | |
72 | } | |
73 | ||
74 | bt_object_init_shared(&message_iterator_class->base, destroy_iterator_class); | |
75 | ||
76 | message_iterator_class->methods.next = next_method; | |
77 | ||
78 | end: | |
79 | return message_iterator_class; | |
80 | } | |
81 | ||
1353b066 | 82 | BT_EXPORT |
a3f0c7db SM |
83 | bt_message_iterator_class_set_method_status |
84 | bt_message_iterator_class_set_initialize_method( | |
85 | bt_message_iterator_class *message_iterator_class, | |
86 | bt_message_iterator_class_initialize_method method) | |
87 | { | |
88 | BT_ASSERT_PRE_NO_ERROR(); | |
d5b13b9b PP |
89 | BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class); |
90 | BT_ASSERT_PRE_METHOD_NON_NULL(method); | |
1778c2a4 | 91 | BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class); |
a3f0c7db SM |
92 | message_iterator_class->methods.initialize = method; |
93 | BT_LIB_LOGD("Set message iterator class's iterator initialization method" | |
94 | ": %!+I", message_iterator_class); | |
95 | return BT_FUNC_STATUS_OK; | |
96 | } | |
97 | ||
1353b066 | 98 | BT_EXPORT |
a3f0c7db SM |
99 | bt_message_iterator_class_set_method_status |
100 | bt_message_iterator_class_set_finalize_method( | |
101 | bt_message_iterator_class *message_iterator_class, | |
102 | bt_message_iterator_class_finalize_method method) | |
103 | { | |
104 | BT_ASSERT_PRE_NO_ERROR(); | |
d5b13b9b PP |
105 | BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class); |
106 | BT_ASSERT_PRE_METHOD_NON_NULL(method); | |
1778c2a4 | 107 | BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class); |
a3f0c7db SM |
108 | message_iterator_class->methods.finalize = method; |
109 | BT_LIB_LOGD("Set message iterator class's finalization method" | |
110 | ": %!+I", message_iterator_class); | |
111 | return BT_FUNC_STATUS_OK; | |
112 | } | |
113 | ||
1353b066 | 114 | BT_EXPORT |
a3f0c7db SM |
115 | bt_message_iterator_class_set_method_status |
116 | bt_message_iterator_class_set_seek_ns_from_origin_methods( | |
117 | bt_message_iterator_class *message_iterator_class, | |
118 | bt_message_iterator_class_seek_ns_from_origin_method seek_method, | |
119 | bt_message_iterator_class_can_seek_ns_from_origin_method can_seek_method) | |
120 | { | |
121 | BT_ASSERT_PRE_NO_ERROR(); | |
d5b13b9b | 122 | BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class); |
1778c2a4 PP |
123 | BT_ASSERT_PRE_NON_NULL("seek-method", seek_method, "Seek method"); |
124 | BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class); | |
a3f0c7db SM |
125 | message_iterator_class->methods.seek_ns_from_origin = seek_method; |
126 | message_iterator_class->methods.can_seek_ns_from_origin = can_seek_method; | |
127 | BT_LIB_LOGD("Set message iterator class's \"seek nanoseconds from origin\" method" | |
128 | ": %!+I", message_iterator_class); | |
129 | return BT_FUNC_STATUS_OK; | |
130 | } | |
131 | ||
1353b066 | 132 | BT_EXPORT |
a3f0c7db SM |
133 | bt_message_iterator_class_set_method_status |
134 | bt_message_iterator_class_set_seek_beginning_methods( | |
135 | bt_message_iterator_class *message_iterator_class, | |
136 | bt_message_iterator_class_seek_beginning_method seek_method, | |
137 | bt_message_iterator_class_can_seek_beginning_method can_seek_method) | |
138 | { | |
139 | BT_ASSERT_PRE_NO_ERROR(); | |
d5b13b9b | 140 | BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class); |
1778c2a4 PP |
141 | BT_ASSERT_PRE_NON_NULL("seek-method", seek_method, "Seek method"); |
142 | BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class); | |
a3f0c7db SM |
143 | message_iterator_class->methods.seek_beginning = seek_method; |
144 | message_iterator_class->methods.can_seek_beginning = can_seek_method; | |
145 | BT_LIB_LOGD("Set message iterator class's \"seek beginning\" methods" | |
d8a3c3be | 146 | ": %!+I", message_iterator_class); |
a3f0c7db SM |
147 | return BT_FUNC_STATUS_OK; |
148 | } |