Add serialization of trigger, condition and action classes
[lttng-tools.git] / src / lib / lttng-ctl / buffer-usage.c
index b6e4c8cd86ebfba1fd095d570aeee8988cc65c52..233aa8ed157cd64534315e1a3d42d76e23dbd7c2 100644 (file)
@@ -78,6 +78,52 @@ end:
        return valid;
 }
 
+static
+ssize_t lttng_condition_buffer_usage_serialize(struct lttng_condition *condition,
+               char *buf)
+{
+       struct lttng_condition_buffer_usage *usage;
+       ssize_t size;
+       size_t session_name_len, channel_name_len;
+
+       if (!condition || !is_usage_condition(condition)) {
+               size = -1;
+               goto end;
+       }
+
+       usage = container_of(condition, struct lttng_condition_buffer_usage,
+                       parent);
+       size = sizeof(struct lttng_condition_buffer_usage_comm);
+       session_name_len = strlen(usage->session_name) + 1;
+       channel_name_len = strlen(usage->channel_name) + 1;
+       size += session_name_len + channel_name_len;
+       if (buf) {
+               struct lttng_condition_buffer_usage_comm usage_comm = {
+                       .threshold_set_in_bytes = usage->threshold_bytes.set ? 1 : 0,
+                       .session_name_len = session_name_len,
+                       .channel_name_len = channel_name_len,
+                       .domain_type = (int8_t) usage->domain.type,
+               };
+
+               if (usage->threshold_bytes.set) {
+                       usage_comm.threshold.bytes =
+                                       usage->threshold_bytes.value;
+               } else {
+                       usage_comm.threshold.percent =
+                                       usage->threshold_percent.value;
+               }
+
+               memcpy(buf, &usage_comm, sizeof(usage_comm));
+               buf += sizeof(usage_comm);
+               memcpy(buf, usage->session_name, session_name_len);
+               buf += session_name_len;
+               memcpy(buf, usage->channel_name, channel_name_len);
+               buf += channel_name_len;
+       }
+end:
+       return size;
+}
+
 static
 struct lttng_condition *lttng_condition_buffer_usage_create(
                enum lttng_condition_type type)
@@ -91,6 +137,7 @@ struct lttng_condition *lttng_condition_buffer_usage_create(
 
        condition->parent.type = type;
        condition->parent.validate = lttng_condition_buffer_usage_validate;
+       condition->parent.serialize = lttng_condition_buffer_usage_serialize;
        condition->parent.destroy = lttng_condition_buffer_usage_destroy;
 end:
        return &condition->parent;
This page took 0.028586 seconds and 5 git commands to generate.