struct bt_config *bt_config_cli_args_create_with_default(int argc,
		const char *argv[], int *retcode)
{
	struct bt_value *initial_plugin_paths;
	struct bt_config *cfg = NULL;
	int ret;

	initial_plugin_paths = bt_value_array_create();
	if (!initial_plugin_paths) {
		goto error;
	}

	ret = bt_config_append_plugin_paths(initial_plugin_paths,
		CONFIG_IN_TREE_PLUGIN_PATH);
	if (ret) {
		goto error;
	}

	cfg = bt_config_cli_args_create(argc, argv, retcode, true, true,
		BT_ENABLE_DEBUG_INFO == 0, initial_plugin_paths);
	goto end;

error:
	*retcode = 1;
	BT_PUT(cfg);

end:
	bt_put(initial_plugin_paths);
	return cfg;
}
Beispiel #2
0
BT_HIDDEN
struct bt_value *bt_attributes_create(void)
{
	struct bt_value *attr_obj;

	/*
	 * Attributes: array value object of array value objects, each one
	 * containing two entries: a string value object (attributes
	 * field name), and a value object (attributes field value).
	 *
	 * Example (JSON representation):
	 *
	 *     [
	 *         ["hostname", "eeppdesk"],
	 *         ["sysname", "Linux"],
	 *         ["tracer_major", 2],
	 *         ["tracer_minor", 5]
	 *     ]
	 */
	BT_LOGD_STR("Creating attributes object.");
	attr_obj = bt_value_array_create();
	if (!attr_obj) {
		BT_LOGE_STR("Failed to create array value.");
	} else {
		BT_LOGD("Created attributes object: addr=%p",
			attr_obj);
	}

	return attr_obj;
}
Beispiel #3
0
enum bt_value_status bt_value_array_append_empty_array_element(
		struct bt_value *array_obj)
{
	enum bt_value_status ret;
	struct bt_value *empty_array_obj = NULL;

	empty_array_obj = bt_value_array_create();
	ret = bt_value_array_append_element(array_obj,
		(void *) empty_array_obj);
	bt_object_put_ref(empty_array_obj);
	return ret;
}
Beispiel #4
0
enum bt_value_status bt_value_map_insert_empty_array_entry(
		struct bt_value *map_obj, const char *key)
{
	enum bt_value_status ret;
	struct bt_value *array_obj = NULL;

	array_obj = bt_value_array_create();
	ret = bt_value_map_insert_entry(map_obj, key,
		(void *) array_obj);
	bt_object_put_ref(array_obj);
	return ret;
}
Beispiel #5
0
static
struct bt_value *bt_value_array_copy(const struct bt_value *array_obj)
{
	int i;
	int ret;
	struct bt_value *copy_obj;
	struct bt_value_array *typed_array_obj;

	BT_LOGD("Copying array value: addr=%p", array_obj);
	typed_array_obj = BT_VALUE_TO_ARRAY(array_obj);
	copy_obj = bt_value_array_create();
	if (!copy_obj) {
		BT_LOGE_STR("Cannot create empty array value.");
		goto end;
	}

	for (i = 0; i < typed_array_obj->garray->len; ++i) {
		struct bt_value *element_obj_copy = NULL;
		const struct bt_value *element_obj =
			bt_value_array_borrow_element_by_index_const(
				array_obj, i);

		BT_ASSERT(element_obj);
		BT_LOGD("Copying array value's element: element-addr=%p, "
			"index=%d", element_obj, i);
		ret = bt_value_copy(element_obj, &element_obj_copy);
		if (ret) {
			BT_LOGE("Cannot copy array value's element: "
				"array-addr=%p, index=%d",
				array_obj, i);
			BT_OBJECT_PUT_REF_AND_RESET(copy_obj);
			goto end;
		}

		BT_ASSERT(element_obj_copy);
		ret = bt_value_array_append_element(copy_obj,
			(void *) element_obj_copy);
		BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy);
		if (ret) {
			BT_LOGE("Cannot append to array value: addr=%p",
				array_obj);
			BT_OBJECT_PUT_REF_AND_RESET(copy_obj);
			goto end;
		}
	}

	BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
		array_obj, copy_obj);

end:
	return copy_obj;
}
Beispiel #6
0
BT_HIDDEN
int bt_attributes_set_field_value(struct bt_value *attr_obj,
		const char *name, struct bt_value *value_obj)
{
	int ret = 0;
	struct bt_value *attr_field_obj = NULL;

	if (!attr_obj || !name || !value_obj) {
		BT_LOGW("Invalid parameter: attributes object, name, or value object is NULL: "
			"attr-value-addr=%p, name-addr=%p, value-addr=%p",
			attr_obj, name, value_obj);
		ret = -1;
		goto end;
	}

	attr_field_obj = bt_attributes_get_field_by_name(attr_obj, name);
	if (attr_field_obj) {
		ret = bt_value_array_set(attr_field_obj,
			BT_ATTR_VALUE_INDEX, value_obj);
		goto end;
	}

	attr_field_obj = bt_value_array_create();
	if (!attr_field_obj) {
		BT_LOGE_STR("Failed to create empty array value.");
		ret = -1;
		goto end;
	}

	ret = bt_value_array_append_string(attr_field_obj, name);
	ret |= bt_value_array_append(attr_field_obj, value_obj);
	if (ret) {
		BT_LOGE("Cannot append elements to array value: addr=%p",
			attr_field_obj);
		goto end;
	}

	ret = bt_value_array_append(attr_obj, attr_field_obj);
	if (ret) {
		BT_LOGE("Cannot append element to array value: "
			"array-value-addr=%p, element-value-addr=%p",
			attr_obj, attr_field_obj);
	}

end:
	BT_PUT(attr_field_obj);

	return ret;
}