Skip to content

Commit

Permalink
[eclipse-iceoryx#264] Add update_connection call to C API
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Sep 19, 2024
1 parent 5bd86ec commit f0bf0ff
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
33 changes: 33 additions & 0 deletions iceoryx2-ffi/ffi/src/api/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
};

use iceoryx2::port::publisher::{Publisher, PublisherLoanError, PublisherSendError};
use iceoryx2::port::update_connections::UpdateConnections;
use iceoryx2::prelude::*;
use iceoryx2_bb_elementary::static_assert::*;
use iceoryx2_ffi_macros::iceoryx2_ffi;
Expand Down Expand Up @@ -419,6 +420,38 @@ pub unsafe extern "C" fn iox2_publisher_loan(
}
}

/// Updates all connections to new and obsolete subscriber ports and automatically delivery the history if
/// requested.
///
/// # Arguments
///
/// * `subscriber_handle` - Must be a valid [`iox2_subscriber_ref_h`]
/// obtained by [`iox2_port_factory_subscriber_builder_create`](crate::iox2_port_factory_subscriber_builder_create) and
/// casted by [`iox2_cast_subscriber_ref_h`].
///
/// # Safety
///
/// * The `subscriber_handle` is still valid after the return of this function and can be use in another function call.
#[no_mangle]
pub unsafe extern "C" fn iox2_publisher_update_connections(
publisher_handle: iox2_publisher_ref_h,
) -> c_int {
debug_assert!(!publisher_handle.is_null());

let publisher = &mut *publisher_handle.as_type();

match publisher.service_type {
iox2_service_type_e::IPC => match publisher.value.as_ref().ipc.update_connections() {
Ok(()) => IOX2_OK,
Err(error) => error.into_c_int(),
},
iox2_service_type_e::LOCAL => match publisher.value.as_ref().local.update_connections() {
Ok(()) => IOX2_OK,
Err(error) => error.into_c_int(),
},
}
}

/// This function needs to be called to destroy the publisher!
///
/// # Arguments
Expand Down
33 changes: 32 additions & 1 deletion iceoryx2-ffi/ffi/src/api/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::api::{
use crate::{iox2_unique_subscriber_id_h, iox2_unique_subscriber_id_t};

use iceoryx2::port::subscriber::{Subscriber, SubscriberReceiveError};
use iceoryx2::port::update_connections::ConnectionFailure;
use iceoryx2::port::update_connections::{ConnectionFailure, UpdateConnections};
use iceoryx2::prelude::*;
use iceoryx2_bb_elementary::static_assert::*;
use iceoryx2_ffi_macros::iceoryx2_ffi;
Expand Down Expand Up @@ -358,6 +358,37 @@ pub unsafe extern "C" fn iox2_subscriber_has_samples(
}
}

/// Updates all connections to new and obsolete publisher ports
///
/// # Arguments
///
/// * `subscriber_handle` - Must be a valid [`iox2_subscriber_ref_h`]
/// obtained by [`iox2_port_factory_subscriber_builder_create`](crate::iox2_port_factory_subscriber_builder_create) and
/// casted by [`iox2_cast_subscriber_ref_h`].
///
/// # Safety
///
/// * The `subscriber_handle` is still valid after the return of this function and can be use in another function call.
#[no_mangle]
pub unsafe extern "C" fn iox2_subscriber_update_connections(
subscriber_handle: iox2_subscriber_ref_h,
) -> c_int {
debug_assert!(!subscriber_handle.is_null());

let subscriber = &mut *subscriber_handle.as_type();

match subscriber.service_type {
iox2_service_type_e::IPC => match subscriber.value.as_ref().ipc.update_connections() {
Ok(()) => IOX2_OK,
Err(error) => error.into_c_int(),
},
iox2_service_type_e::LOCAL => match subscriber.value.as_ref().local.update_connections() {
Ok(()) => IOX2_OK,
Err(error) => error.into_c_int(),
},
}
}

/// This function needs to be called to destroy the subscriber!
///
/// # Arguments
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2/src/port/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ impl<Service: service::Service, Payload: Debug, UserHeader: Debug>
// END: sliced API
////////////////////////

impl<Service: service::Service, Payload: Debug, UserHeader: Debug> UpdateConnections
impl<Service: service::Service, Payload: Debug + ?Sized, UserHeader: Debug> UpdateConnections
for Publisher<Service, Payload, UserHeader>
{
fn update_connections(&self) -> Result<(), ConnectionFailure> {
Expand Down

0 comments on commit f0bf0ff

Please sign in to comment.