Rename group action files to list files
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 20 Apr 2021 02:06:33 +0000 (22:06 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 22 Apr 2021 05:55:27 +0000 (01:55 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iea4c2fe0a2d7001e8c05b4bb33c24e5641b193b0

14 files changed:
include/Makefile.am
include/lttng/action/group-internal.h [deleted file]
include/lttng/action/group.h [deleted file]
include/lttng/action/list-internal.h [new file with mode: 0644]
include/lttng/action/list.h [new file with mode: 0644]
include/lttng/lttng.h
src/bin/lttng-sessiond/action-executor.c
src/bin/lttng-sessiond/notification-thread-events.c
src/common/Makefile.am
src/common/actions/action.c
src/common/actions/group.c [deleted file]
src/common/actions/list.c [new file with mode: 0644]
src/common/error-query.c
tests/regression/tools/notification/base_client.c

index 1ced46c2b4c6d93dc07f9d9ab26fbec137c32572..a49d37d5c64cc201675b1ea8a8d5dcdfb9359ace 100644 (file)
@@ -126,7 +126,7 @@ lttnginclude_HEADERS = \
 
 lttngactioninclude_HEADERS= \
        lttng/action/action.h \
-       lttng/action/group.h \
+       lttng/action/list.h \
        lttng/action/notify.h \
        lttng/action/rotate-session.h \
        lttng/action/snapshot-session.h \
@@ -158,7 +158,7 @@ lttngeventruleinclude_HEADERS= \
 
 noinst_HEADERS = \
        lttng/action/action-internal.h \
-       lttng/action/group-internal.h \
+       lttng/action/list-internal.h \
        lttng/action/notify-internal.h \
        lttng/action/rotate-session-internal.h \
        lttng/action/snapshot-session-internal.h \
diff --git a/include/lttng/action/group-internal.h b/include/lttng/action/group-internal.h
deleted file mode 100644 (file)
index 9e88422..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
- *
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- */
-
-#ifndef LTTNG_ACTION_LIST_INTERNAL_H
-#define LTTNG_ACTION_LIST_INTERNAL_H
-
-#include <sys/types.h>
-
-#include <common/macros.h>
-
-struct lttng_action;
-struct lttng_payload_view;
-
-/*
- * Create an action list from a payload view.
- *
- * On success, return the number of bytes consumed from `view`, and the created
- * group in `*group`. On failure, return -1.
- */
-LTTNG_HIDDEN
-extern ssize_t lttng_action_list_create_from_payload(
-               struct lttng_payload_view *view,
-               struct lttng_action **group);
-
-LTTNG_HIDDEN
-extern struct lttng_action *lttng_action_list_borrow_mutable_at_index(
-               const struct lttng_action *group, unsigned int index);
-
-#endif /* LTTNG_ACTION_LIST_INTERNAL_H */
diff --git a/include/lttng/action/group.h b/include/lttng/action/group.h
deleted file mode 100644 (file)
index 888c123..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
- *
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- */
-
-#ifndef LTTNG_ACTION_LIST_H
-#define LTTNG_ACTION_LIST_H
-
-struct lttng_action;
-struct lttng_action_list;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Create a newly allocated action list object.
- *
- * Returns a new action list on success, NULL on failure. This action list
- * must be destroyed using lttng_action_list_destroy().
- */
-extern struct lttng_action *lttng_action_list_create(void);
-
-/*
- * Add an action to an lttng_action object of type LTTNG_ACTION_LIST.
- *
- * The action list acquires a reference to the action. The action can be
- * safely destroyed after calling this function. An action must not be
- * modified after adding it to a group.
- *
- * Adding an action list to an action list is not supported.
- */
-extern enum lttng_action_status lttng_action_list_add_action(
-               struct lttng_action *group, struct lttng_action *action);
-
-/*
- * Get the number of actions in an action list.
- */
-extern enum lttng_action_status lttng_action_list_get_count(
-               const struct lttng_action *group, unsigned int *count);
-
-/*
- * Get an action from the action list at a given index.
- *
- * Note that the group maintains the ownership of the returned action.
- * It must not be destroyed by the user, nor should it be held beyond
- * the lifetime of the action list.
- *
- * Returns an action, or NULL on error.
- */
-extern const struct lttng_action *lttng_action_list_get_at_index(
-               const struct lttng_action *group,
-               unsigned int index);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LTTNG_ACTION_LIST_H */
diff --git a/include/lttng/action/list-internal.h b/include/lttng/action/list-internal.h
new file mode 100644 (file)
index 0000000..9e88422
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#ifndef LTTNG_ACTION_LIST_INTERNAL_H
+#define LTTNG_ACTION_LIST_INTERNAL_H
+
+#include <sys/types.h>
+
+#include <common/macros.h>
+
+struct lttng_action;
+struct lttng_payload_view;
+
+/*
+ * Create an action list from a payload view.
+ *
+ * On success, return the number of bytes consumed from `view`, and the created
+ * group in `*group`. On failure, return -1.
+ */
+LTTNG_HIDDEN
+extern ssize_t lttng_action_list_create_from_payload(
+               struct lttng_payload_view *view,
+               struct lttng_action **group);
+
+LTTNG_HIDDEN
+extern struct lttng_action *lttng_action_list_borrow_mutable_at_index(
+               const struct lttng_action *group, unsigned int index);
+
+#endif /* LTTNG_ACTION_LIST_INTERNAL_H */
diff --git a/include/lttng/action/list.h b/include/lttng/action/list.h
new file mode 100644 (file)
index 0000000..888c123
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#ifndef LTTNG_ACTION_LIST_H
+#define LTTNG_ACTION_LIST_H
+
+struct lttng_action;
+struct lttng_action_list;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Create a newly allocated action list object.
+ *
+ * Returns a new action list on success, NULL on failure. This action list
+ * must be destroyed using lttng_action_list_destroy().
+ */
+extern struct lttng_action *lttng_action_list_create(void);
+
+/*
+ * Add an action to an lttng_action object of type LTTNG_ACTION_LIST.
+ *
+ * The action list acquires a reference to the action. The action can be
+ * safely destroyed after calling this function. An action must not be
+ * modified after adding it to a group.
+ *
+ * Adding an action list to an action list is not supported.
+ */
+extern enum lttng_action_status lttng_action_list_add_action(
+               struct lttng_action *group, struct lttng_action *action);
+
+/*
+ * Get the number of actions in an action list.
+ */
+extern enum lttng_action_status lttng_action_list_get_count(
+               const struct lttng_action *group, unsigned int *count);
+
+/*
+ * Get an action from the action list at a given index.
+ *
+ * Note that the group maintains the ownership of the returned action.
+ * It must not be destroyed by the user, nor should it be held beyond
+ * the lifetime of the action list.
+ *
+ * Returns an action, or NULL on error.
+ */
+extern const struct lttng_action *lttng_action_list_get_at_index(
+               const struct lttng_action *group,
+               unsigned int index);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LTTNG_ACTION_LIST_H */
index 67267f7b72f0f3bee38a9b34e6ba81c485bf631d..0ee2d2abd562db372d39276ccca3e1749f8b4b90 100644 (file)
@@ -17,7 +17,7 @@
 
 /* Include every LTTng ABI/API available. */
 #include <lttng/action/action.h>
-#include <lttng/action/group.h>
+#include <lttng/action/list.h>
 #include <lttng/action/notify.h>
 #include <lttng/action/rate-policy.h>
 #include <lttng/action/rotate-session.h>
index cbcd08b5f84c0047cf14ae6b601a8b158a574c25..aa55782e2ded7b8fb68e4eec7e9395e7fab8baa8 100644 (file)
@@ -16,8 +16,8 @@
 #include <common/macros.h>
 #include <common/optional.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/group-internal.h>
-#include <lttng/action/group.h>
+#include <lttng/action/list-internal.h>
+#include <lttng/action/list.h>
 #include <lttng/action/notify-internal.h>
 #include <lttng/action/notify.h>
 #include <lttng/action/rotate-session.h>
index d1b1ca01771af8d21c104c88faed33ea2310758f..9e4ad7cb82b44295a212ab89abc4daf001a64b61 100644 (file)
@@ -21,7 +21,7 @@
 #include <common/macros.h>
 #include <lttng/condition/condition.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/group-internal.h>
+#include <lttng/action/list-internal.h>
 #include <lttng/domain-internal.h>
 #include <lttng/notification/notification-internal.h>
 #include <lttng/condition/condition-internal.h>
index 4ea732e014ea672d1cadca4b59312a9017e3c35e..df278fa4796cf497bcb70e573061c92aaf1eec46 100644 (file)
@@ -35,7 +35,7 @@ EXTRA_DIST = mi-lttng-4.0.xsd
 
 libcommon_la_SOURCES = \
        actions/action.c \
-       actions/group.c \
+       actions/list.c \
        actions/notify.c \
        actions/rotate-session.c \
        actions/snapshot-session.c \
index 1c1049ebee3adead84689bcb396fbe0dd27ea65d..f9236c87811e1d3241b22b6bfbe60117102a4bd8 100644 (file)
@@ -8,7 +8,7 @@
 #include <assert.h>
 #include <common/error.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/group-internal.h>
+#include <lttng/action/list-internal.h>
 #include <lttng/action/notify-internal.h>
 #include <lttng/action/rate-policy-internal.h>
 #include <lttng/action/rotate-session-internal.h>
diff --git a/src/common/actions/group.c b/src/common/actions/group.c
deleted file mode 100644 (file)
index fd3e65f..0000000
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
- *
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- */
-
-#include <assert.h>
-#include <common/dynamic-array.h>
-#include <common/payload.h>
-#include <common/payload-view.h>
-#include <common/error.h>
-#include <common/macros.h>
-#include <lttng/action/action-internal.h>
-#include <lttng/action/group-internal.h>
-#include <lttng/action/group.h>
-
-#define IS_GROUP_ACTION(action) \
-       (lttng_action_get_type(action) == LTTNG_ACTION_TYPE_GROUP)
-
-struct lttng_action_list {
-       struct lttng_action parent;
-
-       /* The array owns the action elements. */
-       struct lttng_dynamic_pointer_array actions;
-};
-
-struct lttng_action_list_comm {
-       uint32_t action_count;
-
-       /*
-        * Variable data: each element serialized sequentially.
-        */
-       char data[];
-} LTTNG_PACKED;
-
-static void destroy_lttng_action_list_element(void *ptr)
-{
-       struct lttng_action *element = (struct lttng_action *) ptr;
-
-       lttng_action_destroy(element);
-}
-
-static struct lttng_action_list *action_list_from_action(
-               const struct lttng_action *action)
-{
-       assert(action);
-
-       return container_of(action, struct lttng_action_list, parent);
-}
-
-static const struct lttng_action_list *action_list_from_action_const(
-               const struct lttng_action *action)
-{
-       assert(action);
-
-       return container_of(action, struct lttng_action_list, parent);
-}
-
-static bool lttng_action_list_validate(struct lttng_action *action)
-{
-       unsigned int i, count;
-       struct lttng_action_list *action_list;
-       bool valid;
-
-       assert(IS_GROUP_ACTION(action));
-
-       action_list = action_list_from_action(action);
-
-       count = lttng_dynamic_pointer_array_get_count(&action_list->actions);
-
-       for (i = 0; i < count; i++) {
-               struct lttng_action *child =
-                               lttng_dynamic_pointer_array_get_pointer(
-                                               &action_list->actions, i);
-
-               assert(child);
-
-               if (!lttng_action_validate(child)) {
-                       valid = false;
-                       goto end;
-               }
-       }
-
-       valid = true;
-
-end:
-       return valid;
-}
-
-static bool lttng_action_list_is_equal(
-               const struct lttng_action *_a, const struct lttng_action *_b)
-{
-       bool is_equal = false;
-       unsigned int i;
-       unsigned int a_count, b_count;
-
-       if (lttng_action_list_get_count(_a, &a_count) !=
-                       LTTNG_ACTION_STATUS_OK) {
-               goto end;
-       }
-
-       if (lttng_action_list_get_count(_b, &b_count) !=
-                       LTTNG_ACTION_STATUS_OK) {
-               goto end;
-       }
-
-       if (a_count != b_count) {
-               goto end;
-       }
-
-       for (i = 0; i < a_count; i++) {
-               const struct lttng_action *child_a =
-                       lttng_action_list_get_at_index(_a, i);
-               const struct lttng_action *child_b =
-                       lttng_action_list_get_at_index(_b, i);
-
-               assert(child_a);
-               assert(child_b);
-
-               if (!lttng_action_is_equal(child_a, child_b)) {
-                       goto end;
-               }
-       }
-
-       is_equal = true;
-end:
-       return is_equal;
-}
-
-static int lttng_action_list_serialize(
-               struct lttng_action *action, struct lttng_payload *payload)
-{
-       struct lttng_action_list *action_list;
-       struct lttng_action_list_comm comm;
-       int ret;
-       unsigned int i, count;
-
-       assert(action);
-       assert(payload);
-       assert(IS_GROUP_ACTION(action));
-
-       action_list = action_list_from_action(action);
-
-       DBG("Serializing action list");
-
-       count = lttng_dynamic_pointer_array_get_count(&action_list->actions);
-
-       comm.action_count = count;
-
-       ret = lttng_dynamic_buffer_append(
-                       &payload->buffer, &comm, sizeof(comm));
-       if (ret) {
-               ret = -1;
-               goto end;
-       }
-
-       for (i = 0; i < count; i++) {
-               struct lttng_action *child =
-                               lttng_dynamic_pointer_array_get_pointer(
-                                               &action_list->actions, i);
-
-               assert(child);
-
-               ret = lttng_action_serialize(child, payload);
-               if (ret) {
-                       goto end;
-               }
-       }
-
-       ret = 0;
-
-end:
-       return ret;
-}
-
-static void lttng_action_list_destroy(struct lttng_action *action)
-{
-       struct lttng_action_list *action_list;
-
-       if (!action) {
-               goto end;
-       }
-
-       action_list = action_list_from_action(action);
-       lttng_dynamic_pointer_array_reset(&action_list->actions);
-       free(action_list);
-
-end:
-       return;
-}
-
-ssize_t lttng_action_list_create_from_payload(
-               struct lttng_payload_view *view,
-               struct lttng_action **p_action)
-{
-       ssize_t consumed_len;
-       const struct lttng_action_list_comm *comm;
-       struct lttng_action *group;
-       struct lttng_action *child_action = NULL;
-       enum lttng_action_status status;
-       size_t i;
-
-       group = lttng_action_list_create();
-       if (!group) {
-               consumed_len = -1;
-               goto end;
-       }
-
-       comm = (typeof(comm)) view->buffer.data;
-
-       consumed_len = sizeof(struct lttng_action_list_comm);
-
-       for (i = 0; i < comm->action_count; i++) {
-               ssize_t consumed_len_child;
-               struct lttng_payload_view child_view =
-                               lttng_payload_view_from_view(view, consumed_len,
-                                               view->buffer.size - consumed_len);
-
-               if (!lttng_payload_view_is_valid(&child_view)) {
-                       consumed_len = -1;
-                       goto end;
-               }
-
-               consumed_len_child = lttng_action_create_from_payload(
-                               &child_view, &child_action);
-               if (consumed_len_child < 0) {
-                       consumed_len = -1;
-                       goto end;
-               }
-
-               status = lttng_action_list_add_action(group, child_action);
-               if (status != LTTNG_ACTION_STATUS_OK) {
-                       consumed_len = -1;
-                       goto end;
-               }
-
-               /* Transfer ownership to the action list. */
-               lttng_action_put(child_action);
-               child_action = NULL;
-
-               consumed_len += consumed_len_child;
-       }
-
-       *p_action = group;
-       group = NULL;
-
-end:
-       lttng_action_list_destroy(group);
-       return consumed_len;
-}
-
-static enum lttng_action_status lttng_action_list_add_error_query_results(
-               const struct lttng_action *action,
-               struct lttng_error_query_results *results)
-{
-       unsigned int i, count;
-       enum lttng_action_status action_status;
-       const struct lttng_action_list *group =
-                       container_of(action, typeof(*group), parent);
-
-       action_status = lttng_action_list_get_count(action, &count);
-       if (action_status != LTTNG_ACTION_STATUS_OK) {
-               goto end;
-       }
-
-       for (i = 0; i < count; i++) {
-               struct lttng_action *inner_action =
-                               lttng_action_list_borrow_mutable_at_index(action, i);
-
-               action_status = lttng_action_add_error_query_results(
-                               inner_action, results);
-               if (action_status != LTTNG_ACTION_STATUS_OK) {
-                       goto end;
-               }
-       }
-end:
-       return action_status;
-}
-
-struct lttng_action *lttng_action_list_create(void)
-{
-       struct lttng_action_list *action_list;
-       struct lttng_action *action;
-
-       action_list = zmalloc(sizeof(struct lttng_action_list));
-       if (!action_list) {
-               action = NULL;
-               goto end;
-       }
-
-       action = &action_list->parent;
-
-       lttng_action_init(action, LTTNG_ACTION_TYPE_GROUP,
-                       lttng_action_list_validate,
-                       lttng_action_list_serialize,
-                       lttng_action_list_is_equal, lttng_action_list_destroy,
-                       NULL,
-                       lttng_action_list_add_error_query_results);
-
-       lttng_dynamic_pointer_array_init(&action_list->actions,
-                       destroy_lttng_action_list_element);
-
-end:
-       return action;
-}
-
-enum lttng_action_status lttng_action_list_add_action(
-               struct lttng_action *group, struct lttng_action *action)
-{
-       struct lttng_action_list *action_list;
-       enum lttng_action_status status;
-       int ret;
-
-       if (!group || !IS_GROUP_ACTION(group) || !action) {
-               status = LTTNG_ACTION_STATUS_INVALID;
-               goto end;
-       }
-
-       /*
-        * Don't allow adding groups in groups for now, since we're afraid of
-        * cycles.
-        */
-       if (IS_GROUP_ACTION(action)) {
-               status = LTTNG_ACTION_STATUS_INVALID;
-               goto end;
-       }
-
-       action_list = action_list_from_action(group);
-
-       ret = lttng_dynamic_pointer_array_add_pointer(&action_list->actions,
-                       action);
-       if (ret < 0) {
-               status = LTTNG_ACTION_STATUS_ERROR;
-               goto end;
-       }
-
-       /* Take ownership of the object. */
-       lttng_action_get(action);
-       status = LTTNG_ACTION_STATUS_OK;
-end:
-       return status;
-}
-
-enum lttng_action_status lttng_action_list_get_count(
-               const struct lttng_action *group, unsigned int *count)
-{
-       const struct lttng_action_list *action_list;
-       enum lttng_action_status status = LTTNG_ACTION_STATUS_OK;
-
-       if (!group || !IS_GROUP_ACTION(group)) {
-               status = LTTNG_ACTION_STATUS_INVALID;
-               *count = 0;
-               goto end;
-       }
-
-       action_list = action_list_from_action_const(group);
-       *count = lttng_dynamic_pointer_array_get_count(&action_list->actions);
-end:
-       return status;
-}
-
-const struct lttng_action *lttng_action_list_get_at_index(
-               const struct lttng_action *group, unsigned int index)
-{
-       return lttng_action_list_borrow_mutable_at_index(group, index);
-}
-
-LTTNG_HIDDEN
-struct lttng_action *lttng_action_list_borrow_mutable_at_index(
-               const struct lttng_action *group, unsigned int index)
-{
-       unsigned int count;
-       const struct lttng_action_list *action_list;
-       struct lttng_action *action = NULL;
-
-       if (lttng_action_list_get_count(group, &count) !=
-                       LTTNG_ACTION_STATUS_OK) {
-               goto end;
-       }
-
-       if (index >= count) {
-               goto end;
-       }
-
-       action_list = action_list_from_action_const(group);
-       action = lttng_dynamic_pointer_array_get_pointer(&action_list->actions,
-                       index);
-end:
-       return action;
-}
diff --git a/src/common/actions/list.c b/src/common/actions/list.c
new file mode 100644 (file)
index 0000000..4c325df
--- /dev/null
@@ -0,0 +1,391 @@
+/*
+ * Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#include <assert.h>
+#include <common/dynamic-array.h>
+#include <common/payload.h>
+#include <common/payload-view.h>
+#include <common/error.h>
+#include <common/macros.h>
+#include <lttng/action/action-internal.h>
+#include <lttng/action/list-internal.h>
+#include <lttng/action/list.h>
+
+#define IS_GROUP_ACTION(action) \
+       (lttng_action_get_type(action) == LTTNG_ACTION_TYPE_GROUP)
+
+struct lttng_action_list {
+       struct lttng_action parent;
+
+       /* The array owns the action elements. */
+       struct lttng_dynamic_pointer_array actions;
+};
+
+struct lttng_action_list_comm {
+       uint32_t action_count;
+
+       /*
+        * Variable data: each element serialized sequentially.
+        */
+       char data[];
+} LTTNG_PACKED;
+
+static void destroy_lttng_action_list_element(void *ptr)
+{
+       struct lttng_action *element = (struct lttng_action *) ptr;
+
+       lttng_action_destroy(element);
+}
+
+static struct lttng_action_list *action_list_from_action(
+               const struct lttng_action *action)
+{
+       assert(action);
+
+       return container_of(action, struct lttng_action_list, parent);
+}
+
+static const struct lttng_action_list *action_list_from_action_const(
+               const struct lttng_action *action)
+{
+       assert(action);
+
+       return container_of(action, struct lttng_action_list, parent);
+}
+
+static bool lttng_action_list_validate(struct lttng_action *action)
+{
+       unsigned int i, count;
+       struct lttng_action_list *action_list;
+       bool valid;
+
+       assert(IS_GROUP_ACTION(action));
+
+       action_list = action_list_from_action(action);
+
+       count = lttng_dynamic_pointer_array_get_count(&action_list->actions);
+
+       for (i = 0; i < count; i++) {
+               struct lttng_action *child =
+                               lttng_dynamic_pointer_array_get_pointer(
+                                               &action_list->actions, i);
+
+               assert(child);
+
+               if (!lttng_action_validate(child)) {
+                       valid = false;
+                       goto end;
+               }
+       }
+
+       valid = true;
+
+end:
+       return valid;
+}
+
+static bool lttng_action_list_is_equal(
+               const struct lttng_action *_a, const struct lttng_action *_b)
+{
+       bool is_equal = false;
+       unsigned int i;
+       unsigned int a_count, b_count;
+
+       if (lttng_action_list_get_count(_a, &a_count) !=
+                       LTTNG_ACTION_STATUS_OK) {
+               goto end;
+       }
+
+       if (lttng_action_list_get_count(_b, &b_count) !=
+                       LTTNG_ACTION_STATUS_OK) {
+               goto end;
+       }
+
+       if (a_count != b_count) {
+               goto end;
+       }
+
+       for (i = 0; i < a_count; i++) {
+               const struct lttng_action *child_a =
+                       lttng_action_list_get_at_index(_a, i);
+               const struct lttng_action *child_b =
+                       lttng_action_list_get_at_index(_b, i);
+
+               assert(child_a);
+               assert(child_b);
+
+               if (!lttng_action_is_equal(child_a, child_b)) {
+                       goto end;
+               }
+       }
+
+       is_equal = true;
+end:
+       return is_equal;
+}
+
+static int lttng_action_list_serialize(
+               struct lttng_action *action, struct lttng_payload *payload)
+{
+       struct lttng_action_list *action_list;
+       struct lttng_action_list_comm comm;
+       int ret;
+       unsigned int i, count;
+
+       assert(action);
+       assert(payload);
+       assert(IS_GROUP_ACTION(action));
+
+       action_list = action_list_from_action(action);
+
+       DBG("Serializing action list");
+
+       count = lttng_dynamic_pointer_array_get_count(&action_list->actions);
+
+       comm.action_count = count;
+
+       ret = lttng_dynamic_buffer_append(
+                       &payload->buffer, &comm, sizeof(comm));
+       if (ret) {
+               ret = -1;
+               goto end;
+       }
+
+       for (i = 0; i < count; i++) {
+               struct lttng_action *child =
+                               lttng_dynamic_pointer_array_get_pointer(
+                                               &action_list->actions, i);
+
+               assert(child);
+
+               ret = lttng_action_serialize(child, payload);
+               if (ret) {
+                       goto end;
+               }
+       }
+
+       ret = 0;
+
+end:
+       return ret;
+}
+
+static void lttng_action_list_destroy(struct lttng_action *action)
+{
+       struct lttng_action_list *action_list;
+
+       if (!action) {
+               goto end;
+       }
+
+       action_list = action_list_from_action(action);
+       lttng_dynamic_pointer_array_reset(&action_list->actions);
+       free(action_list);
+
+end:
+       return;
+}
+
+ssize_t lttng_action_list_create_from_payload(
+               struct lttng_payload_view *view,
+               struct lttng_action **p_action)
+{
+       ssize_t consumed_len;
+       const struct lttng_action_list_comm *comm;
+       struct lttng_action *group;
+       struct lttng_action *child_action = NULL;
+       enum lttng_action_status status;
+       size_t i;
+
+       group = lttng_action_list_create();
+       if (!group) {
+               consumed_len = -1;
+               goto end;
+       }
+
+       comm = (typeof(comm)) view->buffer.data;
+
+       consumed_len = sizeof(struct lttng_action_list_comm);
+
+       for (i = 0; i < comm->action_count; i++) {
+               ssize_t consumed_len_child;
+               struct lttng_payload_view child_view =
+                               lttng_payload_view_from_view(view, consumed_len,
+                                               view->buffer.size - consumed_len);
+
+               if (!lttng_payload_view_is_valid(&child_view)) {
+                       consumed_len = -1;
+                       goto end;
+               }
+
+               consumed_len_child = lttng_action_create_from_payload(
+                               &child_view, &child_action);
+               if (consumed_len_child < 0) {
+                       consumed_len = -1;
+                       goto end;
+               }
+
+               status = lttng_action_list_add_action(group, child_action);
+               if (status != LTTNG_ACTION_STATUS_OK) {
+                       consumed_len = -1;
+                       goto end;
+               }
+
+               /* Transfer ownership to the action list. */
+               lttng_action_put(child_action);
+               child_action = NULL;
+
+               consumed_len += consumed_len_child;
+       }
+
+       *p_action = group;
+       group = NULL;
+
+end:
+       lttng_action_list_destroy(group);
+       return consumed_len;
+}
+
+static enum lttng_action_status lttng_action_list_add_error_query_results(
+               const struct lttng_action *action,
+               struct lttng_error_query_results *results)
+{
+       unsigned int i, count;
+       enum lttng_action_status action_status;
+       const struct lttng_action_list *group =
+                       container_of(action, typeof(*group), parent);
+
+       action_status = lttng_action_list_get_count(action, &count);
+       if (action_status != LTTNG_ACTION_STATUS_OK) {
+               goto end;
+       }
+
+       for (i = 0; i < count; i++) {
+               struct lttng_action *inner_action =
+                               lttng_action_list_borrow_mutable_at_index(action, i);
+
+               action_status = lttng_action_add_error_query_results(
+                               inner_action, results);
+               if (action_status != LTTNG_ACTION_STATUS_OK) {
+                       goto end;
+               }
+       }
+end:
+       return action_status;
+}
+
+struct lttng_action *lttng_action_list_create(void)
+{
+       struct lttng_action_list *action_list;
+       struct lttng_action *action;
+
+       action_list = zmalloc(sizeof(struct lttng_action_list));
+       if (!action_list) {
+               action = NULL;
+               goto end;
+       }
+
+       action = &action_list->parent;
+
+       lttng_action_init(action, LTTNG_ACTION_TYPE_GROUP,
+                       lttng_action_list_validate,
+                       lttng_action_list_serialize,
+                       lttng_action_list_is_equal, lttng_action_list_destroy,
+                       NULL,
+                       lttng_action_list_add_error_query_results);
+
+       lttng_dynamic_pointer_array_init(&action_list->actions,
+                       destroy_lttng_action_list_element);
+
+end:
+       return action;
+}
+
+enum lttng_action_status lttng_action_list_add_action(
+               struct lttng_action *group, struct lttng_action *action)
+{
+       struct lttng_action_list *action_list;
+       enum lttng_action_status status;
+       int ret;
+
+       if (!group || !IS_GROUP_ACTION(group) || !action) {
+               status = LTTNG_ACTION_STATUS_INVALID;
+               goto end;
+       }
+
+       /*
+        * Don't allow adding groups in groups for now, since we're afraid of
+        * cycles.
+        */
+       if (IS_GROUP_ACTION(action)) {
+               status = LTTNG_ACTION_STATUS_INVALID;
+               goto end;
+       }
+
+       action_list = action_list_from_action(group);
+
+       ret = lttng_dynamic_pointer_array_add_pointer(&action_list->actions,
+                       action);
+       if (ret < 0) {
+               status = LTTNG_ACTION_STATUS_ERROR;
+               goto end;
+       }
+
+       /* Take ownership of the object. */
+       lttng_action_get(action);
+       status = LTTNG_ACTION_STATUS_OK;
+end:
+       return status;
+}
+
+enum lttng_action_status lttng_action_list_get_count(
+               const struct lttng_action *group, unsigned int *count)
+{
+       const struct lttng_action_list *action_list;
+       enum lttng_action_status status = LTTNG_ACTION_STATUS_OK;
+
+       if (!group || !IS_GROUP_ACTION(group)) {
+               status = LTTNG_ACTION_STATUS_INVALID;
+               *count = 0;
+               goto end;
+       }
+
+       action_list = action_list_from_action_const(group);
+       *count = lttng_dynamic_pointer_array_get_count(&action_list->actions);
+end:
+       return status;
+}
+
+const struct lttng_action *lttng_action_list_get_at_index(
+               const struct lttng_action *group, unsigned int index)
+{
+       return lttng_action_list_borrow_mutable_at_index(group, index);
+}
+
+LTTNG_HIDDEN
+struct lttng_action *lttng_action_list_borrow_mutable_at_index(
+               const struct lttng_action *group, unsigned int index)
+{
+       unsigned int count;
+       const struct lttng_action_list *action_list;
+       struct lttng_action *action = NULL;
+
+       if (lttng_action_list_get_count(group, &count) !=
+                       LTTNG_ACTION_STATUS_OK) {
+               goto end;
+       }
+
+       if (index >= count) {
+               goto end;
+       }
+
+       action_list = action_list_from_action_const(group);
+       action = lttng_dynamic_pointer_array_get_pointer(&action_list->actions,
+                       index);
+end:
+       return action;
+}
index 266597b3dcc935ec5444444bcce9b2f30760f3e6..a3663ad7c72e3bccd8926a28e2655459729655c5 100644 (file)
@@ -12,7 +12,7 @@
 #include <common/macros.h>
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/group-internal.h>
+#include <lttng/action/list-internal.h>
 #include <lttng/error-query-internal.h>
 #include <lttng/error-query.h>
 #include <lttng/trigger/trigger-internal.h>
index ae150500eb99911e110341903bbeba3b13efe75e..bb12410e81f7ed971572e2dd3be1400826a9df72 100644 (file)
@@ -17,7 +17,7 @@
 #include <assert.h>
 
 #include <lttng/action/action.h>
-#include <lttng/action/group.h>
+#include <lttng/action/list.h>
 #include <lttng/action/notify.h>
 #include <lttng/condition/buffer-usage.h>
 #include <lttng/condition/condition.h>
This page took 0.038114 seconds and 4 git commands to generate.