typedef bool (*action_validate_cb)(struct lttng_action *action);
typedef void (*action_destroy_cb)(struct lttng_action *action);
+typedef ssize_t (*action_serialize_cb)(struct lttng_action *action, char *buf);
struct lttng_action {
enum lttng_action_type type;
action_validate_cb validate;
+ action_serialize_cb serialize;
action_destroy_cb destroy;
};
+struct lttng_action_comm {
+ /* enum lttng_action_type */
+ int8_t action_type;
+} LTTNG_PACKED;
+
LTTNG_HIDDEN
bool lttng_action_validate(struct lttng_action *action);
+LTTNG_HIDDEN
+ssize_t lttng_action_serialize(struct lttng_action *action, char *buf);
+
#endif /* LTTNG_ACTION_INTERNAL_H */
} domain;
};
+struct lttng_condition_buffer_usage_comm {
+ uint8_t threshold_set_in_bytes;
+ union {
+ double percent;
+ uint64_t bytes;
+ } threshold;
+ /* Both lengths include the trailing \0. */
+ uint32_t session_name_len;
+ uint32_t channel_name_len;
+ /* enum lttng_domain_type */
+ int8_t domain_type;
+ /* session and channel names. */
+ char names[];
+} LTTNG_PACKED;
+
struct lttng_evaluation_buffer_usage {
struct lttng_evaluation parent;
uint64_t buffer_use;
typedef void (*condition_destroy_cb)(struct lttng_condition *condition);
typedef bool (*condition_validate_cb)(struct lttng_condition *condition);
+typedef ssize_t (*condition_serialize_cb)(struct lttng_condition *condition,
+ char *buf);
struct lttng_condition {
enum lttng_condition_type type;
condition_validate_cb validate;
+ condition_serialize_cb serialize;
condition_destroy_cb destroy;
};
+struct lttng_condition_comm {
+ int8_t condition_type;
+};
+
LTTNG_HIDDEN
bool lttng_condition_validate(struct lttng_condition *condition);
+LTTNG_HIDDEN
+ssize_t lttng_condition_serialize(struct lttng_condition *action, char *buf);
+
#endif /* LTTNG_CONDITION_INTERNAL_H */
end:
return valid;
}
+
+LTTNG_HIDDEN
+ssize_t lttng_action_serialize(struct lttng_action *action, char *buf)
+{
+ ssize_t ret, action_size;
+ struct lttng_action_comm action_comm;
+
+ if (!action) {
+ ret = -1;
+ goto end;
+ }
+
+ action_comm.action_type = (int8_t) action->type;
+ ret = sizeof(struct lttng_action_comm);
+ if (buf) {
+ memcpy(buf, &action_comm, ret);
+ buf += ret;
+ }
+
+ action_size = action->serialize(action, buf);
+ if (action_size < 0) {
+ ret = action_size;
+ goto end;
+ }
+ ret += action_size;
+end:
+ return ret;
+}
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)
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;
end:
return valid;
}
+
+LTTNG_HIDDEN
+ssize_t lttng_condition_serialize(struct lttng_condition *condition, char *buf)
+{
+ ssize_t ret, condition_size;
+ struct lttng_condition_comm condition_comm;
+
+ if (!condition) {
+ ret = -1;
+ goto end;
+ }
+
+ condition_comm.condition_type = (int8_t) condition->type;
+ ret = sizeof(struct lttng_condition_comm);
+ if (buf) {
+ memcpy(buf, &condition_comm, ret);
+ buf += ret;
+ }
+
+ condition_size = condition->serialize(condition, buf);
+ if (condition_size < 0) {
+ ret = condition_size;
+ goto end;
+ }
+ ret += condition_size;
+end:
+ return ret;
+}
free(action);
}
+static
+ssize_t lttng_action_notify_serialize(struct lttng_action *action, char *buf)
+{
+ return 0;
+}
+
struct lttng_action *lttng_action_notify_create(void)
{
struct lttng_action_notify *notify;
}
notify->parent.type = LTTNG_ACTION_TYPE_NOTIFY;
+ notify->parent.serialize = lttng_action_notify_serialize;
notify->parent.destroy = lttng_action_notify_destroy;
end:
return ¬ify->parent;
*/
#include <lttng/trigger/trigger-internal.h>
-#include <lttng/condition/condition.h>
-#include <lttng/action/action.h>
+#include <lttng/condition/condition-internal.h>
+#include <lttng/action/action-internal.h>
#include <assert.h>
struct lttng_trigger *lttng_trigger_create(
lttng_action_destroy(trigger->action);
free(trigger);
}
+
+ssize_t lttng_trigger_serialize(struct lttng_trigger *trigger, char *buf)
+{
+ ssize_t action_size, condition_size, ret;
+
+ if (!trigger) {
+ ret = -1;
+ goto end;
+ }
+
+ condition_size = lttng_condition_serialize(trigger->condition, buf);
+ if (condition_size < 0) {
+ ret = -1;
+ goto end;
+ }
+
+ action_size = lttng_action_serialize(trigger->action, buf);
+ if (action_size < 0) {
+ ret = -1;
+ goto end;
+ }
+ ret = action_size + condition_size;
+end:
+ return ret;
+}