*/
#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/ref-internal.h>
#include <babeltrace/plugin/component-factory-internal.h>
#include <babeltrace/plugin/plugin-internal.h>
+#include <babeltrace/object-internal.h>
struct bt_component_class {
- struct bt_ref ref;
+ struct bt_object base;
enum bt_component_type type;
GString *name;
struct bt_plugin *plugin;
enum bt_component_type type, const char *name,
struct bt_plugin *plugin);
-BT_HIDDEN
-void bt_component_class_get(struct bt_component_class *class);
-
-BT_HIDDEN
-void bt_component_class_put(struct bt_component_class *class);
-
#endif /* BABELTRACE_PLUGIN_COMPONENT_CLASS_INTERNAL_H */
*/
#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/ref-internal.h>
+#include <babeltrace/object-internal.h>
#include <babeltrace/plugin/component-factory.h>
#include <babeltrace/plugin/component.h>
#include <babeltrace/plugin/component-class-internal.h>
#include <glib.h>
struct bt_component_factory {
- /** Array of pointers to struct plugin */
+ struct bt_object base;
+ /** Array of pointers to struct bt_plugin */
GPtrArray *plugins;
/** Array of pointers to struct bt_component_class */
GPtrArray *components;
*
* @returns An instance of component factory
*/
-extern
-struct bt_component_factory *bt_component_factory_create(void);
+extern struct bt_component_factory *bt_component_factory_create(void);
/**
* Get the list of components registered to this factory.
*/
-extern
-struct bt_object *bt_component_factory_get_components(
+extern struct bt_object *bt_component_factory_get_components(
struct bt_component_factory *factory);
/**
* @param path A path to a file or directory
* @returns One of #bt_component_factory_status values
*/
-extern
-enum bt_component_factory_status bt_component_factory_load(
+extern enum bt_component_factory_status bt_component_factory_load(
struct bt_component_factory *factory, const char *path);
-extern
-enum bt_component_factory_status
+extern enum bt_component_factory_status
bt_component_factory_register_source_component_class(
struct bt_component_factory *factory, const char *name,
bt_component_source_init_cb init);
-extern
-enum bt_component_factory_status bt_component_factory_register_sink_component_class(
+extern enum bt_component_factory_status
+bt_component_factory_register_sink_component_class(
struct bt_component_factory *factory, const char *name,
bt_component_sink_init_cb init);
-extern
-void bt_component_factory_destroy(struct bt_component_factory *factory);
-
#ifdef __cplusplus
}
#endif
#include <babeltrace/plugin/plugin-system.h>
#include <babeltrace/plugin/component.h>
#include <babeltrace/plugin/component-class-internal.h>
-#include <babeltrace/ref-internal.h>
+#include <babeltrace/object-internal.h>
#include <glib.h>
#include <stdio.h>
struct bt_component {
- struct bt_ref ref;
+ struct bt_object base;
struct bt_component_class *class;
GString *name;
- /** No ownership taken */
+ /** No ownership of stream taken */
FILE *error_stream;
- /** source, sink or filter destroy */
+ /** Source, Sink or Filter destroy */
bt_component_destroy_cb destroy;
+ /** User-defined data and its destruction callback */
void *user_data;
bt_component_destroy_cb user_destroy;
};
#include <babeltrace/ref-internal.h>
struct bt_notification_iterator {
- struct bt_ref ref;
+ struct bt_object base;
bt_notification_iterator_get_cb get;
bt_notification_iterator_next_cb next;
void *user_data;
struct bt_notification_iterator *iterator, int whence,
int64_t time);
-/**
- * Increments the reference count of \p iterator.
- *
- * @param iterator Iterator of which to increment the reference count
- *
- * @see bt_notification_iterator_put()
- */
-extern void bt_notification_iterator_get(
- struct bt_notification_iterator *iterator);
-
-/**
- * Decrements the reference count of \p iterator, destroying it when this
- * count reaches 0.
- *
- * @param iterator Iterator of which to decrement the reference count
- *
- * @see bt_notification_iterator_get()
- */
-extern void bt_notification_iterator_put(
- struct bt_notification_iterator *iterator);
-
#ifdef __cplusplus
}
#endif
#include <babeltrace/ctf-writer/ref-internal.h>
#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/object-internal.h>
#include <babeltrace/plugin/notification/notification.h>
#ifdef __cplusplus
#endif
struct bt_notification {
- struct bt_ctf_ref ref;
+ struct bt_object base;
enum bt_notification_type type;
};
#include <babeltrace/ref-internal.h>
#include <babeltrace/plugin/component.h>
#include <babeltrace/plugin/plugin.h>
+#include <babeltrace/object-internal.h>
#include <gmodule.h>
/**
* reference to their plugin.
*
* This ensures that a plugin's library is not closed while it is being used
- * even if the bt_component_factory which created its components is destroyed.
+ * even if the bt_component_factory, which created its components, is destroyed.
*/
struct bt_plugin {
- struct bt_ref ref;
+ struct bt_object base;
const char *name;
const char *author;
const char *license;
enum bt_component_status bt_plugin_register_component_classes(
struct bt_plugin *plugin, struct bt_component_factory *factory);
-BT_HIDDEN
-void bt_plugin_get(struct bt_plugin *plugin);
-
-BT_HIDDEN
-void bt_plugin_put(struct bt_plugin *plugin);
-
#endif /* BABELTRACE_PLUGIN_COMPONENT_CLASS_INTERNAL_H */
#include <babeltrace/compiler.h>
#include <babeltrace/plugin/component-class-internal.h>
+#include <babeltrace/ref.h>
#include <glib.h>
static
-void bt_component_class_destroy(struct bt_ref *ref)
+void bt_component_class_destroy(struct bt_object *obj)
{
struct bt_component_class *class;
- assert(ref);
- class = container_of(ref, struct bt_component_class, ref);
+ assert(obj);
+ class = container_of(obj, struct bt_component_class, base);
if (class->name) {
g_string_free(class->name, TRUE);
}
- bt_plugin_put(class->plugin);
+
+ bt_put(class->plugin);
g_free(class);
}
goto end;
}
- bt_ref_init(&class->ref, bt_component_class_destroy);
+ bt_object_init(class, bt_component_class_destroy);
class->type = type;
class->name = g_string_new(name);
if (!class->name) {
- bt_component_class_put(class);
- class = NULL;
+ BT_PUT(class);
goto end;
}
- bt_plugin_get(plugin);
+
+ bt_get(plugin);
class->plugin = plugin;
end:
return class;
}
-
-BT_HIDDEN
-void bt_component_class_get(struct bt_component_class *class)
-{
- if (!class) {
- return;
- }
-
- bt_ref_get(&class->ref);
-}
-
-BT_HIDDEN
-void bt_component_class_put(struct bt_component_class *class)
-{
- if (!class) {
- return;
- }
-
- bt_ref_put(&class->ref);
-}
#include <babeltrace/plugin/component-factory-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/compiler.h>
+#include <babeltrace/ref.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
* or .la on Linux).
*/
if (strncmp(NATIVE_PLUGIN_SUFFIX,
- path + path_len - NATIVE_PLUGIN_SUFFIX_LEN,
- NATIVE_PLUGIN_SUFFIX_LEN) &&
- strncmp(LIBTOOL_PLUGIN_SUFFIX,
- path + path_len - LIBTOOL_PLUGIN_SUFFIX_LEN,
- LIBTOOL_PLUGIN_SUFFIX_LEN)) {
+ path + path_len - NATIVE_PLUGIN_SUFFIX_LEN,
+ NATIVE_PLUGIN_SUFFIX_LEN) &&
+ strncmp(LIBTOOL_PLUGIN_SUFFIX,
+ path + path_len - LIBTOOL_PLUGIN_SUFFIX_LEN,
+ LIBTOOL_PLUGIN_SUFFIX_LEN)) {
/* Name indicates that this is not a plugin file. */
ret = BT_COMPONENT_FACTORY_STATUS_INVAL;
goto end;
}
component_status = bt_plugin_register_component_classes(plugin,
- factory);
+ factory);
if (component_status != BT_COMPONENT_STATUS_OK) {
switch (component_status) {
case BT_COMPONENT_STATUS_NOMEM:
ret = BT_COMPONENT_FACTORY_STATUS_ERROR;
break;
}
- bt_plugin_put(plugin);
- plugin = NULL;
+
+ BT_PUT(plugin);
goto end;
}
g_ptr_array_add(factory->plugins, plugin);
if (S_ISDIR(st.st_mode)) {
ret = bt_component_factory_load_dir_recursive(factory,
- file_path);
+ file_path);
if (ret != BT_COMPONENT_FACTORY_STATUS_OK) {
goto end;
}
return ret;
}
-void bt_component_factory_destroy(struct bt_component_factory *factory)
+static
+void bt_component_factory_destroy(struct bt_object *obj)
{
- if (!factory) {
- return;
- }
+ struct bt_component_factory *factory = NULL;
+
+ assert(obj);
+ factory = container_of(obj, struct bt_component_factory, base);
if (factory->plugins) {
g_ptr_array_free(factory->plugins, TRUE);
g_free(factory);
}
-struct bt_component_factory *
-bt_component_factory_create(void)
+struct bt_component_factory *bt_component_factory_create(void)
{
struct bt_component_factory *factory;
goto end;
}
+ bt_object_init(factory, bt_component_factory_destroy);
factory->plugins = g_ptr_array_new_with_free_func(
- (GDestroyNotify) bt_plugin_put);
+ (GDestroyNotify) bt_put);
if (!factory->plugins) {
goto error;
}
factory->components = g_ptr_array_new_with_free_func(
- (GDestroyNotify) bt_component_put);
+ (GDestroyNotify) bt_put);
if (!factory->components) {
goto error;
}
end:
return factory;
error:
- bt_component_factory_destroy(factory);
- return NULL;
+ BT_PUT(factory);
+ return factory;
}
enum bt_component_factory_status bt_component_factory_load(
struct bt_component_factory *factory, const char *path)
{
enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK;
- DIR *directory = NULL;
if (!factory || !path) {
ret = BT_COMPONENT_FACTORY_STATUS_INVAL;
goto end;
}
- directory = opendir(path) ;
- if (!directory) {
- switch (errno) {
- case ENOTDIR:
- /* Try loading as a file. */
- break;
- case ENOENT:
- ret = BT_COMPONENT_FACTORY_STATUS_NOENT;
- goto end;
- default:
- ret = BT_COMPONENT_FACTORY_STATUS_IO;
- goto end;
- }
+ if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
+ ret = BT_COMPONENT_FACTORY_STATUS_NOENT;
+ goto end;
}
- if (directory) {
+ if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
ret = bt_component_factory_load_dir_recursive(factory, path);
- } else {
+ } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) ||
+ g_file_test(path, G_FILE_TEST_IS_SYMLINK)) {
ret = bt_component_factory_load_file(factory, path);
+ } else {
+ ret = BT_COMPONENT_FACTORY_STATUS_INVAL;
+ goto end;
}
end:
- if (directory) {
- closedir(directory);
- }
return ret;
}
#include <babeltrace/plugin/component-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/compiler.h>
+#include <babeltrace/ref.h>
-static void bt_component_destroy(struct bt_ref *ref);
+static
+void bt_component_destroy(struct bt_object *obj)
+{
+ struct bt_component *component = NULL;
+ struct bt_component_class *component_class = NULL;
+
+ if (!obj) {
+ return;
+ }
+
+ component = container_of(obj, struct bt_component, base);
+
+ /**
+ * User data is destroyed first, followed by the concrete component
+ * instance.
+ */
+ assert(!component->user_data || component->user_destroy);
+ component->user_destroy(component->user_data);
+
+ g_string_free(component->name, TRUE);
+
+ assert(component->destroy);
+ component_class = component->class;
+
+ /* Frees the component, which becomes invalid */
+ component->destroy(component);
+ component = NULL;
+
+ bt_put(component_class);
+}
+
+BT_HIDDEN
+enum bt_component_status bt_component_init(struct bt_component *component,
+ struct bt_component_class *class, const char *name,
+ bt_component_destroy_cb destroy)
+{
+ enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+
+ if (!component || !class || !name || name[0] == '\0' || !destroy) {
+ ret = BT_COMPONENT_STATUS_INVAL;
+ goto end;
+ }
+
+ bt_object_init(component, bt_component_destroy);
+ bt_get(class);
+ component->class = class;
+ component->name = g_string_new(name);
+ if (!component->name) {
+ ret = BT_COMPONENT_STATUS_NOMEM;
+ goto end;
+ }
+ component->destroy = destroy;
+end:
+ return ret;
+}
const char *bt_component_get_name(struct bt_component *component)
{
return ret;
}
-void bt_component_get(struct bt_component *component)
-{
- if (!component) {
- return;
- }
-
- bt_ref_get(&component->ref);
-}
-
-void bt_component_put(struct bt_component *component)
-{
- if (!component) {
- return;
- }
-
- bt_ref_put(&component->ref);
-}
-
-BT_HIDDEN
-enum bt_component_status bt_component_init(struct bt_component *component,
- struct bt_component_class *class, const char *name,
- bt_component_destroy_cb destroy)
-{
- enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
- if (!component || !class || !name || name[0] == '\0' || destroy) {
- ret = BT_COMPONENT_STATUS_INVAL;
- goto end;
- }
-
- bt_ref_init(&component->ref, bt_component_destroy);
- bt_component_class_get(class);
- component->class = class;
- component->name = g_string_new(name);
- if (!component->name) {
- ret = BT_COMPONENT_STATUS_NOMEM;
- goto end;
- }
- component->destroy = destroy;
-end:
- return ret;
-}
-
void *bt_component_get_private_data(struct bt_component *component)
{
void *ret = NULL;
end:
return ret;
}
-
-static
-void bt_component_destroy(struct bt_ref *ref)
-{
- struct bt_component *component = NULL;
-
- if (!ref) {
- return;
- }
-
- component = container_of(ref, struct bt_component, ref);
-
- /**
- * User data is destroyed first, followed by the concrete component
- * instance.
- */
- assert(!component->user_data || component->user_destroy);
- component->user_destroy(component->user_data);
-
- g_string_free(component->name, TRUE);
-
- assert(component->destroy);
- component->destroy(component);
- bt_component_class_put(component->class);
-}
*/
#include <babeltrace/compiler.h>
+#include <babeltrace/ref.h>
#include <babeltrace/plugin/component.h>
#include <babeltrace/plugin/source-internal.h>
#include <babeltrace/plugin/notification/iterator.h>
#include <babeltrace/plugin/notification/iterator-internal.h>
static
-void bt_notification_iterator_destroy(struct bt_ref *ref)
+void bt_notification_iterator_destroy(struct bt_object *obj)
{
struct bt_notification_iterator *iterator;
- if (!ref) {
- return;
- }
-
- iterator = container_of(ref, struct bt_notification_iterator,
- ref);
+ assert(obj);
+ iterator = container_of(obj, struct bt_notification_iterator,
+ base);
assert(iterator->user_destroy || !iterator->user_data);
iterator->user_destroy(iterator);
g_free(iterator);
goto end;
}
- bt_ref_init(&iterator->ref, bt_notification_iterator_destroy);
+ bt_object_init(iterator, bt_notification_iterator_destroy);
end:
return iterator;
}
return ret;
}
-void bt_notification_iterator_get(struct bt_notification_iterator *iterator)
-{
- if (!iterator) {
- return;
- }
-
- bt_ref_get(&iterator->ref);
-}
-
-void bt_notification_iterator_put(struct bt_notification_iterator *iterator)
-{
- if (!iterator) {
- return;
- }
-
- bt_ref_put(&iterator->ref);
-}
-
enum bt_notification_iterator_status bt_notification_iterator_set_get_cb(
struct bt_notification_iterator *iterator,
bt_notification_iterator_get_cb get)
*/
#include <babeltrace/compiler.h>
+#include <babeltrace/ref.h>
#include <babeltrace/plugin/plugin-internal.h>
#include <glib.h>
#define PLUGIN_SYMBOL_EXIT "__bt_plugin_exit"
static
-void bt_plugin_destroy(struct bt_ref *ref)
+void bt_plugin_destroy(struct bt_object *obj)
{
struct bt_plugin *plugin;
- assert(ref);
- plugin = container_of(ref, struct bt_plugin, ref);
+ assert(obj);
+ plugin = container_of(obj, struct bt_plugin, base);
+
if (plugin->module) {
if (!g_module_close(plugin->module)) {
printf_error("Module close error: %s",
goto error;
}
- bt_ref_init(&plugin->ref, bt_plugin_destroy);
+ bt_object_init(plugin, bt_plugin_destroy);
if (!g_module_symbol(module, PLUGIN_SYMBOL_NAME,
(gpointer *) &plugin->name))
{
return plugin;
error:
- bt_plugin_put(plugin);
- return NULL;
+ BT_PUT(plugin);
+ return plugin;
}
BT_HIDDEN
assert(plugin && factory);
return plugin->init(factory);
}
-
-BT_HIDDEN
-void bt_plugin_get(struct bt_plugin *plugin)
-{
- if (!plugin) {
- return;
- }
-
- bt_ref_get(&plugin->ref);
-}
-
-BT_HIDDEN
-void bt_plugin_put(struct bt_plugin *plugin)
-{
- if (!plugin) {
- return;
- }
-
- bt_ref_put(&plugin->ref);
-}
* SOFTWARE.
*/
+#include <babeltrace/ref.h>
#include <babeltrace/compiler.h>
#include <babeltrace/plugin/source-internal.h>
#include <babeltrace/plugin/component-internal.h>
end:
return iterator;
error:
- bt_notification_iterator_put(iterator);
- return NULL;
+ BT_PUT(iterator);
+ return iterator;
}