Add deserialization of condition class
[lttng-tools.git] / src / lib / lttng-ctl / condition.c
index b3091576a6011baf649d3b45e22913d9f1cc6c31..9f9795d5511446b04edd15f18864f29c6e808cb0 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <lttng/condition/condition-internal.h>
+#include <lttng/condition/buffer-usage-internal.h>
 #include <common/macros.h>
 #include <stdbool.h>
 #include <assert.h>
@@ -84,3 +85,45 @@ ssize_t lttng_condition_serialize(struct lttng_condition *condition, char *buf)
 end:
        return ret;
 }
+
+LTTNG_HIDDEN
+ssize_t lttng_condition_create_from_buffer(const char *buf,
+               struct lttng_condition **condition)
+{
+       ssize_t ret, condition_size = 0;
+       struct lttng_condition_comm *condition_comm =
+                       (struct lttng_condition_comm *) buf;
+
+       if (!buf || !condition) {
+               ret = -1;
+               goto end;
+       }
+
+       condition_size += sizeof(*condition_comm);
+       buf += condition_size;
+
+       switch (condition_comm->condition_type) {
+       case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
+               ret = lttng_condition_buffer_usage_low_create_from_buffer(buf,
+                               condition);
+               if (ret < 0) {
+                       goto end;
+               }
+               condition_size += ret;
+               break;
+       case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
+               ret = lttng_condition_buffer_usage_high_create_from_buffer(buf,
+                               condition);
+               if (ret < 0) {
+                       goto end;
+               }
+               condition_size += ret;
+               break;
+       default:
+               ret = -1;
+               goto end;
+       }
+       ret = condition_size;
+end:
+       return ret;
+}
This page took 0.025554 seconds and 5 git commands to generate.