.gitignore: ignore local vscode workspace settings file
[lttng-tools.git] / src / common / actions / rate-policy.cpp
index 58db624d8312814bff23b1fec56e78ee4d5c698a..60def0d9d45231b45878890543f17447a120e271 100644 (file)
 #include <common/mi-lttng.hpp>
 #include <common/payload-view.hpp>
 #include <common/payload.hpp>
-#include <limits.h>
+
 #include <lttng/action/rate-policy-internal.hpp>
 #include <lttng/action/rate-policy.h>
+
+#include <limits.h>
 #include <stdbool.h>
 #include <sys/types.h>
 
 #define IS_EVERY_N_RATE_POLICY(policy) \
        (lttng_rate_policy_get_type(policy) == LTTNG_RATE_POLICY_TYPE_EVERY_N)
 
-#define IS_ONCE_AFTER_N_RATE_POLICY(policy)    \
-       (lttng_rate_policy_get_type(policy) == \
-                       LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N)
-
-typedef void (*rate_policy_destroy_cb)(struct lttng_rate_policy *rate_policy);
-typedef int (*rate_policy_serialize_cb)(struct lttng_rate_policy *rate_policy,
-               struct lttng_payload *payload);
-typedef bool (*rate_policy_equal_cb)(const struct lttng_rate_policy *a,
-               const struct lttng_rate_policy *b);
-typedef ssize_t (*rate_policy_create_from_payload_cb)(
-               struct lttng_payload_view *view,
-               struct lttng_rate_policy **rate_policy);
-typedef struct lttng_rate_policy *(*rate_policy_copy_cb)(
-               const struct lttng_rate_policy *source);
-typedef enum lttng_error_code (*rate_policy_mi_serialize_cb)(
-               const struct lttng_rate_policy *rate_policy,
-               struct mi_writer *writer);
+#define IS_ONCE_AFTER_N_RATE_POLICY(policy) \
+       (lttng_rate_policy_get_type(policy) == LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N)
+
+using rate_policy_destroy_cb = void (*)(struct lttng_rate_policy *);
+using rate_policy_serialize_cb = int (*)(struct lttng_rate_policy *, struct lttng_payload *);
+using rate_policy_equal_cb = bool (*)(const struct lttng_rate_policy *,
+                                     const struct lttng_rate_policy *);
+using rate_policy_create_from_payload_cb = ssize_t (*)(struct lttng_payload_view *,
+                                                      struct lttng_rate_policy **);
+using rate_policy_copy_cb = struct lttng_rate_policy *(*) (const struct lttng_rate_policy *);
+using rate_policy_mi_serialize_cb = enum lttng_error_code (*)(const struct lttng_rate_policy *,
+                                                             struct mi_writer *);
 
 struct lttng_rate_policy {
        enum lttng_rate_policy_type type;
@@ -48,6 +45,7 @@ struct lttng_rate_policy {
        rate_policy_mi_serialize_cb mi_serialize;
 };
 
+namespace {
 struct lttng_rate_policy_every_n {
        struct lttng_rate_policy parent;
        uint64_t interval;
@@ -70,26 +68,26 @@ struct lttng_rate_policy_once_after_n_comm {
 struct lttng_rate_policy_every_n_comm {
        uint64_t interval;
 } LTTNG_PACKED;
+} /* namespace */
 
 /* Forward declaration. */
 static void lttng_rate_policy_init(struct lttng_rate_policy *rate_policy,
-               enum lttng_rate_policy_type type,
-               rate_policy_serialize_cb serialize,
-               rate_policy_equal_cb equal,
-               rate_policy_destroy_cb destroy,
-               rate_policy_copy_cb copy,
-               rate_policy_mi_serialize_cb mi);
+                                  enum lttng_rate_policy_type type,
+                                  rate_policy_serialize_cb serialize,
+                                  rate_policy_equal_cb equal,
+                                  rate_policy_destroy_cb destroy,
+                                  rate_policy_copy_cb copy,
+                                  rate_policy_mi_serialize_cb mi);
 
 /* Forward declaration. Every n */
-static bool lttng_rate_policy_every_n_should_execute(
-               const struct lttng_rate_policy *policy, uint64_t counter);
+static bool lttng_rate_policy_every_n_should_execute(const struct lttng_rate_policy *policy,
+                                                    uint64_t counter);
 
 /* Forward declaration. Once after N */
-static bool lttng_rate_policy_once_after_n_should_execute(
-               const struct lttng_rate_policy *policy, uint64_t counter);
+static bool lttng_rate_policy_once_after_n_should_execute(const struct lttng_rate_policy *policy,
+                                                         uint64_t counter);
 
-const char *lttng_rate_policy_type_string(
-               enum lttng_rate_policy_type rate_policy_type)
+const char *lttng_rate_policy_type_string(enum lttng_rate_policy_type rate_policy_type)
 {
        switch (rate_policy_type) {
        case LTTNG_RATE_POLICY_TYPE_EVERY_N:
@@ -101,19 +99,18 @@ const char *lttng_rate_policy_type_string(
        }
 }
 
-enum lttng_rate_policy_type lttng_rate_policy_get_type(
-               const struct lttng_rate_policy *policy)
+enum lttng_rate_policy_type lttng_rate_policy_get_type(const struct lttng_rate_policy *policy)
 {
        return policy ? policy->type : LTTNG_RATE_POLICY_TYPE_UNKNOWN;
 }
 
 void lttng_rate_policy_init(struct lttng_rate_policy *rate_policy,
-               enum lttng_rate_policy_type type,
-               rate_policy_serialize_cb serialize,
-               rate_policy_equal_cb equal,
-               rate_policy_destroy_cb destroy,
-               rate_policy_copy_cb copy,
-               rate_policy_mi_serialize_cb mi)
+                           enum lttng_rate_policy_type type,
+                           rate_policy_serialize_cb serialize,
+                           rate_policy_equal_cb equal,
+                           rate_policy_destroy_cb destroy,
+                           rate_policy_copy_cb copy,
+                           rate_policy_mi_serialize_cb mi)
 {
        rate_policy->type = type;
        rate_policy->serialize = serialize;
@@ -133,15 +130,15 @@ void lttng_rate_policy_destroy(struct lttng_rate_policy *rate_policy)
 }
 
 int lttng_rate_policy_serialize(struct lttng_rate_policy *rate_policy,
-               struct lttng_payload *payload)
+                               struct lttng_payload *payload)
 {
        int ret;
        struct lttng_rate_policy_comm rate_policy_comm = {
-                       .rate_policy_type = (int8_t) rate_policy->type,
+               .rate_policy_type = (int8_t) rate_policy->type,
        };
 
-       ret = lttng_dynamic_buffer_append(&payload->buffer, &rate_policy_comm,
-                       sizeof(rate_policy_comm));
+       ret = lttng_dynamic_buffer_append(
+               &payload->buffer, &rate_policy_comm, sizeof(rate_policy_comm));
        if (ret) {
                goto end;
        }
@@ -154,15 +151,15 @@ end:
        return ret;
 }
 
-static ssize_t lttng_rate_policy_once_after_n_create_from_payload(
-               struct lttng_payload_view *view,
-               struct lttng_rate_policy **rate_policy)
+static ssize_t
+lttng_rate_policy_once_after_n_create_from_payload(struct lttng_payload_view *view,
+                                                  struct lttng_rate_policy **rate_policy)
 {
        ssize_t consumed_len = -1;
-       struct lttng_rate_policy *policy = NULL;
+       struct lttng_rate_policy *policy = nullptr;
        const struct lttng_rate_policy_once_after_n_comm *comm;
        const struct lttng_payload_view comm_view =
-                       lttng_payload_view_from_view(view, 0, sizeof(*comm));
+               lttng_payload_view_from_view(view, 0, sizeof(*comm));
 
        if (!view || !rate_policy) {
                consumed_len = -1;
@@ -175,11 +172,10 @@ static ssize_t lttng_rate_policy_once_after_n_create_from_payload(
                goto end;
        }
 
-       comm = (const struct lttng_rate_policy_once_after_n_comm *)
-                              comm_view.buffer.data;
+       comm = (const struct lttng_rate_policy_once_after_n_comm *) comm_view.buffer.data;
 
        policy = lttng_rate_policy_once_after_n_create(comm->threshold);
-       if (policy == NULL) {
+       if (policy == nullptr) {
                consumed_len = -1;
                goto end;
        }
@@ -191,15 +187,14 @@ end:
        return consumed_len;
 }
 
-static ssize_t lttng_rate_policy_every_n_create_from_payload(
-               struct lttng_payload_view *view,
-               struct lttng_rate_policy **rate_policy)
+static ssize_t lttng_rate_policy_every_n_create_from_payload(struct lttng_payload_view *view,
+                                                            struct lttng_rate_policy **rate_policy)
 {
        ssize_t consumed_len = -1;
-       struct lttng_rate_policy *policy = NULL;
+       struct lttng_rate_policy *policy = nullptr;
        const struct lttng_rate_policy_every_n_comm *comm;
        const struct lttng_payload_view comm_view =
-                       lttng_payload_view_from_view(view, 0, sizeof(*comm));
+               lttng_payload_view_from_view(view, 0, sizeof(*comm));
 
        if (!view || !rate_policy) {
                consumed_len = -1;
@@ -212,11 +207,10 @@ static ssize_t lttng_rate_policy_every_n_create_from_payload(
                goto end;
        }
 
-       comm = (const struct lttng_rate_policy_every_n_comm *)
-                              comm_view.buffer.data;
+       comm = (const struct lttng_rate_policy_every_n_comm *) comm_view.buffer.data;
 
        policy = lttng_rate_policy_every_n_create(comm->interval);
-       if (policy == NULL) {
+       if (policy == nullptr) {
                consumed_len = -1;
                goto end;
        }
@@ -229,14 +223,13 @@ end:
 }
 
 ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view,
-               struct lttng_rate_policy **rate_policy)
+                                             struct lttng_rate_policy **rate_policy)
 {
        ssize_t consumed_len, specific_rate_policy_consumed_len;
        rate_policy_create_from_payload_cb create_from_payload_cb;
        const struct lttng_rate_policy_comm *rate_policy_comm;
        const struct lttng_payload_view rate_policy_comm_view =
-               lttng_payload_view_from_view(
-                       view, 0, sizeof(*rate_policy_comm));
+               lttng_payload_view_from_view(view, 0, sizeof(*rate_policy_comm));
 
        if (!view || !rate_policy) {
                consumed_len = -1;
@@ -249,27 +242,25 @@ ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view,
                goto end;
        }
 
-       rate_policy_comm = (const struct lttng_rate_policy_comm *)
-                                          rate_policy_comm_view.buffer.data;
+       rate_policy_comm =
+               (const struct lttng_rate_policy_comm *) rate_policy_comm_view.buffer.data;
 
        DBG("Create rate_policy from payload: rate-policy-type=%s",
-               lttng_rate_policy_type_string(
-                       (lttng_rate_policy_type) rate_policy_comm->rate_policy_type));
+           lttng_rate_policy_type_string(
+                   (lttng_rate_policy_type) rate_policy_comm->rate_policy_type));
 
        switch (rate_policy_comm->rate_policy_type) {
        case LTTNG_RATE_POLICY_TYPE_EVERY_N:
-               create_from_payload_cb =
-                               lttng_rate_policy_every_n_create_from_payload;
+               create_from_payload_cb = lttng_rate_policy_every_n_create_from_payload;
                break;
        case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N:
-               create_from_payload_cb =
-                               lttng_rate_policy_once_after_n_create_from_payload;
+               create_from_payload_cb = lttng_rate_policy_once_after_n_create_from_payload;
                break;
        default:
                ERR("Failed to create rate-policy from payload, unhandled rate-policy type: rate-policy-type=%u (%s)",
-                               rate_policy_comm->rate_policy_type,
-                               lttng_rate_policy_type_string(
-                                       (lttng_rate_policy_type) rate_policy_comm->rate_policy_type));
+                   rate_policy_comm->rate_policy_type,
+                   lttng_rate_policy_type_string(
+                           (lttng_rate_policy_type) rate_policy_comm->rate_policy_type));
                consumed_len = -1;
                goto end;
        }
@@ -277,13 +268,11 @@ ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view,
        {
                /* Create buffer view for the rate_policy-type-specific data.
                 */
-               struct lttng_payload_view specific_rate_policy_view =
-                               lttng_payload_view_from_view(view,
-                                               sizeof(struct lttng_rate_policy_comm),
-                                               -1);
+               struct lttng_payload_view specific_rate_policy_view = lttng_payload_view_from_view(
+                       view, sizeof(struct lttng_rate_policy_comm), -1);
 
-               specific_rate_policy_consumed_len = create_from_payload_cb(
-                               &specific_rate_policy_view, rate_policy);
+               specific_rate_policy_consumed_len =
+                       create_from_payload_cb(&specific_rate_policy_view, rate_policy);
        }
        if (specific_rate_policy_consumed_len < 0) {
                ERR("Failed to create specific rate_policy from buffer.");
@@ -293,15 +282,14 @@ ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view,
 
        LTTNG_ASSERT(*rate_policy);
 
-       consumed_len = sizeof(struct lttng_rate_policy_comm) +
-                       specific_rate_policy_consumed_len;
+       consumed_len = sizeof(struct lttng_rate_policy_comm) + specific_rate_policy_consumed_len;
 
 end:
        return consumed_len;
 }
 
 bool lttng_rate_policy_is_equal(const struct lttng_rate_policy *a,
-               const struct lttng_rate_policy *b)
+                               const struct lttng_rate_policy *b)
 {
        bool is_equal = false;
 
@@ -324,16 +312,13 @@ end:
        return is_equal;
 }
 
-bool lttng_rate_policy_should_execute(
-               const struct lttng_rate_policy *policy, uint64_t counter)
+bool lttng_rate_policy_should_execute(const struct lttng_rate_policy *policy, uint64_t counter)
 {
        switch (policy->type) {
        case LTTNG_RATE_POLICY_TYPE_EVERY_N:
-               return lttng_rate_policy_every_n_should_execute(
-                               policy, counter);
+               return lttng_rate_policy_every_n_should_execute(policy, counter);
        case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N:
-               return lttng_rate_policy_once_after_n_should_execute(
-                               policy, counter);
+               return lttng_rate_policy_once_after_n_should_execute(policy, counter);
        default:
                abort();
                break;
@@ -341,25 +326,24 @@ bool lttng_rate_policy_should_execute(
 }
 
 /* Every N */
-static struct lttng_rate_policy_every_n *rate_policy_every_n_from_rate_policy(
-               struct lttng_rate_policy *policy)
+static struct lttng_rate_policy_every_n *
+rate_policy_every_n_from_rate_policy(struct lttng_rate_policy *policy)
 {
        LTTNG_ASSERT(policy);
 
-       return container_of(policy, struct lttng_rate_policy_every_n, parent);
+       return lttng::utils::container_of(policy, &lttng_rate_policy_every_n::parent);
 }
 
 static const struct lttng_rate_policy_every_n *
-rate_policy_every_n_from_rate_policy_const(
-               const struct lttng_rate_policy *policy)
+rate_policy_every_n_from_rate_policy_const(const struct lttng_rate_policy *policy)
 {
        LTTNG_ASSERT(policy);
 
-       return container_of(policy, struct lttng_rate_policy_every_n, parent);
+       return lttng::utils::container_of(policy, &lttng_rate_policy_every_n::parent);
 }
 
-static int lttng_rate_policy_every_n_serialize(
-               struct lttng_rate_policy *policy, struct lttng_payload *payload)
+static int lttng_rate_policy_every_n_serialize(struct lttng_rate_policy *policy,
+                                              struct lttng_payload *payload)
 {
        int ret;
 
@@ -372,14 +356,12 @@ static int lttng_rate_policy_every_n_serialize(
        every_n_policy = rate_policy_every_n_from_rate_policy(policy);
        comm.interval = every_n_policy->interval;
 
-       ret = lttng_dynamic_buffer_append(
-                       &payload->buffer, &comm, sizeof(comm));
+       ret = lttng_dynamic_buffer_append(&payload->buffer, &comm, sizeof(comm));
        return ret;
 }
 
-static bool lttng_rate_policy_every_n_is_equal(
-               const struct lttng_rate_policy *_a,
-               const struct lttng_rate_policy *_b)
+static bool lttng_rate_policy_every_n_is_equal(const struct lttng_rate_policy *_a,
+                                              const struct lttng_rate_policy *_b)
 {
        bool is_equal = false;
        const struct lttng_rate_policy_every_n *a, *b;
@@ -413,10 +395,10 @@ end:
        return;
 }
 
-static struct lttng_rate_policy *lttng_rate_policy_every_n_copy(
-               const struct lttng_rate_policy *source)
+static struct lttng_rate_policy *
+lttng_rate_policy_every_n_copy(const struct lttng_rate_policy *source)
 {
-       struct lttng_rate_policy *copy = NULL;
+       struct lttng_rate_policy *copy = nullptr;
        const struct lttng_rate_policy_every_n *every_n_policy;
 
        if (!source) {
@@ -430,32 +412,29 @@ end:
        return copy;
 }
 
-static enum lttng_error_code lttng_rate_policy_every_n_mi_serialize(
-               const struct lttng_rate_policy *rate_policy,
-               struct mi_writer *writer)
+static enum lttng_error_code
+lttng_rate_policy_every_n_mi_serialize(const struct lttng_rate_policy *rate_policy,
+                                      struct mi_writer *writer)
 {
        int ret;
        enum lttng_error_code ret_code;
-       const struct lttng_rate_policy_every_n *every_n_policy = NULL;
+       const struct lttng_rate_policy_every_n *every_n_policy = nullptr;
 
        LTTNG_ASSERT(rate_policy);
        LTTNG_ASSERT(IS_EVERY_N_RATE_POLICY(rate_policy));
        LTTNG_ASSERT(writer);
 
-       every_n_policy = rate_policy_every_n_from_rate_policy_const(
-                       rate_policy);
+       every_n_policy = rate_policy_every_n_from_rate_policy_const(rate_policy);
 
        /* Open rate_policy_every_n element. */
-       ret = mi_lttng_writer_open_element(
-                       writer, mi_lttng_element_rate_policy_every_n);
+       ret = mi_lttng_writer_open_element(writer, mi_lttng_element_rate_policy_every_n);
        if (ret) {
                goto mi_error;
        }
 
        /* Interval. */
-       ret = mi_lttng_writer_write_element_unsigned_int(writer,
-                       mi_lttng_element_rate_policy_every_n_interval,
-                       every_n_policy->interval);
+       ret = mi_lttng_writer_write_element_unsigned_int(
+               writer, mi_lttng_element_rate_policy_every_n_interval, every_n_policy->interval);
        if (ret) {
                goto mi_error;
        }
@@ -477,8 +456,8 @@ end:
 
 struct lttng_rate_policy *lttng_rate_policy_every_n_create(uint64_t interval)
 {
-       struct lttng_rate_policy_every_n *policy = NULL;
-       struct lttng_rate_policy *_policy = NULL;
+       struct lttng_rate_policy_every_n *policy = nullptr;
+       struct lttng_rate_policy *_policy = nullptr;
 
        if (interval == 0) {
                /*
@@ -487,30 +466,31 @@ struct lttng_rate_policy *lttng_rate_policy_every_n_create(uint64_t interval)
                goto end;
        }
 
-       policy = (lttng_rate_policy_every_n *) zmalloc(sizeof(struct lttng_rate_policy_every_n));
+       policy = zmalloc<lttng_rate_policy_every_n>();
        if (!policy) {
                goto end;
        }
 
-       lttng_rate_policy_init(&policy->parent, LTTNG_RATE_POLICY_TYPE_EVERY_N,
-                       lttng_rate_policy_every_n_serialize,
-                       lttng_rate_policy_every_n_is_equal,
-                       lttng_rate_policy_every_n_destroy,
-                       lttng_rate_policy_every_n_copy,
-                       lttng_rate_policy_every_n_mi_serialize);
+       lttng_rate_policy_init(&policy->parent,
+                              LTTNG_RATE_POLICY_TYPE_EVERY_N,
+                              lttng_rate_policy_every_n_serialize,
+                              lttng_rate_policy_every_n_is_equal,
+                              lttng_rate_policy_every_n_destroy,
+                              lttng_rate_policy_every_n_copy,
+                              lttng_rate_policy_every_n_mi_serialize);
 
        policy->interval = interval;
 
        _policy = &policy->parent;
-       policy = NULL;
+       policy = nullptr;
 
 end:
        free(policy);
        return _policy;
 }
 
-enum lttng_rate_policy_status lttng_rate_policy_every_n_get_interval(
-               const struct lttng_rate_policy *policy, uint64_t *interval)
+enum lttng_rate_policy_status
+lttng_rate_policy_every_n_get_interval(const struct lttng_rate_policy *policy, uint64_t *interval)
 {
        const struct lttng_rate_policy_every_n *every_n_policy;
        enum lttng_rate_policy_status status;
@@ -528,8 +508,8 @@ end:
        return status;
 }
 
-static bool lttng_rate_policy_every_n_should_execute(
-               const struct lttng_rate_policy *policy, uint64_t counter)
+static bool lttng_rate_policy_every_n_should_execute(const struct lttng_rate_policy *policy,
+                                                    uint64_t counter)
 {
        const struct lttng_rate_policy_every_n *every_n_policy;
        LTTNG_ASSERT(policy);
@@ -543,10 +523,10 @@ static bool lttng_rate_policy_every_n_should_execute(
 
        execute = (counter % every_n_policy->interval) == 0;
 
-       DBG("Policy every N = %" PRIu64
-           ": execution %s. Execution count: %" PRIu64,
-                       every_n_policy->interval,
-                       execute ? "accepted" : "denied", counter);
+       DBG("Policy every N = %" PRIu64 ": execution %s. Execution count: %" PRIu64,
+           every_n_policy->interval,
+           execute ? "accepted" : "denied",
+           counter);
 
        return execute;
 }
@@ -558,21 +538,18 @@ rate_policy_once_after_n_from_rate_policy(struct lttng_rate_policy *policy)
 {
        LTTNG_ASSERT(policy);
 
-       return container_of(
-                       policy, struct lttng_rate_policy_once_after_n, parent);
+       return lttng::utils::container_of(policy, &lttng_rate_policy_once_after_n::parent);
 }
 
 static const struct lttng_rate_policy_once_after_n *
-rate_policy_once_after_n_from_rate_policy_const(
-               const struct lttng_rate_policy *policy)
+rate_policy_once_after_n_from_rate_policy_const(const struct lttng_rate_policy *policy)
 {
        LTTNG_ASSERT(policy);
 
-       return container_of(
-                       policy, struct lttng_rate_policy_once_after_n, parent);
+       return lttng::utils::container_of(policy, &lttng_rate_policy_once_after_n::parent);
 }
-static int lttng_rate_policy_once_after_n_serialize(
-               struct lttng_rate_policy *policy, struct lttng_payload *payload)
+static int lttng_rate_policy_once_after_n_serialize(struct lttng_rate_policy *policy,
+                                                   struct lttng_payload *payload)
 {
        int ret;
 
@@ -585,14 +562,12 @@ static int lttng_rate_policy_once_after_n_serialize(
        once_after_n_policy = rate_policy_once_after_n_from_rate_policy(policy);
        comm.threshold = once_after_n_policy->threshold;
 
-       ret = lttng_dynamic_buffer_append(
-                       &payload->buffer, &comm, sizeof(comm));
+       ret = lttng_dynamic_buffer_append(&payload->buffer, &comm, sizeof(comm));
        return ret;
 }
 
-static bool lttng_rate_policy_once_after_n_is_equal(
-               const struct lttng_rate_policy *_a,
-               const struct lttng_rate_policy *_b)
+static bool lttng_rate_policy_once_after_n_is_equal(const struct lttng_rate_policy *_a,
+                                                   const struct lttng_rate_policy *_b)
 {
        bool is_equal = false;
        const struct lttng_rate_policy_once_after_n *a, *b;
@@ -610,8 +585,7 @@ end:
        return is_equal;
 }
 
-static void lttng_rate_policy_once_after_n_destroy(
-               struct lttng_rate_policy *policy)
+static void lttng_rate_policy_once_after_n_destroy(struct lttng_rate_policy *policy)
 {
        struct lttng_rate_policy_once_after_n *once_after_n_policy;
 
@@ -627,51 +601,48 @@ end:
        return;
 }
 
-static struct lttng_rate_policy *lttng_rate_policy_once_after_n_copy(
-               const struct lttng_rate_policy *source)
+static struct lttng_rate_policy *
+lttng_rate_policy_once_after_n_copy(const struct lttng_rate_policy *source)
 {
-       struct lttng_rate_policy *copy = NULL;
+       struct lttng_rate_policy *copy = nullptr;
        const struct lttng_rate_policy_once_after_n *once_after_n_policy;
 
        if (!source) {
                goto end;
        }
 
-       once_after_n_policy =
-                       rate_policy_once_after_n_from_rate_policy_const(source);
-       copy = lttng_rate_policy_once_after_n_create(
-                       once_after_n_policy->threshold);
+       once_after_n_policy = rate_policy_once_after_n_from_rate_policy_const(source);
+       copy = lttng_rate_policy_once_after_n_create(once_after_n_policy->threshold);
 
 end:
        return copy;
 }
 
-static enum lttng_error_code lttng_rate_policy_once_after_n_mi_serialize(
-               const struct lttng_rate_policy *rate_policy,
-               struct mi_writer *writer)
+static enum lttng_error_code
+lttng_rate_policy_once_after_n_mi_serialize(const struct lttng_rate_policy *rate_policy,
+                                           struct mi_writer *writer)
 {
        int ret;
        enum lttng_error_code ret_code;
-       const struct lttng_rate_policy_once_after_n *once_after_n_policy = NULL;
+       const struct lttng_rate_policy_once_after_n *once_after_n_policy = nullptr;
 
        LTTNG_ASSERT(rate_policy);
        LTTNG_ASSERT(IS_ONCE_AFTER_N_RATE_POLICY(rate_policy));
        LTTNG_ASSERT(writer);
 
-       once_after_n_policy = rate_policy_once_after_n_from_rate_policy_const(
-                       rate_policy);
+       once_after_n_policy = rate_policy_once_after_n_from_rate_policy_const(rate_policy);
 
        /* Open rate_policy_once_after_n. */
-       ret = mi_lttng_writer_open_element(
-                       writer, mi_lttng_element_rate_policy_once_after_n);
+       ret = mi_lttng_writer_open_element(writer, mi_lttng_element_rate_policy_once_after_n);
        if (ret) {
                goto mi_error;
        }
 
        /* Threshold. */
-       ret = mi_lttng_writer_write_element_unsigned_int(writer,
-                       mi_lttng_element_rate_policy_once_after_n_threshold,
-                       once_after_n_policy->threshold);
+       ret = mi_lttng_writer_write_element_unsigned_int(
+               writer,
+               mi_lttng_element_rate_policy_once_after_n_threshold,
+               once_after_n_policy->threshold);
        if (ret) {
                goto mi_error;
        }
@@ -691,42 +662,42 @@ end:
        return ret_code;
 }
 
-struct lttng_rate_policy *lttng_rate_policy_once_after_n_create(
-               uint64_t threshold)
+struct lttng_rate_policy *lttng_rate_policy_once_after_n_create(uint64_t threshold)
 {
-       struct lttng_rate_policy_once_after_n *policy = NULL;
-       struct lttng_rate_policy *_policy = NULL;
+       struct lttng_rate_policy_once_after_n *policy = nullptr;
+       struct lttng_rate_policy *_policy = nullptr;
 
        if (threshold == 0) {
                /* threshold is expected to be > 0 */
                goto end;
        }
 
-       policy = (lttng_rate_policy_once_after_n *) zmalloc(sizeof(struct lttng_rate_policy_once_after_n));
+       policy = zmalloc<lttng_rate_policy_once_after_n>();
        if (!policy) {
                goto end;
        }
 
        lttng_rate_policy_init(&policy->parent,
-                       LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N,
-                       lttng_rate_policy_once_after_n_serialize,
-                       lttng_rate_policy_once_after_n_is_equal,
-                       lttng_rate_policy_once_after_n_destroy,
-                       lttng_rate_policy_once_after_n_copy,
-                       lttng_rate_policy_once_after_n_mi_serialize);
+                              LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N,
+                              lttng_rate_policy_once_after_n_serialize,
+                              lttng_rate_policy_once_after_n_is_equal,
+                              lttng_rate_policy_once_after_n_destroy,
+                              lttng_rate_policy_once_after_n_copy,
+                              lttng_rate_policy_once_after_n_mi_serialize);
 
        policy->threshold = threshold;
 
        _policy = &policy->parent;
-       policy = NULL;
+       policy = nullptr;
 
 end:
        free(policy);
        return _policy;
 }
 
-enum lttng_rate_policy_status lttng_rate_policy_once_after_n_get_threshold(
-               const struct lttng_rate_policy *policy, uint64_t *threshold)
+enum lttng_rate_policy_status
+lttng_rate_policy_once_after_n_get_threshold(const struct lttng_rate_policy *policy,
+                                            uint64_t *threshold)
 {
        const struct lttng_rate_policy_once_after_n *once_after_n_policy;
        enum lttng_rate_policy_status status;
@@ -736,8 +707,7 @@ enum lttng_rate_policy_status lttng_rate_policy_once_after_n_get_threshold(
                goto end;
        }
 
-       once_after_n_policy =
-                       rate_policy_once_after_n_from_rate_policy_const(policy);
+       once_after_n_policy = rate_policy_once_after_n_from_rate_policy_const(policy);
        *threshold = once_after_n_policy->threshold;
        status = LTTNG_RATE_POLICY_STATUS_OK;
 end:
@@ -745,36 +715,33 @@ end:
        return status;
 }
 
-struct lttng_rate_policy *lttng_rate_policy_copy(
-               const struct lttng_rate_policy *source)
+struct lttng_rate_policy *lttng_rate_policy_copy(const struct lttng_rate_policy *source)
 {
        LTTNG_ASSERT(source->copy);
        return source->copy(source);
 }
 
-static bool lttng_rate_policy_once_after_n_should_execute(
-               const struct lttng_rate_policy *policy, uint64_t counter)
+static bool lttng_rate_policy_once_after_n_should_execute(const struct lttng_rate_policy *policy,
+                                                         uint64_t counter)
 {
        const struct lttng_rate_policy_once_after_n *once_after_n_policy;
        bool execute = false;
        LTTNG_ASSERT(policy);
 
-       once_after_n_policy =
-                       rate_policy_once_after_n_from_rate_policy_const(policy);
+       once_after_n_policy = rate_policy_once_after_n_from_rate_policy_const(policy);
 
        execute = counter == once_after_n_policy->threshold;
 
-       DBG("Policy once after N = %" PRIu64
-           ": execution %s. Execution count: %" PRIu64,
-                       once_after_n_policy->threshold,
-                       execute ? "accepted" : "denied", counter);
+       DBG("Policy once after N = %" PRIu64 ": execution %s. Execution count: %" PRIu64,
+           once_after_n_policy->threshold,
+           execute ? "accepted" : "denied",
+           counter);
 
        return counter == once_after_n_policy->threshold;
 }
 
-enum lttng_error_code lttng_rate_policy_mi_serialize(
-               const struct lttng_rate_policy *rate_policy,
-               struct mi_writer *writer)
+enum lttng_error_code lttng_rate_policy_mi_serialize(const struct lttng_rate_policy *rate_policy,
+                                                    struct mi_writer *writer)
 {
        int ret;
        enum lttng_error_code ret_code;
@@ -784,8 +751,7 @@ enum lttng_error_code lttng_rate_policy_mi_serialize(
        LTTNG_ASSERT(rate_policy->mi_serialize);
 
        /* Open rate policy element. */
-       ret = mi_lttng_writer_open_element(
-                       writer, mi_lttng_element_rate_policy);
+       ret = mi_lttng_writer_open_element(writer, mi_lttng_element_rate_policy);
        if (ret) {
                goto mi_error;
        }
This page took 0.033786 seconds and 4 git commands to generate.