Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align api #245

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/universal/z_pong.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int _main(int argc, char **argv) {
auto session = Session::open(std::move(config));

auto pub = session.declare_publisher(KeyExpr("test/pong"));
auto sub = session.declare_subscriber(
session.declare_background_subscriber(
KeyExpr("test/ping"),
[pub = std::move(pub)](const Sample &sample) mutable { pub.put(sample.get_payload().clone()); },
closures::none);
Expand Down
2 changes: 1 addition & 1 deletion examples/universal/z_sub_thr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int _main(int argc, char **argv) {
Stats stats;
auto on_receive = [&stats](const Sample &s) { stats(s); };
auto on_drop = [&stats]() { stats(); };
auto subscriber = session.declare_subscriber(keyexpr, on_receive, on_drop);
session.declare_background_subscriber(keyexpr, on_receive, on_drop);

std::cout << "Press CTRL-C to quit...\n";
while (true) {
Expand Down
105 changes: 13 additions & 92 deletions include/zenoh/api/encoding.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,108 +86,29 @@ class Encoding : public Owned<::z_owned_encoding_t> {

/// Just some bytes.
/// Constant alias for string: `"zenoh/bytes"`.
/// Usually used for types: `uint8_t[]`.
/// This encoding supposes that the payload was constructed directly from `std::vector<uint8_t>` and
/// its data can be accessed via `Bytes::as_vector`.
static const Encoding& zenoh_bytes() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_bytes());
};

/// A VLE-encoded signed little-endian 8bit integer. Binary representation uses two's complement.
/// Constant alias for string: `"zenoh/int8"`.
/// Usually used for types: `int8_t`.
static const Encoding& zenoh_int8() { return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_int8()); };

/// A VLE-encoded signed little-endian 16bit integer. Binary representation uses two's complement.
/// Constant alias for string: `"zenoh/int16"`.
/// Usually used for types: `int16_t`.
static const Encoding& zenoh_int16() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_int16());
};

/// A VLE-encoded signed little-endian 32bit integer. Binary representation uses two's complement.
/// Constant alias for string: `"zenoh/int32"`.
/// Usually used for types: `int32_t`.
static const Encoding& zenoh_int32() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_int32());
};

/// A VLE-encoded signed little-endian 64bit integer. Binary representation uses two's complement.
/// Constant alias for string: `"zenoh/int64"`.
/// Usually used for types: `int64_t`.
static const Encoding& zenoh_int64() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_int64());
};

/// A VLE-encoded signed little-endian 128bit integer. Binary representation uses two's complement.
/// Constant alias for string: `"zenoh/int128"`.
static const Encoding& zenoh_int128() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_int128());
};

/// A VLE-encoded unsigned little-endian 8bit integer.
/// Constant alias for string: `"zenoh/uint8"`.
/// Usually used for types: `uint8_t`.
static const Encoding& zenoh_uint8() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_uint8());
};

/// A VLE-encoded unsigned little-endian 16bit integer.
/// Constant alias for string: `"zenoh/uint16"`.
/// Usually used for types: `uint16_t`.
static const Encoding& zenoh_uint16() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_uint16());
};

/// A VLE-encoded unsigned little-endian 32bit integer.
/// Constant alias for string: `"zenoh/uint32"`.
/// Usually used for types: `uint32_t`.
static const Encoding& zenoh_uint32() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_uint32());
};

/// A VLE-encoded unsigned little-endian 64bit integer.
/// Constant alias for string: `"zenoh/uint64"`.
/// Usually used for types: `uint64_t`.
static const Encoding& zenoh_uint64() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_uint64());
};

/// A VLE-encoded unsigned little-endian 128bit integer.
/// Constant alias for string: `"zenoh/uint128"`.
static const Encoding& zenoh_uint128() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_uint128());
};

/// A VLE-encoded 32bit float. Binary representation uses *IEEE 754-2008* *binary32*.
/// Constant alias for string: `"zenoh/float32"`.
/// Usually used for types: `float`.
static const Encoding& zenoh_float32() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_float32());
};

/// A VLE-encoded 64bit float. Binary representation uses *IEEE 754-2008* *binary64*.
/// Constant alias for string: `"zenoh/float64"`.
/// Usually used for types: `double`.
static const Encoding& zenoh_float64() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_float64());
};

/// A boolean. `0` is `false`, `1` is `true`. Other values are invalid.
/// Constant alias for string: `"zenoh/bool"`.
/// Usually used for types: `bool`.
static const Encoding& zenoh_bool() { return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_bool()); };

/// A UTF-8 string.
/// Constant alias for string: `"zenoh/string"`.
/// Usually used for types: `char[]`.
/// This encoding supposes that the payload was created directly from `std::string`, `std::string_view` or a
/// null-terminated string and its data can be accessed via `Bytes::as_string`.
static const Encoding& zenoh_string() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_string());
};

/// A zenoh error.
/// Constant alias for string: `"zenoh/error"`.
/// Usually used for types: `z_reply_err_t`.
static const Encoding& zenoh_error() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_error());
/// Zenoh serialized data.
///
/// Constant alias for string: `"zenoh/serialized"`.
///
/// This encoding supposes that the payload was created using `zenoh::ext::serialize` or with the help of
/// `zenoh::ext::Serializer` and its data can be accessed via `zenoh::ext::deserialize` or with the help of
/// `zenoh::ext::Deserializer`.
static const Encoding& zenoh_serialized() {
return interop::as_owned_cpp_ref<Encoding>(::z_encoding_zenoh_serialized());
};

/// An application-specific stream of bytes.
Expand Down
21 changes: 1 addition & 20 deletions include/zenoh/api/queryable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ class QueryableBase : public Owned<::z_owned_queryable_t> {
protected:
QueryableBase(zenoh::detail::null_object_t) : Owned(nullptr){};
QueryableBase(::z_owned_queryable_t* q) : Owned(q){};

public:
/// @brief Undeclares queryable.
/// @param err if not null, the result code will be written to this location, otherwise ZException exception will be
/// thrown in case of error.
void undeclare(ZResult* err = nullptr) && {
__ZENOH_RESULT_CHECK(::z_undeclare_queryable(interop::as_moved_c_ptr(*this)), err,
"Failed to undeclare queryable");
}

friend class zenoh::Session;
};
} // namespace detail
Expand All @@ -49,15 +39,12 @@ class Queryable<void> : public detail::QueryableBase {

public:
using QueryableBase::QueryableBase;
using QueryableBase::undeclare;
friend class Session;
};

/// A Zenoh queryable. Constructed by ``Session::declare_queryable`` method.
/// @tparam Handler Streaming handler exposing data. If `void`, no handler access is provided and instead data is being
/// processed inside the callback. Dropping handler-less queryable does not disable the callback. The corresponding
/// messages are still received and processed unti the corresponding session is destroyed or closed. If callback needs
/// to be disabled undeclare method should be called instead.
/// processed inside the callback.
template <class Handler>
class Queryable : public detail::QueryableBase {
Handler _handler;
Expand All @@ -78,13 +65,7 @@ class Queryable : public detail::QueryableBase {
/// @brief Return handler to queryable data stream.
const Handler& handler() const { return _handler; };

using QueryableBase::undeclare;
friend class Session;

~Queryable() {
ZResult err;
std::move(*this).undeclare(&err);
}
};

namespace interop {
Expand Down
Loading
Loading