Decouple component class from plugin subsystem, remove component factory
[babeltrace.git] / lib / component / iterator.c
1 /*
2 * iterator.c
3 *
4 * Babeltrace Notification Iterator
5 *
6 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
29 #include <babeltrace/compiler.h>
30 #include <babeltrace/ref.h>
31 #include <babeltrace/component/component.h>
32 #include <babeltrace/component/source-internal.h>
33 #include <babeltrace/component/notification/iterator.h>
34 #include <babeltrace/component/notification/iterator-internal.h>
35
36 static
37 void bt_notification_iterator_destroy(struct bt_object *obj)
38 {
39 struct bt_notification_iterator *iterator;
40
41 assert(obj);
42 iterator = container_of(obj, struct bt_notification_iterator,
43 base);
44 assert(iterator->user_destroy || !iterator->user_data);
45 if (iterator->user_destroy) {
46 iterator->user_destroy(iterator);
47 }
48 BT_PUT(iterator->component);
49 g_free(iterator);
50 }
51
52 BT_HIDDEN
53 struct bt_notification_iterator *bt_notification_iterator_create(
54 struct bt_component *component)
55 {
56 enum bt_component_type type;
57 struct bt_notification_iterator *iterator = NULL;
58
59 if (!component) {
60 goto end;
61 }
62
63 type = bt_component_get_type(component);
64 switch (type) {
65 case BT_COMPONENT_TYPE_SOURCE:
66 case BT_COMPONENT_TYPE_FILTER:
67 break;
68 default:
69 goto end;
70 }
71
72 iterator = g_new0(struct bt_notification_iterator, 1);
73 if (!iterator) {
74 goto end;
75 }
76
77 iterator->component = bt_get(component);
78 bt_object_init(iterator, bt_notification_iterator_destroy);
79 end:
80 return iterator;
81 }
82
83 BT_HIDDEN
84 enum bt_notification_iterator_status bt_notification_iterator_validate(
85 struct bt_notification_iterator *iterator)
86 {
87 enum bt_notification_iterator_status ret =
88 BT_NOTIFICATION_ITERATOR_STATUS_OK;
89
90 if (!iterator || !iterator->get || !iterator->next) {
91 ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
92 goto end;
93 }
94 end:
95 return ret;
96 }
97
98 enum bt_notification_iterator_status bt_notification_iterator_set_get_cb(
99 struct bt_notification_iterator *iterator,
100 bt_notification_iterator_get_cb get)
101 {
102 enum bt_notification_iterator_status ret =
103 BT_NOTIFICATION_ITERATOR_STATUS_OK;
104
105 if (!iterator || !get) {
106 ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
107 goto end;
108 }
109
110 iterator->get = get;
111 end:
112 return ret;
113 }
114
115 enum bt_notification_iterator_status
116 bt_notification_iterator_set_next_cb(struct bt_notification_iterator *iterator,
117 bt_notification_iterator_next_cb next)
118 {
119 enum bt_notification_iterator_status ret =
120 BT_NOTIFICATION_ITERATOR_STATUS_OK;
121
122 if (!iterator || !next) {
123 ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
124 goto end;
125 }
126
127 iterator->next = next;
128 end:
129 return ret;
130 }
131
132 enum bt_notification_iterator_status
133 bt_notification_iterator_set_seek_time_cb(
134 struct bt_notification_iterator *iterator,
135 bt_notification_iterator_seek_time_cb seek_time)
136 {
137 enum bt_notification_iterator_status ret =
138 BT_NOTIFICATION_ITERATOR_STATUS_OK;
139
140 if (!iterator || !seek_time) {
141 ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
142 goto end;
143 }
144
145 iterator->seek_time = seek_time;
146 end:
147 return ret;
148 }
149
150 enum bt_notification_iterator_status
151 bt_notification_iterator_set_destroy_cb(
152 struct bt_notification_iterator *iterator,
153 bt_notification_iterator_destroy_cb destroy)
154 {
155 enum bt_notification_iterator_status ret =
156 BT_NOTIFICATION_ITERATOR_STATUS_OK;
157
158 if (!iterator || !destroy) {
159 ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
160 goto end;
161 }
162
163 iterator->user_destroy = destroy;
164 end:
165 return ret;
166 }
167
168 void *bt_notification_iterator_get_private_data(
169 struct bt_notification_iterator *iterator)
170 {
171 return iterator ? iterator->user_data : NULL;
172 }
173
174 enum bt_notification_iterator_status
175 bt_notification_iterator_set_private_data(
176 struct bt_notification_iterator *iterator, void *data)
177 {
178 enum bt_notification_iterator_status ret =
179 BT_NOTIFICATION_ITERATOR_STATUS_OK;
180
181 if (!iterator || !data) {
182 ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
183 goto end;
184 }
185
186 iterator->user_data = data;
187 end:
188 return ret;
189 }
190
191 struct bt_notification *bt_notification_iterator_get_notification(
192 struct bt_notification_iterator *iterator)
193 {
194 assert(iterator);
195 assert(iterator->get);
196 return iterator->get(iterator);
197 }
198
199 enum bt_notification_iterator_status
200 bt_notification_iterator_next(struct bt_notification_iterator *iterator)
201 {
202 assert(iterator);
203 assert(iterator->next);
204 return iterator->next(iterator);
205 }
206
207 struct bt_component *bt_notification_iterator_get_component(
208 struct bt_notification_iterator *iterator)
209 {
210 return bt_get(iterator->component);
211 }
212
213 enum bt_notification_iterator_status bt_notification_iterator_seek_time(
214 struct bt_notification_iterator *iterator,
215 enum bt_notification_iterator_seek_origin seek_origin,
216 int64_t time)
217 {
218 enum bt_notification_iterator_status ret =
219 BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED;
220 return ret;
221 }
This page took 0.033635 seconds and 4 git commands to generate.