lib: assign a unique ID to each pre/postcond. and report it on failure
[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 BT_HIDDEN
22 void _bt_message_iterator_class_freeze(
23 const struct bt_message_iterator_class *msg_iter_cls)
24 {
25 BT_ASSERT(msg_iter_cls);
26 BT_LIB_LOGD("Freezing message iterator class: %!+I", msg_iter_cls);
27 ((struct bt_message_iterator_class *) msg_iter_cls)->frozen = true;
28 }
29
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 void bt_message_iterator_class_put_ref(
37 const bt_message_iterator_class *message_iterator_class)
38 {
39 bt_object_put_ref(message_iterator_class);
40 }
41
42 static
43 void destroy_iterator_class(struct bt_object *obj)
44 {
45 struct bt_message_iterator_class *class;
46
47 BT_ASSERT(obj);
48 class = container_of(obj, struct bt_message_iterator_class, base);
49
50 BT_LIB_LOGI("Destroying message iterator class: %!+I", class);
51
52 g_free(class);
53 }
54
55 struct bt_message_iterator_class *bt_message_iterator_class_create(
56 bt_message_iterator_class_next_method next_method)
57 {
58 struct bt_message_iterator_class *message_iterator_class;
59
60 BT_ASSERT_PRE_NO_ERROR();
61 BT_ASSERT_PRE_NON_NULL("next-method", next_method, "Next method");
62 BT_LOGI("Creating message iterator class: next-method-addr=%p",
63 next_method);
64
65 message_iterator_class = g_new0(struct bt_message_iterator_class, 1);
66 if (!message_iterator_class) {
67 BT_LIB_LOGE_APPEND_CAUSE(
68 "Failed to allocate one message iterator class.");
69 goto end;
70 }
71
72 bt_object_init_shared(&message_iterator_class->base, destroy_iterator_class);
73
74 message_iterator_class->methods.next = next_method;
75
76 end:
77 return message_iterator_class;
78 }
79
80 bt_message_iterator_class_set_method_status
81 bt_message_iterator_class_set_initialize_method(
82 bt_message_iterator_class *message_iterator_class,
83 bt_message_iterator_class_initialize_method method)
84 {
85 BT_ASSERT_PRE_NO_ERROR();
86 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
87 BT_ASSERT_PRE_METHOD_NON_NULL(method);
88 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
89 message_iterator_class->methods.initialize = method;
90 BT_LIB_LOGD("Set message iterator class's iterator initialization method"
91 ": %!+I", message_iterator_class);
92 return BT_FUNC_STATUS_OK;
93 }
94
95 bt_message_iterator_class_set_method_status
96 bt_message_iterator_class_set_finalize_method(
97 bt_message_iterator_class *message_iterator_class,
98 bt_message_iterator_class_finalize_method method)
99 {
100 BT_ASSERT_PRE_NO_ERROR();
101 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
102 BT_ASSERT_PRE_METHOD_NON_NULL(method);
103 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
104 message_iterator_class->methods.finalize = method;
105 BT_LIB_LOGD("Set message iterator class's finalization method"
106 ": %!+I", message_iterator_class);
107 return BT_FUNC_STATUS_OK;
108 }
109
110 bt_message_iterator_class_set_method_status
111 bt_message_iterator_class_set_seek_ns_from_origin_methods(
112 bt_message_iterator_class *message_iterator_class,
113 bt_message_iterator_class_seek_ns_from_origin_method seek_method,
114 bt_message_iterator_class_can_seek_ns_from_origin_method can_seek_method)
115 {
116 BT_ASSERT_PRE_NO_ERROR();
117 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
118 BT_ASSERT_PRE_NON_NULL("seek-method", seek_method, "Seek method");
119 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
120 message_iterator_class->methods.seek_ns_from_origin = seek_method;
121 message_iterator_class->methods.can_seek_ns_from_origin = can_seek_method;
122 BT_LIB_LOGD("Set message iterator class's \"seek nanoseconds from origin\" method"
123 ": %!+I", message_iterator_class);
124 return BT_FUNC_STATUS_OK;
125 }
126
127 bt_message_iterator_class_set_method_status
128 bt_message_iterator_class_set_seek_beginning_methods(
129 bt_message_iterator_class *message_iterator_class,
130 bt_message_iterator_class_seek_beginning_method seek_method,
131 bt_message_iterator_class_can_seek_beginning_method can_seek_method)
132 {
133 BT_ASSERT_PRE_NO_ERROR();
134 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
135 BT_ASSERT_PRE_NON_NULL("seek-method", seek_method, "Seek method");
136 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
137 message_iterator_class->methods.seek_beginning = seek_method;
138 message_iterator_class->methods.can_seek_beginning = can_seek_method;
139 BT_LIB_LOGD("Set message iterator class's \"seek beginning\" methods"
140 ": %!+C", message_iterator_class);
141 return BT_FUNC_STATUS_OK;
142 }
This page took 0.032221 seconds and 4 git commands to generate.