use std::os::raw::{c_char, c_void};
use super::{HddsDataReader, HddsDataWriter, HddsError};
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct HddsSubscriptionMatchedStatus {
pub total_count: u32,
pub total_count_change: i32,
pub current_count: u32,
pub current_count_change: i32,
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct HddsPublicationMatchedStatus {
pub total_count: u32,
pub total_count_change: i32,
pub current_count: u32,
pub current_count_change: i32,
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct HddsLivelinessChangedStatus {
pub alive_count: u32,
pub alive_count_change: i32,
pub not_alive_count: u32,
pub not_alive_count_change: i32,
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct HddsSampleLostStatus {
pub total_count: u32,
pub total_count_change: i32,
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct HddsSampleRejectedStatus {
pub total_count: u32,
pub total_count_change: i32,
pub last_reason: u32,
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct HddsDeadlineMissedStatus {
pub total_count: u32,
pub total_count_change: i32,
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct HddsIncompatibleQosStatus {
pub total_count: u32,
pub total_count_change: i32,
pub last_policy_id: u32,
}
pub type HddsOnDataAvailable =
Option<unsafe extern "C" fn(data: *const u8, len: usize, user_data: *mut c_void)>;
pub type HddsOnSubscriptionMatched = Option<
unsafe extern "C" fn(status: *const HddsSubscriptionMatchedStatus, user_data: *mut c_void),
>;
pub type HddsOnPublicationMatched = Option<
unsafe extern "C" fn(status: *const HddsPublicationMatchedStatus, user_data: *mut c_void),
>;
pub type HddsOnLivelinessChanged = Option<
unsafe extern "C" fn(status: *const HddsLivelinessChangedStatus, user_data: *mut c_void),
>;
pub type HddsOnSampleLost =
Option<unsafe extern "C" fn(status: *const HddsSampleLostStatus, user_data: *mut c_void)>;
pub type HddsOnSampleRejected =
Option<unsafe extern "C" fn(status: *const HddsSampleRejectedStatus, user_data: *mut c_void)>;
pub type HddsOnDeadlineMissed =
Option<unsafe extern "C" fn(status: *const HddsDeadlineMissedStatus, user_data: *mut c_void)>;
pub type HddsOnIncompatibleQos =
Option<unsafe extern "C" fn(status: *const HddsIncompatibleQosStatus, user_data: *mut c_void)>;
pub type HddsOnSampleWritten = Option<
unsafe extern "C" fn(data: *const u8, len: usize, sequence_number: u64, user_data: *mut c_void),
>;
pub type HddsOnOfferedDeadlineMissed =
Option<unsafe extern "C" fn(instance_handle: u64, user_data: *mut c_void)>;
pub type HddsOnOfferedIncompatibleQos = Option<
unsafe extern "C" fn(policy_id: u32, policy_name: *const c_char, user_data: *mut c_void),
>;
pub type HddsOnLivelinessLost = Option<unsafe extern "C" fn(user_data: *mut c_void)>;
#[repr(C)]
pub struct HddsReaderListener {
pub on_data_available: HddsOnDataAvailable,
pub on_subscription_matched: HddsOnSubscriptionMatched,
pub on_liveliness_changed: HddsOnLivelinessChanged,
pub on_sample_lost: HddsOnSampleLost,
pub on_sample_rejected: HddsOnSampleRejected,
pub on_deadline_missed: HddsOnDeadlineMissed,
pub on_incompatible_qos: HddsOnIncompatibleQos,
pub user_data: *mut c_void,
}
unsafe impl Send for HddsReaderListener {}
unsafe impl Sync for HddsReaderListener {}
#[repr(C)]
pub struct HddsWriterListener {
pub on_sample_written: HddsOnSampleWritten,
pub on_publication_matched: HddsOnPublicationMatched,
pub on_offered_deadline_missed: HddsOnOfferedDeadlineMissed,
pub on_offered_incompatible_qos: HddsOnOfferedIncompatibleQos,
pub on_liveliness_lost: HddsOnLivelinessLost,
pub user_data: *mut c_void,
}
unsafe impl Send for HddsWriterListener {}
unsafe impl Sync for HddsWriterListener {}
#[no_mangle]
pub unsafe extern "C" fn hdds_reader_set_listener(
reader: *mut HddsDataReader,
listener: *const HddsReaderListener,
) -> HddsError {
if reader.is_null() || listener.is_null() {
return HddsError::HddsInvalidArgument;
}
let _ = listener;
log::warn!("hdds_reader_set_listener: not yet implemented");
HddsError::HddsUnsupported
}
#[no_mangle]
pub unsafe extern "C" fn hdds_reader_clear_listener(reader: *mut HddsDataReader) -> HddsError {
if reader.is_null() {
return HddsError::HddsInvalidArgument;
}
log::warn!("hdds_reader_clear_listener: not yet implemented");
HddsError::HddsUnsupported
}
#[no_mangle]
pub unsafe extern "C" fn hdds_writer_set_listener(
writer: *mut HddsDataWriter,
listener: *const HddsWriterListener,
) -> HddsError {
if writer.is_null() || listener.is_null() {
return HddsError::HddsInvalidArgument;
}
let _ = listener;
log::warn!("hdds_writer_set_listener: not yet implemented");
HddsError::HddsUnsupported
}
#[no_mangle]
pub unsafe extern "C" fn hdds_writer_clear_listener(writer: *mut HddsDataWriter) -> HddsError {
if writer.is_null() {
return HddsError::HddsInvalidArgument;
}
log::warn!("hdds_writer_clear_listener: not yet implemented");
HddsError::HddsUnsupported
}