1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
//
// Copyright (c) 2021 - 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>
//
use std::sync::Arc;
use zenoh_flow_commons::{InstanceId, RuntimeId};
/// The `Context` structure provides information about the data flow and the Zenoh-Flow runtime.
///
/// In particular, it allows accessing:
/// - the [name](Context::name()) of the data flow,
/// - the [instance id](Context::instance_id()) of this instance of the data flow,
/// - the [runtime id](Context::runtime_id()) of the Zenoh-Flow runtime managing the **node**.
#[derive(Clone, Debug)]
pub struct Context {
pub(crate) flow_name: Arc<str>,
pub(crate) instance_id: InstanceId,
pub(crate) runtime_id: RuntimeId,
}
impl Context {
/// Creates a new node `Context`.
pub fn new(flow_name: Arc<str>, instance_id: InstanceId, runtime_id: RuntimeId) -> Self {
Self {
flow_name,
instance_id,
runtime_id,
}
}
/// Returns the name of the data flow.
///
/// Note all instances of the same data flow will share the same `name`.
pub fn name(&self) -> &str {
self.flow_name.as_ref()
}
/// Returns the unique identifier of this instance of the data flow.
pub fn instance_id(&self) -> &InstanceId {
&self.instance_id
}
/// Returns the unique identifier of the Zenoh-Flow runtime managing the **node**.
///
/// Note that, for the same instance, different nodes might return different runtime identifier if they are running
/// on different Zenoh-Flow runtimes.
pub fn runtime_id(&self) -> &RuntimeId {
&self.runtime_id
}
}