Delete src/plugins/bad-chanel.rs
This commit is contained in:
parent
92628736e7
commit
de119b9b15
@ -1,134 +0,0 @@
|
||||
//! Каналы для коммуникации между потоками в системе плагинов
|
||||
|
||||
use std::sync::Arc;
|
||||
use crossbeam::channel::{Sender, Receiver, unbounded, TryRecvError};
|
||||
use parking_lot::RwLock;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::plugins::traits::{PluginEvent, PluginHook};
|
||||
|
||||
/// Тип сообщения для канала плагинов
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PluginMessage {
|
||||
/// Событие для обработки
|
||||
Event(PluginEvent),
|
||||
|
||||
/// Запрос на выполнение хука
|
||||
HookRequest {
|
||||
hook_name: String,
|
||||
data: Value,
|
||||
response_sender: Sender<HookResponse>,
|
||||
},
|
||||
|
||||
/// Запрос на загрузку плагина
|
||||
LoadPlugin {
|
||||
path: String,
|
||||
response_sender: Sender<LoadPluginResponse>,
|
||||
},
|
||||
|
||||
/// Запрос на выгрузку плагина
|
||||
UnloadPlugin {
|
||||
plugin_id: String,
|
||||
response_sender: Sender<UnloadPluginResponse>,
|
||||
},
|
||||
|
||||
/// Запрос на получение списка плагинов
|
||||
ListPlugins {
|
||||
response_sender: Sender<ListPluginsResponse>,
|
||||
},
|
||||
|
||||
/// Запрос на получение информации о плагине
|
||||
GetPlugin {
|
||||
plugin_id: String,
|
||||
response_sender: Sender<GetPluginResponse>,
|
||||
},
|
||||
|
||||
/// Команда остановки
|
||||
Shutdown,
|
||||
}
|
||||
|
||||
/// Ответ на выполнение хука
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum HookResponse {
|
||||
Success(Value),
|
||||
Error(String),
|
||||
NoHandler,
|
||||
}
|
||||
|
||||
/// Ответ на загрузку плагина
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum LoadPluginResponse {
|
||||
Success(String), // plugin_id
|
||||
Error(String),
|
||||
}
|
||||
|
||||
/// Ответ на выгрузку плагина
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum UnloadPluginResponse {
|
||||
Success,
|
||||
Error(String),
|
||||
}
|
||||
|
||||
/// Ответ на получение списка плагинов
|
||||
#[derive(Debug)]
|
||||
pub struct ListPluginsResponse {
|
||||
pub plugins: Vec<PluginInfo>,
|
||||
}
|
||||
|
||||
/// Ответ на получение информации о плагине
|
||||
#[derive(Debug)]
|
||||
pub enum GetPluginResponse {
|
||||
Found(PluginInfo),
|
||||
NotFound,
|
||||
Error(String),
|
||||
}
|
||||
|
||||
/// Информация о плагине для передачи через канал
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PluginInfo {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub description: String,
|
||||
pub author: String,
|
||||
pub path: String,
|
||||
pub state: String,
|
||||
pub hooks: Vec<PluginHook>,
|
||||
}
|
||||
|
||||
/// Каналы для системы плагинов
|
||||
#[derive(Clone)]
|
||||
pub struct PluginChannels {
|
||||
pub message_sender: Sender<PluginMessage>,
|
||||
pub message_receiver: Arc<RwLock<Receiver<PluginMessage>>>,
|
||||
}
|
||||
|
||||
impl PluginChannels {
|
||||
/// Создать новые каналы
|
||||
pub fn new() -> Self {
|
||||
let (sender, receiver) = unbounded();
|
||||
Self {
|
||||
message_sender: sender,
|
||||
message_receiver: Arc::new(RwLock::new(receiver)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Отправить сообщение
|
||||
pub fn send(&self, message: PluginMessage) -> Result<(), String> {
|
||||
self.message_sender.send(message)
|
||||
.map_err(|e| format!("Failed to send message: {}", e))
|
||||
}
|
||||
|
||||
/// Попробовать получить сообщение
|
||||
pub fn try_recv(&self) -> Result<PluginMessage, TryRecvError> {
|
||||
let receiver = self.message_receiver.read();
|
||||
receiver.try_recv()
|
||||
}
|
||||
|
||||
/// Ожидать сообщение (блокирующая операция)
|
||||
pub fn recv(&self) -> Result<PluginMessage, String> {
|
||||
let receiver = self.message_receiver.read();
|
||||
receiver.recv()
|
||||
.map_err(|e| format!("Failed to receive message: {}", e))
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user