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_COND_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))
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;
29 void bt_message_iterator_class_get_ref(
30 const bt_message_iterator_class
*message_iterator_class
)
32 bt_object_get_ref(message_iterator_class
);
35 void bt_message_iterator_class_put_ref(
36 const bt_message_iterator_class
*message_iterator_class
)
38 bt_object_put_ref(message_iterator_class
);
42 void destroy_iterator_class(struct bt_object
*obj
)
44 struct bt_message_iterator_class
*class;
47 class = container_of(obj
, struct bt_message_iterator_class
, base
);
49 BT_LIB_LOGI("Destroying message iterator class: %!+I", class);
54 struct bt_message_iterator_class
*bt_message_iterator_class_create(
55 bt_message_iterator_class_next_method next_method
)
57 struct bt_message_iterator_class
*message_iterator_class
;
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",
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.");
71 bt_object_init_shared(&message_iterator_class
->base
, destroy_iterator_class
);
73 message_iterator_class
->methods
.next
= next_method
;
76 return message_iterator_class
;
79 bt_message_iterator_class_set_method_status
80 bt_message_iterator_class_set_initialize_method(
81 bt_message_iterator_class
*message_iterator_class
,
82 bt_message_iterator_class_initialize_method method
)
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_COND_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
;
94 bt_message_iterator_class_set_method_status
95 bt_message_iterator_class_set_finalize_method(
96 bt_message_iterator_class
*message_iterator_class
,
97 bt_message_iterator_class_finalize_method method
)
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_COND_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
;
109 bt_message_iterator_class_set_method_status
110 bt_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
)
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_COND_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
;
126 bt_message_iterator_class_set_method_status
127 bt_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
)
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_COND_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
;