Skip to content

Commit

Permalink
feat(zenoh-flow-nodes): expose node's node id in Context
Browse files Browse the repository at this point in the history
This allows providing more accurate information in, for instance,
logging. The same node could be instantiated several times, being able
to add the `NodeId` to the logging information helps differentiating
them.

* zenoh-flow-nodes/src/context.rs: add a field keeping track of the
  node id and a corresponding getter method.
* zenoh-flow-runtime/src/runtime/load.rs: add the operator, sink and
  source id when creating the Context.

Signed-off-by: Julien Loudet <[email protected]>
  • Loading branch information
J-Loudet committed Jun 4, 2024
1 parent 6ea5296 commit cebf975
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion zenoh-flow-nodes/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use std::{path::PathBuf, sync::Arc};

use zenoh_flow_commons::{InstanceId, RuntimeId};
use zenoh_flow_commons::{InstanceId, NodeId, RuntimeId};

/// The `Context` structure provides information about the data flow and the Zenoh-Flow runtime.
///
Expand All @@ -24,6 +24,7 @@ use zenoh_flow_commons::{InstanceId, RuntimeId};
/// - the [runtime id](Context::runtime_id()) of the Zenoh-Flow runtime managing the **node**.
#[derive(Clone, Debug)]
pub struct Context {
pub(crate) node_id: NodeId,
pub(crate) flow_name: Arc<str>,
pub(crate) instance_id: InstanceId,
pub(crate) runtime_id: RuntimeId,
Expand All @@ -37,12 +38,14 @@ impl Context {
instance_id: InstanceId,
runtime_id: RuntimeId,
library_path: Arc<PathBuf>,
node_id: NodeId,
) -> Self {
Self {
flow_name,
instance_id,
runtime_id,
library_path,
node_id,
}
}

Expand Down Expand Up @@ -72,4 +75,9 @@ impl Context {
pub fn library_path(&self) -> &PathBuf {
&self.library_path
}

/// Returns the node unique identifier in the data flow.
pub fn node_id(&self) -> &NodeId {
&self.node_id
}
}
3 changes: 3 additions & 0 deletions zenoh-flow-runtime/src/runtime/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ The channels for the Inputs and Outputs of Operator < {} > were not created.
record.instance_id().clone(),
self.runtime_id.clone(),
path,
operator_id.clone(),
);

let operator_node = (constructor)(
Expand Down Expand Up @@ -343,6 +344,7 @@ The channels for the Outputs of Source < {} > were not created.
record.instance_id().clone(),
self.runtime_id.clone(),
path,
source_id.clone(),
);

let source_node =
Expand Down Expand Up @@ -424,6 +426,7 @@ The channels for the Inputs of Sink < {} > were not created.
record.instance_id().clone(),
self.runtime_id.clone(),
library_path,
sink_id.clone(),
);

let sink_node =
Expand Down

0 comments on commit cebf975

Please sign in to comment.