2 * SPDX-License-Identifier: MIT
4 * Copyright 2019 EfficiOS, Inc.
7 #define BT_LOG_TAG "LIB/MESSAGE-ITERATOR-CLASS"
8 #include "lib/logging.h"
10 #include "message-iterator-class.h"
12 #include "compat/compiler.h"
13 #include "lib/assert-cond.h"
14 #include "lib/func-status.h"
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))
21 void _bt_message_iterator_class_freeze(
22 const struct bt_message_iterator_class
*msg_iter_cls
)
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;
30 void bt_message_iterator_class_get_ref(
31 const bt_message_iterator_class
*message_iterator_class
)
33 bt_object_get_ref(message_iterator_class
);
37 void bt_message_iterator_class_put_ref(
38 const bt_message_iterator_class
*message_iterator_class
)
40 bt_object_put_ref(message_iterator_class
);
44 void destroy_iterator_class(struct bt_object
*obj
)
46 struct bt_message_iterator_class
*class;
49 class = container_of(obj
, struct bt_message_iterator_class
, base
);
51 BT_LIB_LOGI("Destroying message iterator class: %!+I", class);
57 struct bt_message_iterator_class
*bt_message_iterator_class_create(
58 bt_message_iterator_class_next_method next_method
)
60 struct bt_message_iterator_class
*message_iterator_class
;
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",
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.");
74 bt_object_init_shared(&message_iterator_class
->base
, destroy_iterator_class
);
76 message_iterator_class
->methods
.next
= next_method
;
79 return message_iterator_class
;
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
)
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
;
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
)
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
;
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
)
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
;
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
)
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
;