Skip to content

Commit fb7e11c

Browse files
committed
Move and rename macros for define owned/loaned/view types
1 parent cd525c4 commit fb7e11c

File tree

4 files changed

+257
-215
lines changed

4 files changed

+257
-215
lines changed

include/zenoh-pico/api/primitives.h

+28-54
Original file line numberDiff line numberDiff line change
@@ -1029,60 +1029,34 @@ int8_t z_closure_hello(z_owned_closure_hello_t *closure, z_loaned_hello_handler_
10291029
int8_t z_closure_zid(z_owned_closure_zid_t *closure, z_id_handler_t call, z_dropper_handler_t drop, void *context);
10301030

10311031
/**************** Loans ****************/
1032-
#define _OWNED_FUNCTIONS(loanedtype, ownedtype, name) \
1033-
_Bool z_##name##_check(const ownedtype *obj); \
1034-
const loanedtype *z_##name##_loan(const ownedtype *obj); \
1035-
loanedtype *z_##name##_loan_mut(ownedtype *obj); \
1036-
ownedtype *z_##name##_move(ownedtype *obj); \
1037-
int8_t z_##name##_clone(ownedtype *obj, const loanedtype *src); \
1038-
void z_##name##_drop(ownedtype *obj); \
1039-
void z_##name##_null(ownedtype *obj);
1040-
1041-
_OWNED_FUNCTIONS(z_loaned_string_t, z_owned_string_t, string)
1042-
_OWNED_FUNCTIONS(z_loaned_keyexpr_t, z_owned_keyexpr_t, keyexpr)
1043-
_OWNED_FUNCTIONS(z_loaned_config_t, z_owned_config_t, config)
1044-
_OWNED_FUNCTIONS(z_loaned_scouting_config_t, z_owned_scouting_config_t, scouting_config)
1045-
_OWNED_FUNCTIONS(z_loaned_session_t, z_owned_session_t, session)
1046-
_OWNED_FUNCTIONS(z_loaned_subscriber_t, z_owned_subscriber_t, subscriber)
1047-
_OWNED_FUNCTIONS(z_loaned_publisher_t, z_owned_publisher_t, publisher)
1048-
_OWNED_FUNCTIONS(z_loaned_queryable_t, z_owned_queryable_t, queryable)
1049-
_OWNED_FUNCTIONS(z_loaned_hello_t, z_owned_hello_t, hello)
1050-
_OWNED_FUNCTIONS(z_loaned_reply_t, z_owned_reply_t, reply)
1051-
_OWNED_FUNCTIONS(z_loaned_string_array_t, z_owned_string_array_t, string_array)
1052-
_OWNED_FUNCTIONS(z_loaned_sample_t, z_owned_sample_t, sample)
1053-
_OWNED_FUNCTIONS(z_loaned_query_t, z_owned_query_t, query)
1054-
_OWNED_FUNCTIONS(z_loaned_slice_t, z_owned_slice_t, slice)
1055-
_OWNED_FUNCTIONS(z_loaned_bytes_t, z_owned_bytes_t, bytes)
1056-
_OWNED_FUNCTIONS(z_loaned_value_t, z_owned_value_t, value)
1057-
1058-
#define _OWNED_FUNCTIONS_CLOSURE(ownedtype, name) \
1059-
_Bool z_##name##_check(const ownedtype *val); \
1060-
ownedtype *z_##name##_move(ownedtype *val); \
1061-
void z_##name##_drop(ownedtype *val); \
1062-
void z_##name##_null(ownedtype *name);
1063-
1064-
_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_sample_t, closure_sample)
1065-
_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_sample_t, closure_owned_sample)
1066-
_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_query_t, closure_query)
1067-
_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_query_t, closure_owned_query)
1068-
_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_reply_t, closure_reply)
1069-
_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_reply_t, closure_owned_reply)
1070-
_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_hello_t, closure_hello)
1071-
_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_zid_t, closure_zid)
1072-
1073-
#define _VIEW_FUNCTIONS(loanedtype, viewtype, name) \
1074-
const loanedtype *z_view_##name##_loan(const viewtype *name); \
1075-
loanedtype *z_view_##name##_loan_mut(viewtype *name); \
1076-
void z_view_##name##_null(viewtype *name);
1077-
1078-
_VIEW_FUNCTIONS(z_loaned_keyexpr_t, z_view_keyexpr_t, keyexpr)
1079-
_VIEW_FUNCTIONS(z_loaned_string_t, z_view_string_t, string)
1080-
1081-
// Gets internal value from refcounted type (e.g. z_loaned_session_t, z_query_t)
1082-
#define _Z_RC_IN_VAL(arg) ((arg)->in->val)
1083-
1084-
// Gets internal value from refcounted owned type (e.g. z_owned_session_t, z_owned_query_t)
1085-
#define _Z_OWNED_RC_IN_VAL(arg) ((arg)->_rc.in->val)
1032+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_string_t, z_owned_string_t, string)
1033+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_keyexpr_t, z_owned_keyexpr_t, keyexpr)
1034+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_config_t, z_owned_config_t, config)
1035+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_scouting_config_t, z_owned_scouting_config_t, scouting_config)
1036+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_session_t, z_owned_session_t, session)
1037+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_subscriber_t, z_owned_subscriber_t, subscriber)
1038+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_publisher_t, z_owned_publisher_t, publisher)
1039+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_queryable_t, z_owned_queryable_t, queryable)
1040+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_hello_t, z_owned_hello_t, hello)
1041+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_reply_t, z_owned_reply_t, reply)
1042+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_string_array_t, z_owned_string_array_t, string_array)
1043+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_sample_t, z_owned_sample_t, sample)
1044+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_query_t, z_owned_query_t, query)
1045+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_slice_t, z_owned_slice_t, slice)
1046+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_bytes_t, z_owned_bytes_t, bytes)
1047+
_Z_OWNED_FUNCTIONS_DEF(z_loaned_value_t, z_owned_value_t, value)
1048+
1049+
_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_sample_t, closure_sample)
1050+
_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_owned_sample_t, closure_owned_sample)
1051+
_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_query_t, closure_query)
1052+
_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_owned_query_t, closure_owned_query)
1053+
_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_reply_t, closure_reply)
1054+
_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_owned_reply_t, closure_owned_reply)
1055+
_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_hello_t, closure_hello)
1056+
_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_zid_t, closure_zid)
1057+
1058+
_Z_VIEW_FUNCTIONS_DEF(z_loaned_keyexpr_t, z_view_keyexpr_t, keyexpr)
1059+
_Z_VIEW_FUNCTIONS_DEF(z_loaned_string_t, z_view_string_t, string)
10861060

