use quickfix_ffi::{
FixFileMessageStoreFactory_new, FixMemoryMessageStoreFactory_new,
FixMessageStoreFactory_delete, FixMessageStoreFactory_t, FixNullMessageStoreFactory_new,
};
use crate::{QuickFixError, SessionSettings};
#[cfg(feature = "build-with-mysql")]
pub mod mysql;
#[cfg(feature = "build-with-postgres")]
pub mod postgres;
pub trait FfiMessageStoreFactory {
fn as_ffi_ptr(&self) -> FixMessageStoreFactory_t;
}
#[derive(Debug)]
pub struct FileMessageStoreFactory(FixMessageStoreFactory_t);
impl FileMessageStoreFactory {
pub fn try_new(settings: &SessionSettings) -> Result<Self, QuickFixError> {
unsafe { FixFileMessageStoreFactory_new(settings.0) }
.map(Self)
.ok_or_else(QuickFixError::from_last_error)
}
}
impl FfiMessageStoreFactory for FileMessageStoreFactory {
fn as_ffi_ptr(&self) -> FixMessageStoreFactory_t {
self.0
}
}
impl Drop for FileMessageStoreFactory {
fn drop(&mut self) {
unsafe { FixMessageStoreFactory_delete(self.0) }
}
}
#[derive(Debug)]
pub struct MemoryMessageStoreFactory(FixMessageStoreFactory_t);
impl MemoryMessageStoreFactory {
pub fn new() -> Self {
Self::default()
}
}
impl FfiMessageStoreFactory for MemoryMessageStoreFactory {
fn as_ffi_ptr(&self) -> FixMessageStoreFactory_t {
self.0
}
}
impl Default for MemoryMessageStoreFactory {
fn default() -> Self {
unsafe { FixMemoryMessageStoreFactory_new() }
.map(Self)
.expect("Fail to allocate MemoryMessageStore")
}
}
impl Drop for MemoryMessageStoreFactory {
fn drop(&mut self) {
unsafe { FixMessageStoreFactory_delete(self.0) }
}
}
#[derive(Debug)]
pub struct NullMessageStoreFactory(FixMessageStoreFactory_t);
impl NullMessageStoreFactory {
pub fn new() -> Self {
Self::default()
}
}
impl FfiMessageStoreFactory for NullMessageStoreFactory {
fn as_ffi_ptr(&self) -> FixMessageStoreFactory_t {
self.0
}
}
impl Default for NullMessageStoreFactory {
fn default() -> Self {
unsafe { FixNullMessageStoreFactory_new() }
.map(Self)
.expect("Fail to allocate NullMessageStore")
}
}
impl Drop for NullMessageStoreFactory {
fn drop(&mut self) {
unsafe { FixMessageStoreFactory_delete(self.0) }
}
}