use crate::core::{RiResult, RiServiceContext};
pub trait ServiceModule: Send + Sync {
fn name(&self) -> &str;
fn is_critical(&self) -> bool {
true
}
fn priority(&self) -> i32 {
0
}
fn dependencies(&self) -> Vec<&str> {
Vec::new()
}
fn init(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn before_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn after_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn before_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn after_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
}
#[async_trait::async_trait]
pub trait RiModule: Send + Sync {
fn name(&self) -> &str;
fn is_critical(&self) -> bool {
true
}
fn priority(&self) -> i32 {
0
}
fn dependencies(&self) -> Vec<&str> {
Vec::new()
}
async fn init(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn before_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn after_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn before_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn after_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
}
#[cfg(feature = "pyo3")]
use pyo3::prelude::*;
#[cfg(feature = "pyo3")]
#[pyclass]
#[pyo3(name = "RiPythonModule")]
#[derive(Clone)]
pub struct RiPythonModule {
#[pyo3(get)]
name: String,
#[pyo3(get)]
is_critical: bool,
#[pyo3(get)]
priority: i32,
#[pyo3(get)]
dependencies: Vec<String>,
}
#[cfg(feature = "pyo3")]
#[pymethods]
impl RiPythonModule {
#[new]
fn new(name: String) -> Self {
RiPythonModule {
name,
is_critical: true,
priority: 0,
dependencies: Vec::new(),
}
}
#[getter]
pub fn name(&self) -> String {
self.name.clone()
}
#[setter]
pub fn set_name(&mut self, name: String) {
self.name = name;
}
#[getter]
pub fn is_critical(&self) -> bool {
self.is_critical
}
#[setter]
pub fn set_is_critical(&mut self, is_critical: bool) {
self.is_critical = is_critical;
}
#[getter]
pub fn priority(&self) -> i32 {
self.priority
}
#[setter]
pub fn set_priority(&mut self, priority: i32) {
self.priority = priority;
}
#[getter]
pub fn dependencies(&self) -> Vec<String> {
self.dependencies.clone()
}
#[setter]
pub fn set_dependencies(&mut self, dependencies: Vec<String>) {
self.dependencies = dependencies;
}
}
#[cfg(feature = "pyo3")]
#[pyclass]
#[derive(Clone)]
pub struct RiPythonModuleAdapter {
#[pyo3(get, set)]
pub name: String,
#[pyo3(get, set)]
pub is_critical: bool,
#[pyo3(get, set)]
pub priority: i32,
#[pyo3(get, set)]
pub dependencies: Vec<String>,
}
#[cfg(feature = "pyo3")]
#[pymethods]
impl RiPythonModuleAdapter {
#[new]
fn new(name: String) -> Self {
RiPythonModuleAdapter {
name,
is_critical: true,
priority: 0,
dependencies: Vec::new(),
}
}
}
#[cfg(feature = "pyo3")]
#[pyclass(subclass)]
#[derive(Clone)]
pub struct RiPythonServiceModule {
name: String,
is_critical: bool,
priority: i32,
dependencies: Vec<String>,
}
#[cfg(feature = "pyo3")]
#[pymethods]
impl RiPythonServiceModule {
#[new]
fn new(name: String) -> Self {
RiPythonServiceModule {
name,
is_critical: true,
priority: 0,
dependencies: Vec::new(),
}
}
#[getter]
pub fn name(&self) -> String {
self.name.clone()
}
#[setter]
pub fn set_name(&mut self, name: String) {
self.name = name;
}
#[getter]
pub fn is_critical(&self) -> bool {
self.is_critical
}
#[setter]
pub fn set_is_critical(&mut self, is_critical: bool) {
self.is_critical = is_critical;
}
#[getter]
pub fn priority(&self) -> i32 {
self.priority
}
#[setter]
pub fn set_priority(&mut self, priority: i32) {
self.priority = priority;
}
#[getter]
pub fn dependencies(&self) -> Vec<String> {
self.dependencies.clone()
}
#[setter]
pub fn set_dependencies(&mut self, dependencies: Vec<String>) {
self.dependencies = dependencies;
}
}
#[cfg(feature = "pyo3")]
#[pyclass(subclass)]
#[derive(Clone)]
pub struct RiPythonAsyncServiceModule {
name: String,
is_critical: bool,
priority: i32,
dependencies: Vec<String>,
}
#[cfg(feature = "pyo3")]
#[pymethods]
impl RiPythonAsyncServiceModule {
#[new]
fn new(name: String) -> Self {
RiPythonAsyncServiceModule {
name,
is_critical: true,
priority: 0,
dependencies: Vec::new(),
}
}
#[getter]
pub fn name(&self) -> String {
self.name.clone()
}
#[setter]
pub fn set_name(&mut self, name: String) {
self.name = name;
}
#[getter]
pub fn is_critical(&self) -> bool {
self.is_critical
}
#[setter]
pub fn set_is_critical(&mut self, is_critical: bool) {
self.is_critical = is_critical;
}
#[getter]
pub fn priority(&self) -> i32 {
self.priority
}
#[setter]
pub fn set_priority(&mut self, priority: i32) {
self.priority = priority;
}
#[getter]
pub fn dependencies(&self) -> Vec<String> {
self.dependencies.clone()
}
#[setter]
pub fn set_dependencies(&mut self, dependencies: Vec<String>) {
self.dependencies = dependencies;
}
}
#[cfg(feature = "pyo3")]
#[async_trait::async_trait]
impl AsyncServiceModule for RiPythonModuleAdapter {
fn name(&self) -> &str {
&self.name
}
fn is_critical(&self) -> bool {
self.is_critical
}
fn priority(&self) -> i32 {
self.priority
}
fn dependencies(&self) -> Vec<&str> {
self.dependencies.iter().map(|s| s.as_str()).collect()
}
async fn init(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn before_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn after_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn before_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn after_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
}
#[cfg(feature = "pyo3")]
impl ServiceModule for RiPythonServiceModule {
fn name(&self) -> &str {
&self.name
}
fn is_critical(&self) -> bool {
self.is_critical
}
fn priority(&self) -> i32 {
self.priority
}
fn dependencies(&self) -> Vec<&str> {
self.dependencies.iter().map(|s| s.as_str()).collect()
}
fn init(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn before_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn after_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn before_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
fn after_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
}
#[cfg(feature = "pyo3")]
#[async_trait::async_trait]
impl AsyncServiceModule for RiPythonAsyncServiceModule {
fn name(&self) -> &str {
&self.name
}
fn is_critical(&self) -> bool {
self.is_critical
}
fn priority(&self) -> i32 {
self.priority
}
fn dependencies(&self) -> Vec<&str> {
self.dependencies.iter().map(|s| s.as_str()).collect()
}
async fn init(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn before_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn after_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn before_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn after_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
}
#[async_trait::async_trait]
pub trait AsyncServiceModule: Send + Sync {
fn name(&self) -> &str;
fn is_critical(&self) -> bool {
true
}
fn priority(&self) -> i32 {
0
}
fn dependencies(&self) -> Vec<&str> {
Vec::new()
}
async fn init(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn before_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn after_start(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn before_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
async fn after_shutdown(&mut self, _ctx: &mut RiServiceContext) -> RiResult<()> {
Ok(())
}
}