10871061
/**
10881062
* Loans a :c:type:`z_owned_sample_t`.

include/zenoh-pico/api/types.h

+38-58
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,12 @@
2727
#include "zenoh-pico/net/session.h"
2828
#include "zenoh-pico/net/subscribe.h"
2929
#include "zenoh-pico/protocol/core.h"
30+
#include "zenoh-pico/utils/olv_macros.h"
3031

3132
#ifdef __cplusplus
3233
extern "C" {
3334
#endif
3435

35-
/* Owned/Loaned types */
36-
37-
// For pointer types
38-
#define _OWNED_TYPE_PTR(type, name) \
39-
typedef struct { \
40-
type *_val; \
41-
} z_owned_##name##_t;
42-
43-
// For refcounted types
44-
#define _OWNED_TYPE_RC(type, name) \
45-
typedef struct { \
46-
type _rc; \
47-
} z_owned_##name##_t;
48-
49-
#define _LOANED_TYPE(type, name) typedef type z_loaned_##name##_t;
50-
51-
#define _VIEW_TYPE(type, name) \
52-
typedef struct { \
53-
type _val; \
54-
} z_view_##name##_t;
55-
5636
/**
5737
* Represents a variable-length encoding unsigned integer.
5838
*
@@ -82,17 +62,17 @@ typedef _z_timestamp_t z_timestamp_t;
8262
* size_t len: The length of the bytes array.
8363
* uint8_t *start: A pointer to the bytes array.
8464
*/
85-
_OWNED_TYPE_PTR(_z_slice_t, slice)
86-
_LOANED_TYPE(_z_slice_t, slice)
65+
_Z_OWNED_TYPE_PTR(_z_slice_t, slice)
66+
_Z_LOANED_TYPE(_z_slice_t, slice)
8767

8868
/**
8969
* Represents a container for slices.
9070
*
9171
* Members:
9272
* _z_slice_t slice: content of the container.
9373
*/
94-
_OWNED_TYPE_PTR(_z_bytes_t, bytes)
95-
_LOANED_TYPE(_z_bytes_t, bytes)
74+
_Z_OWNED_TYPE_PTR(_z_bytes_t, bytes)
75+
_Z_LOANED_TYPE(_z_bytes_t, bytes)
9676

9777
/**
9878
* Represents a string without null-terminator.
@@ -101,9 +81,9 @@ _LOANED_TYPE(_z_bytes_t, bytes)
10181
* size_t len: The length of the string.
10282
* const char *val: A pointer to the string.
10383
*/
104-
_OWNED_TYPE_PTR(_z_string_t, string)
105-
_LOANED_TYPE(_z_string_t, string)
106-
_VIEW_TYPE(_z_string_t, string)
84+
_Z_OWNED_TYPE_PTR(_z_string_t, string)
85+
_Z_LOANED_TYPE(_z_string_t, string)
86+
_Z_VIEW_TYPE(_z_string_t, string)
10787

