use crate::{
channel::mpsc::{UnboundedReceiver, create_unbounded_channel},
collections::HashMap,
core_compiler::{
core_compilation_context::DXBWithSharedValues, core_compile,
instruction_input::InstructionInput,
},
datex_registry::{all_datex_types, get_all_modules},
dif::dif_interface::DIFInterface,
disassembler::{
options::DisassemblerOptions, print_disassembled_with_options,
},
global::{
dxb_block::{
DXBBlock, IncomingEndpointContextSectionId, IncomingSection,
OutgoingContextId,
},
protocol_structures::{
block_header::{BlockHeader, FlagsAndTimestamp},
encrypted_header::EncryptedHeader,
routing_header::RoutingHeader,
},
},
libs::core::CoreLibrary,
network::{
block_handler::{
IncomingSectionReceiver, create_incoming_sections_channel,
},
com_hub::{
ComHub, ComInterfaceReconnectRequest, InterfacePriority,
network_response::ResponseOptions,
},
com_interfaces::local_loopback_interface::LocalLoopbackInterfaceSetupData,
},
prelude::*,
random::RandomState,
runtime::{
Runtime, RuntimeConfig, RuntimeConfigInterface,
cache::shared_references_cache::SharedReferencesCache,
execution::{
ExecutionError,
context::{
ExecutionContext, ExecutionMode,
FinalOrPersistedExecutionContext, RemoteExecutionContext,
RemoteExecutionTarget, ScriptExecutionError,
},
execution_input::ExecutionCallerMetadata,
remote_execution_options::RemoteExecutionOptions,
},
pointer_address_provider::SelfOwnedPointerAddressProvider,
pointer_availability_lookup::PointerAvailabilityLookup,
remote_value_sync::{
SubscriberError, synced_value_data::SyncedValueData,
},
},
shared_values::{
SharedContainer, base_shared_value_container::observers::TransceiverId,
},
time::{Instant, now_ms},
types::r#type::Type,
utils::task_manager::TaskManager,
values::{
core_values::endpoint::Endpoint, value_container::ValueContainer,
},
};
use alloc::rc::Rc;
use core::{
cell::{Ref, RefCell, RefMut, UnsafeCell},
ops::DerefMut,
pin::Pin,
};
use datex_macros_internal::Datex;
use futures_util::future::join_all;
use indexmap::IndexMap;
use log::{debug, error, info};
pub type RemoteExecutionResult = Result<Option<ValueContainer>, ExecutionError>;
#[derive(Datex, Debug, Clone, PartialEq, Eq, Hash)]
#[datex(structural)]
pub struct HeapStats {
pub total: usize,
pub used: usize,
pub max_used: usize,
}
#[derive(Datex, Debug, Clone, PartialEq, Eq, Hash, Default)]
#[datex(structural)]
pub struct RuntimeStats {
pub heap: Option<HeapStats>,
}
#[derive(Datex, Debug, Clone)]
#[datex(structural)]
pub struct RuntimeInfo {
datex_version: String,
other_versions: IndexMap<String, String, RandomState>,
device_type: Option<String>,
running_since: u64,
}
#[derive(Debug, Clone, Default)]
pub struct CustomRuntimeInfo {
pub device_type: Option<String>,
pub other_versions: IndexMap<String, String, RandomState>,
}
#[derive(Debug)]
pub struct RuntimeInternal {
endpoint: UnsafeCell<Endpoint>,
info: RefCell<RuntimeInfo>,
core_library: CoreLibrary,
shared_references_cache: RefCell<SharedReferencesCache>,
pointer_address_provider: Rc<RefCell<SelfOwnedPointerAddressProvider>>,
com_hub: Rc<ComHub>,
config: UnsafeCell<RuntimeConfig>,
endpoint_properties: RefCell<IndexMap<String, ValueContainer, RandomState>>,
transceiver_counter: RefCell<u8>,
task_manager: TaskManager,
incoming_sections_receiver: RefCell<IncomingSectionReceiver>,
com_interface_reconnect_request_receiver:
RefCell<UnboundedReceiver<ComInterfaceReconnectRequest>>,
execution_contexts:
RefCell<HashMap<IncomingEndpointContextSectionId, ExecutionContext>>,
pointer_availability_lookup: RefCell<PointerAvailabilityLookup>,
synced_value_data: RefCell<SyncedValueData>,
stats_provider: RefCell<fn() -> RuntimeStats>,
}
impl From<Rc<RuntimeInternal>> for Runtime {
fn from(value: Rc<RuntimeInternal>) -> Self {
Runtime { internal: value }
}
}
impl RuntimeInternal {
pub(crate) fn new(
endpoint: Endpoint,
shared_references_cache: RefCell<SharedReferencesCache>,
pointer_address_provider: Rc<RefCell<SelfOwnedPointerAddressProvider>>,
config: RuntimeConfig,
com_hub: Rc<ComHub>,
task_manager: TaskManager,
incoming_sections_receiver: IncomingSectionReceiver,
com_interface_reconnect_request_receiver: UnboundedReceiver<
ComInterfaceReconnectRequest,
>,
info: CustomRuntimeInfo,
) -> RuntimeInternal {
let pointer_availability_lookup =
PointerAvailabilityLookup::new(endpoint.clone());
let internal = RuntimeInternal {
info: RefCell::new(RuntimeInfo {
device_type: info.device_type,
other_versions: info.other_versions,
datex_version: env!("CARGO_PKG_VERSION").to_string(),
running_since: now_ms(),
}),
endpoint: UnsafeCell::new(endpoint),
shared_references_cache,
pointer_address_provider,
config: UnsafeCell::new(config),
com_hub,
task_manager,
endpoint_properties: RefCell::new(IndexMap::default()),
core_library: CoreLibrary::default(),
incoming_sections_receiver: RefCell::new(
incoming_sections_receiver,
),
com_interface_reconnect_request_receiver: RefCell::new(
com_interface_reconnect_request_receiver,
),
synced_value_data: RefCell::new(SyncedValueData::default()),
execution_contexts: RefCell::new(HashMap::new()),
transceiver_counter: RefCell::new(0),
pointer_availability_lookup: RefCell::new(
pointer_availability_lookup,
),
stats_provider: RefCell::new(RuntimeStats::default),
};
internal.register_static_data();
internal
}
fn register_static_data(&self) {
let mut cache = self.shared_references_cache_mut();
let cache = cache.deref_mut();
let modules = get_all_modules(cache);
for (name, value) in modules {
self.register_endpoint_property(&name, value.into());
}
let types = all_datex_types(cache);
for ty in types {
if let Type::Entity(ty) = ty
&& let SharedContainer::Owned(container) = ty.shared_container()
{
cache.register_owned_shared_container(
&container.derive_with_max_mutability(),
)
}
}
}
pub fn version(&self) -> Ref<'_, String> {
Ref::map(self.info.borrow(), |info| &info.datex_version)
}
pub fn info(&self) -> Ref<'_, RuntimeInfo> {
self.info.borrow()
}
pub fn config(&self) -> &RuntimeConfig {
unsafe { &*self.config.get() }
}
pub unsafe fn set_config(&self, config: RuntimeConfig) {
unsafe {
*self.config.get() = config;
}
unsafe {
let endpoint = self.config().endpoint.clone();
*self.endpoint.get() = endpoint.clone();
*self.com_hub.endpoint.get() = endpoint;
}
}
pub fn reset_running_since(&self) {
self.info.borrow_mut().running_since = now_ms();
}
pub fn set_stats_provider(&self, stats_provider: fn() -> RuntimeStats) {
*self.stats_provider.borrow_mut() = stats_provider;
}
pub fn get_stats(&self) -> RuntimeStats {
self.stats_provider.borrow()()
}
pub fn com_hub(&self) -> Rc<ComHub> {
self.com_hub.clone()
}
pub fn endpoint(&self) -> &Endpoint {
unsafe { &*self.endpoint.get() }
}
pub fn endpoint_properties(
&self,
) -> Ref<'_, IndexMap<String, ValueContainer, RandomState>> {
self.endpoint_properties.borrow()
}
pub fn endpoint_properties_mut(
&self,
) -> RefMut<'_, IndexMap<String, ValueContainer, RandomState>> {
self.endpoint_properties.borrow_mut()
}
pub fn get_endpoint_property_by_name(
&'_ self,
key: &str,
) -> Option<Ref<'_, ValueContainer>> {
Ref::filter_map(self.endpoint_properties.borrow(), |props| {
props.get(key)
})
.ok()
}
pub fn get_endpoint_property_by_name_mut(
&'_ self,
key: &str,
) -> Option<RefMut<'_, ValueContainer>> {
RefMut::filter_map(self.endpoint_properties.borrow_mut(), |props| {
props.get_mut(key)
})
.ok()
}
pub fn register_endpoint_property(
&self,
name: &str,
value: ValueContainer,
) {
self.endpoint_properties_mut()
.insert(name.to_string(), value);
}
pub fn pointer_availability_lookup(
&self,
) -> Ref<'_, PointerAvailabilityLookup> {
self.pointer_availability_lookup.borrow()
}
pub fn pointer_availability_lookup_mut(
&self,
) -> RefMut<'_, PointerAvailabilityLookup> {
self.pointer_availability_lookup.borrow_mut()
}
pub fn synced_value_data(&self) -> Ref<'_, SyncedValueData> {
self.synced_value_data.borrow()
}
pub fn synced_value_data_mut(&self) -> RefMut<'_, SyncedValueData> {
self.synced_value_data.borrow_mut()
}
pub fn shared_references_cache_refcell(
&self,
) -> &RefCell<SharedReferencesCache> {
&self.shared_references_cache
}
pub fn shared_references_cache(&self) -> Ref<'_, SharedReferencesCache> {
self.shared_references_cache.borrow()
}
pub fn shared_references_cache_mut(
&self,
) -> RefMut<'_, SharedReferencesCache> {
self.shared_references_cache.borrow_mut()
}
pub fn core_library(&self) -> &CoreLibrary {
&self.core_library
}
pub fn pointer_address_provider_mut(
&self,
) -> RefMut<'_, SelfOwnedPointerAddressProvider> {
self.pointer_address_provider.borrow_mut()
}
pub fn incoming_sections_receiver_mut(
&self,
) -> RefMut<'_, IncomingSectionReceiver> {
self.incoming_sections_receiver.borrow_mut()
}
pub fn com_interface_reconnect_request_receiver_mut(
&self,
) -> RefMut<'_, UnboundedReceiver<ComInterfaceReconnectRequest>> {
self.com_interface_reconnect_request_receiver.borrow_mut()
}
pub fn task_manager(&self) -> &TaskManager {
&self.task_manager
}
pub fn stub() -> RuntimeInternal {
let (incoming_sections_sender, incoming_sections_receiver) =
create_incoming_sections_channel();
let (reconnect_request_sender, reconnect_request_receiver) =
create_unbounded_channel();
RuntimeInternal::new(
Endpoint::default(),
RefCell::new(SharedReferencesCache::default()),
Rc::new(RefCell::new(SelfOwnedPointerAddressProvider::new(
Endpoint::default(),
))),
RuntimeConfig::default(),
ComHub::create(
Endpoint::default(),
incoming_sections_sender,
reconnect_request_sender,
0,
)
.0,
TaskManager::create().0,
incoming_sections_receiver,
reconnect_request_receiver,
CustomRuntimeInfo::default(),
)
}
async fn create_configured_interfaces(&self) {
if let Some(interfaces) = &self.config().interfaces {
for RuntimeConfigInterface {
interface_type,
config,
priority,
} in interfaces.iter()
{
let create_future = self
.com_hub
.clone()
.create_interface(interface_type, config.clone(), *priority)
.await;
match create_future {
Err(err) => {
error!(
"Failed to create interface \"{interface_type}\": {err}"
);
self.com_hub
.reconnect_interface_sender
.borrow_mut()
.start_send(ComInterfaceReconnectRequest::new(
interface_type.clone(),
config.clone(),
*priority,
))
.unwrap();
}
Ok((_, ready_receiver)) => {
if let Some(ready_receiver) = ready_receiver {
let _ = ready_receiver.await;
}
}
}
}
}
}
async fn init_local_loopback_interface(&self) {
let local_interface_setup_data =
LocalLoopbackInterfaceSetupData.create_interface().unwrap();
let ready_signal = self
.com_hub
.clone()
.add_interface_from_configuration(
local_interface_setup_data,
InterfacePriority::None,
)
.expect("Failed to add local loopback interface");
ready_signal.unwrap().await.unwrap()
}
pub(crate) async fn init_async(&self) {
self.init_local_loopback_interface().await;
self.create_configured_interfaces().await;
}
#[cfg(feature = "compiler")]
pub async fn execute<'a>(
self: Rc<RuntimeInternal>,
script: &'a str,
inserted_values: &'a [ValueContainer],
execution_context: Option<
impl Into<FinalOrPersistedExecutionContext<'a>>,
>,
mark_as_debug: bool,
) -> Result<Option<ValueContainer>, ScriptExecutionError> {
let mut execution_context = Runtime::from(self.clone())
.get_or_create_execution_context(execution_context);
let compile_start = Instant::now();
let execution_context_mut = execution_context.as_mut();
let dxb = execution_context_mut.compile(
script,
inserted_values,
execution_context_mut.receivers(),
)?;
debug!(
"[Compilation took {} ms]",
compile_start.elapsed().as_millis()
);
let execute_start = Instant::now();
let result = RuntimeInternal::execute_dxb(
self,
dxb,
None,
Some(execution_context),
mark_as_debug,
)
.await
.map_err(ScriptExecutionError::from);
debug!(
"[Execution took {} ms]",
execute_start.elapsed().as_millis()
);
result
}
#[cfg(feature = "compiler")]
pub fn execute_sync<'a>(
self: Rc<RuntimeInternal>,
script: &'a str,
inserted_values: &'a [ValueContainer],
execution_context: Option<
impl Into<FinalOrPersistedExecutionContext<'a>>,
>,
) -> Result<Option<ValueContainer>, ScriptExecutionError> {
let mut execution_context = Runtime::from(self.clone())
.get_or_create_execution_context(execution_context);
let execution_context_mut = execution_context.as_mut();
let compile_start = Instant::now();
let dxb = execution_context_mut.compile(
script,
inserted_values,
execution_context_mut.receivers(),
)?;
debug!(
"[Compilation took {} ms]",
compile_start.elapsed().as_millis()
);
let execute_start = Instant::now();
let result = RuntimeInternal::execute_dxb_sync(
self,
dxb,
None,
Some(execution_context),
)
.map_err(ScriptExecutionError::from);
debug!(
"[Execution took {} ms]",
execute_start.elapsed().as_millis()
);
result
}
pub fn execute_dxb<'a>(
self: Rc<RuntimeInternal>,
input: DXBWithSharedValues,
initial_stack_values: Option<Vec<ValueContainer>>,
execution_context: Option<
impl Into<FinalOrPersistedExecutionContext<'a>> + 'a,
>,
mark_as_debug: bool,
) -> Pin<
Box<
dyn Future<Output = Result<Option<ValueContainer>, ExecutionError>>
+ 'a,
>,
> {
Box::pin(async move {
let mut execution_context = Runtime::from(self.clone())
.get_or_create_execution_context(execution_context);
let is_end_of_context = execution_context.is_end_of_context();
let execution_context_mut = execution_context.as_mut();
match execution_context_mut {
ExecutionContext::Remote(context) => {
if initial_stack_values.is_some() {
return Err(ExecutionError::InvalidExecutionState);
}
RuntimeInternal::execute_remote_single_receiver(
self,
&context.target,
input,
RemoteExecutionOptions {
is_end_of_context,
mark_as_debug,
},
)
.await
}
ExecutionContext::Local(_) => {
execution_context_mut
.execute_dxb(input, initial_stack_values)
.await
}
}
})
}
pub fn execute_dxb_sync<'a>(
self: Rc<RuntimeInternal>,
dxb: DXBWithSharedValues,
initial_stack_values: Option<Vec<ValueContainer>>,
execution_context: Option<
impl Into<FinalOrPersistedExecutionContext<'a>>,
>,
) -> Result<Option<ValueContainer>, ExecutionError> {
let mut execution_context = Runtime::from(self.clone())
.get_or_create_execution_context(execution_context);
let execution_context_mut = execution_context.as_mut();
match execution_context_mut {
ExecutionContext::Remote(_) => {
Err(ExecutionError::RequiresAsyncExecution)
}
ExecutionContext::Local(_) => execution_context_mut
.execute_dxb_sync(dxb, initial_stack_values),
}
}
fn take_or_create_execution_context(
self: Rc<RuntimeInternal>,
context_id: &IncomingEndpointContextSectionId,
incoming_section: &IncomingSection,
) -> ExecutionContext {
let runtime = Runtime::from(self.clone());
let mut execution_contexts = self.execution_contexts.borrow_mut();
let execution_context = execution_contexts.remove(context_id);
if let Some(context) = execution_context {
context
} else {
let caller_metadata = ExecutionCallerMetadata {
endpoint: incoming_section.get_sender(),
};
ExecutionContext::local(
ExecutionMode::unbounded(),
runtime,
caller_metadata,
)
}
}
pub async fn execute_remote_single_receiver(
self: Rc<RuntimeInternal>,
remote_execution_target: &RemoteExecutionTarget,
input: DXBWithSharedValues,
options: RemoteExecutionOptions,
) -> RemoteExecutionResult {
if remote_execution_target.endpoints().len() != 1 {
panic!(
"execute_remote_single_receiver called with remote_execution_context that has more than one endpoint"
);
}
self.execute_remote(remote_execution_target, input, options)
.await?
.remove(0)
.0
}
pub async fn execute_remote(
self: Rc<RuntimeInternal>,
remote_execution_target: &RemoteExecutionTarget,
input: DXBWithSharedValues,
options: RemoteExecutionOptions,
) -> Result<Vec<(RemoteExecutionResult, Endpoint)>, SubscriberError> {
let routing_header: RoutingHeader = RoutingHeader::default()
.with_sender(self.endpoint().clone())
.to_owned();
let context_id = {
let mut context_ref =
remote_execution_target.context_id.borrow_mut();
context_ref.unwrap_or_else(|| {
let id = self.com_hub.block_handler.get_new_context_id();
*context_ref = Some(id);
id
})
};
let block_header = BlockHeader {
context_id,
flags_and_timestamp: FlagsAndTimestamp::default()
.with_is_end_of_context(options.is_end_of_context)
.with_is_debug_block(options.mark_as_debug),
..BlockHeader::default()
};
let encrypted_header = EncryptedHeader::default();
let mut block = DXBBlock::new(
routing_header,
block_header,
encrypted_header,
input.dxb,
);
block.set_receivers(remote_execution_target.endpoints());
unsafe {
self.clone().register_shared_containers_for_endpoints(
&(remote_execution_target
.endpoints()
.iter()
.collect::<Vec<_>>()),
input.shared_values,
)?;
}
let responses = self
.com_hub
.send_own_block_await_response(block, ResponseOptions::default())
.await;
let self_clone = self.clone();
let futures_with_endpoint = responses
.into_iter()
.filter(|response| {
response.is_err()
|| matches!(response, Ok(re) if re.endpoint().is_some())
})
.map(|response| {
let self_clone = self_clone.clone();
let endpoint = response
.as_ref()
.map(|r| {
r.endpoint()
.cloned()
.expect("Expected endpoint to be present")
})
.unwrap_or_else(|e| e.endpoint().clone());
(
async move {
let response = response?;
let incoming_section = response.take_incoming_section();
RuntimeInternal::execute_incoming_section(
self_clone,
incoming_section,
None,
)
.await
.0
},
endpoint,
)
});
let (future, endpoint) = futures_with_endpoint
.into_iter()
.unzip::<_, _, Vec<_>, Vec<_>>();
Ok(join_all(future)
.await
.into_iter()
.zip(endpoint)
.collect::<Vec<_>>())
}
pub async fn execute_instructions_remote(
self: Rc<RuntimeInternal>,
endpoints: Vec<Endpoint>,
instructions_input: Vec<InstructionInput>,
mark_as_debug: bool,
) -> Result<Vec<(RemoteExecutionResult, Endpoint)>, SubscriberError> {
let dxb = core_compile(
&self.pointer_availability_lookup(),
&endpoints,
instructions_input,
self.shared_references_cache_mut().deref_mut(),
);
let remote_execution_context = RemoteExecutionContext::new(
endpoints,
ExecutionMode::Static,
Runtime::from(self.clone()),
);
self.execute_remote(
&remote_execution_context.target,
dxb,
RemoteExecutionOptions {
mark_as_debug,
is_end_of_context: true,
},
)
.await
}
pub async fn execute_instructions_remote_single_receiver(
self: Rc<RuntimeInternal>,
endpoint: Endpoint,
instructions_input: Vec<InstructionInput>,
mark_as_debug: bool,
) -> RemoteExecutionResult {
RuntimeInternal::execute_instructions_remote(
self,
vec![endpoint],
instructions_input,
mark_as_debug,
)
.await?
.remove(0)
.0
}
pub(crate) async fn execute_incoming_section(
self: Rc<RuntimeInternal>,
mut incoming_section: IncomingSection,
shared_values: Option<Vec<SharedContainer>>,
) -> (
Result<Option<ValueContainer>, ExecutionError>,
Endpoint,
OutgoingContextId,
bool,
) {
let section_context_id =
incoming_section.get_section_context_id().clone();
let mut context = Self::take_or_create_execution_context(
self.clone(),
§ion_context_id,
&incoming_section,
);
info!(
"Executing incoming section with index: {}",
incoming_section.get_section_index()
);
let mut result = None;
let mut last_block = None;
loop {
let block = incoming_section.next().await;
if let Some(block) = block {
let res = RuntimeInternal::execute_dxb_block_local(
self.clone(),
block.clone(),
Some(&mut context),
shared_values.clone(),
)
.await;
if let Err(err) = res {
return (
Err(err),
block.sender().clone(),
block.block_header.context_id,
block.block_header.flags_and_timestamp.is_debug_block(),
);
}
result = res.unwrap();
last_block = Some(block);
} else {
break;
}
}
if last_block.is_none() {
unreachable!("Incoming section must contain at least one block");
}
let last_block = last_block.unwrap();
let sender_endpoint = last_block.sender().clone();
let context_id = last_block.block_header.context_id;
let is_end_of_context = last_block
.block_header
.flags_and_timestamp
.is_end_of_context();
let is_debug =
last_block.block_header.flags_and_timestamp.is_debug_block();
if !is_end_of_context {
self.execution_contexts
.borrow_mut()
.insert(section_context_id, context);
}
(Ok(result), sender_endpoint, context_id, is_debug)
}
async fn execute_dxb_block_local(
self: Rc<RuntimeInternal>,
block: DXBBlock,
execution_context: Option<&mut ExecutionContext>,
shared_values: Option<Vec<SharedContainer>>,
) -> Result<Option<ValueContainer>, ExecutionError> {
let mut execution_context = Runtime::from(self.clone())
.get_or_create_execution_context(execution_context);
let execution_context_mut = execution_context.as_mut();
if !core::matches!(execution_context_mut, ExecutionContext::Local(_)) {
unreachable!(
"Execution context must be local for executing a DXB block"
);
}
let dxb = block.body;
info!("executing on {}:\n", self.endpoint());
print_disassembled_with_options(&dxb, DisassemblerOptions::default());
let _end_execution =
block.block_header.flags_and_timestamp.is_end_of_section();
RuntimeInternal::execute_dxb(
self,
DXBWithSharedValues::new(dxb, shared_values.unwrap_or_default()),
None,
Some(execution_context),
false,
)
.await
}
pub fn register_shared_containers_for_single_endpoint(
self: Rc<Self>,
endpoint: &Endpoint,
shared_containers: Vec<SharedContainer>,
) {
unsafe {
self.register_shared_containers_for_endpoints(
&[endpoint],
shared_containers,
)
.unwrap()
}
}
pub unsafe fn register_shared_containers_for_endpoints(
self: Rc<Self>,
endpoints: &[&Endpoint],
shared_containers: Vec<SharedContainer>,
) -> Result<(), SubscriberError> {
if endpoints.is_empty() {
panic!("endpoints must not be empty");
}
for shared_container in shared_containers {
if shared_container.is_self_owned() {
for endpoint in endpoints {
unsafe {
self.clone()
.subscribe_endpoint_to_owned_value(
&shared_container,
endpoint,
shared_container
.derive_reference_with_max_mutability()
.reference_mutability(),
)
.map_err(SubscriberError::Observer)?
}
self.shared_references_cache
.borrow_mut()
.register_owned_shared_container(
&shared_container
.derive_reference_with_max_mutability(),
);
}
}
}
Ok(())
}
pub fn get_env(&self) -> IndexMap<String, String, RandomState> {
self.config().env.clone().unwrap_or_default()
}
pub fn get_name(&self) -> Option<String> {
self.config().name.clone()
}
pub fn create_dif_interface(&self) -> DIFInterface {
let count = *self.transceiver_counter.borrow();
let id = TransceiverId::Dif(count);
self.transceiver_counter.replace(count + 1);
DIFInterface::new(id, self.pointer_address_provider.clone())
}
}