* SOFTWARE.
*/
-#include <babeltrace/ctf-writer/clock.h>
#include <babeltrace/ctf-ir/clock-internal.h>
+#include <babeltrace/ctf-ir/utils.h>
#include <babeltrace/ctf-writer/writer-internal.h>
#include <babeltrace/compiler.h>
#include <inttypes.h>
static
void bt_ctf_clock_destroy(struct bt_ctf_ref *ref);
+BT_HIDDEN
+struct bt_ctf_clock *_bt_ctf_clock_create(void)
+{
+ struct bt_ctf_clock *clock = g_new0(
+ struct bt_ctf_clock, 1);
+
+ if (!clock) {
+ goto end;
+ }
+
+ clock->precision = 1;
+ clock->frequency = 1000000000;
+ bt_ctf_ref_init(&clock->ref_count);
+end:
+ return clock;
+}
+
+BT_HIDDEN
+int bt_ctf_clock_set_name(struct bt_ctf_clock *clock,
+ const char *name)
+{
+ int ret = 0;
+
+ if (bt_ctf_validate_identifier(name)) {
+ ret = -1;
+ goto end;
+ }
+
+ if (clock->name) {
+ g_string_assign(clock->name, name);
+ } else {
+ clock->name = g_string_new(name);
+ if (!clock->name) {
+ ret = -1;
+ goto end;
+ }
+ }
+
+end:
+ return ret;
+}
+
struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
{
+ int ret;
struct bt_ctf_clock *clock = NULL;
- if (validate_identifier(name)) {
+ clock = _bt_ctf_clock_create();
+ if (!clock) {
goto error;
}
- clock = g_new0(struct bt_ctf_clock, 1);
- if (!clock) {
- goto error;
+ ret = bt_ctf_clock_set_name(clock, name);
+ if (ret) {
+ goto error_destroy;
}
- clock->name = g_string_new(name);
- if (!clock->name) {
+ ret = babeltrace_uuid_generate(clock->uuid);
+ if (ret) {
goto error_destroy;
}
- clock->precision = 1;
- clock->frequency = 1000000000;
- uuid_generate(clock->uuid);
- bt_ctf_ref_init(&clock->ref_count);
+ clock->uuid_set = 1;
return clock;
error_destroy:
bt_ctf_clock_destroy(&clock->ref_count);
{
const unsigned char *ret;
- if (!clock) {
+ if (!clock || !clock->uuid_set) {
ret = NULL;
goto end;
}
{
int ret = 0;
- if (!clock || !uuid) {
+ if (!clock || !uuid || clock->frozen) {
ret = -1;
goto end;
}
memcpy(clock->uuid, uuid, sizeof(uuid_t));
+ clock->uuid_set = 1;
end:
return ret;
}
uuid[4], uuid[5], uuid[6], uuid[7],
uuid[8], uuid[9], uuid[10], uuid[11],
uuid[12], uuid[13], uuid[14], uuid[15]);
- if (clock->description->len) {
+ if (clock->description) {
g_string_append_printf(context->string, "\tdescription = \"%s\";\n",
clock->description->str);
}