10888
/**
10989
* Represents a key expression in Zenoh.
@@ -115,9 +95,9 @@ _VIEW_TYPE(_z_string_t, string)
11595
* - :c:func:`z_keyexpr_to_string`
11696
* - :c:func:`zp_keyexpr_resolve`
11797
*/
118-
_OWNED_TYPE_PTR(_z_keyexpr_t, keyexpr)
119-
_LOANED_TYPE(_z_keyexpr_t, keyexpr)
120-
_VIEW_TYPE(_z_keyexpr_t, keyexpr)
98+
_Z_OWNED_TYPE_PTR(_z_keyexpr_t, keyexpr)
99+
_Z_LOANED_TYPE(_z_keyexpr_t, keyexpr)
100+
_Z_VIEW_TYPE(_z_keyexpr_t, keyexpr)
121101

122102
/**
123103
* Represents a Zenoh configuration, used to configure Zenoh sessions upon opening.
@@ -129,8 +109,8 @@ _VIEW_TYPE(_z_keyexpr_t, keyexpr)
129109
* - :c:func:`zp_config_get`
130110
* - :c:func:`zp_config_insert`
131111
*/
132-
_OWNED_TYPE_PTR(_z_config_t, config)
133-
_LOANED_TYPE(_z_config_t, config)
112+
_Z_OWNED_TYPE_PTR(_z_config_t, config)
113+
_Z_LOANED_TYPE(_z_config_t, config)
134114

135115
/**
136116
* Represents a scouting configuration, used to configure a scouting procedure.
@@ -142,14 +122,14 @@ _LOANED_TYPE(_z_config_t, config)
142122
* - :c:func:`zp_scouting_config_get`
143123
* - :c:func:`zp_scouting_config_insert`
144124
*/
145-
_OWNED_TYPE_PTR(_z_scouting_config_t, scouting_config)
146-
_LOANED_TYPE(_z_scouting_config_t, scouting_config)
125+
_Z_OWNED_TYPE_PTR(_z_scouting_config_t, scouting_config)
126+
_Z_LOANED_TYPE(_z_scouting_config_t, scouting_config)
147127

148128
/**
149129
* Represents a Zenoh Session.
150130
*/
151-
_OWNED_TYPE_RC(_z_session_rc_t, session)
152-
_LOANED_TYPE(_z_session_rc_t, session)
131+
_Z_OWNED_TYPE_RC(_z_session_rc_t, session)
132+
_Z_LOANED_TYPE(_z_session_rc_t, session)
153133

154134
/**
155135
* Represents a Zenoh Subscriber entity.
@@ -159,8 +139,8 @@ _LOANED_TYPE(_z_session_rc_t, session)
159139
* - :c:func:`z_declare_subscriber`
160140
* - :c:func:`z_undeclare_subscriber`
161141
*/
162-
_OWNED_TYPE_PTR(_z_subscriber_t, subscriber)
163-
_LOANED_TYPE(_z_subscriber_t, subscriber)
142+
_Z_OWNED_TYPE_PTR(_z_subscriber_t, subscriber)
143+
_Z_LOANED_TYPE(_z_subscriber_t, subscriber)
164144

165145
/**
166146
* Represents a Zenoh Publisher entity.
@@ -172,8 +152,8 @@ _LOANED_TYPE(_z_subscriber_t, subscriber)
172152
* - :c:func:`z_publisher_put`
173153
* - :c:func:`z_publisher_delete`
174154
*/
175-
_OWNED_TYPE_PTR(_z_publisher_t, publisher)
176-
_LOANED_TYPE(_z_publisher_t, publisher)
155+
_Z_OWNED_TYPE_PTR(_z_publisher_t, publisher)
156+
_Z_LOANED_TYPE(_z_publisher_t, publisher)
177157

178158
/**
179159
* Represents a Zenoh Queryable entity.
@@ -183,15 +163,15 @@ _LOANED_TYPE(_z_publisher_t, publisher)
183163
* - :c:func:`z_declare_queryable`
184164
* - :c:func:`z_undeclare_queryable`
185165
*/
186-
_OWNED_TYPE_PTR(_z_queryable_t, queryable)
187-
_LOANED_TYPE(_z_queryable_t, queryable)
166+
_Z_OWNED_TYPE_PTR(_z_queryable_t, queryable)
167+
_Z_LOANED_TYPE(_z_queryable_t, queryable)
188168

