use crate::runtime::InstanceContext;
use crate::types::{FlowId, RuntimeId};
use std::ops::Deref;
use std::sync::Arc;
use uhlc::HLC;
use uuid::Uuid;
use zenoh::prelude::ZenohId;
use zenoh::Session;
#[derive(Clone)]
pub struct Context {
instance_ctx: InstanceContext,
}
impl Context {
pub(crate) fn new(instance_ctx: &InstanceContext) -> Self {
Self {
instance_ctx: instance_ctx.clone(),
}
}
pub fn get_runtime_name(&self) -> &RuntimeId {
&self.instance_ctx.runtime.runtime_name
}
pub fn get_runtime_uuid(&self) -> &ZenohId {
&self.instance_ctx.runtime.runtime_uuid
}
pub fn get_flow_name(&self) -> &FlowId {
&self.instance_ctx.flow_id
}
pub fn get_instance_id(&self) -> &Uuid {
&self.instance_ctx.instance_id
}
pub fn zenoh_session(&self) -> Arc<Session> {
self.instance_ctx.runtime.session.clone()
}
pub fn shared_memory_element_size(&self) -> &usize {
&self.instance_ctx.runtime.shared_memory_element_size
}
pub fn shared_memory_elements(&self) -> &usize {
&self.instance_ctx.runtime.shared_memory_elements
}
pub fn shared_memory_backoff(&self) -> &u64 {
&self.instance_ctx.runtime.shared_memory_backoff
}
pub fn shared_memory_enabled(&self) -> &bool {
&self.instance_ctx.runtime.use_shm
}
}
impl Deref for Context {
type Target = HLC;
fn deref(&self) -> &Self::Target {
&self.instance_ctx.runtime.hlc
}
}