2 * Copyright 2019 EfficiOS, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define BT_LOG_TAG "LIB/MESSAGE-ITERATOR-CLASS"
24 #include "lib/logging.h"
26 #include "message-iterator-class.h"
28 #include "compat/compiler.h"
29 #include "lib/assert-pre.h"
30 #include "lib/func-status.h"
32 #define BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(_msg_iter_cls) \
33 BT_ASSERT_PRE_DEV_HOT((_msg_iter_cls), \
34 "Message iterator class", ": %!+I", (_msg_iter_cls))
37 void _bt_message_iterator_class_freeze(
38 const struct bt_message_iterator_class
*msg_iter_cls
)
40 BT_ASSERT(msg_iter_cls
);
41 BT_LIB_LOGD("Freezing message iterator class: %!+I", msg_iter_cls
);
42 ((struct bt_message_iterator_class
*) msg_iter_cls
)->frozen
= true;
45 void bt_message_iterator_class_get_ref(
46 const bt_message_iterator_class
*message_iterator_class
)
48 bt_object_get_ref(message_iterator_class
);
51 void bt_message_iterator_class_put_ref(
52 const bt_message_iterator_class
*message_iterator_class
)
54 bt_object_put_ref(message_iterator_class
);
58 void destroy_iterator_class(struct bt_object
*obj
)
60 struct bt_message_iterator_class
*class;
63 class = container_of(obj
, struct bt_message_iterator_class
, base
);
65 BT_LIB_LOGI("Destroying message iterator class: %!+I", class);
70 struct bt_message_iterator_class
*bt_message_iterator_class_create(
71 bt_message_iterator_class_next_method next_method
)
73 struct bt_message_iterator_class
*message_iterator_class
;
75 BT_ASSERT_PRE_NO_ERROR();
76 BT_ASSERT_PRE_NON_NULL(next_method
, "Next method");
77 BT_LOGI("Creating message iterator class: next-method-addr=%p",
80 message_iterator_class
= g_new0(struct bt_message_iterator_class
, 1);
81 if (!message_iterator_class
) {
82 BT_LIB_LOGE_APPEND_CAUSE(
83 "Failed to allocate one message iterator class.");
87 bt_object_init_shared(&message_iterator_class
->base
, destroy_iterator_class
);
89 message_iterator_class
->methods
.next
= next_method
;
92 return message_iterator_class
;
95 bt_message_iterator_class_set_method_status
96 bt_message_iterator_class_set_initialize_method(
97 bt_message_iterator_class
*message_iterator_class
,
98 bt_message_iterator_class_initialize_method method
)
100 BT_ASSERT_PRE_NO_ERROR();
101 BT_ASSERT_PRE_NON_NULL(message_iterator_class
, "Message iterator class");
102 BT_ASSERT_PRE_NON_NULL(method
, "Method");
103 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class
);
104 message_iterator_class
->methods
.initialize
= method
;
105 BT_LIB_LOGD("Set message iterator class's iterator initialization 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_finalize_method(
112 bt_message_iterator_class
*message_iterator_class
,
113 bt_message_iterator_class_finalize_method 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(method
, "Method");
118 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class
);
119 message_iterator_class
->methods
.finalize
= method
;
120 BT_LIB_LOGD("Set message iterator class's finalization method"
121 ": %!+I", message_iterator_class
);
122 return BT_FUNC_STATUS_OK
;
125 bt_message_iterator_class_set_method_status
126 bt_message_iterator_class_set_seek_ns_from_origin_methods(
127 bt_message_iterator_class
*message_iterator_class
,
128 bt_message_iterator_class_seek_ns_from_origin_method seek_method
,
129 bt_message_iterator_class_can_seek_ns_from_origin_method can_seek_method
)
131 BT_ASSERT_PRE_NO_ERROR();
132 BT_ASSERT_PRE_NON_NULL(message_iterator_class
, "Message iterator class");
133 BT_ASSERT_PRE_NON_NULL(seek_method
, "Seek method");
134 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class
);
135 message_iterator_class
->methods
.seek_ns_from_origin
= seek_method
;
136 message_iterator_class
->methods
.can_seek_ns_from_origin
= can_seek_method
;
137 BT_LIB_LOGD("Set message iterator class's \"seek nanoseconds from origin\" method"
138 ": %!+I", message_iterator_class
);
139 return BT_FUNC_STATUS_OK
;
142 bt_message_iterator_class_set_method_status
143 bt_message_iterator_class_set_seek_beginning_methods(
144 bt_message_iterator_class
*message_iterator_class
,
145 bt_message_iterator_class_seek_beginning_method seek_method
,
146 bt_message_iterator_class_can_seek_beginning_method can_seek_method
)
148 BT_ASSERT_PRE_NO_ERROR();
149 BT_ASSERT_PRE_NON_NULL(message_iterator_class
, "Message iterator class");
150 BT_ASSERT_PRE_NON_NULL(seek_method
, "Seek method");
151 BT_ASSERT_PRE_DEV_MSG_ITER_CLS_HOT(message_iterator_class
);
152 message_iterator_class
->methods
.seek_beginning
= seek_method
;
153 message_iterator_class
->methods
.can_seek_beginning
= can_seek_method
;
154 BT_LIB_LOGD("Set message iterator class's \"seek beginning\" methods"
155 ": %!+C", message_iterator_class
);
156 return BT_FUNC_STATUS_OK
;