Skip to content

Commit

Permalink
[eclipse-iceoryx#532] Add repr(C) to all structs inside the dynamic s…
Browse files Browse the repository at this point in the history
…ervice segment; add data segment type to the publisher port details
  • Loading branch information
elfenpiff committed Nov 28, 2024
1 parent be56154 commit b15ae4f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
13 changes: 11 additions & 2 deletions iceoryx2/src/port/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ use crate::raw_sample::RawSampleMut;
use crate::sample_mut_uninit::SampleMutUninit;
use crate::service::builder::publish_subscribe::CustomPayloadMarker;
use crate::service::config_scheme::{connection_config, data_segment_config};
use crate::service::dynamic_config::publish_subscribe::{PublisherDetails, SubscriberDetails};
use crate::service::dynamic_config::publish_subscribe::{
DataSegmentType, PublisherDetails, SubscriberDetails,
};
use crate::service::header::publish_subscribe::Header;
use crate::service::naming_scheme::{
data_segment_name, extract_publisher_id_from_connection, extract_subscriber_id_from_connection,
Expand All @@ -135,7 +137,7 @@ use iceoryx2_cal::shared_memory::{
SharedMemory, SharedMemoryBuilder, SharedMemoryCreateError, ShmPointer,
};
use iceoryx2_cal::shm_allocator::pool_allocator::PoolAllocator;
use iceoryx2_cal::shm_allocator::{self, PointerOffset, ShmAllocationError};
use iceoryx2_cal::shm_allocator::{self, AllocationStrategy, PointerOffset, ShmAllocationError};
use iceoryx2_cal::zero_copy_connection::{
ZeroCopyConnection, ZeroCopyCreationError, ZeroCopySendError, ZeroCopySender,
};
Expand Down Expand Up @@ -582,6 +584,12 @@ impl<Service: service::Service, Payload: Debug + ?Sized, UserHeader: Debug>
.messaging_pattern
.required_amount_of_samples_per_data_segment(config.max_loaned_samples);

let data_segment_type = if config.allocation_strategy == AllocationStrategy::Static {
DataSegmentType::Static
} else {
DataSegmentType::Dynamic
};

let data_segment = fail!(from origin,
when Self::create_data_segment(&port_id, service.__internal_state().shared_node.config(), number_of_samples, static_config, &config),
with PublisherCreateError::UnableToCreateDataSegment,
Expand Down Expand Up @@ -653,6 +661,7 @@ impl<Service: service::Service, Payload: Debug + ?Sized, UserHeader: Debug>
.get()
.publish_subscribe()
.add_publisher_id(PublisherDetails {
data_segment_type,
publisher_id: port_id,
number_of_samples,
max_slice_len,
Expand Down
4 changes: 4 additions & 0 deletions iceoryx2/src/service/dynamic_config/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::{

use super::PortCleanupAction;

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub(crate) struct DynamicConfigSettings {
pub number_of_listeners: usize,
Expand All @@ -46,18 +47,21 @@ pub(crate) struct DynamicConfigSettings {

/// The dynamic configuration of an [`crate::service::messaging_pattern::MessagingPattern::Event`]
/// based service. Contains dynamic parameters like the connected endpoints etc..
#[repr(C)]
#[derive(Debug)]
pub struct DynamicConfig {
pub(crate) listeners: Container<ListenerDetails>,
pub(crate) notifiers: Container<NotifierDetails>,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub(crate) struct ListenerDetails {
pub(crate) listener_id: UniqueListenerId,
pub(crate) node_id: NodeId,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub(crate) struct NotifierDetails {
pub(crate) notifier_id: UniqueNotifierId,
Expand Down
12 changes: 12 additions & 0 deletions iceoryx2/src/service/dynamic_config/publish_subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,31 @@ use crate::{

use super::PortCleanupAction;

#[repr(C)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub(crate) enum DataSegmentType {
Dynamic,
Static,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub(crate) struct DynamicConfigSettings {
pub number_of_subscribers: usize,
pub number_of_publishers: usize,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub(crate) struct PublisherDetails {
pub(crate) publisher_id: UniquePublisherId,
pub(crate) node_id: NodeId,
pub(crate) number_of_samples: usize,
pub(crate) max_slice_len: usize,
pub(crate) data_segment_type: DataSegmentType,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub(crate) struct SubscriberDetails {
pub(crate) subscriber_id: UniqueSubscriberId,
Expand All @@ -61,6 +72,7 @@ pub(crate) struct SubscriberDetails {

/// The dynamic configuration of an [`crate::service::messaging_pattern::MessagingPattern::Event`]
/// based service. Contains dynamic parameters like the connected endpoints etc..
#[repr(C)]
#[derive(Debug)]
pub struct DynamicConfig {
pub(crate) subscribers: Container<SubscriberDetails>,
Expand Down

0 comments on commit b15ae4f

Please sign in to comment.