Skip to content

Commit

Permalink
Remove z_query_value
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Jun 11, 2024
1 parent ad3ed38 commit 03c361d
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 132 deletions.
5 changes: 0 additions & 5 deletions build-resources/opaque-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ get_opaque_type_data!(Option<Reply>, z_owned_reply_t);
/// A loaned reply.
get_opaque_type_data!(Reply, z_loaned_reply_t);

/// A Zenoh value - a compination of payload and its encoding.
get_opaque_type_data!(Value, z_owned_value_t);
/// A loaned Zenoh value.
get_opaque_type_data!(Value, z_loaned_value_t);

/// An owned Zenoh query received by a queryable.
///
/// Queries are atomically reference-counted, letting you extract them from the callback that handed them to you by cloning.
Expand Down
2 changes: 1 addition & 1 deletion examples/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void query_handler(const z_loaned_query_t *query, void *context) {
z_view_string_t params;
z_query_parameters(query, &params);

const z_loaned_bytes_t* payload = z_value_payload(z_query_value(query));
const z_loaned_bytes_t *payload = z_query_payload(query);
if (z_bytes_len(payload) > 0) {
z_owned_string_t payload_string;
z_bytes_decode_into_string(payload, &payload_string);
Expand Down
2 changes: 1 addition & 1 deletion examples/z_queryable_with_channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main(int argc, char **argv) {
z_view_string_t params;
z_query_parameters(query, &params);

const z_loaned_bytes_t* payload = z_value_payload(z_query_value(query));
const z_loaned_bytes_t *payload = z_query_payload(query);
if (z_bytes_len(payload) > 0) {
z_owned_string_t payload_string;
z_bytes_decode_into_string(payload, &payload_string);
Expand Down
54 changes: 22 additions & 32 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,13 @@ ZENOHC_API struct z_query_consolidation_t z_query_consolidation_none(void);
* Destroys the query resetting it to its gravestone value.
*/
ZENOHC_API void z_query_drop(struct z_owned_query_t *this_);
/**
* Gets query <a href="https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Query%20Payload.md">payload encoding</a>.
*
* Returns NULL if query does not hame an encoding.
*/
ZENOHC_API
const struct z_loaned_encoding_t *z_query_encoding(const struct z_loaned_query_t *this_);
/**
* Gets query key expression.
*/
Expand All @@ -2399,6 +2406,13 @@ ZENOHC_API void z_query_null(struct z_owned_query_t *this_);
ZENOHC_API
void z_query_parameters(const struct z_loaned_query_t *this_,
struct z_view_string_t *parameters);
/**
* Gets query <a href="https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Query%20Payload.md">payload</a>.
*
* Returns NULL if query does not contain a payload.
*/
ZENOHC_API
const struct z_loaned_bytes_t *z_query_payload(const struct z_loaned_query_t *this_);
/**
* Sends a reply to a query.
*
Expand Down Expand Up @@ -2471,13 +2485,6 @@ ZENOHC_API void z_query_reply_options_default(struct z_query_reply_options_t *th
* Create a default `z_query_target_t`.
*/
ZENOHC_API enum z_query_target_t z_query_target_default(void);
/**
* Gets query <a href="https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Query%20Payload.md">payload value</a>.
*
* Returns NULL if query does not contain a value.
*/
ZENOHC_API
const struct z_loaned_value_t *z_query_value(const struct z_loaned_query_t *this_);
/**
* Returns ``true`` if queryable is valid, ``false`` otherwise.
*/
Expand Down Expand Up @@ -2532,12 +2539,19 @@ ZENOHC_API void z_reply_clone(const struct z_loaned_reply_t *this_, struct z_own
* Frees reply, resetting it to its gravestone state.
*/
ZENOHC_API void z_reply_drop(struct z_owned_reply_t *this_);
/**
* Yields the encoding of the contents of the reply by asserting it indicates a failure.
*
* Returns `NULL` if reply does not contain a error (i. e. if `z_reply_is_ok` returns ``true``).
*/
ZENOHC_API
const struct z_loaned_encoding_t *z_reply_err_encoding(const struct z_loaned_reply_t *this_);
/**
* Yields the contents of the reply by asserting it indicates a failure.
*
* Returns `NULL` if reply does not contain a error (i. e. if `z_reply_is_ok` returns ``true``).
*/
ZENOHC_API const struct z_loaned_value_t *z_reply_err(const struct z_loaned_reply_t *this_);
ZENOHC_API const struct z_loaned_bytes_t *z_reply_err_payload(const struct z_loaned_reply_t *this_);
/**
* Returns ``true`` if reply contains a valid response, ``false`` otherwise (in this case it contains a errror value).
*/
Expand Down Expand Up @@ -3460,30 +3474,6 @@ ZENOHC_API z_error_t z_undeclare_queryable(struct z_owned_queryable_t *this_);
* @return 0 in case of success, negative error code otherwise.
*/
ZENOHC_API z_error_t z_undeclare_subscriber(struct z_owned_subscriber_t *this_);
/**
* Returns ``true`` if value is in non-default state, ``false`` otherwise.
*/
ZENOHC_API bool z_value_check(const struct z_owned_value_t *this_);
/**
* Frees the memory and resets the value it to its default value.
*/
ZENOHC_API void z_value_drop(struct z_owned_value_t *this_);
/**
* Returns value encoding.
*/
ZENOHC_API const struct z_loaned_encoding_t *z_value_encoding(const struct z_loaned_value_t *this_);
/**
* Borrows value.
*/
ZENOHC_API const struct z_loaned_value_t *z_value_loan(const struct z_owned_value_t *this_);
/**
* Constructs an empty `z_owned_value_t`.
*/
ZENOHC_API void z_value_null(struct z_owned_value_t *this_);
/**
* Returns value payload.
*/
ZENOHC_API const struct z_loaned_bytes_t *z_value_payload(const struct z_loaned_value_t *this_);
/**
* Returns ``true`` if `keyexpr` is valid, ``false`` if it is in gravestone state.
*/
Expand Down
11 changes: 0 additions & 11 deletions include/zenoh_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
z_owned_string_array_t : z_string_array_loan, \
z_owned_string_t : z_string_loan, \
z_owned_subscriber_t : z_subscriber_loan, \
z_owned_value_t : z_value_loan, \
z_view_keyexpr_t : z_view_keyexpr_loan, \
z_view_slice_t : z_view_slice_loan, \
z_view_string_t : z_view_string_loan, \
Expand Down Expand Up @@ -91,7 +90,6 @@
z_owned_string_array_t* : z_string_array_drop, \
z_owned_string_t* : z_string_drop, \
z_owned_subscriber_t* : z_subscriber_drop, \
z_owned_value_t* : z_value_drop, \
zc_owned_liveliness_token_t* : zc_liveliness_token_drop, \
zcu_owned_closure_matching_status_t* : zcu_closure_matching_status_drop, \
ze_owned_publication_cache_t* : ze_publication_cache_drop, \
Expand Down Expand Up @@ -134,7 +132,6 @@
z_owned_string_t* : z_string_null, \
z_owned_subscriber_t* : z_subscriber_null, \
z_owned_task_t* : z_task_null, \
z_owned_value_t* : z_value_null, \
z_view_keyexpr_t* : z_view_keyexpr_null, \
z_view_slice_t* : z_view_slice_null, \
z_view_string_t* : z_view_string_null, \
Expand Down Expand Up @@ -178,7 +175,6 @@
z_owned_string_t : z_string_check, \
z_owned_subscriber_t : z_subscriber_check, \
z_owned_task_t : z_task_check, \
z_owned_value_t : z_value_check, \
z_view_keyexpr_t : z_view_keyexpr_check, \
z_view_slice_t : z_view_slice_check, \
z_view_string_t : z_view_string_check, \
Expand Down Expand Up @@ -256,7 +252,6 @@ inline const z_loaned_source_info_t* z_loan(const z_owned_source_info_t& this_)
inline const z_loaned_string_array_t* z_loan(const z_owned_string_array_t& this_) { return z_string_array_loan(&this_); };
inline const z_loaned_string_t* z_loan(const z_owned_string_t& this_) { return z_string_loan(&this_); };
inline const z_loaned_subscriber_t* z_loan(const z_owned_subscriber_t& this_) { return z_subscriber_loan(&this_); };
inline const z_loaned_value_t* z_loan(const z_owned_value_t& this_) { return z_value_loan(&this_); };
inline const z_loaned_keyexpr_t* z_loan(const z_view_keyexpr_t& this_) { return z_view_keyexpr_loan(&this_); };
inline const z_loaned_slice_t* z_loan(const z_view_slice_t& this_) { return z_view_slice_loan(&this_); };
inline const z_loaned_string_t* z_loan(const z_view_string_t& this_) { return z_view_string_loan(&this_); };
Expand Down Expand Up @@ -306,7 +301,6 @@ inline void z_drop(z_owned_source_info_t* this_) { return z_source_info_drop(thi
inline void z_drop(z_owned_string_array_t* this_) { return z_string_array_drop(this_); };
inline void z_drop(z_owned_string_t* this_) { return z_string_drop(this_); };
inline void z_drop(z_owned_subscriber_t* this_) { return z_subscriber_drop(this_); };
inline void z_drop(z_owned_value_t* this_) { return z_value_drop(this_); };
inline void z_drop(zc_owned_liveliness_token_t* this_) { return zc_liveliness_token_drop(this_); };
inline void z_drop(zcu_owned_closure_matching_status_t* closure) { return zcu_closure_matching_status_drop(closure); };
inline void z_drop(ze_owned_publication_cache_t* this_) { return ze_publication_cache_drop(this_); };
Expand Down Expand Up @@ -345,7 +339,6 @@ inline z_owned_source_info_t* z_move(z_owned_source_info_t& this_) { return (&th
inline z_owned_string_array_t* z_move(z_owned_string_array_t& this_) { return (&this_); };
inline z_owned_string_t* z_move(z_owned_string_t& this_) { return (&this_); };
inline z_owned_subscriber_t* z_move(z_owned_subscriber_t& this_) { return (&this_); };
inline z_owned_value_t* z_move(z_owned_value_t& this_) { return (&this_); };
inline zc_owned_liveliness_token_t* z_move(zc_owned_liveliness_token_t& this_) { return (&this_); };
inline zcu_owned_closure_matching_status_t* z_move(zcu_owned_closure_matching_status_t& closure) { return (&closure); };
inline ze_owned_publication_cache_t* z_move(ze_owned_publication_cache_t& this_) { return (&this_); };
Expand Down Expand Up @@ -384,7 +377,6 @@ inline void z_null(z_owned_string_array_t* this_) { return z_string_array_null(t
inline void z_null(z_owned_string_t* this_) { return z_string_null(this_); };
inline void z_null(z_owned_subscriber_t* this_) { return z_subscriber_null(this_); };
inline void z_null(z_owned_task_t* this_) { return z_task_null(this_); };
inline void z_null(z_owned_value_t* this_) { return z_value_null(this_); };
inline void z_null(z_view_keyexpr_t* this_) { return z_view_keyexpr_null(this_); };
inline void z_null(z_view_slice_t* this_) { return z_view_slice_null(this_); };
inline void z_null(z_view_string_t* this_) { return z_view_string_null(this_); };
Expand Down Expand Up @@ -426,7 +418,6 @@ inline bool z_check(const z_owned_string_array_t& this_) { return z_string_array
inline bool z_check(const z_owned_string_t& this_) { return z_string_check(&this_); };
inline bool z_check(const z_owned_subscriber_t& this_) { return z_subscriber_check(&this_); };
inline bool z_check(const z_owned_task_t& this_) { return z_task_check(&this_); };
inline bool z_check(const z_owned_value_t& this_) { return z_value_check(&this_); };
inline bool z_check(const z_view_keyexpr_t& this_) { return z_view_keyexpr_check(&this_); };
inline bool z_check(const z_view_slice_t& this_) { return z_view_slice_check(&this_); };
inline bool z_check(const z_view_string_t& this_) { return z_view_string_check(&this_); };
Expand Down Expand Up @@ -627,8 +618,6 @@ template<> struct z_loaned_to_owned_type_t<z_loaned_string_t> { typedef z_owned_
template<> struct z_owned_to_loaned_type_t<z_owned_string_t> { typedef z_loaned_string_t type; };
template<> struct z_loaned_to_owned_type_t<z_loaned_subscriber_t> { typedef z_owned_subscriber_t type; };
template<> struct z_owned_to_loaned_type_t<z_owned_subscriber_t> { typedef z_loaned_subscriber_t type; };
template<> struct z_loaned_to_owned_type_t<z_loaned_value_t> { typedef z_owned_value_t type; };
template<> struct z_owned_to_loaned_type_t<z_owned_value_t> { typedef z_loaned_value_t type; };
template<> struct z_loaned_to_owned_type_t<zc_loaned_liveliness_token_t> { typedef zc_owned_liveliness_token_t type; };
template<> struct z_owned_to_loaned_type_t<zc_owned_liveliness_token_t> { typedef zc_loaned_liveliness_token_t type; };
template<> struct z_loaned_to_owned_type_t<zcu_loaned_closure_matching_status_t> { typedef zcu_owned_closure_matching_status_t type; };
Expand Down
2 changes: 0 additions & 2 deletions splitguide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ zenoh_opaque.h:
- z_loaned_encoding_t!
- z_owned_reply_t!
- z_loaned_reply_t!
- z_owned_value_t!
- z_loaned_value_t!
- z_owned_query_t!
- z_loaned_query_t!
- z_owned_queryable_t!
Expand Down
43 changes: 0 additions & 43 deletions src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use zenoh::sample::Sample;
use zenoh::sample::SampleKind;
use zenoh::sample::SourceInfo;
use zenoh::time::Timestamp;
use zenoh::value::Value;
use zenoh_protocol::core::EntityGlobalId;
use zenoh_protocol::zenoh::Consolidation;

Expand Down Expand Up @@ -312,48 +311,6 @@ pub extern "C" fn z_encoding_loan(this: &z_owned_encoding_t) -> &z_loaned_encodi
this.transmute_ref().transmute_handle()
}

pub use crate::opaque_types::z_owned_value_t;
decl_transmute_owned!(Value, z_owned_value_t);
pub use crate::opaque_types::z_loaned_value_t;
decl_transmute_handle!(Value, z_loaned_value_t);

/// Constructs an empty `z_owned_value_t`.
#[no_mangle]
pub extern "C" fn z_value_null(this: *mut MaybeUninit<z_owned_value_t>) {
Inplace::empty(this.transmute_uninit_ptr());
}

/// Returns ``true`` if value is in non-default state, ``false`` otherwise.
#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub extern "C" fn z_value_check(this: &'static z_owned_value_t) -> bool {
!this.transmute_ref().is_empty()
}

/// Returns value payload.
#[no_mangle]
pub extern "C" fn z_value_payload(this: &z_loaned_value_t) -> &z_loaned_bytes_t {
this.transmute_ref().payload().transmute_handle()
}

/// Returns value encoding.
#[no_mangle]
pub extern "C" fn z_value_encoding(this: &z_loaned_value_t) -> &z_loaned_encoding_t {
this.transmute_ref().encoding().transmute_handle()
}

/// Borrows value.
#[no_mangle]
pub extern "C" fn z_value_loan(this: &z_owned_value_t) -> &z_loaned_value_t {
this.transmute_ref().transmute_handle()
}

/// Frees the memory and resets the value it to its default value.
#[no_mangle]
pub extern "C" fn z_value_drop(this: &mut z_owned_value_t) {
Inplace::drop(this.transmute_mut());
}

/// The locality of samples to be received by subscribers or targeted by publishers.
#[repr(C)]
#[derive(Clone, Copy, Debug)]
Expand Down
21 changes: 18 additions & 3 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ use crate::transmute::TransmuteRef;
use crate::transmute::TransmuteUninitPtr;
use crate::z_closure_reply_loan;
use crate::z_consolidation_mode_t;
use crate::z_loaned_bytes_t;
use crate::z_loaned_encoding_t;
use crate::z_loaned_sample_t;
use crate::z_loaned_value_t;
use crate::z_owned_bytes_t;
use crate::z_owned_encoding_t;
use crate::z_owned_source_info_t;
Expand Down Expand Up @@ -72,10 +73,24 @@ pub unsafe extern "C" fn z_reply_ok(this: &z_loaned_reply_t) -> *const z_loaned_
/// Returns `NULL` if reply does not contain a error (i. e. if `z_reply_is_ok` returns ``true``).
#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn z_reply_err(this: &z_loaned_reply_t) -> *const z_loaned_value_t {
pub unsafe extern "C" fn z_reply_err_payload(this: &z_loaned_reply_t) -> *const z_loaned_bytes_t {
match this.transmute_ref().result() {
Ok(_) => null(),
Err(v) => v.transmute_handle(),
Err(v) => v.payload().transmute_handle(),
}
}

/// Yields the encoding of the contents of the reply by asserting it indicates a failure.
///
/// Returns `NULL` if reply does not contain a error (i. e. if `z_reply_is_ok` returns ``true``).
#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn z_reply_err_encoding(
this: &z_loaned_reply_t,
) -> *const z_loaned_encoding_t {
match this.transmute_ref().result() {
Ok(_) => null(),
Err(v) => v.encoding().transmute_handle(),
}
}

Expand Down
20 changes: 15 additions & 5 deletions src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::transmute::{
};
use crate::{
errors, z_closure_query_call, z_closure_query_loan, z_congestion_control_t, z_loaned_bytes_t,
z_loaned_keyexpr_t, z_loaned_session_t, z_loaned_value_t, z_owned_bytes_t,
z_loaned_encoding_t, z_loaned_keyexpr_t, z_loaned_session_t, z_owned_bytes_t,
z_owned_closure_query_t, z_owned_encoding_t, z_owned_source_info_t, z_priority_t,
z_timestamp_t, z_view_string_from_substring, z_view_string_t,
};
Expand Down Expand Up @@ -428,12 +428,22 @@ pub unsafe extern "C" fn z_query_parameters(
unsafe { z_view_string_from_substring(parameters, params.as_ptr() as _, params.len()) };
}

/// Gets query <a href="https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Query%20Payload.md">payload value</a>.
/// Gets query <a href="https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Query%20Payload.md">payload</a>.
///
/// Returns NULL if query does not contain a value.
/// Returns NULL if query does not contain a payload.
#[no_mangle]
pub extern "C" fn z_query_value(this: &z_loaned_query_t) -> Option<&z_loaned_value_t> {
this.transmute_ref().value().map(|v| v.transmute_handle())
pub extern "C" fn z_query_payload(this: &z_loaned_query_t) -> Option<&z_loaned_bytes_t> {
this.transmute_ref().payload().map(|v| v.transmute_handle())
}

/// Gets query <a href="https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Query%20Payload.md">payload encoding</a>.
///
/// Returns NULL if query does not hame an encoding.
#[no_mangle]
pub extern "C" fn z_query_encoding(this: &z_loaned_query_t) -> Option<&z_loaned_encoding_t> {
this.transmute_ref()
.encoding()
.map(|v| v.transmute_handle())
}

/// Gets query attachment.
Expand Down
10 changes: 6 additions & 4 deletions tests/z_api_alignment_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ void query_handler(const z_loaned_query_t *query, void *arg) {
z_view_string_t params;
z_query_parameters(query, &params);
(void)(params);
const z_loaned_value_t* payload_value = z_query_value(query);
(void)(payload_value);
const z_loaned_bytes_t *in_payload = z_query_payload(query);
(void)(in_payload);
const z_loaned_encoding_t *encoding = z_query_encoding(query);
(void)(encoding);
z_query_reply_options_t _ret_qreply_opt;
z_query_reply_options_default(&_ret_qreply_opt);

Expand All @@ -80,8 +82,8 @@ void reply_handler(const z_loaned_reply_t *reply, void *arg) {
}
#endif
} else {
const z_loaned_value_t* _ret_zvalue = z_reply_err(reply);
(void)(_ret_zvalue);
const z_loaned_bytes_t *_ret_zpayload = z_reply_err_payload(reply);
(void)(_ret_zpayload);
}
}

Expand Down
Loading

0 comments on commit 03c361d

Please sign in to comment.