Skip to content

Commit

Permalink
move publication cache and querying_subscriber under SessionExt class
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Dec 13, 2024
1 parent ce1111f commit b14b6a0
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 292 deletions.
1 change: 0 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ API Reference
publish_subscribe
query_reply
matching
serialization_deserialization
channels
interop
shared_memory
Expand Down
28 changes: 26 additions & 2 deletions docs/ext.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,34 @@ Extensions
==========
Extra functionality, which is not a part of core Zenoh API.

.. doxygenclass:: zenoh::ext::PublicationCache
Serialization / Deserialization
-------------------------------
Support for data serialization and deserialization.

.. doxygenclass:: zenoh::ext::Serializer
:members:
:membergroups: Constructors Operators Methods

.. doxygenclass:: zenoh::ext::Deserializer
:members:
:membergroups: Constructors Operators Methods

.. doxygenfunction:: zenoh::ext::serialize
.. doxygenfunction:: zenoh::ext::deserialize


Session Extension
-----------------
Extra Zenoh entities.

.. doxygenclass:: zenoh::ext::SessionExt
:members:
:membergroups: Constructors Operators Methods Fields

.. doxygenclass:: zenoh::ext::PublicationCache
:members:
:membergroups: Constructors Operators Methods Fields

.. doxygenclass:: zenoh::ext::QueryingSubscriber
:members:
:membergroups: Constructors Operators Methods
:membergroups: Constructors Operators Methods Fields
26 changes: 0 additions & 26 deletions docs/serialization_deserialization.rst

This file was deleted.

4 changes: 2 additions & 2 deletions examples/zenohc/z_pub_cache.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int _main(int argc, char **argv) {
auto session = Session::open(std::move(config));

std::cout << "Declaring Publication cache on '" << keyexpr << "'..." << std::endl;
Session::PublicationCacheOptions opts;
ext::SessionExt::PublicationCacheOptions opts;
opts.history = history;
opts.queryable_complete = complete;
if (!prefix.empty()) {
Expand All @@ -63,7 +63,7 @@ int _main(int argc, char **argv) {
if (!std::string(prefix).empty()) {
opts.queryable_prefix = KeyExpr(prefix);
}
auto pub_cache = session.declare_publication_cache(keyexpr, std::move(opts));
auto pub_cache = session.ext().declare_publication_cache(keyexpr, std::move(opts));

std::cout << "Press CTRL-C to quit..." << std::endl;
for (int idx = 0; idx < std::numeric_limits<int>::max(); ++idx) {
Expand Down
5 changes: 3 additions & 2 deletions examples/zenohc/z_query_sub.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ int _main(int argc, char **argv) {

std::cout << "Declaring Querying Subscriber on '" << keyexpr << "' with initial query on '" << query << "'"
<< std::endl;
Session::QueryingSubscriberOptions opts;
ext::SessionExt::QueryingSubscriberOptions opts;

if (!query.empty()) {
opts.query_keyexpr = KeyExpr(query);
opts.query_accept_replies = ReplyKeyExpr::ZC_REPLY_KEYEXPR_ANY;
}
auto querying_subscriber = session.declare_querying_subscriber(keyexpr, channels::FifoChannel(16), std::move(opts));
auto querying_subscriber =
session.ext().declare_querying_subscriber(keyexpr, channels::FifoChannel(16), std::move(opts));

std::cout << "Press CTRL-C to quit..." << std::endl;
for (auto res = querying_subscriber.handler().recv(); std::holds_alternative<Sample>(res);
Expand Down
45 changes: 41 additions & 4 deletions include/zenoh/api/ext/publication_cache.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
#pragma once

#if defined(ZENOHCXX_ZENOHC) && defined(Z_FEATURE_UNSTABLE_API)
#include "../../detail/closures_concrete.hxx"
#include "../base.hxx"
#include "../interop.hxx"
#include "../keyexpr.hxx"
#include "../sample.hxx"
#include "session_ext.hxx"

namespace zenoh {
namespace ext {
namespace zenoh::ext {

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief A Zenoh publication cache.
Expand Down Expand Up @@ -47,6 +50,40 @@ class PublicationCache : public Owned<::ze_owned_publication_cache_t> {
}
};

} // namespace ext
} // namespace zenoh
[[nodiscard]] PublicationCache SessionExt::declare_publication_cache(const KeyExpr& key_expr,
PublicationCacheOptions&& options,
ZResult* err) const {
::ze_publication_cache_options_t opts;
ze_publication_cache_options_default(&opts);
opts.queryable_prefix = interop::as_loaned_c_ptr(options.queryable_prefix);
#if defined(Z_FEATURE_UNSTABLE_API)
opts.queryable_origin = options.queryable_origin;
#endif
opts.queryable_complete = options.queryable_complete;
opts.history = options.history;
opts.resources_limit = options.resources_limit;
ext::PublicationCache p = interop::detail::null<ext::PublicationCache>();
ZResult res = ::ze_declare_publication_cache(interop::as_loaned_c_ptr(this->_session), interop::as_owned_c_ptr(p),
interop::as_loaned_c_ptr(key_expr), &opts);
__ZENOH_RESULT_CHECK(res, err, "Failed to declare Publication Cache");
return p;
}

void SessionExt::declare_background_publication_cache(const KeyExpr& key_expr, PublicationCacheOptions&& options,
ZResult* err) const {
::ze_publication_cache_options_t opts;
ze_publication_cache_options_default(&opts);
opts.queryable_prefix = interop::as_loaned_c_ptr(options.queryable_prefix);
#if defined(Z_FEATURE_UNSTABLE_API)
opts.queryable_origin = options.queryable_origin;
#endif
opts.queryable_complete = options.queryable_complete;
opts.history = options.history;
opts.resources_limit = options.resources_limit;
ZResult res = ::ze_declare_background_publication_cache(interop::as_loaned_c_ptr(this->_session),
interop::as_loaned_c_ptr(key_expr), &opts);
__ZENOH_RESULT_CHECK(res, err, "Failed to declare Background Publication Cache");
}

} // namespace zenoh::ext
#endif
Loading

0 comments on commit b14b6a0

Please sign in to comment.