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