MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ start()

void MayaFlux::Core::NetworkSubsystem::start ( )
overridevirtual

Start the subsystem's processing/event loops.

Begins active processing. After this call, the subsystem should be actively responding to callbacks and processing data according to its domain requirements.

Implements MayaFlux::Core::ISubsystem.

Definition at line 65 of file NetworkSubsystem.cpp.

66{
67 if (!m_ready.load()) {
69 "Cannot start NetworkSubsystem: not initialized");
70 return;
71 }
72
73 if (m_running.load()) {
74 return;
75 }
76
77 {
78 std::shared_lock lock(m_backends_mutex);
79 for (auto& [transport, backend] : m_backends) {
80 backend->start();
81 }
82 }
83
84 m_work_guard = std::make_unique<asio::executor_work_guard<asio::io_context::executor_type>>(
85 m_io_context->get_executor());
86
87#if MAYAFLUX_USE_JTHREAD
88 m_io_thread = std::jthread([this](const std::stop_token& token) {
89 while (!token.stop_requested()) {
90 try {
91 m_io_context->run();
92 break;
93 } catch (const std::exception& e) {
95 "IO context exception: {}", e.what());
96 }
97 }
98
100 "Network IO thread exiting");
101 });
102#else
103 m_io_stop_requested.store(false);
104 m_io_thread = std::thread([this]() {
105 while (!m_io_stop_requested.load()) {
106 try {
107 m_io_context->run();
108 break;
109 } catch (const std::exception& e) {
111 "IO context exception: {}", e.what());
112 }
113 }
114
116 "Network IO thread exiting");
117 });
118#endif
119
120 m_running.store(true);
121
123 "Network Subsystem started");
124}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::unique_ptr< asio::io_context > m_io_context
std::unique_ptr< asio::executor_work_guard< asio::io_context::executor_type > > m_work_guard
std::unordered_map< NetworkTransport, std::unique_ptr< INetworkBackend > > m_backends
@ Init
Engine/subsystem initialization.
@ Networking
Network operations (data transfer, protocol handling)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, MayaFlux::Journal::Init, m_backends, m_backends_mutex, m_io_context, m_io_thread, m_ready, m_running, m_work_guard, MF_DEBUG, and MF_ERROR.