lib: assign a unique ID to each pre/postcond. and report it on failure
[babeltrace.git] / src / lib / graph / message-iterator-class.c
CommitLineData
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
SM
20
21BT_HIDDEN
22void _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
30void 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
36void 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
42static
43void 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
55struct 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();
1778c2a4 61 BT_ASSERT_PRE_NON_NULL("next-method", next_method, "Next method");
a3f0c7db
SM
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
76end:
77 return message_iterator_class;
78}
79
80bt_message_iterator_class_set_method_status
81bt_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();
d5b13b9b
PP
86 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
87 BT_ASSERT_PRE_METHOD_NON_NULL(method);
1778c2a4 88 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
a3f0c7db
SM
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
95bt_message_iterator_class_set_method_status
96bt_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();
d5b13b9b
PP
101 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
102 BT_ASSERT_PRE_METHOD_NON_NULL(method);
1778c2a4 103 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
a3f0c7db
SM
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
110bt_message_iterator_class_set_method_status
111bt_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();
d5b13b9b 117 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
1778c2a4
PP
118 BT_ASSERT_PRE_NON_NULL("seek-method", seek_method, "Seek method");
119 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
a3f0c7db
SM
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
127bt_message_iterator_class_set_method_status
128bt_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();
d5b13b9b 134 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
1778c2a4
PP
135 BT_ASSERT_PRE_NON_NULL("seek-method", seek_method, "Seek method");
136 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class);
a3f0c7db
SM
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.034422 seconds and 4 git commands to generate.