|
MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
|
TCP server for interactive live coding sessions in MayaFlux. More...
#include <Server.hpp>
Collaboration diagram for Lila::Server:Public Types | |
| using | MessageHandler = std::function< std::expected< std::string, std::string >(std::string_view)> |
| Handler for processing incoming client messages. | |
| using | ConnectionHandler = std::function< void(const ClientInfo &)> |
| Handler for client connection/disconnection events. | |
| using | StartHandler = std::function< void()> |
| Handler for server start events. | |
Public Member Functions | |
| Server (int port=9090) | |
| Constructs a Server instance. | |
| ~Server () | |
| Destructor; stops the server if running. | |
| bool | start () noexcept |
| Starts the server and begins accepting clients. | |
| void | stop () noexcept |
| Stops the server and disconnects all clients. | |
| bool | is_running () const |
| Checks if the server is currently running. | |
| void | set_message_handler (MessageHandler handler) |
| Sets the handler for incoming client messages. | |
| void | on_client_connected (ConnectionHandler handler) |
| Registers a handler for client connection events. | |
| void | on_client_disconnected (ConnectionHandler handler) |
| Registers a handler for client disconnection events. | |
| void | on_server_started (StartHandler handler) |
| Registers a handler for server start events. | |
| EventBus & | event_bus () |
| Accesses the event bus for subscribing to server events. | |
| const EventBus & | event_bus () const noexcept |
| Const access to the event bus. | |
| void | broadcast_event (const StreamEvent &event, std::optional< std::string_view > target_session=std::nullopt) |
| Broadcasts an event to connected clients. | |
| void | broadcast_to_all (std::string_view message) |
| Broadcasts a raw message to all connected clients. | |
| void | set_client_session (int client_fd, std::string session_id) |
| Sets the session ID for a client. | |
| std::optional< std::string > | get_client_session (int client_fd) const |
| Gets the session ID for a client. | |
| std::vector< ClientInfo > | get_connected_clients () const |
| Gets a list of all currently connected clients. | |
Private Member Functions | |
| void | server_loop (const ServerThread::StopToken &stop_token) |
| Main server loop; accepts and manages clients. | |
| void | handle_client (int client_fd) |
| Handles communication with a single client. | |
| std::expected< std::string, std::string > | read_message (int client_fd) |
| Reads a message from a client. | |
| bool | send_message (int client_fd, std::string_view message) |
| Sends a message to a client. | |
| void | process_control_message (int client_fd, std::string_view message) |
| Processes control messages (e.g., session, ping) | |
| void | cleanup_client (int client_fd) |
| Cleans up resources for a disconnected client. | |
Private Attributes | |
| int | m_port |
| TCP port to listen on. | |
| int | m_server_fd { -1 } |
| Server socket file descriptor. | |
| std::atomic< bool > | m_running { false } |
| Server running state. | |
| ServerThread | m_server_thread |
| Server thread. | |
| MessageHandler | m_message_handler |
| Handler for client messages. | |
| ConnectionHandler | m_connect_handler |
| Handler for client connections. | |
| ConnectionHandler | m_disconnect_handler |
| Handler for client disconnections. | |
| StartHandler | m_start_handler |
| Handler for server start. | |
| EventBus | m_event_bus |
| Event bus for publishing server events. | |
| std::shared_mutex | m_clients_mutex |
| Mutex for client map. | |
| std::unordered_map< int, ClientInfo > | m_connected_clients |
| Map of connected clients. | |
TCP server for interactive live coding sessions in MayaFlux.
The Server class provides the underlying network infrastructure for Lila's live coding capabilities. It manages client connections, message handling, session management, and event broadcasting. While end users interact with MayaFlux through higher-level interfaces, Server enables real-time code evaluation and communication between clients and the interpreter.
The Server is designed for internal use by Lila and is not intended for direct user interaction.
Definition at line 41 of file Server.hpp.