/*
+ * SPDX-License-Identifier: MIT
+ *
* Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
* Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
*/
#define BT_LOG_TAG "LIB/COMPONENT-CLASS"
#include "lib/assert-pre.h"
#include "compat/compiler.h"
#include <babeltrace2/graph/component-class.h>
-#include <babeltrace2/graph/component-class-const.h>
-#include <babeltrace2/graph/component-class-source.h>
-#include <babeltrace2/graph/component-class-source-const.h>
-#include <babeltrace2/graph/component-class-filter.h>
-#include <babeltrace2/graph/component-class-filter-const.h>
-#include <babeltrace2/graph/component-class-sink.h>
-#include <babeltrace2/graph/component-class-sink-const.h>
#include <babeltrace2/types.h>
#include <glib.h>
class->destroy_listeners = NULL;
}
- if (class->type == BT_COMPONENT_CLASS_TYPE_SOURCE) {
- struct bt_component_class_source *class_src
- = container_of(class, struct bt_component_class_source,
- parent);
-
- BT_ASSERT(class_src->msg_iter_cls);
- bt_message_iterator_class_put_ref(class_src->msg_iter_cls);
- class_src->msg_iter_cls = NULL;
- } else if (class->type == BT_COMPONENT_CLASS_TYPE_FILTER) {
- struct bt_component_class_filter *class_flt
- = container_of(class, struct bt_component_class_filter,
- parent);
-
- BT_ASSERT(class_flt->msg_iter_cls);
- bt_message_iterator_class_put_ref(class_flt->msg_iter_cls);
- class_flt->msg_iter_cls = NULL;
+ if (bt_component_class_has_message_iterator_class(class)) {
+ struct bt_component_class_with_iterator_class *class_with_iter_class =
+ container_of(class, struct bt_component_class_with_iterator_class, parent);
+
+ BT_ASSERT(class_with_iter_class->msg_iter_cls);
+ bt_message_iterator_class_put_ref(class_with_iter_class->msg_iter_cls);
+ class_with_iter_class->msg_iter_cls = NULL;
}
g_free(class);
return ret;
}
+static
+int bt_component_class_with_iterator_class_init(
+ struct bt_component_class_with_iterator_class *class,
+ enum bt_component_class_type type, const char *name,
+ struct bt_message_iterator_class *message_iterator_class)
+{
+ int ret;
+
+ ret = bt_component_class_init(&class->parent, type, name);
+ if (ret != 0) {
+ goto end;
+ }
+
+ class->msg_iter_cls = message_iterator_class;
+ bt_message_iterator_class_get_ref(class->msg_iter_cls);
+ bt_message_iterator_class_freeze(class->msg_iter_cls);
+
+end:
+ return ret;
+}
+
struct bt_component_class_source *bt_component_class_source_create(
const char *name,
struct bt_message_iterator_class *message_iterator_class)
}
/* bt_component_class_init() logs errors */
- ret = bt_component_class_init(&source_class->parent,
- BT_COMPONENT_CLASS_TYPE_SOURCE, name);
+ ret = bt_component_class_with_iterator_class_init(&source_class->parent,
+ BT_COMPONENT_CLASS_TYPE_SOURCE, name, message_iterator_class);
if (ret) {
/*
* If bt_component_class_init() fails, the component
goto end;
}
- source_class->msg_iter_cls = message_iterator_class;
- bt_message_iterator_class_get_ref(source_class->msg_iter_cls);
- bt_message_iterator_class_freeze(source_class->msg_iter_cls);
-
BT_LIB_LOGI("Created source component class: %!+C", source_class);
end:
}
/* bt_component_class_init() logs errors */
- ret = bt_component_class_init(&filter_class->parent,
- BT_COMPONENT_CLASS_TYPE_FILTER, name);
+ ret = bt_component_class_with_iterator_class_init(&filter_class->parent,
+ BT_COMPONENT_CLASS_TYPE_FILTER, name, message_iterator_class);
if (ret) {
/*
* If bt_component_class_init() fails, the component
goto end;
}
- filter_class->msg_iter_cls = message_iterator_class;
- bt_message_iterator_class_get_ref(filter_class->msg_iter_cls);
- bt_message_iterator_class_freeze(filter_class->msg_iter_cls);
-
BT_LIB_LOGI("Created filter component class: %!+C", filter_class);
end: