예제 #1
0
파일: value.c 프로젝트: efficios/babeltrace
static
void bt_value_array_freeze(struct bt_value *object)
{
	int i;
	struct bt_value_array *typed_array_obj =
		BT_VALUE_TO_ARRAY(object);

	for (i = 0; i < typed_array_obj->garray->len; ++i) {
		bt_value_freeze(g_ptr_array_index(typed_array_obj->garray, i));
	}

	bt_value_generic_freeze(object);
}
예제 #2
0
파일: value.c 프로젝트: efficios/babeltrace
static
void bt_value_map_freeze(struct bt_value *object)
{
	GHashTableIter iter;
	gpointer key, element_obj;
	const struct bt_value_map *map_obj = BT_VALUE_TO_MAP(object);

	g_hash_table_iter_init(&iter, map_obj->ght);

	while (g_hash_table_iter_next(&iter, &key, &element_obj)) {
		bt_value_freeze(element_obj);
	}

	bt_value_generic_freeze(object);
}
예제 #3
0
파일: trace.c 프로젝트: brianrob/babeltrace
int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace *trace,
		const char *name, const char *value)
{
	int ret = 0;
	struct bt_value *env_value_string_obj = NULL;

	if (!trace || !name || !value) {
		ret = -1;
		goto end;
	}

	if (trace->frozen) {
		/*
		 * New environment fields may be added to a frozen trace,
		 * but existing fields may not be changed.
		 */
		struct bt_value *attribute =
			bt_ctf_attributes_get_field_value_by_name(
				trace->environment, name);

		if (attribute) {
			BT_PUT(attribute);
			ret = -1;
			goto end;
		}
	}

	env_value_string_obj = bt_value_string_create_init(value);

	if (!env_value_string_obj) {
		ret = -1;
		goto end;
	}

	if (trace->frozen) {
		bt_value_freeze(env_value_string_obj);
	}
	ret = bt_ctf_trace_set_environment_field(trace, name,
		env_value_string_obj);

end:
	BT_PUT(env_value_string_obj);
	return ret;
}
예제 #4
0
파일: trace.c 프로젝트: brianrob/babeltrace
int bt_ctf_trace_set_environment_field(struct bt_ctf_trace *trace,
		const char *name, struct bt_value *value)
{
	int ret = 0;

	if (!trace || !name || !value ||
		bt_ctf_validate_identifier(name) ||
		!(bt_value_is_integer(value) || bt_value_is_string(value))) {
		ret = -1;
		goto end;
	}

	if (strchr(name, ' ')) {
		ret = -1;
		goto end;
	}

	if (trace->frozen) {
		/*
		 * New environment fields may be added to a frozen trace,
		 * but existing fields may not be changed.
		 *
		 * The object passed is frozen like all other attributes.
		 */
		struct bt_value *attribute =
			bt_ctf_attributes_get_field_value_by_name(
				trace->environment, name);

		if (attribute) {
			BT_PUT(attribute);
			ret = -1;
			goto end;
		}

		bt_value_freeze(value);
	}

	ret = bt_ctf_attributes_set_field_value(trace->environment, name,
		value);

end:
	return ret;
}
예제 #5
0
BT_HIDDEN
int bt_attributes_freeze(struct bt_value *attr_obj)
{
	uint64_t i;
	int64_t count;
	int ret = 0;

	if (!attr_obj) {
		BT_LOGW_STR("Invalid parameter: attributes object is NULL.");
		ret = -1;
		goto end;
	}

	BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj);
	count = bt_value_array_size(attr_obj);
	assert(count >= 0);

	/*
	 * We do not freeze the array value object itself here, since
	 * internal stuff could need to modify/add attributes. Each
	 * attribute is frozen one by one.
	 */
	for (i = 0; i < count; ++i) {
		struct bt_value *obj = NULL;

		obj = bt_attributes_get_field_value(attr_obj, i);
		if (!obj) {
			BT_LOGE("Cannot get attributes object's field value by index: "
				"value-addr=%p, index=%" PRIu64,
				attr_obj, i);
			ret = -1;
			goto end;
		}

		bt_value_freeze(obj);
		BT_PUT(obj);
	}

end:
	return ret;
}