-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add publication cache support (#274)
* add publication cache support * do not build z_pub_cache_example if unstable api is not enabled * docs update
- Loading branch information
1 parent
602bca8
commit e060cf0
Showing
11 changed files
with
267 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,5 @@ API Reference | |
serialization_deserialization | ||
channels | ||
interop | ||
shared_memory | ||
shared_memory | ||
ext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.. | ||
.. Copyright (c) 2024 ZettaScale Technology | ||
.. | ||
.. This program and the accompanying materials are made available under the | ||
.. terms of the Eclipse Public License 2.0 which is available at | ||
.. http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
.. which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
.. | ||
.. SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
.. | ||
.. Contributors: | ||
.. ZettaScale Zenoh Team, <zenoh@zettascale.tech> | ||
.. | ||
Extensions | ||
========== | ||
Extra functionality, which is not a part of core Zenoh API. | ||
|
||
.. doxygenclass:: zenoh::ext::PublicationCache | ||
:members: | ||
:membergroups: Constructors Operators Methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// Copyright (c) 2022 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <zenoh@zettascale.tech> | ||
// | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include <chrono> | ||
#include <iostream> | ||
#include <limits> | ||
#include <sstream> | ||
#include <thread> | ||
|
||
#include "../getargs.h" | ||
#include "zenoh.hxx" | ||
|
||
using namespace zenoh; | ||
using namespace std::chrono_literals; | ||
|
||
const char *default_value = "Pub from C++ zenoh-c!"; | ||
const char *default_keyexpr = "demo/example/zenoh-cpp-zenoh-c-pub"; | ||
const char *default_history = "1"; | ||
const char *default_prefix = ""; | ||
|
||
int _main(int argc, char **argv) { | ||
const char *keyexpr = default_keyexpr; | ||
const char *value = default_value; | ||
const char *history = default_history; | ||
const char *prefix = default_prefix; | ||
Config config = parse_args(argc, argv, {}, {{"key_expression", &keyexpr}, {"payload_value", &value}}, | ||
{{"-i", {"history", &history}}, {"-x", {"query prefix", &prefix}}}); | ||
config.insert_json5(Z_CONFIG_ADD_TIMESTAMP_KEY, "true"); | ||
|
||
std::cout << "Opening session..." << std::endl; | ||
auto session = Session::open(std::move(config)); | ||
|
||
std::cout << "Declaring Publication cache on '" << keyexpr << "'..." << std::endl; | ||
Session::PublicationCacheOptions opts; | ||
opts.history = std::atoi(history); | ||
if (!std::string(prefix).empty()) { | ||
opts.queryable_prefix = KeyExpr(prefix); | ||
} | ||
auto pub_cache = session.declare_publication_cache(keyexpr, std::move(opts)); | ||
|
||
std::cout << "Publication cache on '" << keyexpr << "' declared" << std::endl; | ||
|
||
std::cout << "Press CTRL-C to quit..." << std::endl; | ||
for (int idx = 0; idx < std::numeric_limits<int>::max(); ++idx) { | ||
std::this_thread::sleep_for(1s); | ||
std::ostringstream ss; | ||
ss << "[" << idx << "] " << value; | ||
auto s = ss.str(); | ||
std::cout << "Putting Data ('" << keyexpr << "': '" << s << "')...\n"; | ||
Session::PutOptions put_options; | ||
put_options.encoding = Encoding("text/plain"); | ||
session.put(keyexpr, std::move(s), std::move(put_options)); | ||
} | ||
return 0; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
try { | ||
init_log_from_env_or("error"); | ||
_main(argc, argv); | ||
} catch (ZException e) { | ||
std::cout << "Received an error :" << e.what() << "\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Copyright (c) 2024 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <zenoh@zettascale.tech> | ||
|
||
#pragma once | ||
|
||
#if defined(ZENOHCXX_ZENOHC) && defined(Z_FEATURE_UNSTABLE_API) | ||
#include "../base.hxx" | ||
#include "../interop.hxx" | ||
|
||
namespace zenoh { | ||
namespace 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. | ||
/// | ||
/// Used to store publications on intersecting key expressions. Can be queried later via `zenoh::Session::get` to | ||
/// retrieve this data. | ||
/// @note Zenoh-c only | ||
class PublicationCache : public Owned<::ze_owned_publication_cache_t> { | ||
PublicationCache(zenoh::detail::null_object_t) : Owned(nullptr){}; | ||
friend struct interop::detail::Converter; | ||
|
||
public: | ||
/// @name Methods | ||
|
||
/// @brief Get the key expression of the publication cache. | ||
const KeyExpr& get_keyexpr() const { | ||
return interop::as_owned_cpp_ref<KeyExpr>(::ze_publication_cache_keyexpr(interop::as_loaned_c_ptr(*this))); | ||
} | ||
|
||
/// @brief Undeclare publication cache. | ||
/// @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(::ze_undeclare_publication_cache(interop::as_moved_c_ptr(*this)), err, | ||
"Failed to undeclare Publication Cache"); | ||
} | ||
}; | ||
|
||
} // namespace ext | ||
} // namespace zenoh | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.