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))
22 void _bt_message_iterator_class_freeze(
23 const struct bt_message_iterator_class
*msg_iter_cls
)
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;
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
);
36 void bt_message_iterator_class_put_ref(
37 const bt_message_iterator_class
*message_iterator_class
)
39 bt_object_put_ref(message_iterator_class
);
43 void destroy_iterator_class(struct bt_object
*obj
)
45 struct bt_message_iterator_class
*class;
48 class = container_of(obj
, struct bt_message_iterator_class
, base
);
50 BT_LIB_LOGI("Destroying message iterator class: %!+I", class);
55 struct bt_message_iterator_class
*bt_message_iterator_class_create(
56 bt_message_iterator_class_next_method next_method
)
58 struct bt_message_iterator_class
*message_iterator_class
;
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",
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.");
72 bt_object_init_shared(&message_iterator_class
->base
, destroy_iterator_class
);
74 message_iterator_class
->methods
.next
= next_method
;
77 return message_iterator_class
;
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
)
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
;
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
)
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
;
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
)
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
;
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
)
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 ": %!+I", message_iterator_class
);
141 return BT_FUNC_STATUS_OK
;