Change backing type of lttng_uuid to std::array
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 2 May 2022 19:33:09 +0000 (15:33 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 13 Jun 2022 20:34:46 +0000 (16:34 -0400)
Changing the backing type of lttng_uuid to std::array allows us to
return lttng_uuid from a function. This, in return, makes it possible to
initialize const attributes from the return value of a function
returning a UUID.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ie092eab4a848a41ddd9c63f779514f1e4ca2a441

20 files changed:
src/bin/lttng-relayd/cmd-2-11.cpp
src/bin/lttng-relayd/cmd-2-11.hpp
src/bin/lttng-relayd/session.cpp
src/bin/lttng-relayd/session.hpp
src/bin/lttng-relayd/sessiond-trace-chunks.cpp
src/bin/lttng-relayd/sessiond-trace-chunks.hpp
src/bin/lttng-sessiond/consumer.cpp
src/bin/lttng-sessiond/consumer.hpp
src/bin/lttng-sessiond/ust-registry.hpp
src/common/consumer/consumer.cpp
src/common/consumer/consumer.hpp
src/common/kernel-consumer/kernel-consumer.cpp
src/common/relayd/relayd.cpp
src/common/relayd/relayd.hpp
src/common/sessiond-comm/relayd.hpp
src/common/sessiond-comm/sessiond-comm.hpp
src/common/ust-consumer/ust-consumer.cpp
src/common/uuid.cpp
src/common/uuid.hpp
tests/unit/test_uuid.cpp

index 680cb307b15bfa12999a8b1039bde4fca99f98f4..73c3a3c513fadd563dc9052e6abfd670f08282f6 100644 (file)
@@ -22,7 +22,7 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
                char *session_name, char *hostname, char *base_path,
                uint32_t *live_timer, bool *snapshot,
                uint64_t *id_sessiond,
-               lttng_uuid sessiond_uuid,
+               lttng_uuid& sessiond_uuid,
                bool *has_current_chunk, uint64_t *current_chunk_id,
                time_t *creation_time,
                bool *session_name_contains_creation_time)
@@ -53,7 +53,7 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
        header.creation_time = be64toh(header.creation_time);
        header.session_id = be64toh(header.session_id);
 
-       lttng_uuid_copy(sessiond_uuid, header.sessiond_uuid);
+       std::copy(std::begin(header.sessiond_uuid), std::end(header.sessiond_uuid), sessiond_uuid.begin());
 
        received_names_size = header.session_name_len + header.hostname_len +
                                header.base_path_len;
index 4b004f0d3f4232865d831c962ce97a9379af6c8f..79f241aaa249fce2a50378f1a8abd72684ae62f2 100644 (file)
@@ -15,7 +15,7 @@
 int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
                char *session_name, char *hostname, char *base_path,
                uint32_t *live_timer, bool *snapshot,
-               uint64_t *id_sessiond, lttng_uuid sessiond_uuid,
+               uint64_t *id_sessiond, lttng_uuid& sessiond_uuid,
                bool *has_current_chunk, uint64_t *current_chunk_id,
                time_t *creation_time,
                bool *session_name_contains_creation_time);
