ouch_connect/
lib.rs

1pub mod clt;
2pub mod svc;
3
4use std::num::NonZeroUsize;
5
6use clt::{CltAuto, CltManual};
7use links_bindings_python::prelude::{create_register_atexit, ConId, ConType};
8use pyo3::prelude::*;
9use svc::{SvcAuto, SvcManual};
10
11const DEFAULT_MAX_HBEAT_INTERVAL: f64 = 15.0;
12const DEFAULT_USR_PWD: &str = "dummy";
13const DEFAULT_CONNECT_TIMEOUT: f64 = 1.0;
14const DEFAULT_RETRY_CONNECT_AFTER: f64 = 0.1;
15const DEFAULT_IO_TIMEOUT: f64 = 0.5;
16const DEFAULT_MAX_CONNECTIONS: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(1) };
17
18create_register_atexit!();
19/// This is a Python extension-module over the `ouch_connect_nonblocking` library. Please refer to readme for more information.
20#[pymodule]
21fn ouch_connect(_py: Python, m: &PyModule) -> PyResult<()> {
22    register_atexit()?;
23    // IMPORTANT - py03 logger can cause background threads to block or deadlock as they need to acquire the GIL to log messages in python.
24    // IMPORTANT - py03_log::init() will enable all logging including debug to be passed to python, even if PYTHON only logs INFO.
25    // hence being conservative and only allowing INFO & above to be logged in release mode
26    // https://docs.rs/pyo3-log/latest/pyo3_log/ LOGGING WILL DEAD LOCK PYTHON
27    #[cfg(debug_assertions)]
28    {
29        // pyo3_log::init();
30        let log = pyo3_log::try_init();
31        if log.is_err() {
32            log::info!("Looks like someone initialized logging prior to pyo3_log::try_init() -> {}", log.unwrap_err());
33        }
34    }
35    #[cfg(not(debug_assertions))]
36    {
37        use pyo3_log::{Caching, Logger};
38        Logger::new(_py, Caching::LoggersAndLevels)?.filter(log::LevelFilter::Info).install().expect("Someone installed a logger before us :-(");
39    }
40
41    m.add_class::<ConId>()?;
42    m.add_class::<ConType>()?;
43    m.add_class::<CltAuto>()?;
44    m.add_class::<CltManual>()?;
45    m.add_class::<SvcManual>()?;
46    m.add_class::<SvcAuto>()?;
47
48    Ok(())
49}