Cleanup: enforce const-correctness in notification thread
[lttng-tools.git] / src / common / evaluation.c
index c6243d232e82690ab9ca4a39cea3ed4aff1de974..e239193025f6e7abfe64273e92a1b199288e84ef 100644 (file)
 
 #include <lttng/condition/evaluation-internal.h>
 #include <lttng/condition/buffer-usage-internal.h>
+#include <lttng/condition/session-consumed-size-internal.h>
+#include <lttng/condition/session-rotation-internal.h>
 #include <common/macros.h>
 #include <common/error.h>
 #include <stdbool.h>
 #include <assert.h>
 
 LTTNG_HIDDEN
-ssize_t lttng_evaluation_serialize(struct lttng_evaluation *evaluation,
-               char *buf)
+void lttng_evaluation_init(struct lttng_evaluation *evaluation,
+               enum lttng_condition_type type)
 {
-       ssize_t ret, offset = 0;
-       struct lttng_evaluation_comm evaluation_comm;
+       evaluation->type = type;
+}
+
+LTTNG_HIDDEN
+int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation,
+               struct lttng_dynamic_buffer *buf)
+{
+       int ret;
+       struct lttng_evaluation_comm evaluation_comm = {
+               .type = (int8_t) evaluation->type
+       };
 
-       evaluation_comm.type = (int8_t) evaluation->type;
-       if (buf) {
-               memcpy(buf, &evaluation_comm, sizeof(evaluation_comm));
+       ret = lttng_dynamic_buffer_append(buf, &evaluation_comm,
+                       sizeof(evaluation_comm));
+       if (ret) {
+               goto end;
        }
-       offset += sizeof(evaluation_comm);
 
        if (evaluation->serialize) {
-               ret = evaluation->serialize(evaluation,
-                               buf ? (buf + offset) : NULL);
-               if (ret < 0) {
+               ret = evaluation->serialize(evaluation, buf);
+               if (ret) {
                        goto end;
                }
-               offset += ret;
        }
-
-       ret = offset;
 end:
        return ret;
 }
@@ -85,6 +92,30 @@ ssize_t lttng_evaluation_create_from_buffer(
                }
                evaluation_size += ret;
                break;
+       case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
+               ret = lttng_evaluation_session_consumed_size_create_from_buffer(
+                               &evaluation_view, evaluation);
+               if (ret < 0) {
+                       goto end;
+               }
+               evaluation_size += ret;
+               break;
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
+               ret = lttng_evaluation_session_rotation_ongoing_create_from_buffer(
+                               &evaluation_view, evaluation);
+               if (ret < 0) {
+                       goto end;
+               }
+               evaluation_size += ret;
+               break;
+       case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
+               ret = lttng_evaluation_session_rotation_completed_create_from_buffer(
+                               &evaluation_view, evaluation);
+               if (ret < 0) {
+                       goto end;
+               }
+               evaluation_size += ret;
+               break;
        default:
                ERR("Attempted to create evaluation of unknown type (%i)",
                                (int) evaluation_comm->type);
This page took 0.023905 seconds and 4 git commands to generate.