Skip to content

Commit

Permalink
[#69] Move traits into separate directory
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Jan 26, 2024
1 parent 82fbb5f commit c8c5ca9
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 51 deletions.
9 changes: 3 additions & 6 deletions iceoryx2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,9 @@ pub mod port;

pub(crate) mod raw_sample;

/// The interface for the payload that is received by a [`crate::port::subscriber::Subscriber`].
pub mod sample;

/// The payload that is received by a [`crate::port::subscriber::Subscriber`].
pub mod sample_impl;

/// The interface for the payload that is sent by a [`crate::port::publisher::Publisher`].
pub mod sample_mut;

/// The payload that is sent by a [`crate::port::publisher::Publisher`].
pub mod sample_mut_impl;

Expand All @@ -305,3 +299,6 @@ pub mod service;

/// Loads a meaninful subset to cover 90% of the iceoryx2 communication use cases.
pub mod prelude;

/// The interfaces of all public constructs.
pub mod traits;
2 changes: 1 addition & 1 deletion iceoryx2/src/port/listener_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::{port::port_identifiers::UniqueListenerId, service};
use std::{marker::PhantomData, time::Duration};

use super::event_id::EventId;
use super::listener::{Listener, ListenerCreateError};
use crate::traits::listener::{Listener, ListenerCreateError};

/// Represents the receiving endpoint of an event based communication.
#[derive(Debug)]
Expand Down
8 changes: 0 additions & 8 deletions iceoryx2/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,14 @@ pub(crate) mod details;

/// Defines the event id used to identify the source of an event.
pub mod event_id;
/// The interface of the receiving endpoint for event based communication
pub mod listener;
/// Receiving endpoint (port) for event based communication
pub mod listener_impl;
/// The interface of the sending endpoint for event based communication
pub mod notifier;
/// Sending endpoint (port) for event based communication
pub mod notifier_impl;
/// Defines port specific unique ids. Used to identify source/destination while communicating.
pub mod port_identifiers;
/// The interface of the sending endpoint for publish-subscribe based communication
pub mod publisher;
/// Sending endpoint (port) for publish-subscribe based communication
pub mod publisher_impl;
/// The interface of the receiving endpoint for publish-subscribe based communication
pub mod subscriber;
/// Receiving endpoint (port) for publish-subscribe based communication
pub mod subscriber_impl;

Expand Down
7 changes: 2 additions & 5 deletions iceoryx2/src/port/notifier_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
//!
//! See also [`crate::port::notifier::Notifier`]
use crate::traits::notifier::{Notifier, NotifierConnectionUpdateFailure, NotifierCreateError};
use crate::{
port::port_identifiers::UniqueNotifierId,
service::{self, naming_scheme::event_concept_name},
Expand All @@ -47,11 +48,7 @@ use iceoryx2_cal::named_concept::NamedConceptBuilder;
use iceoryx2_cal::{dynamic_storage::DynamicStorage, event::NotifierBuilder};
use std::{cell::UnsafeCell, marker::PhantomData};

use super::{
event_id::EventId,
notifier::{Notifier, NotifierConnectionUpdateFailure, NotifierCreateError},
port_identifiers::UniqueListenerId,
};
use super::{event_id::EventId, port_identifiers::UniqueListenerId};

#[derive(Debug, Default)]
struct ListenerConnections<'config, Service: service::Details<'config>> {
Expand Down
11 changes: 5 additions & 6 deletions iceoryx2/src/port/publisher_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,21 @@ use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use std::{alloc::Layout, marker::PhantomData, mem::MaybeUninit};

use super::port_identifiers::{UniquePublisherId, UniqueSubscriberId};
use super::publisher::internal::PublisherMgmt;
use super::publisher::{
PublisherCreateError, PublisherLoan, PublisherLoanError, PublisherSendError,
};
use crate::message::Message;
use crate::port::details::subscriber_connections::*;
use crate::port::publisher::Publisher;
use crate::port::{DegrationAction, DegrationCallback};
use crate::raw_sample::RawSampleMut;
use crate::sample_mut::{internal::SampleMgmt, SampleMut, UninitializedSampleMut};
use crate::service;
use crate::service::config_scheme::data_segment_config;
use crate::service::header::publish_subscribe::Header;
use crate::service::naming_scheme::data_segment_name;
use crate::service::port_factory::publisher::{LocalPublisherConfig, UnableToDeliverStrategy};
use crate::service::static_config::publish_subscribe;
use crate::traits::publisher::{
internal::PublisherMgmt, Publisher, PublisherCreateError, PublisherLoan, PublisherLoanError,
PublisherSendError,
};
use crate::traits::sample_mut::{internal::SampleMgmt, SampleMut, UninitializedSampleMut};
use crate::{config, sample_mut_impl::SampleMutImpl};
use iceoryx2_bb_container::queue::Queue;
use iceoryx2_bb_elementary::allocator::AllocationError;
Expand Down
5 changes: 3 additions & 2 deletions iceoryx2/src/port/subscriber_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ use crate::{

use super::details::publisher_connections::{Connection, ConnectionFailure, PublisherConnections};
use super::port_identifiers::{UniquePublisherId, UniqueSubscriberId};
use super::subscriber::internal::SubscriberMgmt;
use super::subscriber::{Subscriber, SubscriberCreateError, SubscriberReceiveError};
use super::DegrationCallback;
use crate::traits::subscriber::{
internal::SubscriberMgmt, Subscriber, SubscriberCreateError, SubscriberReceiveError,
};

/// The receiving endpoint of a publish-subscribe communication.
#[derive(Debug)]
Expand Down
15 changes: 9 additions & 6 deletions iceoryx2/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

pub use crate::iox2::Iox2;
pub use crate::iox2::Iox2Event;
pub use crate::port::{
event_id::EventId, listener::Listener, notifier::Notifier, publisher::Publisher,
publisher::PublisherLoan, subscriber::Subscriber,
};
pub use crate::sample::Sample;
pub use crate::sample_mut::{SampleMut, UninitializedSampleMut};
pub use crate::port::event_id::EventId;
pub use crate::service::{process_local, service_name::ServiceName, zero_copy, Details, Service};
pub use crate::traits::{
listener::Listener,
notifier::Notifier,
publisher::{Publisher, PublisherLoan},
sample::Sample,
sample_mut::{SampleMut, UninitializedSampleMut},
subscriber::Subscriber,
};
4 changes: 2 additions & 2 deletions iceoryx2/src/sample_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
use std::{fmt::Debug, ops::Deref};

use crate::port::subscriber::internal::SubscriberMgmt;
use crate::raw_sample::RawSample;
use crate::service::header::publish_subscribe::Header;
use crate::{raw_sample::RawSample, sample::Sample};
use crate::traits::{sample::Sample, subscriber::internal::SubscriberMgmt};

/// It stores the payload and is acquired by the [`crate::port::subscriber::Subscriber`] whenever
/// it receives new data from a [`crate::port::publisher::Publisher`] via
Expand Down
8 changes: 4 additions & 4 deletions iceoryx2/src/sample_mut_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
//!
//! See also, [`crate::sample_mut::SampleMut`].
use crate::{
port::publisher::internal::PublisherMgmt,
raw_sample::RawSampleMut,
use crate::traits::{
publisher::internal::PublisherMgmt,
sample_mut::{internal::SampleMgmt, SampleMut, UninitializedSampleMut},
service::header::publish_subscribe::Header,
};
use crate::{raw_sample::RawSampleMut, service::header::publish_subscribe::Header};

use iceoryx2_cal::shared_memory::*;
use std::{fmt::Debug, mem::MaybeUninit};

Expand Down
3 changes: 2 additions & 1 deletion iceoryx2/src/service/port_factory/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use std::fmt::Debug;

use iceoryx2_bb_log::fail;

use crate::port::{listener::ListenerCreateError, listener_impl::ListenerImpl};
use crate::port::listener_impl::ListenerImpl;
use crate::service;
use crate::traits::listener::ListenerCreateError;

use super::event::PortFactory;

Expand Down
3 changes: 2 additions & 1 deletion iceoryx2/src/service/port_factory/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
//! ```
use std::fmt::Debug;

use crate::port::{event_id::EventId, notifier::NotifierCreateError, notifier_impl::NotifierImpl};
use crate::port::{event_id::EventId, notifier_impl::NotifierImpl};
use crate::traits::notifier::NotifierCreateError;
use iceoryx2_bb_log::fail;

use crate::service;
Expand Down
4 changes: 3 additions & 1 deletion iceoryx2/src/service/port_factory/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ use iceoryx2_bb_log::fail;
use serde::{de::Visitor, Deserialize, Serialize};

use super::publish_subscribe::PortFactory;
use crate::{port::publisher::PublisherCreateError, port::publisher_impl::PublisherImpl, service};
use crate::{
port::publisher_impl::PublisherImpl, service, traits::publisher::PublisherCreateError,
};

/// Defines the strategy the [`PublisherImpl`] shall pursue in
/// [`crate::sample_mut::SampleMut::send()`] or
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2/src/service/port_factory/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::fmt::Debug;
use iceoryx2_bb_log::fail;

use crate::{
port::subscriber::SubscriberCreateError, port::subscriber_impl::SubscriberImpl, service,
port::subscriber_impl::SubscriberImpl, service, traits::subscriber::SubscriberCreateError,
};

use super::publish_subscribe::PortFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use std::time::Duration;

use iceoryx2_cal::event::ListenerWaitError;

use super::event_id::EventId;
use crate::port::event_id::EventId;

/// Defines the failures that can occur when a [`Listener`] is created with the
/// [`crate::service::port_factory::listener::PortFactoryListener`].
Expand Down
29 changes: 29 additions & 0 deletions iceoryx2/src/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

/// The interface for the payload that is received by a [`crate::port::subscriber::Subscriber`].
pub mod sample;

/// The interface for the payload that is sent by a [`crate::port::publisher::Publisher`].
pub mod sample_mut;

/// The interface of the receiving endpoint for publish-subscribe based communication
pub mod subscriber;

/// The interface of the sending endpoint for publish-subscribe based communication
pub mod publisher;

/// The interface of the sending endpoint for event based communication
pub mod notifier;

/// The interface of the receiving endpoint for event based communication
pub mod listener;
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
//!
//! See also [`crate::port::notifier_impl::NotifierImpl`]
use super::event_id::EventId;
use crate::port::event_id::EventId;

/// Failures that can occur when a new [`Notifier`] is created with the
/// [`crate::service::port_factory::notifier::PortFactoryNotifier`].
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use std::fmt::Debug;

use crate::sample_impl::SampleImpl;

use super::details::publisher_connections::ConnectionFailure;
use crate::port::details::publisher_connections::ConnectionFailure;

/// Defines the failure that can occur when receiving data with [`Subscriber::receive()`].
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
Expand Down
3 changes: 1 addition & 2 deletions iceoryx2/tests/publisher_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
mod publisher {
use std::time::{Duration, Instant};

use iceoryx2::port::publisher::PublisherLoanError;
use iceoryx2::prelude::*;
use iceoryx2::sample_mut::UninitializedSampleMut;
use iceoryx2::service::port_factory::publisher::UnableToDeliverStrategy;
use iceoryx2::service::{service_name::ServiceName, Service};
use iceoryx2::traits::publisher::*;
use iceoryx2_bb_posix::barrier::{BarrierBuilder, BarrierHandle};
use iceoryx2_bb_posix::unique_system_id::UniqueSystemId;
use iceoryx2_bb_testing::assert_that;
Expand Down
4 changes: 2 additions & 2 deletions iceoryx2/tests/service_publish_subscribe_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#[generic_tests::define]
mod service_publish_subscribe {
use iceoryx2::config::Config;
use iceoryx2::port::publisher::{PublisherCreateError, PublisherLoanError};
use iceoryx2::port::subscriber::SubscriberCreateError;
use iceoryx2::prelude::*;
use iceoryx2::service::builder::publish_subscribe::PublishSubscribeCreateError;
use iceoryx2::service::builder::publish_subscribe::PublishSubscribeOpenError;
use iceoryx2::service::port_factory::publisher::UnableToDeliverStrategy;
use iceoryx2::service::static_config::StaticConfig;
use iceoryx2::service::{Details, Service};
use iceoryx2::traits::publisher::{PublisherCreateError, PublisherLoanError};
use iceoryx2::traits::subscriber::SubscriberCreateError;
use iceoryx2_bb_posix::unique_system_id::UniqueSystemId;
use iceoryx2_bb_testing::assert_that;

Expand Down

0 comments on commit c8c5ca9

Please sign in to comment.