* SOFTWARE.
*/
+#include <babeltrace/plugin/component.h>
#include <babeltrace/plugin/component-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/compiler.h>
-static void bt_component_destroy(struct bt_ctf_ref *ref);
+static void bt_component_destroy(struct bt_ref *ref);
const char *bt_component_get_name(struct bt_component *component)
{
goto end;
}
- type = component->type;
+ type = component->class->type;
end:
return type;
}
return;
}
- bt_ctf_ref_get(&component->ref_count);
+ bt_ref_get(&component->ref);
}
void bt_component_put(struct bt_component *component)
return;
}
- bt_ctf_ref_put(&component->ref_count, bt_component_destroy);
+ bt_ref_put(&component->ref);
}
BT_HIDDEN
-enum bt_component_status bt_component_init(struct bt_component *component, const char *name,
- void *user_data, bt_component_destroy_cb user_destroy_func,
- enum bt_component_type component_type,
- bt_component_destroy_cb component_destroy)
+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 || !name || name[0] == '\0' ||
- !user_destroy_func || !user_data || !component_destroy) {
+ if (!component || !class || !name || name[0] == '\0' || destroy) {
ret = BT_COMPONENT_STATUS_INVAL;
goto end;
}
- bt_ctf_ref_init(&component->ref_count);
- component->type = component_type;
- component->user_data = user_data;
- component->user_data_destroy = user_destroy_func;
- component->destroy = component_destroy;
-
+ 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;
+ void *ret = NULL;
if (!component) {
goto end;
}
static
-void bt_component_destroy(struct bt_ctf_ref *ref)
+void bt_component_destroy(struct bt_ref *ref)
{
struct bt_component *component = NULL;
return;
}
- component = container_of(ref, struct bt_component, ref_count);
+ 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_data_destroy);
- component->user_data_destroy(component->user_data);
+ 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);
}