GString *name;
int frozen;
uuid_t uuid;
+ bool uuid_set;
enum bt_ctf_byte_order native_byte_order;
struct bt_value *environment;
GPtrArray *clocks; /* Array of pointers to bt_ctf_clock_class */
\link ctfirfieldtypes field types\endlink eventually part of the trace
class with a byte order set to #BT_CTF_BYTE_ORDER_NATIVE have this
"real" byte order.
+- A \b UUID.
- An \b environment, which is a custom key-value mapping. Keys are
strings and values can be strings or integers.
extern int bt_ctf_trace_set_native_byte_order(struct bt_ctf_trace *trace_class,
enum bt_ctf_byte_order native_byte_order);
+/**
+@brief Returns the UUID of the CTF IR trace class \p trace_class.
+
+On success, the return value is an array of 16 bytes.
+
+@param[in] trace_class Trace class of which to get the UUID.
+@returns UUID of trace class \p trace_class, or
+ \c NULL if \p trace_class has no UUID or on error.
+
+@prenotnull{trace_class}
+@postrefcountsame{trace_class}
+
+@sa bt_ctf_trace_set_uuid(): Sets the UUID of a given trace class.
+*/
+extern const unsigned char *bt_ctf_trace_get_uuid(
+ struct bt_ctf_trace *trace_class);
+
+/**
+@brief Sets the UUID of the CTF IR trace class \p trace_class to
+ \p uuid.
+
+\p uuid \em must be an array of 16 bytes.
+
+@param[in] trace_class Trace class of which to set the UUID.
+@param[in] uuid UUID of the \p trace_class (copied on
+ success).
+@returns 0 on success, or a negative value on error.
+
+@prenotnull{trace_class}
+@prenotnull{uuid}
+@prehot{trace_class}
+@pre \p uuid is an array of 16 bytes.
+@postrefcountsame{trace_class}
+
+@sa bt_ctf_trace_get_uuid(): Returns the UUID of a given trace class.
+*/
+extern int bt_ctf_trace_set_uuid(struct bt_ctf_trace *trace_class,
+ const unsigned char *uuid);
+
/**
@brief Returns the number of entries contained in the environment of
the CTF IR trace class \p trace_class.
#include <babeltrace/endian-internal.h>
#include <inttypes.h>
#include <stdint.h>
+#include <string.h>
#define DEFAULT_IDENTIFIER_SIZE 128
#define DEFAULT_METADATA_STRING_SIZE 4096
goto error;
}
- /* Generate a trace UUID */
- uuid_generate(trace->uuid);
if (init_trace_packet_header(trace)) {
goto error;
}
return ret;
}
+const unsigned char *bt_ctf_trace_get_uuid(struct bt_ctf_trace *trace)
+{
+ return trace && trace->uuid_set ? trace->uuid : NULL;
+}
+
+int bt_ctf_trace_set_uuid(struct bt_ctf_trace *trace, const unsigned char *uuid)
+{
+ int ret = 0;
+
+ if (!trace || !uuid || trace->frozen) {
+ ret = -1;
+ goto end;
+ }
+
+ memcpy(trace->uuid, uuid, sizeof(uuid_t));
+ trace->uuid_set = true;
+
+end:
+ return ret;
+}
+
void bt_ctf_trace_destroy(struct bt_object *obj)
{
struct bt_ctf_trace *trace;
unsigned char *uuid = trace->uuid;
int ret;
- g_string_append(context->string, "trace {\n");
+ if (trace->native_byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
+ ret = -1;
+ goto end;
+ }
+ g_string_append(context->string, "trace {\n");
g_string_append(context->string, "\tmajor = 1;\n");
g_string_append(context->string, "\tminor = 8;\n");
assert(trace->native_byte_order == BT_CTF_BYTE_ORDER_LITTLE_ENDIAN ||
trace->native_byte_order == BT_CTF_BYTE_ORDER_BIG_ENDIAN ||
trace->native_byte_order == BT_CTF_BYTE_ORDER_NETWORK);
- g_string_append_printf(context->string,
- "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
- uuid[0], uuid[1], uuid[2], uuid[3],
- 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 (trace->uuid_set) {
+ g_string_append_printf(context->string,
+ "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
+ uuid[0], uuid[1], uuid[2], uuid[3],
+ uuid[4], uuid[5], uuid[6], uuid[7],
+ uuid[8], uuid[9], uuid[10], uuid[11],
+ uuid[12], uuid[13], uuid[14], uuid[15]);
+ }
+
g_string_append_printf(context->string, "\tbyte_order = %s;\n",
get_byte_order_string(trace->native_byte_order));
#include <babeltrace/ref.h>
#include <babeltrace/endian-internal.h>
#include <babeltrace/compiler-internal.h>
+#include <babeltrace/compat/uuid-internal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
{
int ret;
struct bt_ctf_writer *writer = NULL;
+ unsigned char uuid[16];
if (!path) {
goto error;
goto error_destroy;
}
+ /* Generate a UUID for this writer's trace */
+ uuid_generate(uuid);
+ ret = bt_ctf_trace_set_uuid(writer->trace, uuid);
+ if (ret) {
+ goto error_destroy;
+ }
+
writer->trace->is_created_by_writer = 1;
bt_object_set_parent(writer->trace, writer);
bt_put(writer->trace);
#define DEFAULT_CLOCK_TIME 0
#define DEFAULT_CLOCK_VALUE 0
-#define NR_TESTS 607
+#define NR_TESTS 614
static int64_t current_time = 42;
bt_put(clock_class);
}
+static
+void test_trace_uuid(void)
+{
+ struct bt_ctf_trace *trace;
+ const unsigned char uuid[] = {
+ 0x35, 0x92, 0x63, 0xab, 0xb4, 0xbe, 0x40, 0xb4,
+ 0xb2, 0x60, 0xd3, 0xf1, 0x3b, 0xb0, 0xd8, 0x59,
+ };
+ const unsigned char *ret_uuid;
+
+ trace = bt_ctf_trace_create();
+ assert(trace);
+ ok(!bt_ctf_trace_get_uuid(NULL),
+ "bt_ctf_trace_get_uuid() handles NULL");
+ ok(!bt_ctf_trace_get_uuid(trace),
+ "bt_ctf_trace_get_uuid() returns NULL initially");
+ ok(bt_ctf_trace_set_uuid(NULL, uuid),
+ "bt_ctf_trace_set_uuid() handles NULL (trace)");
+ ok(bt_ctf_trace_set_uuid(trace, NULL),
+ "bt_ctf_trace_set_uuid() handles NULL (UUID)");
+ ok(bt_ctf_trace_set_uuid(trace, uuid) == 0,
+ "bt_ctf_trace_set_uuid() succeeds with a valid UUID");
+ ret_uuid = bt_ctf_trace_get_uuid(trace);
+ ok(ret_uuid, "bt_ctf_trace_get_uuid() returns a UUID");
+ ok(memcmp(uuid, ret_uuid, 16) == 0,
+ "bt_ctf_trace_get_uuid() returns the expected UUID");
+
+ bt_put(trace);
+}
+
int main(int argc, char **argv)
{
char trace_path[] = "/tmp/ctfwriter_XXXXXX";
test_static_trace();
+ test_trace_uuid();
+
metadata_string = bt_ctf_writer_get_metadata_string(writer);
ok(metadata_string, "Get metadata string");