17 std::shared_ptr<Nodes::NodeGraphManager> node_graph_manager,
18 std::shared_ptr<Buffers::BufferManager> buffer_manager,
19 std::shared_ptr<Vruta::TaskScheduler> task_scheduler,
20 std::shared_ptr<Core::WindowManager> window_manager,
21 std::shared_ptr<InputManager> input_manager)
22 : m_node_graph_manager(
std::move(node_graph_manager))
23 , m_buffer_manager(
std::move(buffer_manager))
24 , m_task_scheduler(
std::move(task_scheduler))
25 , m_window_manager(
std::move(window_manager))
26 , m_input_manager(
std::move(input_manager))
30 std::source_location::current(),
31 "SubsystemManager requires valid NodeGraphManager");
35 std::source_location::current(),
36 "SubsystemManager requires valid BufferManager");
40 std::source_location::current(),
41 "SubsystemManager requires valid TaskScheduler");
45 "No WindowManager provided - Graphics subsystems will be unavailable");
49 "No InputManager provided - Input subsystems will be unavailable");
61 error<std::runtime_error>(
64 std::source_location::current(),
65 "Cannot create GraphicsSubsystem without a valid WindowManager");
74 error<std::runtime_error>(
77 std::source_location::current(),
78 "Cannot create InputSubsystem without a valid InputManager");
86 auto tokens = subsystem->get_tokens();
87 auto handle = std::make_unique<SubsystemProcessingHandle>(
95 subsystem->initialize(*handle);
96 subsystem->register_callbacks();
129 if (subsystem->is_ready()) {
138 if (subsystem->is_running()) {
147 if (subsystem->is_ready()) {
161 it->second->shutdown();
170 std::unordered_map<SubsystemType, std::pair<bool, bool>> statuses;
172 if (subsystem ==
nullptr) {
173 statuses[type] = {
false,
false };
176 statuses[type] = { subsystem->is_ready(), subsystem->is_running() };
184 if (subsystem && subsystem->is_running()) {
214 if (subsystem && subsystem->is_ready()) {
215 subsystem->shutdown();
237 std::shared_lock lock(
m_mutex);
247 auto target_token =
m_subsystems[target_type]->get_tokens();
261 "Invalid subsystem type: Subsystem not found.");
265 auto handle = subsystem_it->second->get_processing_context_handle();
268 "Invalid processing context handle: Handle is null.");
283 "Invalid process hook: Hook cannot be null or invalid.");
288 handle->pre_process_hooks[name] = std::move(hook);
290 handle->post_process_hooks[name] = std::move(hook);
300 if (handle->pre_process_hooks.erase(name) == 0) {
301 handle->post_process_hooks.erase(name);
311 return handle->pre_process_hooks.contains(name) || handle->post_process_hooks.contains(name);
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::shared_ptr< Buffers::BufferManager > m_buffer_manager
void unregister_process_hook(SubsystemType type, const std::string &name)
Remove a previously registered processing hook.
bool has_process_hook(SubsystemType type, const std::string &name)
Check if a processing hook exists.
void stop()
Stop all subsystems.
void stop_input_subsystem()
Stop the input subsystem.
std::shared_ptr< Nodes::NodeGraphManager > m_node_graph_manager
void pause_all_subsystems()
Pause all subsystems.
std::shared_ptr< Vruta::TaskScheduler > m_task_scheduler
void create_graphics_subsystem(const GlobalGraphicsConfig &graphics_config)
Create and register the graphics subsystem.
void resume_all_subsystems()
Resume all paused subsystems.
std::unordered_map< SubsystemType, std::unordered_set< SubsystemType > > m_cross_access_permissions
void register_process_hook(SubsystemType type, const std::string &name, ProcessHook hook, HookPosition position=HookPosition::POST_PROCESS)
Register a processing hook for a specific subsystem.
bool has_subsystem(SubsystemType type) const
Check if a subsystem type exists.
void allow_cross_access(SubsystemType from, SubsystemType to)
Configure cross-subsystem data access permissions.
std::shared_ptr< AudioSubsystem > get_audio_subsystem()
Get typed access to the audio subsystem.
void stop_graphics_subsystem()
Stop the graphics subsystem.
void add_subsystem(SubsystemType type, const std::shared_ptr< ISubsystem > &subsystem)
Register a subsystem instance with the manager.
std::shared_ptr< ISubsystem > get_subsystem(SubsystemType type)
Get access to a specific subsystem by type.
void start_all_subsystems()
Start all registered subsystems in coordination.
std::shared_ptr< InputSubsystem > get_input_subsystem()
Get typed access to the input subsystem.
std::shared_ptr< Core::WindowManager > m_window_manager
bool is_cross_access_allowed(SubsystemType from, SubsystemType to) const
void shutdown()
Shutdown all subsystems in proper order.
void stop_audio_subsystem()
Stop the audio subsystem.
std::unordered_map< SubsystemType, std::pair< bool, bool > > query_subsystem_status() const
Query operational status of all subsystems.
std::unordered_map< SubsystemType, std::unique_ptr< SubsystemProcessingHandle > > m_handles
void remove_subsystem(SubsystemType type)
Remove and shutdown a subsystem.
SubsystemProcessingHandle * get_validated_handle(SubsystemType type) const
Get processing handle with validation.
std::unordered_map< SubsystemType, std::shared_ptr< ISubsystem > > m_subsystems
std::optional< std::span< const double > > read_cross_subsystem_buffer(SubsystemType requesting_type, SubsystemType target_type, uint32_t channel)
Read data from another subsystem's buffers.
std::shared_ptr< GraphicsSubsystem > get_graphics_subsystem()
Get typed access to the graphics subsystem.
std::shared_mutex m_mutex
Thread safety for subsystem operations.
std::shared_ptr< InputManager > m_input_manager
void create_audio_subsystem(GlobalStreamInfo &stream_info)
Create and register the audio subsystem.
void create_input_subsystem(GlobalInputConfig &input_config)
Create and register the input subsystem.
SubsystemManager(std::shared_ptr< Nodes::NodeGraphManager > node_graph_manager, std::shared_ptr< Buffers::BufferManager > buffer_manager, std::shared_ptr< Vruta::TaskScheduler > task_scheduler, std::shared_ptr< Core::WindowManager > window_manager=nullptr, std::shared_ptr< InputManager > input_manager=nullptr)
Constructs SubsystemManager with required processing managers.
Unified interface combining buffer and node processing for subsystems.
std::function< void(unsigned int num_frames)> ProcessHook
Function type for process hooks that can be registered with the engine.
HookPosition
Defines the position in the processing cycle where a hook should be executed.
@ PRE_PROCESS
Execute hook before any audio processing occurs.
@ Init
Engine/subsystem initialization.
@ Runtime
General runtime operations (default fallback)
@ Core
Core engine, backend, subsystems.
Comprehensive configuration for digital audio stream processing.