* SOFTWARE.
*/
-#include <babeltrace/compiler.h>
+#include <babeltrace/compiler-internal.h>
#include <babeltrace/ref.h>
-#include <babeltrace/component/component.h>
-#include <babeltrace/component/source-internal.h>
-#include <babeltrace/component/notification/iterator.h>
-#include <babeltrace/component/notification/iterator-internal.h>
+#include <babeltrace/graph/component.h>
+#include <babeltrace/graph/component-source-internal.h>
+#include <babeltrace/graph/component-class-internal.h>
+#include <babeltrace/graph/notification-iterator.h>
+#include <babeltrace/graph/notification-iterator-internal.h>
+#include <babeltrace/graph/notification-internal.h>
static
void bt_notification_iterator_destroy(struct bt_object *obj)
{
struct bt_notification_iterator *iterator;
+ struct bt_component_class *comp_class;
assert(obj);
iterator = container_of(obj, struct bt_notification_iterator,
base);
- assert(iterator->user_destroy || !iterator->user_data);
- if (iterator->user_destroy) {
- iterator->user_destroy(iterator);
+ assert(iterator->component);
+ comp_class = iterator->component->class;
+
+ /* Call user-defined destroy method */
+ switch (comp_class->type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ {
+ struct bt_component_class_source *source_class;
+
+ source_class = container_of(comp_class, struct bt_component_class_source, parent);
+
+ if (source_class->methods.iterator.finalize) {
+ source_class->methods.iterator.finalize(
+ bt_private_notification_iterator_from_notification_iterator(iterator));
+ }
+ break;
+ }
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ {
+ struct bt_component_class_filter *filter_class;
+
+ filter_class = container_of(comp_class, struct bt_component_class_filter, parent);
+
+ if (filter_class->methods.iterator.finalize) {
+ filter_class->methods.iterator.finalize(
+ bt_private_notification_iterator_from_notification_iterator(iterator));
+ }
+ break;
+ }
+ default:
+ /* Unreachable */
+ assert(0);
}
+
+ BT_PUT(iterator->current_notification);
BT_PUT(iterator->component);
g_free(iterator);
}
struct bt_notification_iterator *bt_notification_iterator_create(
struct bt_component *component)
{
- enum bt_component_type type;
+ enum bt_component_class_type type;
struct bt_notification_iterator *iterator = NULL;
if (!component) {
goto end;
}
- type = bt_component_get_type(component);
+ type = bt_component_get_class_type(component);
switch (type) {
- case BT_COMPONENT_TYPE_SOURCE:
- case BT_COMPONENT_TYPE_FILTER:
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
break;
default:
goto end;
enum bt_notification_iterator_status ret =
BT_NOTIFICATION_ITERATOR_STATUS_OK;
- if (!iterator || !iterator->get || !iterator->next) {
+ if (!iterator) {
ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
goto end;
}
return ret;
}
-enum bt_notification_iterator_status bt_notification_iterator_set_get_cb(
- struct bt_notification_iterator *iterator,
- bt_notification_iterator_get_cb get)
+void *bt_private_notification_iterator_get_user_data(
+ struct bt_private_notification_iterator *private_iterator)
{
- enum bt_notification_iterator_status ret =
- BT_NOTIFICATION_ITERATOR_STATUS_OK;
-
- if (!iterator || !get) {
- ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
- goto end;
- }
+ struct bt_notification_iterator *iterator =
+ bt_notification_iterator_from_private(private_iterator);
- iterator->get = get;
-end:
- return ret;
+ return iterator ? iterator->user_data : NULL;
}
enum bt_notification_iterator_status
-bt_notification_iterator_set_next_cb(struct bt_notification_iterator *iterator,
- bt_notification_iterator_next_cb next)
+bt_private_notification_iterator_set_user_data(
+ struct bt_private_notification_iterator *private_iterator,
+ void *data)
{
enum bt_notification_iterator_status ret =
BT_NOTIFICATION_ITERATOR_STATUS_OK;
+ struct bt_notification_iterator *iterator =
+ bt_notification_iterator_from_private(private_iterator);
- if (!iterator || !next) {
+ if (!iterator) {
ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
goto end;
}
- iterator->next = next;
+ iterator->user_data = data;
end:
return ret;
}
-enum bt_notification_iterator_status
-bt_notification_iterator_set_seek_time_cb(
- struct bt_notification_iterator *iterator,
- bt_notification_iterator_seek_time_cb seek_time)
+struct bt_notification *bt_notification_iterator_get_notification(
+ struct bt_notification_iterator *iterator)
{
- enum bt_notification_iterator_status ret =
- BT_NOTIFICATION_ITERATOR_STATUS_OK;
+ struct bt_notification *notification = NULL;
- if (!iterator || !seek_time) {
- ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
+ if (!iterator) {
goto end;
}
- iterator->seek_time = seek_time;
+ notification = bt_get(iterator->current_notification);
+
end:
- return ret;
+ return notification;
}
enum bt_notification_iterator_status
-bt_notification_iterator_set_destroy_cb(
- struct bt_notification_iterator *iterator,
- bt_notification_iterator_destroy_cb destroy)
+bt_notification_iterator_next(struct bt_notification_iterator *iterator)
{
- enum bt_notification_iterator_status ret =
- BT_NOTIFICATION_ITERATOR_STATUS_OK;
+ struct bt_private_notification_iterator *priv_iterator =
+ bt_private_notification_iterator_from_notification_iterator(iterator);
+ bt_component_class_notification_iterator_next_method next_method = NULL;
+ struct bt_notification_iterator_next_return next_return;
+ enum bt_notification_iterator_status status =
+ BT_NOTIFICATION_ITERATOR_STATUS_OK;
- if (!iterator || !destroy) {
- ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
+ if (!iterator) {
+ status = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
goto end;
}
- iterator->user_destroy = destroy;
-end:
- return ret;
-}
+ assert(iterator->component);
+ assert(iterator->component->class);
-void *bt_notification_iterator_get_private_data(
- struct bt_notification_iterator *iterator)
-{
- return iterator ? iterator->user_data : NULL;
-}
+ switch (iterator->component->class->type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ {
+ struct bt_component_class_source *source_class =
+ container_of(iterator->component->class,
+ struct bt_component_class_source, parent);
-enum bt_notification_iterator_status
-bt_notification_iterator_set_private_data(
- struct bt_notification_iterator *iterator, void *data)
-{
- enum bt_notification_iterator_status ret =
- BT_NOTIFICATION_ITERATOR_STATUS_OK;
+ assert(source_class->methods.iterator.next);
+ next_method = source_class->methods.iterator.next;
+ break;
+ }
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ {
+ struct bt_component_class_filter *filter_class =
+ container_of(iterator->component->class,
+ struct bt_component_class_filter, parent);
- if (!iterator || !data) {
- ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
- goto end;
+ assert(filter_class->methods.iterator.next);
+ next_method = filter_class->methods.iterator.next;
+ break;
+ }
+ default:
+ assert(false);
+ break;
}
- iterator->user_data = data;
-end:
- return ret;
-}
+ assert(next_method);
+ next_return = next_method(priv_iterator);
+ if (next_return.status == BT_NOTIFICATION_ITERATOR_STATUS_OK) {
+ if (!next_return.notification) {
+ status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR;
+ goto end;
+ }
-struct bt_notification *bt_notification_iterator_get_notification(
- struct bt_notification_iterator *iterator)
-{
- assert(iterator);
- assert(iterator->get);
- return iterator->get(iterator);
-}
+ BT_MOVE(iterator->current_notification,
+ next_return.notification);
+ bt_notification_freeze(iterator->current_notification);
+ }
-enum bt_notification_iterator_status
-bt_notification_iterator_next(struct bt_notification_iterator *iterator)
-{
- assert(iterator);
- assert(iterator->next);
- return iterator->next(iterator);
+end:
+ return next_return.status;
}
struct bt_component *bt_notification_iterator_get_component(
return bt_get(iterator->component);
}
+struct bt_private_component *
+bt_private_notification_iterator_get_private_component(
+ struct bt_private_notification_iterator *private_iterator)
+{
+ return bt_private_component_from_component(
+ bt_notification_iterator_get_component(
+ bt_notification_iterator_from_private(private_iterator)));
+}
+
enum bt_notification_iterator_status bt_notification_iterator_seek_time(
struct bt_notification_iterator *iterator,
enum bt_notification_iterator_seek_origin seek_origin,