int bt_ctf_event_class_set_attribute(
		struct bt_ctf_event_class *event_class, const char *name,
		struct bt_value *value)
{
	int ret = 0;

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

	if (!strcmp(name, "id") || !strcmp(name, "loglevel")) {
		if (!bt_value_is_integer(value)) {
			ret = -1;
			goto end;
		}
	} else if (!strcmp(name, "name") || !strcmp(name, "model.emf.uri")) {
		if (!bt_value_is_string(value)) {
			ret = -1;
			goto end;
		}
	} else {
		/* unknown attribute */
		ret = -1;
		goto end;
	}

	/* "id" special case: >= 0 */
	if (!strcmp(name, "id")) {
		int64_t val;

		ret = bt_value_integer_get(value, &val);

		if (ret) {
			goto end;
		}

		if (val < 0) {
			ret = -1;
			goto end;
		}
	}

	ret = bt_ctf_attributes_set_field_value(event_class->attributes,
		name, value);

end:
	return ret;
}
Exemple #2
0
static
int set_trace_name(bt_trace *trace, const char *name_suffix)
{
	int ret = 0;
	const bt_trace_class *tc = bt_trace_borrow_class_const(trace);
	const bt_value *val;
	GString *name;

	name = g_string_new(NULL);
	if (!name) {
		BT_LOGE_STR("Failed to allocate a GString.");
		ret = -1;
		goto end;
	}

	/*
	 * Check if we have a trace environment string value named `hostname`.
	 * If so, use it as the trace name's prefix.
	 */
	val = bt_trace_class_borrow_environment_entry_value_by_name_const(
		tc, "hostname");
	if (val && bt_value_is_string(val)) {
		g_string_append(name, bt_value_string_get(val));

		if (name_suffix) {
			g_string_append_c(name, G_DIR_SEPARATOR);
		}
	}

	if (name_suffix) {
		g_string_append(name, name_suffix);
	}

	ret = bt_trace_set_name(trace, name->str);
	if (ret) {
		goto end;
	}

	goto end;

end:
	if (name) {
		g_string_free(name, TRUE);
	}

	return ret;
}
Exemple #3
0
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;
}