zenoh icon indicating copy to clipboard operation
zenoh copied to clipboard

API alignment

Open Mallets opened this issue 4 years ago • 4 comments

Semantic and naming should be aligned across all zenoh API bindings: Rust, C, Python, and more to come.

Mallets avatar Mar 31 '22 14:03 Mallets

Tracking upstream roadmap issue https://github.com/eclipse-zenoh/roadmap/issues/3

Mallets avatar Apr 06 '22 14:04 Mallets

After some discussion, it was agreed by the zenoh team that the common behaviour for subscribe(), queryable(), and get() is to be based on callbacks. This approach simplifies the bindings from Rust towards other programming languages (e.g., C, Python, Java, etc.).

Then , departing from those callbacks, is then possible to create a stream for all subscriptions, queries, and replies by using the most appropriate library and mechanism depending on the language.

In the particular case of Rust, taking as examples the subscribe() operation, we would have the following API for creating a subscriber:

// Subscriber operating on a callback
let sub = session.subscribe("/key/expression").callback(|s| ...);

// Subscriber providing back a stream based on a flume channel.
// Other channel implementations may be provided by the user.
let sub = session.subscribe("/key/expression").channel(flume::bounded(64));

Moreover, providing a default shortcut for subscribe() is also considered practical and more user-friendly:

// Shortcut for session.subscribe("/key/expression").channel(flume::bounded(64))
let sub = session.subscribe("/key/expression"); 

Mallets avatar Apr 07 '22 13:04 Mallets

Update: the look-and-feel of the new API is captured in https://github.com/eclipse-zenoh/roadmap/discussions/23

Mallets avatar May 16 '22 10:05 Mallets

API:

  • [x] Move the .forward(...) (from a subscriber to a publisher) from basic zenoh API to zenoh-ext
  • [x] Replace .mode(...) in .declare_subscriber(...) builder with an option for SubMode::Pull returning a dedicated builder for pull subscribers.
  • [ ] Return HashMap<String, String> instead of Properties in .info()

Examples:

  • [x] Convert z_pong from stream-based subscriber to callback-based subscriber
  • [x] Use .declare_publisher() in z_pub_shm_thr
  • [ ] Add a stats report to z_pub_thr when the test is finished
  • [ ] Bugfix z_sub keyexpr arg
  • [ ] Use .race() instead of select! in all examples
  • [x] Verify all examples work as expected

Mallets avatar Jun 16 '22 14:06 Mallets

Merged into master.

Mallets avatar Sep 28 '22 09:09 Mallets