index a8a1520694025f3843b6cfabe9aebddca8a9488a..a776587b333a66c2c499d558b0c28c162fc8ae96 100644 (file)
@@ -281,7 +281,7 @@ struct relay_session *session_create(const char *session_name,
                const char *hostname, const char *base_path,
                uint32_t live_timer,
                bool snapshot,
-               const lttng_uuid sessiond_uuid,
+               const lttng_uuid& sessiond_uuid,
                const uint64_t *id_sessiond,
                const uint64_t *current_chunk_id,
                const time_t *creation_time,
@@ -363,7 +363,7 @@ struct relay_session *session_create(const char *session_name,
 
        session->live_timer = live_timer;
        session->snapshot = snapshot;
-       lttng_uuid_copy(session->sessiond_uuid, sessiond_uuid);
+       session->sessiond_uuid = sessiond_uuid;
 
        if (id_sessiond) {
                LTTNG_OPTIONAL_SET(&session->id_sessiond, *id_sessiond);
@@ -527,8 +527,7 @@ bool session_has_ongoing_rotation(const struct relay_session *session)
                        goto next_session;
                }
 
-               if (!lttng_uuid_is_equal(session->sessiond_uuid,
-                               iterated_session->sessiond_uuid)) {
+               if (session->sessiond_uuid != iterated_session->sessiond_uuid) {
                        /* Sessions do not originate from the same sessiond. */
                        goto next_session;
                }
index 9c61b942bed04f251fd57538c2973fe2db61fc63..986eca68f041868b569ead28977034f8aaa88d2d 100644 (file)
@@ -142,7 +142,7 @@ struct relay_session *session_create(const char *session_name,
                const char *hostname, const char *base_path,
                uint32_t live_timer,
                bool snapshot,
-               const lttng_uuid sessiond_uuid,
+               const lttng_uuid& sessiond_uuid,
                const uint64_t *id_sessiond,
                const uint64_t *current_chunk_id,
                const time_t *creation_time,
index 34f14f187fbe5d615cc0fd849a9fb3855722bced..60f1b975453c5612a4b1ee136cc4ce91c37e1fe3 100644 (file)
@@ -77,8 +77,8 @@ static
 unsigned long trace_chunk_registry_ht_key_hash(
                const struct trace_chunk_registry_ht_key *key)
 {
-       uint64_t uuid_h1 = ((uint64_t *) key->sessiond_uuid)[0];
-       uint64_t uuid_h2 = ((uint64_t *) key->sessiond_uuid)[1];
+       const uint64_t uuid_h1 = *reinterpret_cast<const uint64_t *>(&key->sessiond_uuid[0]);
+       const uint64_t uuid_h2 = *reinterpret_cast<const uint64_t *>(&key->sessiond_uuid[1]);
 
        return hash_key_u64(&uuid_h1, lttng_ht_seed) ^
                        hash_key_u64(&uuid_h2, lttng_ht_seed);
@@ -94,8 +94,7 @@ int trace_chunk_registry_ht_key_match(struct cds_lfht_node *node,
        struct trace_chunk_registry_ht_element *registry;
 
        registry = container_of(node, typeof(*registry), ht_node);
-       return lttng_uuid_is_equal(key->sessiond_uuid,
-                       registry->key.sessiond_uuid);
+       return key->sessiond_uuid == registry->key.sessiond_uuid;
 }
 
 static
@@ -295,13 +294,13 @@ void sessiond_trace_chunk_registry_destroy(
 
 int sessiond_trace_chunk_registry_session_created(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid)
+               const lttng_uuid& sessiond_uuid)
 {
        int ret = 0;
        struct trace_chunk_registry_ht_key key;
        struct trace_chunk_registry_ht_element *element;
 
-       lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+       key.sessiond_uuid = sessiond_uuid;
 
        element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
        if (element) {
@@ -321,7 +320,7 @@ end:
 
 int sessiond_trace_chunk_registry_session_destroyed(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid)
+               const lttng_uuid& sessiond_uuid)
 {
        int ret = 0;
        struct trace_chunk_registry_ht_key key;
@@ -329,7 +328,7 @@ int sessiond_trace_chunk_registry_session_destroyed(
        char uuid_str[LTTNG_UUID_STR_LEN];
 
        lttng_uuid_to_str(sessiond_uuid, uuid_str);
-       lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+       key.sessiond_uuid = sessiond_uuid;
 
        element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
        if (element) {
@@ -351,7 +350,7 @@ int sessiond_trace_chunk_registry_session_destroyed(
 
 struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid, uint64_t session_id,
+               const lttng_uuid& sessiond_uuid, uint64_t session_id,
                struct lttng_trace_chunk *new_chunk)
 {
        enum lttng_trace_chunk_status status;
@@ -365,7 +364,7 @@ struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk(
        bool trace_chunk_already_published;
 
        lttng_uuid_to_str(sessiond_uuid, uuid_str);
-       lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+       key.sessiond_uuid = sessiond_uuid;
 
        status = lttng_trace_chunk_get_id(new_chunk, &chunk_id);
        if (status == LTTNG_TRACE_CHUNK_STATUS_OK) {
@@ -428,7 +427,7 @@ end:
 struct lttng_trace_chunk *
 sessiond_trace_chunk_registry_get_anonymous_chunk(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid,
+               const lttng_uuid& sessiond_uuid,
                uint64_t session_id)
 {
        struct lttng_trace_chunk *chunk = NULL;
@@ -438,7 +437,7 @@ sessiond_trace_chunk_registry_get_anonymous_chunk(
 
        lttng_uuid_to_str(sessiond_uuid, uuid_str);
 
-       lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+       key.sessiond_uuid = sessiond_uuid;
        element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
        if (!element) {
                ERR("Failed to find trace chunk registry of sessiond {%s}",
@@ -457,7 +456,7 @@ end:
 struct lttng_trace_chunk *
 sessiond_trace_chunk_registry_get_chunk(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid,
+               const lttng_uuid& sessiond_uuid,
                uint64_t session_id, uint64_t chunk_id)
 {
        struct lttng_trace_chunk *chunk = NULL;
@@ -467,7 +466,7 @@ sessiond_trace_chunk_registry_get_chunk(
 
        lttng_uuid_to_str(sessiond_uuid, uuid_str);
 
-       lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+       key.sessiond_uuid = sessiond_uuid;
        element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
        if (!element) {
                ERR("Failed to find trace chunk registry of sessiond {%s}",
@@ -485,14 +484,14 @@ end:
 
 int sessiond_trace_chunk_registry_chunk_exists(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid,
+               const lttng_uuid& sessiond_uuid,
                uint64_t session_id, uint64_t chunk_id, bool *chunk_exists)
 {
        int ret;
        struct trace_chunk_registry_ht_element *element;
        struct trace_chunk_registry_ht_key key;
 
-       lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid);
+       key.sessiond_uuid = sessiond_uuid;
        element = trace_chunk_registry_ht_element_find(sessiond_registry, &key);
        if (!element) {
                char uuid_str[LTTNG_UUID_STR_LEN];
index 2e494292ac00e2d4f797427fc52a86c20cd9ca57..4d5759d87b28d663d88aabc1dd06b4ca475c2636 100644 (file)
@@ -33,32 +33,32 @@ void sessiond_trace_chunk_registry_destroy(
 
 int sessiond_trace_chunk_registry_session_created(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid);
+               const lttng_uuid& sessiond_uuid);
 
 int sessiond_trace_chunk_registry_session_destroyed(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid);
+               const lttng_uuid& sessiond_uuid);
 
 struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid, uint64_t session_id,
+               const lttng_uuid& sessiond_uuid, uint64_t session_id,
                struct lttng_trace_chunk *chunk);
 
 struct lttng_trace_chunk *
 sessiond_trace_chunk_registry_get_anonymous_chunk(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid,
+               const lttng_uuid& sessiond_uuid,
                uint64_t session_id);
 
 struct lttng_trace_chunk *
 sessiond_trace_chunk_registry_get_chunk(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid,
+               const lttng_uuid& sessiond_uuid,
                uint64_t session_id, uint64_t chunk_id);
 
 int sessiond_trace_chunk_registry_chunk_exists(
                struct sessiond_trace_chunk_registry *sessiond_registry,
-               const lttng_uuid sessiond_uuid,
+               const lttng_uuid& sessiond_uuid,
                uint64_t session_id, uint64_t chunk_id, bool *chunk_exists);
 
 #endif /* SESSIOND_TRACE_CHUNK_REGISTRY_H */
index bdda3913597a7639150a67473517e92bf31f1180..b87e1d73d2d065ef21ee19c4a015b2c00946c396 100644 (file)
@@ -924,7 +924,7 @@ void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
                const char *name,
                uint64_t relayd_id,
                uint64_t key,
-               unsigned char *uuid,
+               const lttng_uuid& uuid,
                uint32_t chan_id,
                uint64_t tracefile_size,
                uint64_t tracefile_count,
@@ -979,7 +979,7 @@ void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
        msg->u.ask_channel.ust_app_uid = ust_app_uid;
        msg->u.ask_channel.blocking_timeout = blocking_timeout;
 
-       memcpy(msg->u.ask_channel.uuid, uuid, sizeof(msg->u.ask_channel.uuid));
+       std::copy(uuid.begin(), uuid.end(), msg->u.ask_channel.uuid);
 
        if (pathname) {
                strncpy(msg->u.ask_channel.pathname, pathname,
@@ -1782,7 +1782,7 @@ error_socket:
 }
 
 int consumer_init(struct consumer_socket *socket,
-               const lttng_uuid sessiond_uuid)
+               const lttng_uuid& sessiond_uuid)
 {
        int ret;
        struct lttcomm_consumer_msg msg = {
@@ -1793,7 +1793,7 @@ int consumer_init(struct consumer_socket *socket,
        LTTNG_ASSERT(socket);
 
        DBG("Sending consumer initialization command");
-       lttng_uuid_copy(msg.u.init.sessiond_uuid, sessiond_uuid);
+       std::copy(sessiond_uuid.begin(), sessiond_uuid.end(), msg.u.init.sessiond_uuid);
 
        health_code_update();
        ret = consumer_send_msg(socket, &msg);
index 15e2a2fc7c109cc59e0fcc460e3dea085a5dd5a1..d76ec025f85d6773a31747b8092d562932897e6a 100644 (file)
@@ -261,7 +261,7 @@ void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
                const char *name,
                uint64_t relayd_id,
                uint64_t key,
-               unsigned char *uuid,
+               const lttng_uuid& uuid,
                uint32_t chan_id,
                uint64_t tracefile_size,
                uint64_t tracefile_count,
@@ -321,7 +321,7 @@ enum lttng_error_code consumer_snapshot_channel(struct consumer_socket *socket,
 int consumer_rotate_channel(struct consumer_socket *socket, uint64_t key,
                struct consumer_output *output, bool is_metadata_channel);
 int consumer_init(struct consumer_socket *socket,
-               const lttng_uuid sessiond_uuid);
+               const lttng_uuid& sessiond_uuid);
 
 int consumer_create_trace_chunk(struct consumer_socket *socket,
                uint64_t relayd_id, uint64_t session_id,
index d2781ba0b91973dbb71b909f0bb991bcb7982a89..88bd502dbac096d81623669638a906836e032ebf 100644 (file)
@@ -68,7 +68,7 @@ public:
        /* Next enumeration ID available. */
        uint64_t _next_enum_id = 0;
        /* Universal unique identifier used by the tracer. */
-       unsigned char _uuid[LTTNG_UUID_LEN] = {};
+       lttng_uuid _uuid = {};
 
        /* session ABI description */
 
index a9de1696e4ce862d52bf58b5c6ab44f73ad76b28..a5691b1c27df6deec93703bdc38d19121d3e237b 100644 (file)
@@ -4697,7 +4697,7 @@ end:
 
 enum lttcomm_return_code lttng_consumer_init_command(
                struct lttng_consumer_local_data *ctx,
-               const lttng_uuid sessiond_uuid)
+               const lttng_uuid& sessiond_uuid)
 {
        enum lttcomm_return_code ret;
        char uuid_str[LTTNG_UUID_STR_LEN];
@@ -4708,7 +4708,7 @@ enum lttcomm_return_code lttng_consumer_init_command(
        }
 
        ctx->sessiond_uuid.is_set = true;
-       memcpy(ctx->sessiond_uuid.value, sessiond_uuid, sizeof(lttng_uuid));
+       ctx->sessiond_uuid.value = sessiond_uuid;
        ret = LTTCOMM_CONSUMERD_SUCCESS;
        lttng_uuid_to_str(sessiond_uuid, uuid_str);
        DBG("Received session daemon UUID: %s", uuid_str);
index 4bcfe5d9529cc6460f293dc7fbc47e0e04728e2a..2c16ae1fac051edf432dde8cbca73aa8ffa3bba9 100644 (file)
@@ -1075,7 +1075,7 @@ enum lttcomm_return_code lttng_consumer_trace_chunk_exists(
 void lttng_consumer_cleanup_relayd(struct consumer_relayd_sock_pair *relayd);
 enum lttcomm_return_code lttng_consumer_init_command(
                struct lttng_consumer_local_data *ctx,
-               const lttng_uuid sessiond_uuid);
+               const lttng_uuid& sessiond_uuid);
 int lttng_consumer_clear_channel(struct lttng_consumer_channel *channel);
 enum lttcomm_return_code lttng_consumer_open_channel_packets(
                struct lttng_consumer_channel *channel);
index 95036a44cc6bdda6dec41d009182807fbbd76650..9bc66a47880d82247644ba8e1b6c4ba7c707253d 100644 (file)
@@ -1244,9 +1244,13 @@ error_rotate_channel:
        case LTTNG_CONSUMER_INIT:
        {
                int ret_send_status;
+               lttng_uuid sessiond_uuid;
+
+               std::copy(std::begin(msg.u.init.sessiond_uuid), std::end(msg.u.init.sessiond_uuid),
+                               sessiond_uuid.begin());
 
                ret_code = lttng_consumer_init_command(ctx,
-                               msg.u.init.sessiond_uuid);
+                               sessiond_uuid);
                health_code_update();
                ret_send_status = consumer_send_status_msg(sock, ret_code);
                if (ret_send_status < 0) {
index 5148bd03a9ed241e1141add72175fcf137e63f86..f2a19050574667d05c5f00a07542453ec2e416c2 100644 (file)
@@ -144,7 +144,7 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock,
                const char *session_name, const char *hostname,
                const char *base_path, int session_live_timer,
                unsigned int snapshot, uint64_t sessiond_session_id,
-               const lttng_uuid sessiond_uuid, const uint64_t *current_chunk_id,
+               const lttng_uuid& sessiond_uuid, const uint64_t *current_chunk_id,
                time_t creation_time, bool session_name_contains_creation_time,
                struct lttcomm_relayd_create_session_reply_2_11 *reply,
                char *output_path)
@@ -201,7 +201,7 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock,
        msg->live_timer = htobe32(session_live_timer);
        msg->snapshot = !!snapshot;
 
-       lttng_uuid_copy(msg->sessiond_uuid, sessiond_uuid);
+       std::copy(sessiond_uuid.begin(), sessiond_uuid.end(), msg->sessiond_uuid);
        msg->session_id = htobe64(sessiond_session_id);
        msg->session_name_contains_creation_time = session_name_contains_creation_time;
        if (current_chunk_id) {
@@ -316,7 +316,7 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                const char *session_name, const char *hostname,
                const char *base_path, int session_live_timer,
                unsigned int snapshot, uint64_t sessiond_session_id,
-               const lttng_uuid sessiond_uuid,
+               const lttng_uuid& sessiond_uuid,
                const uint64_t *current_chunk_id,
                time_t creation_time, bool session_name_contains_creation_time,
                char *output_path)
index d4a903aceaf26e6682b7e26a354073411750abcc..05d1ec684630a3bb95b6286424aeba78ac646687 100644 (file)
@@ -34,7 +34,7 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                const char *session_name, const char *hostname,
                const char *base_path, int session_live_timer,
                unsigned int snapshot, uint64_t sessiond_session_id,
-               const lttng_uuid sessiond_uuid,
+               const lttng_uuid& sessiond_uuid,
                const uint64_t *current_chunk_id,
                time_t creation_time, bool session_name_contains_creation_time,
                char *output_path);
index febbe4e73ec579d85b1c6fd7219bae5f200559bf..0f5adaa94bba32443286bcefe1d99c9f445e96a8 100644 (file)
@@ -202,7 +202,7 @@ struct lttcomm_relayd_create_session_2_11 {
        uint8_t snapshot;
        uint8_t session_name_contains_creation_time;
        /* Sessiond instance UUID */
-       lttng_uuid sessiond_uuid;
+       uint8_t sessiond_uuid[LTTNG_UUID_LEN];
        /* Sessiond session id */
        uint64_t session_id;
        /* Session creation time, in seconds since UNIX Epoch. */
index ae3111855468f19a1c5551fd2f802e026694a88a..257d70206799c9769290754913bf2d816f84198f 100644 (file)
@@ -830,7 +830,7 @@ struct lttcomm_consumer_msg {
                        uint64_t chunk_id;
                } LTTNG_PACKED trace_chunk_exists;
                struct {
-                       lttng_uuid sessiond_uuid;
+                       uint8_t sessiond_uuid[LTTNG_UUID_LEN];
                } LTTNG_PACKED init;
                struct {
                        uint64_t key;
index 431bb98f6cd25ce1da5315ffd177b37960525d04..0933c33c8b77e4dae3179b741fbe2b08c8e38dce 100644 (file)
@@ -2093,9 +2093,11 @@ end_rotate_channel_nosignal:
        case LTTNG_CONSUMER_INIT:
        {
                int ret_send_status;
+               lttng_uuid sessiond_uuid;
 
-               ret_code = lttng_consumer_init_command(ctx,
-                               msg.u.init.sessiond_uuid);
+               std::copy(std::begin(msg.u.init.sessiond_uuid), std::end(msg.u.init.sessiond_uuid),
+                               sessiond_uuid.begin());
+               ret_code = lttng_consumer_init_command(ctx, sessiond_uuid);
                health_code_update();
                ret_send_status = consumer_send_status_msg(sock, ret_code);
                if (ret_send_status < 0) {
index 23672a96fe131f755df81eb357cc7c865619a0da..a820a8a4191defbef75ae63c2085540f8f5dfcae 100644 (file)
 
 #include "uuid.hpp"
 
-static const lttng_uuid nil_uuid = { 0 };
-static bool lttng_uuid_is_init;
+namespace {
+const lttng_uuid nil_uuid = {};
+bool lttng_uuid_is_init;
+} /* namespace */
 
-void lttng_uuid_to_str(const lttng_uuid uuid, char *uuid_str)
+void lttng_uuid_to_str(const lttng_uuid& uuid, char *uuid_str)
 {
        sprintf(uuid_str, LTTNG_UUID_FMT, LTTNG_UUID_FMT_VALUES(uuid));
 }
 
-int lttng_uuid_from_str(const char *str_in, lttng_uuid uuid_out)
+int lttng_uuid_from_str(const char *str_in, lttng_uuid& uuid_out)
 {
        int ret = 0;
        lttng_uuid uuid_scan;
 
-       if ((str_in == NULL) || (uuid_out == NULL)) {
+       if (str_in == nullptr) {
                ret = -1;
                goto end;
        }
@@ -45,35 +47,23 @@ int lttng_uuid_from_str(const char *str_in, lttng_uuid uuid_out)
                ret = -1;
        }
 
-       lttng_uuid_copy(uuid_out, uuid_scan);
+       uuid_out = uuid_scan;
 end:
        return ret;
 }
 
-bool lttng_uuid_is_equal(const lttng_uuid a, const lttng_uuid b)
+bool lttng_uuid_is_nil(const lttng_uuid& uuid)
 {
-       return memcmp(a, b, LTTNG_UUID_LEN) == 0;
-}
-
-bool lttng_uuid_is_nil(const lttng_uuid uuid)
-{
-       return memcmp(nil_uuid, uuid, sizeof(lttng_uuid)) == 0;
-}
-
-void lttng_uuid_copy(lttng_uuid dst, const lttng_uuid src)
-{
-       memcpy(dst, src, LTTNG_UUID_LEN);
+       return uuid == nil_uuid;
 }
 
 /*
  * Generate a random UUID according to RFC4122, section 4.4.
  */
-int lttng_uuid_generate(lttng_uuid uuid_out)
+int lttng_uuid_generate(lttng_uuid& uuid_out)
 {
        int i, ret = 0;
 
-       LTTNG_ASSERT(uuid_out);
-
        if (!lttng_uuid_is_init) {
                /*
                 * We don't need cryptographic quality randomness to
index 431490ef28a2ed7c468ef5c9a7b7862e00cd5de9..0cd3966becc6f91dd38b63721fe4306794624e68 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <inttypes.h>
+#include <array>
 
 /*
  * Includes final \0.
@@ -36,9 +37,9 @@
        &(uuid)[6], &(uuid)[7], &(uuid)[8], &(uuid)[9], &(uuid)[10], &(uuid)[11], \
        &(uuid)[12], &(uuid)[13], &(uuid)[14], &(uuid)[15]
 
-typedef uint8_t lttng_uuid[LTTNG_UUID_LEN];
+using lttng_uuid = std::array<uint8_t, LTTNG_UUID_LEN>;
 
-int lttng_uuid_from_str(const char *str_in, lttng_uuid uuid_out);
+int lttng_uuid_from_str(const char *str_in, lttng_uuid& uuid_out);
 
 /*
  * Convert a UUID to a human-readable, NULL-terminated, string of the form
@@ -46,17 +47,15 @@ int lttng_uuid_from_str(const char *str_in, lttng_uuid uuid_out);
  *
  * Assumes uuid_str is at least LTTNG_UUID_STR_LEN byte long.
  */
-void lttng_uuid_to_str(const lttng_uuid uuid, char *uuid_str);
+void lttng_uuid_to_str(const lttng_uuid& uuid, char *uuid_str);
 
-bool lttng_uuid_is_equal(const lttng_uuid a, const lttng_uuid b);
+bool lttng_uuid_is_equal(const lttng_uuid& a, const lttng_uuid& b);
 
-bool lttng_uuid_is_nil(const lttng_uuid uuid);
-
-void lttng_uuid_copy(lttng_uuid dst, const lttng_uuid src);
+bool lttng_uuid_is_nil(const lttng_uuid& uuid);
 
 /*
  * Generate a random UUID according to RFC4122, section 4.4.
  */
-int lttng_uuid_generate(lttng_uuid uuid_out);
+int lttng_uuid_generate(lttng_uuid& uuid_out);
 
 #endif /* LTTNG_UUID_H */
index 26ec6b6c68825a281246d942e79ea1540fb8df8f..403e1f0ea22a841da69ca3aca80687f745e07f6a 100644 (file)
@@ -110,22 +110,22 @@ void run_test_lttng_uuid_is_equal(void)
 
        lttng_uuid_from_str(valid_str_1, uuid1);
        lttng_uuid_from_str(valid_str_1, uuid2);
-       ret = lttng_uuid_is_equal(uuid1, uuid2);
+       ret = uuid1 == uuid2;
        ok(ret == true, "lttng_uuid_is_equal - Compare same UUID, expect success");
 
        lttng_uuid_from_str(valid_str_2, uuid2);
-       ret = lttng_uuid_is_equal(uuid1, uuid2);
+       ret = uuid1 == uuid2;
        ok(ret == false, "lttng_uuid_is_equal - Compare different UUID, expect failure");
 }
 
 static
 void run_test_lttng_uuid_copy(void)
 {
-       int ret;
+       bool ret;
        lttng_uuid uuid1;
 
-       lttng_uuid_copy(uuid1, valid_uuid_1);
-       ret = lttng_uuid_is_equal(uuid1, valid_uuid_1);
+       uuid1 = valid_uuid_1;
+       ret = uuid1 == valid_uuid_1;
 
        ok(ret == true, "lttng_uuid_copy - Compare copied UUID with source, expect success");
 }
@@ -139,7 +139,7 @@ void run_test_lttng_uuid_generate(void)
        lttng_uuid_generate(uuid1);
        lttng_uuid_generate(uuid2);
 
-       ok(lttng_uuid_is_equal(uuid1, uuid2) == false, "lttng_uuid_generate - Generated UUIDs are different");
+       ok(uuid1 != uuid2, "lttng_uuid_generate - Generated UUIDs are different");
 
        /*
         * Set the two most significant bits (bits 6 and 7) of the
This page took 0.039925 seconds and 5 git commands to generate.