if (class->description) {
g_string_free(class->description, TRUE);
}
+ if (class->help) {
+ g_string_free(class->help, TRUE);
+ }
if (class->destroy_listeners) {
g_array_free(class->destroy_listeners, TRUE);
}
goto error;
}
+ class->help = g_string_new(NULL);
+ if (!class->help) {
+ goto error;
+ }
+
class->destroy_listeners = g_array_new(FALSE, TRUE,
sizeof(struct bt_component_class_destroy_listener));
if (!class->destroy_listeners) {
}
struct bt_component_class *bt_component_class_source_create(const char *name,
- bt_component_class_source_init_iterator_method init_iterator_method)
+ bt_component_class_notification_iterator_get_method notification_iterator_get_method,
+ bt_component_class_notification_iterator_next_method notification_iterator_next_method)
{
struct bt_component_class_source *source_class = NULL;
int ret;
- if (!name || !init_iterator_method) {
+ if (!name || !notification_iterator_get_method ||
+ !notification_iterator_next_method) {
goto end;
}
goto end;
}
- source_class->methods.init_iterator = init_iterator_method;
+ source_class->methods.iterator.get = notification_iterator_get_method;
+ source_class->methods.iterator.next = notification_iterator_next_method;
end:
return &source_class->parent;
}
struct bt_component_class *bt_component_class_filter_create(const char *name,
- bt_component_class_filter_init_iterator_method init_iterator_method)
+ bt_component_class_notification_iterator_get_method notification_iterator_get_method,
+ bt_component_class_notification_iterator_next_method notification_iterator_next_method)
{
struct bt_component_class_filter *filter_class = NULL;
int ret;
- if (!name || !init_iterator_method) {
+ if (!name || !notification_iterator_get_method ||
+ !notification_iterator_next_method) {
goto end;
}
goto end;
}
- filter_class->methods.init_iterator = init_iterator_method;
+ filter_class->methods.iterator.get = notification_iterator_get_method;
+ filter_class->methods.iterator.next = notification_iterator_next_method;
end:
return &filter_class->parent;
return ret;
}
+int bt_component_class_set_query_method(
+ struct bt_component_class *component_class,
+ bt_component_class_query_method query_method)
+{
+ int ret = 0;
+
+ if (!component_class || component_class->frozen || !query_method) {
+ ret = -1;
+ goto end;
+ }
+
+ component_class->methods.query = query_method;
+
+end:
+ return ret;
+}
+
int bt_component_class_set_destroy_method(
struct bt_component_class *component_class,
bt_component_class_destroy_method destroy_method)
return ret;
}
-extern int bt_component_class_set_description(
+int bt_component_class_source_set_notification_iterator_init_method(
+ struct bt_component_class *component_class,
+ bt_component_class_notification_iterator_init_method notification_iterator_init_method)
+{
+ struct bt_component_class_source *source_class;
+ int ret = 0;
+
+ if (!component_class || component_class->frozen ||
+ !notification_iterator_init_method ||
+ component_class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
+ ret = -1;
+ goto end;
+ }
+
+ source_class = container_of(component_class,
+ struct bt_component_class_source, parent);
+ source_class->methods.iterator.init = notification_iterator_init_method;
+
+end:
+ return ret;
+}
+
+int bt_component_class_source_set_notification_iterator_destroy_method(
+ struct bt_component_class *component_class,
+ bt_component_class_notification_iterator_destroy_method notification_iterator_destroy_method)
+{
+ struct bt_component_class_source *source_class;
+ int ret = 0;
+
+ if (!component_class || component_class->frozen ||
+ !notification_iterator_destroy_method ||
+ component_class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
+ ret = -1;
+ goto end;
+ }
+
+ source_class = container_of(component_class,
+ struct bt_component_class_source, parent);
+ source_class->methods.iterator.destroy =
+ notification_iterator_destroy_method;
+
+end:
+ return ret;
+}
+
+int bt_component_class_source_set_notification_iterator_seek_time_method(
+ struct bt_component_class *component_class,
+ bt_component_class_notification_iterator_seek_time_method notification_iterator_seek_time_method)
+{
+ struct bt_component_class_source *source_class;
+ int ret = 0;
+
+ if (!component_class || component_class->frozen ||
+ !notification_iterator_seek_time_method ||
+ component_class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
+ ret = -1;
+ goto end;
+ }
+
+ source_class = container_of(component_class,
+ struct bt_component_class_source, parent);
+ source_class->methods.iterator.seek_time =
+ notification_iterator_seek_time_method;
+
+end:
+ return ret;
+}
+
+int bt_component_class_filter_set_notification_iterator_init_method(
+ struct bt_component_class *component_class,
+ bt_component_class_notification_iterator_init_method notification_iterator_init_method)
+{
+ struct bt_component_class_filter *filter_class;
+ int ret = 0;
+
+ if (!component_class || component_class->frozen ||
+ !notification_iterator_init_method ||
+ component_class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
+ ret = -1;
+ goto end;
+ }
+
+ filter_class = container_of(component_class,
+ struct bt_component_class_filter, parent);
+ filter_class->methods.iterator.init = notification_iterator_init_method;
+
+end:
+ return ret;
+}
+
+int bt_component_class_filter_set_notification_iterator_destroy_method(
+ struct bt_component_class *component_class,
+ bt_component_class_notification_iterator_destroy_method notification_iterator_destroy_method)
+{
+ struct bt_component_class_filter *filter_class;
+ int ret = 0;
+
+ if (!component_class || component_class->frozen ||
+ !notification_iterator_destroy_method ||
+ component_class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
+ ret = -1;
+ goto end;
+ }
+
+ filter_class = container_of(component_class,
+ struct bt_component_class_filter, parent);
+ filter_class->methods.iterator.destroy =
+ notification_iterator_destroy_method;
+
+end:
+ return ret;
+}
+
+int bt_component_class_filter_set_notification_iterator_seek_time_method(
+ struct bt_component_class *component_class,
+ bt_component_class_notification_iterator_seek_time_method notification_iterator_seek_time_method)
+{
+ struct bt_component_class_filter *filter_class;
+ int ret = 0;
+
+ if (!component_class || component_class->frozen ||
+ !notification_iterator_seek_time_method ||
+ component_class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
+ ret = -1;
+ goto end;
+ }
+
+ filter_class = container_of(component_class,
+ struct bt_component_class_filter, parent);
+ filter_class->methods.iterator.seek_time =
+ notification_iterator_seek_time_method;
+
+end:
+ return ret;
+}
+
+int bt_component_class_set_description(
struct bt_component_class *component_class,
const char *description)
{
return ret;
}
+int bt_component_class_set_help(
+ struct bt_component_class *component_class,
+ const char *help)
+{
+ int ret = 0;
+
+ if (!component_class || component_class->frozen || !help) {
+ ret = -1;
+ goto end;
+ }
+
+ g_string_assign(component_class->help, help);
+
+end:
+ return ret;
+}
+
const char *bt_component_class_get_name(
struct bt_component_class *component_class)
{
const char *bt_component_class_get_description(
struct bt_component_class *component_class)
{
- return component_class && component_class->description ?
+ return component_class && component_class->description &&
+ component_class->description->str[0] != '\0' ?
component_class->description->str : NULL;
}
+const char *bt_component_class_get_help(
+ struct bt_component_class *component_class)
+{
+ return component_class && component_class->help &&
+ component_class->help->str[0] != '\0' ?
+ component_class->help->str : NULL;
+}
+
BT_HIDDEN
int bt_component_class_add_destroy_listener(struct bt_component_class *class,
bt_component_class_destroy_listener_func func, void *data)
end:
return ret;
}
+
+struct bt_value *bt_component_class_query(
+ struct bt_component_class *component_class,
+ const char *object, struct bt_value *params)
+{
+ struct bt_value *results = NULL;
+
+ if (!component_class || !object || !params ||
+ !component_class->methods.query) {
+ goto end;
+ }
+
+ results = component_class->methods.query(component_class,
+ object, params);
+
+end:
+ return results;
+}