@@ -23,13 +23,16 @@ namespace libcyphal
2323namespace transport
2424{
2525
26- // / Internal implementation details of the UDP transport.
26+ // / Internal implementation details of a transport.
2727// / Not supposed to be used directly by the users of the library.
2828// /
2929namespace detail
3030{
3131
32- // / @brief Defines a tree of sessions for the UDP transport.
32+ // / @brief Defines a tree of sessions for a transport.
33+ // /
34+ // / @tparam Node The type of the session node. Expected to be a subclass of `SessionTree::NodeBase`,
35+ // / and to have a method `compareByParams` that compares nodes by its parameters.
3336// /
3437template <typename Node>
3538class SessionTree final
@@ -74,10 +77,21 @@ class SessionTree final
7477 return nodes_.empty ();
7578 }
7679
80+ // / @brief Ensures that a node for the given parameters exists in the tree.
81+ // /
82+ // / @tparam ShouldBeNew If `true`, the function will return an error if node with given
83+ // parametes already exists (see also `Node::compareByParams` method).
84+ // / @tparam Params The type of the parameters to be used to find or create the node.
85+ // / @tparam Args The types of the arguments to be passed to the constructor of the node.
86+ // / @param params The parameters to be used to find or create the node.
87+ // / @param args The extra arguments to be forwarded to the constructor of the node (as a tuple).
88+ // / @return The reference to the node, or an error if the node could not be created.
89+ // /
7790 template <bool ShouldBeNew = false , typename Params, typename ... Args>
7891 CETL_NODISCARD auto ensureNodeFor (const Params& params,
7992 Args&&... args) -> Expected<typename NodeBase::RefWrapper, AnyFailure>
8093 {
94+ // In c++14 we can't capture `args` with forwarding, so we pack them into a tuple.
8195 auto args_tuple = std::make_tuple (std::forward<Args>(args)...);
8296
8397 const auto node_existing = nodes_.search (
@@ -167,6 +181,9 @@ template <typename RxSessionDelegate>
167181class ResponseRxSessionNode final : public SessionTree<ResponseRxSessionNode<RxSessionDelegate>>::NodeBase
168182{
169183public:
184+ // Empty tuple parameter is used to allow for the same constructor signature
185+ // as for other session nodes (see also `SessionTree::ensureNodeFor` method).
186+ //
170187 explicit ResponseRxSessionNode (const ResponseRxParams& params, const std::tuple<>&)
171188 : service_id_{params.service_id }
172189 , server_node_id{params.server_node_id }
0 commit comments