bt2c::Logger: remove unused cLevel() method
[babeltrace.git] / src / lib / graph / message-iterator-class.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2019 EfficiOS, Inc.
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"
13 #include "lib/assert-cond.h"
14 #include "lib/func-status.h"
15
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))
20
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
29 BT_EXPORT
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
36 BT_EXPORT
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
56 BT_EXPORT
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();
63 BT_ASSERT_PRE_NON_NULL("next-method", next_method, "Next method");
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
82 BT_EXPORT
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();
89 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
90 BT_ASSERT_PRE_METHOD_NON_NULL(method);
91 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
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
98 BT_EXPORT
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();
105 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
106 BT_ASSERT_PRE_METHOD_NON_NULL(method);
107 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
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
114 BT_EXPORT
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();
122 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
123 BT_ASSERT_PRE_NON_NULL("seek-method", seek_method, "Seek method");
124 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
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
132 BT_EXPORT
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();
140 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
141 BT_ASSERT_PRE_NON_NULL("seek-method", seek_method, "Seek method");
142 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
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"
146 ": %!+I", message_iterator_class);
147 return BT_FUNC_STATUS_OK;
148 }
This page took 0.032728 seconds and 4 git commands to generate.