189169
/**
190170
* Represents a Zenoh Query entity, received by Zenoh Queryable entities.
191171
*
192172
*/
193-
_OWNED_TYPE_RC(_z_query_rc_t, query)
194-
_LOANED_TYPE(_z_query_rc_t, query)
173+
_Z_OWNED_TYPE_RC(_z_query_rc_t, query)
174+
_Z_LOANED_TYPE(_z_query_rc_t, query)
195175

196176
/**
197177
* Represents the encoding of a payload, in a MIME-like format.
@@ -200,8 +180,8 @@ _LOANED_TYPE(_z_query_rc_t, query)
200180
* z_encoding_id_t prefix: The integer prefix of this encoding.
201181
* z_loaned_slice_t* suffix: The suffix of this encoding. It MUST be a valid UTF-8 string.
202182
*/
203-
_OWNED_TYPE_PTR(_z_encoding_t, encoding)
204-
_LOANED_TYPE(_z_encoding_t, encoding)
183+
_Z_OWNED_TYPE_PTR(_z_encoding_t, encoding)
184+
_Z_LOANED_TYPE(_z_encoding_t, encoding)
205185

206186
/**
207187
* Represents a Zenoh value.
@@ -210,8 +190,8 @@ _LOANED_TYPE(_z_encoding_t, encoding)
210190
* z_loaned_encoding_t encoding: The encoding of the `payload`.
211191
* z_loaned_bytes_t* payload: The payload of this zenoh value.
212192
*/
213-
_OWNED_TYPE_PTR(_z_value_t, value)
214-
_LOANED_TYPE(_z_value_t, value)
193+
_Z_OWNED_TYPE_PTR(_z_value_t, value)
194+
_Z_LOANED_TYPE(_z_value_t, value)
215195

216196
/**
217197
* Represents the configuration used to configure a subscriber upon declaration :c:func:`z_declare_subscriber`.
@@ -422,8 +402,8 @@ static inline z_qos_t z_qos_default(void) { return _Z_N_QOS_DEFAULT; }
422402
* z_timestamp_t timestamp: The timestamp of this data sample.
423403
* z_qos_t qos: Quality of service settings used to deliver this sample.
424404
*/
425-
_OWNED_TYPE_RC(_z_sample_rc_t, sample)
426-
_LOANED_TYPE(_z_sample_rc_t, sample)
405+
_Z_OWNED_TYPE_RC(_z_sample_rc_t, sample)
406+
_Z_LOANED_TYPE(_z_sample_rc_t, sample)
427407

428408
/**
429409
* Represents the content of a `hello` message returned by a zenoh entity as a reply to a `scout` message.
@@ -433,14 +413,14 @@ _LOANED_TYPE(_z_sample_rc_t, sample)
433413
* z_loaned_slice_t* zid: The Zenoh ID of the scouted entity (empty if absent).
434414
* z_loaned_string_array_t locators: The locators of the scouted entity.
435415
*/
436-
_OWNED_TYPE_PTR(_z_hello_t, hello)
437-
_LOANED_TYPE(_z_hello_t, hello)
416+
_Z_OWNED_TYPE_PTR(_z_hello_t, hello)
417+
_Z_LOANED_TYPE(_z_hello_t, hello)
438418

439419
/**
440420
* Represents the reply to a query.
441421
*/
442-
_OWNED_TYPE_RC(_z_reply_rc_t, reply)
443-
_LOANED_TYPE(_z_reply_rc_t, reply)
422+
_Z_OWNED_TYPE_RC(_z_reply_rc_t, reply)
423+
_Z_LOANED_TYPE(_z_reply_rc_t, reply)
444424

445425
/**
446426
* Represents an array of non null-terminated string.
@@ -451,9 +431,9 @@ _LOANED_TYPE(_z_reply_rc_t, reply)
451431
* - :c:func:`z_string_array_len`
452432
* - :c:func:`z_str_array_array_is_empty`
453433
*/
454-
_OWNED_TYPE_PTR(_z_string_vec_t, string_array)
455-
_LOANED_TYPE(_z_string_vec_t, string_array)
456-
_VIEW_TYPE(_z_string_vec_t, string_array)
434+
_Z_OWNED_TYPE_PTR(_z_string_vec_t, string_array)
435+
_Z_LOANED_TYPE(_z_string_vec_t, string_array)
436+
_Z_VIEW_TYPE(_z_string_vec_t, string_array)
457437

458438
const z_loaned_string_t *z_string_array_get(const z_loaned_string_array_t *a, size_t k);
459439
size_t z_string_array_len(const z_loaned_string_array_t *a);

0 commit comments

Comments
 (0)