Provide an idiomatic c++ interface for action lists
[lttng-tools.git] / include / lttng / action / list-internal.hpp
CommitLineData
0c51e8f3
SM
1/*
2 * Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
702f26c8
JR
8#ifndef LTTNG_ACTION_LIST_INTERNAL_H
9#define LTTNG_ACTION_LIST_INTERNAL_H
0c51e8f3 10
b17ed2ad
JG
11#include <common/container-wrapper.hpp>
12#include <common/exception.hpp>
13#include <common/format.hpp>
c9e313bc 14#include <common/macros.hpp>
0c51e8f3 15
b17ed2ad 16#include <lttng/lttng.h>
2460203a
FD
17
18#include <assert.h>
28f23191
JG
19#include <sys/types.h>
20
0c51e8f3
SM
21struct lttng_action;
22struct lttng_payload_view;
6a751b95
JR
23struct mi_writer;
24struct mi_lttng_error_query_callbacks;
25struct lttng_dynamic_array;
26struct lttng_trigger;
0c51e8f3
SM
27
28/*
702f26c8 29 * Create an action list from a payload view.
0c51e8f3
SM
30 *
31 * On success, return the number of bytes consumed from `view`, and the created
a8940c5e 32 * list in `*list`. On failure, return -1.
0c51e8f3 33 */
28f23191
JG
34extern ssize_t lttng_action_list_create_from_payload(struct lttng_payload_view *view,
35 struct lttng_action **list);
36
37extern struct lttng_action *
38lttng_action_list_borrow_mutable_at_index(const struct lttng_action *list, unsigned int index);
39
40enum lttng_error_code
41lttng_action_list_mi_serialize(const struct lttng_trigger *trigger,
42 const struct lttng_action *action,
43 struct mi_writer *writer,
44 const struct mi_lttng_error_query_callbacks *error_query_callbacks,
45 struct lttng_dynamic_array *action_path_indexes);
6a751b95 46
b17ed2ad
JG
47namespace lttng {
48namespace ctl {
49namespace details {
50class action_list_operations {
51public:
52 static lttng_action *get(const lttng_action *list, std::size_t index) noexcept
53 {
54 return lttng_action_list_borrow_mutable_at_index(list, index);
55 }
56
57 static std::size_t size(const lttng_action *list)
58 {
59 unsigned int count;
60 const auto status = lttng_action_list_get_count(list, &count);
61
62 if (status != LTTNG_ACTION_STATUS_OK) {
63 LTTNG_THROW_INVALID_ARGUMENT_ERROR(
64 "Failed to get action list element count");
65 }
66
67 return count;
68 }
69};
70
71class const_action_list_operations {
72public:
73 static const lttng_action *get(const lttng_action *list, std::size_t index) noexcept
74 {
75 return lttng_action_list_get_at_index(list, index);
76 }
77
78 static std::size_t size(const lttng_action *list)
79 {
80 return action_list_operations::size(list);
81 }
82};
83} /* namespace details */
84
85using action_list_view = utils::random_access_container_wrapper<const lttng_action *,
86 lttng_action *,
87 details::action_list_operations>;
88
89using const_action_list_view =
90 utils::random_access_container_wrapper<const lttng_action *,
91 const lttng_action *,
92 details::const_action_list_operations>;
93
94} /* namespace ctl */
95} /* namespace lttng */
2460203a 96
702f26c8 97#endif /* LTTNG_ACTION_LIST_INTERNAL_H */
This page took 0.043051 seconds and 4 git commands to generate.