nros C API
Lightweight ROS 2 client for embedded real-time systems
Loading...
Searching...
No Matches
action.h
Go to the documentation of this file.
1
10#ifndef NROS_ACTION_H
11#define NROS_ACTION_H
12
13/* Type and function definitions live in <nros/nros_generated.h>.
14 * This per-module header is kept as a thin shim so existing code that
15 * does `#include <nros/action.h>` continues to compile. */
16#include "nros/types.h"
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/* ===================================================================
23 * Deprecated compatibility alias (phase 379 W6, decision 3)
24 *
25 * The active-goal count shipped TWICE, tier-disjoint, each spelling
26 * collapsing "did the query work" into "what is the answer":
27 *
28 * size_t nros_action_server_get_active_goal_count(const server)
29 * -- callback tier (state INITIALIZED, executor arena);
30 * answered 0 for every error, so "error" and "no goals"
31 * were the same value.
32 * int32_t nros_action_server_active_goal_count_raw(server)
33 * -- polling tier (state POLLING, inline core); negative
34 * return doubled as the error code.
35 *
36 * Both are replaced by one function in rcl's shape -- return code for the
37 * call, out-param for the answer, exactly as
38 * `rcl_action_server_get_goal_handles(server, ***handles, size_t
39 * *num_goals) -> rcl_ret_t` reports its count:
40 *
41 * nros_ret_t nros_action_server_get_active_goal_count(server, size_t *out);
42 *
43 * which branches on `server->state` internally to serve both tiers.
44 *
45 * ONLY THE `_raw` SPELLING GETS A FORWARDER. The callback-tier spelling
46 * IS the new name -- `nros_action_server_get_active_goal_count` -- with a
47 * new signature, and C has one declaration per identifier, so there is no
48 * way to keep the old `size_t`-returning form alive beside it. A caller of
49 * the old form gets a hard compile error ("too few arguments", or a
50 * `size_t` initialised from `nros_ret_t`), which is the right failure for a
51 * signature change: the alternative would be a silent semantic swap. There
52 * were no callers anywhere in this tree when the merge landed.
53 *
54 * `static inline` (not a second NROS_PUBLIC declaration) is what keeps the
55 * forwarder from becoming a duplicate-symbol problem: an inline definition
56 * in a header has no external linkage. That also makes this a SOURCE
57 * compatibility promise, not a binary one -- an object file built against
58 * the pre-merge library still refers to a
59 * `nros_action_server_active_goal_count_raw` symbol that no longer exists,
60 * and must be recompiled.
61 *
62 * Define NROS_NO_DEPRECATED_ACTION_ALIASES to compile without it -- for a
63 * consumer whose build is `-Werror` and who wants the old name to be a hard
64 * error rather than a warning.
65 *
66 * This is scheduled for removal; migrate.
67 * =================================================================== */
68
69#ifndef NROS_NO_DEPRECATED_ACTION_ALIASES
70
71/* Preserves the OLD tri-state `int32_t` convention exactly:
72 * >= 0 the count
73 * NROS_RET_INVALID_ARGUMENT NULL, or not a polling-tier server
74 * NROS_RET_NOT_INIT built without `rmw-cffi`
75 *
76 * The tier gate is re-applied HERE, before delegating, because the merged
77 * function deliberately answers a callback-tier server too -- and this name
78 * promised the polling tier only. Without the gate a `_raw` caller holding
79 * an INITIALIZED server would start getting a count where it used to get
80 * NROS_RET_INVALID_ARGUMENT.
81 *
82 * One documented difference, in a build WITHOUT `rmw-cffi` only: the old
83 * function returned NROS_RET_NOT_INIT for any non-NULL server regardless of
84 * state, where this returns NROS_RET_INVALID_ARGUMENT for a non-POLLING
85 * one. The old behaviour disagreed with itself across the feature flag (the
86 * `rmw-cffi` build returned NROS_RET_INVALID_ARGUMENT there); the forwarder
87 * keeps the meaningful half.
88 *
89 * The width guard has no reachable failure -- the arena and the inline core
90 * both hold a fixed-capacity goal array far below INT32_MAX -- but the old
91 * body's bare `as i32` would have wrapped a large count into a value a
92 * caller reads as an error code, so the conversion is made explicit rather
93 * than inherited.
94 */
95NROS_DEPRECATED_MSG("nros_action_server_active_goal_count_raw() is deprecated; use "
96 "nros_action_server_get_active_goal_count(server, &count), which "
97 "returns nros_ret_t and serves both tiers")
98static inline int32_t
99nros_action_server_active_goal_count_raw(struct nros_action_server_t* server) {
100 size_t count = 0;
101 nros_ret_t ret;
102
103 if (server == NULL || server->state != NROS_ACTION_SERVER_STATE_POLLING) {
104 return (int32_t)NROS_RET_INVALID_ARGUMENT;
105 }
106 ret = nros_action_server_get_active_goal_count(server, &count);
107 if (ret != NROS_RET_OK) {
108 return (int32_t)ret;
109 }
110 if (count > (size_t)INT32_MAX) {
111 return (int32_t)NROS_RET_ERROR;
112 }
113 return (int32_t)count;
114}
115
116#endif /* NROS_NO_DEPRECATED_ACTION_ALIASES */
117
118#ifdef __cplusplus
119}
120#endif
121
122#endif /* NROS_ACTION_H */
#define NROS_RET_INVALID_ARGUMENT
Definition nros_generated.h:2640
@ NROS_ACTION_SERVER_STATE_POLLING
Definition nros_generated.h:494
int nros_ret_t
Definition nros_generated.h:849
nros_ret_t nros_action_server_get_active_goal_count(struct nros_action_server_t *server, size_t *out)
#define NROS_RET_OK
Definition nros_generated.h:2625
#define NROS_RET_ERROR
Definition nros_generated.h:2630
Definition nros_generated.h:1640
Shared types and constants for the nros C API.
#define NROS_DEPRECATED_MSG(msg)
Definition visibility.h:58