*
*/
-#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 <common/mi-lttng.h>
+#include <common/payload-view.h>
+#include <common/payload.h>
#include <lttng/action/action-internal.h>
#include <lttng/action/list-internal.h>
#include <lttng/action/list.h>
static struct lttng_action_list *action_list_from_action(
const struct lttng_action *action)
{
- assert(action);
+ LTTNG_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);
+ LTTNG_ASSERT(action);
return container_of(action, struct lttng_action_list, parent);
}
struct lttng_action_list *action_list;
bool valid;
- assert(IS_LIST_ACTION(action));
+ LTTNG_ASSERT(IS_LIST_ACTION(action));
action_list = action_list_from_action(action);
lttng_dynamic_pointer_array_get_pointer(
&action_list->actions, i);
- assert(child);
+ LTTNG_ASSERT(child);
if (!lttng_action_validate(child)) {
valid = false;
const struct lttng_action *child_b =
lttng_action_list_get_at_index(_b, i);
- assert(child_a);
- assert(child_b);
+ LTTNG_ASSERT(child_a);
+ LTTNG_ASSERT(child_b);
if (!lttng_action_is_equal(child_a, child_b)) {
goto end;
int ret;
unsigned int i, count;
- assert(action);
- assert(payload);
- assert(IS_LIST_ACTION(action));
+ LTTNG_ASSERT(action);
+ LTTNG_ASSERT(payload);
+ LTTNG_ASSERT(IS_LIST_ACTION(action));
action_list = action_list_from_action(action);
lttng_dynamic_pointer_array_get_pointer(
&action_list->actions, i);
- assert(child);
+ LTTNG_ASSERT(child);
ret = lttng_action_serialize(child, payload);
if (ret) {
return action_status;
}
+enum lttng_error_code lttng_action_list_mi_serialize(
+ const struct lttng_trigger *trigger,
+ const struct lttng_action *action,
+ struct mi_writer *writer,
+ const struct mi_lttng_error_query_callbacks
+ *error_query_callbacks,
+ struct lttng_dynamic_array *action_path_indexes)
+{
+ int ret;
+ struct lttng_action_list *action_list;
+ unsigned int i, count;
+ enum lttng_error_code ret_code;
+
+ LTTNG_ASSERT(action);
+ LTTNG_ASSERT(IS_LIST_ACTION(action));
+ LTTNG_ASSERT(writer);
+
+ /* Open action list. */
+ ret = mi_lttng_writer_open_element(
+ writer, mi_lttng_element_action_list);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Serialize every action of the list. */
+ action_list = action_list_from_action(action);
+ count = lttng_dynamic_pointer_array_get_count(&action_list->actions);
+ for (i = 0; i < count; i++) {
+ const struct lttng_action *child =
+ lttng_action_list_get_at_index(action, i);
+ const uint64_t index = (uint64_t) i;
+
+ LTTNG_ASSERT(child);
+
+ /*
+ * Add the index to the action path.
+ *
+ * This index is replaced on every iteration to walk the action
+ * tree in-order and to re-use the dynamic array instead of
+ * copying it at every level.
+ */
+ ret = lttng_dynamic_array_add_element(
+ action_path_indexes, &index);
+ if (ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ ret_code = lttng_action_mi_serialize(trigger, child, writer,
+ error_query_callbacks, action_path_indexes);
+ if (ret_code != LTTNG_OK) {
+ goto end;
+ }
+
+ ret = lttng_dynamic_array_remove_element(action_path_indexes,
+ lttng_dynamic_array_get_count(
+ action_path_indexes) -
+ 1);
+ if (ret) {
+ ret_code = LTTNG_ERR_UNK;
+ goto end;
+ }
+ }
+
+ /* Close action_list element. */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto mi_error;
+ }
+
+ ret_code = LTTNG_OK;
+ goto end;
+
+mi_error:
+ ret_code = LTTNG_ERR_MI_IO_FAIL;
+end:
+ return ret_code;
+}
+
struct lttng_action *lttng_action_list_create(void)
{
struct lttng_action_list *action_list;
action = &action_list->parent;
+ /*
+ * The mi for the list is handled at the lttng_action_mi level to ease
+ * action path management for error query.
+ */
lttng_action_init(action, LTTNG_ACTION_TYPE_LIST,
- lttng_action_list_validate,
- lttng_action_list_serialize,
+ 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);
+ NULL, lttng_action_list_add_error_query_results, NULL);
lttng_dynamic_pointer_array_init(&action_list->actions,
destroy_lttng_action_list_element);
return lttng_action_list_borrow_mutable_at_index(list, index);
}
-LTTNG_HIDDEN
struct lttng_action *lttng_action_list_borrow_mutable_at_index(
const struct lttng_action *list, unsigned int index)
{