Skip to content

Latest commit

 

History

History
179 lines (151 loc) · 4.46 KB

eventghost_core.rst

File metadata and controls

179 lines (151 loc) · 4.46 KB

EventGhost Core Plugin

Overview

The EventGhost Core Plugin is the foundational plugin that provides essential infrastructure for event handling, macro execution, and system integration. It serves as the backbone for other plugins, providing core services like event processing, Python script execution, and configuration management.

Core Components

Event System

pub struct EventSystem {
    event_queue: Arc<Mutex<VecDeque<Event>>>,
    handlers: HashMap<String, Vec<Box<dyn EventHandler>>>,
    notification_system: NotificationSystem,
}

impl EventSystem {
    pub fn trigger_event(&self, name: &str, payload: Value) -> Result<(), Error> {
        let event = Event::new(name, payload);
        self.process_event(event)
    }
}

Macro Execution Engine

pub struct MacroEngine {
    program_counter: Option<(ActionItem, usize)>,
    return_stack: Vec<(ActionItem, usize)>,
    execution_state: Arc<Mutex<ExecutionState>>,
}

impl MacroEngine {
    pub fn execute_action(&mut self, action: ActionItem) -> Result<(), Error> {
        // Action execution logic
        // Flow control
        // State management
    }
}

Key Features

  1. Event Processing - Event queue management - Event handler registration - Event filtering and routing - Notification system
  2. Macro Control - Action execution flow - Jump conditions (JumpIfElse) - Wait states and timing - AutoRepeat functionality
  3. Python Integration - Script execution environment - Global variable management - Python command execution - Error handling and logging
  4. System Services - Plugin registration and loading - Configuration management - Window management - Process control

Migration Considerations

  1. Core Architecture - Thread-safe event processing - Rust-based macro execution - Plugin system architecture - Configuration persistence
  2. Python Integration - Python/Rust FFI layer - Script execution safety - Global state management - Error propagation

Implementation Strategy

  1. Event System Implementation .. code-block:: rust

    impl EventSystem {
    pub fn register_handler(&mut self, pattern: &str, handler: Box<dyn EventHandler>) {
    self.handlers.entry(pattern.to_string())

    .or_default() .push(handler);

    }

    pub fn process_event(&self, event: Event) -> Result<(), Error> {
    for (pattern, handlers) in &self.handlers {
    if event.matches(pattern) {
    for handler in handlers {

    handler.handle_event(&event)?;

    }

    }

    } Ok(())

    }

    }

  2. Macro Engine Implementation .. code-block:: rust

    impl MacroEngine {
    pub fn run_program(&mut self) -> Result<(), Error> {
    while let Some((item, idx)) = self.program_counter.take() {

    self.execute_action(item)?;

    if self.execution_state.lock()?.is_stopped {

    break;

    }

    self.program_counter = item.get_next_action(idx);

    } Ok(())

    }

    }

Testing Strategy

  1. Unit Tests - Event system functionality - Macro execution flow - Python integration - Configuration management
  2. Integration Tests - Plugin interaction - Event processing chain - Macro execution scenarios - System service integration
  3. Performance Tests - Event throughput - Macro execution speed - Memory usage patterns - Resource management

Error Handling

  1. Event Processing - Invalid event formats - Handler failures - Queue overflow - Timeout handling
  2. Macro Execution - Action failures - State corruption - Resource exhaustion - Deadlock prevention
  3. System Integration - Plugin loading errors - Configuration failures - Resource allocation - Cleanup procedures

Platform Considerations

  1. Windows Integration - Win32 API usage - System event handling - Window management - Process control
  2. Cross-platform Support - Platform abstraction - Event system portability - Resource management - Plugin compatibility